Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/components/TInterpreterCommonCell.py~
blob: 78809ef4660bbe980ba2b93985c7f1b93070bbe0 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
__author__="Rodrigo"
__date__ ="$21-sep-2012 12:25:32$"

from components.TInterpreterCommonControl import TInterpreterCommonControl
import pygtk
pygtk.require('2.0')
import gtk
import pango

class TInterpreterCommonCell(gtk.Button, TInterpreterCommonControl):
#=======SETUP==========================================================

    def __init__(self):
        super(TInterpreterCommonCell, self).__init__()
        self._VerticalTextPosition = 0        
        self._Icon = None
        self._Text = None
        self.BackgroundColor = None;


    def setIcon(self, value):
        self._Icon = value   

    def getIcon(self):
        return self._Icon        

    def setAlternativeBorderColor(self, value):
        self._AlternativeBorderColor = value

    def setAlternativeBorderWidth(self, value):
        self._AlternativeBorderWidth = value

    def setVerticalTextPosition(self, value):
        self._VerticalTextPosition = value

    def setId(self, value):
        #self.set_label(value)
        self._Id = value

#========GET FUNCTIONS========================================================
    def getId(self):
        return self._Id

    def getX(self):
        return self._OriginalRect[0]

    def getY(self):
        return self._OriginalRect[1]

    def getWidth(self):
        return self._OriginalRect[2]

    def getHeight(self):
        return self._OriginalRect[3]


#=======COLORIZE================================================================

    def resaltar(self):
        color = self.get_colormap().alloc_color("#ff0000")

        self.modify_bg(gtk.STATE_NORMAL, color)
        self.modify_bg(gtk.STATE_PRELIGHT, color)

    def desResaltar(self):
        color = self.get_colormap().alloc_color("#" + self.BackgroundColor.upper()[2:])

        self.modify_bg(gtk.STATE_NORMAL, color)
        self.modify_bg(gtk.STATE_PRELIGHT, color)


#=======Events Handlers=========================================================
    def onMouseOver(self, widget):
        pass

    def onMouseOut(self, widget):
        pass

    def onClick(self, widget):
        pass



#=======INITIALIZATION==========================================================
    def initialize(self):
        #bacground color
        #make a gdk.color for red

        if self.BackgroundColor:
            color = self.get_colormap().alloc_color("#" + self.BackgroundColor.upper()[2:])

            self.modify_bg(gtk.STATE_NORMAL, color)
            self.modify_bg(gtk.STATE_PRELIGHT, color)

        


        if self._Text != None and self._Icon != None:
            vbox = gtk.VBox(False, 0)
            lbl = gtk.Label(self._Text)
            if self._VerticalTextPosition == 3: #bottom
                vbox.pack_start(self.loadImage(True))
                vbox.pack_end(lbl)
            else: #top or center = top
                vbox.pack_start(lbl, False, False, 0)
                vbox.pack_end(self.loadImage(True), False, False, 0)

            self.add(vbox)
            text = lbl

        elif self._Text!=None:
            self.set_label(self._Text)
            text = self
        elif self._Icon != None:
            self.add(self.loadImage())
            text = self

        if self._ForegroundColor:
            color = self.get_colormap().alloc_color("#" + self._ForegroundColor.upper()[2:])
            text.modify_fg(gtk.STATE_NORMAL, color)
            text.modify_fg(gtk.STATE_PRELIGHT, color)
        else:
            color = self.get_colormap().alloc_color("black")
            text.modify_fg(gtk.STATE_NORMAL, color)
            text.modify_fg(gtk.STATE_PRELIGHT, color)

        if self._FontSize:
            text.modify_font(pango.FontDescription("sans " + str(self._FontSize)))
            
    def deInitialize(self):
        children = self.get_children()
        for child in children:
            self.remove(child)

    def loadImage(self, texto = False, img = None):
        image = gtk.Image()
        if img==None:
            img = self._Icon
        pixbuf = gtk.gdk.pixbuf_new_from_file(img)

        maxW = float(self.getWidth())
        maxH = float(self.getHeight() if not texto else self.getHeight() - self._FontSize * 4)

        im = pixbuf.scale_simple(int(maxW - 10), int(maxH - 10), gtk.gdk.INTERP_BILINEAR)
        image.set_from_pixbuf(im)
        return image

if __name__ == "__main__":
    print "Hello World"