Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/createtable.py
blob: 415fa5f0b85ca392e6958ddca24634605d507831 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#! /usr/bin/env python
#
#    Copyright (C) 2006, 2007, One Laptop Per Child
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

import gtk, pygtk
import svgcard
import os
import time
import gobject
import math
import gc

class CreateTable(gtk.EventBox):
  
    __gsignals__ = {
        'card-flipped': (gobject.SIGNAL_RUN_FIRST, None, [int, gobject.TYPE_PYOBJECT]), 
        'card-highlighted': (gobject.SIGNAL_RUN_FIRST, None, [int, gobject.TYPE_PYOBJECT]), 
        }

    TARGET_TYPE_TEXT = 80
    TARGET_TYPE_JPG = 81
    TARGET_TYPE_AUDIO = 82
    mime = [ ( "text/plain", 0, TARGET_TYPE_TEXT ), ( "image/x-jpg", 0, TARGET_TYPE_JPG ),
             ( "image/x-audio", 0, TARGET_TYPE_AUDIO ) ]
    
    def __init__(self):
        gtk.EventBox.__init__(self)
        
        # Set table settings
        self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#000000'))
        self.table = gtk.Table()
        self.table.grab_focus()
        self.table.set_flags(gtk.CAN_FOCUS)
        self.table.set_flags(gtk.CAN_DEFAULT)
        self.table.set_row_spacings(11)
        self.table.set_col_spacings(11)
        self.table.set_border_width(11)
        self.table.set_resize_mode(gtk.RESIZE_IMMEDIATE)
        self.set_property('child', self.table)
        self.fist_load = True

    def make_table(self, numpairs):
        ylen=numpairs
        xlen=4
        self.size = int(math.ceil(math.sqrt(xlen*ylen)))
        self.card_size = self.get_card_size(self.size)
        print self.card_size
        props={}
        props['front_border'] = {'opacity':'1'}
        props['front_h_border'] ={'opacity':'1'}
        props['front_text']= {'card_text':'', 'card_line1':'', 'card_line2':'', 'card_line3':'', 'card_line4':''}
        buffer_card = svgcard.SvgCard(-1, {'front_border':{'opacity':'0'}, 'front_h_border':{'opacity':'0.5'},
                                             'back_text':{'card_text':''}}, {}, None, self.card_size)
        
        jpg = None
        x=y=0
        x2=y2=1
        while y < ylen:            
            while x < xlen:
                print '[%d %d %d %d]'%(x,x2,y,y2)
                card = svgcard.SvgCard(id, props, buffer_card.get_cache(), jpg, self.card_size)                
                card.connect('drag_data_received', self.receiveCallback)
                card.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
                                gtk.DEST_DEFAULT_HIGHLIGHT |
                                gtk.DEST_DEFAULT_DROP,
                                   self.mime, gtk.gdk.ACTION_COPY)                
                self.table.attach(card, x, x2, y, y2)
                x+=1
                x2+=1
            x=0
            x2=1
            y+=1
            y2+=1


    def receiveCallback(self, widget, context, x, y, selection, targetType,
                        time):
        print 'receive'
        if targetType == self.TARGET_TYPE_JPG:            
            print 'Img: selection.data: %s x=%f y=%f'%(selection.data, x, y)
            widget.jpeg = selection.data
            widget.flip()

        if targetType == self.TARGET_TYPE_TEXT:            
            print 'Char: selection.data: %s x=%f y=%f'%(selection.data, x, y)
            widget.props['front_text']['card_text'] = selection.data
            widget.flip()

        if targetType == self.TARGET_TYPE_AUDIO:            
            print 'Audio: selection.data: %s x=%f y=%f'%(selection.data, x, y)
            widget.jpeg = 'ohr.jpg'
            widget.flip()

    
    def get_card_size(self, size_table):
        x = (780 - (11*size_table))/size_table
        return x