~jconti/ubuntu/precise/emesene/fix-956422

« back to all changes in this revision

Viewing changes to Widgets.py

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2010-04-14 01:33:51 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20100414013351-r2icbt5gs4ai71j8
Tags: 1.6.1-0ubuntu1
* New upstream release (LP: #562646).
* Fix missing-debian-source-format lintian warning.
* Refresh 20_dont_build_own_libmimic.patch patch.
* Bump Standards-Version to 3.8.4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import pygtk
20
20
import gtk
21
 
import gtk.gdk
22
21
import cairo
23
22
import gobject
24
23
 
42
41
 
43
42
    __gsignals__ = { 'size_request' : 'override', 'expose-event' : 'override' }
44
43
 
45
 
    def __init__(self, cellDimention = 96, crossFade = True, cellRadius = 0.05, cellKeyPosition = gtk.ANCHOR_CENTER):
 
44
    def __init__(self, cellDimention=96, crossFade=True, cellRadius=0.05, cellKeyPosition=gtk.ANCHOR_CENTER):
46
45
        gobject.GObject.__init__(self)
47
46
        gtk.Widget.__init__(self)
48
47
        self.set_flags(self.flags() | gtk.NO_WINDOW )
52
51
        self._radius_factor = cellRadius
53
52
        self._keyPosition = cellKeyPosition
54
53
 
55
 
 
56
54
        # variables related to animation
57
55
        self._crossFade = crossFade
58
56
        self.inAnimation = False
79
77
    def do_set_property(self, property, value):
80
78
        if property.name == 'pixbuf':
81
79
            if self.__shouldReplace(value):
82
 
                if self._crossFade and not (self._pixbuf == None) and not (value == None) :
 
80
                if self._crossFade and not (self._pixbuf == None) and not (value == None):
83
81
                    self.transitionPixbuf = value
84
82
                    if self.fps < 1: self.fps = 24 # reset fps if not valid fps
85
83
                    timeBetweenFrames = 1000 / self.fps
110
108
            self.queue_draw()
111
109
            return True
112
110
 
113
 
 
114
111
    def set_from_pixbuf(self, pixbuf ):
115
112
        self.set_property('pixbuf', pixbuf)
116
113
        self.queue_draw()
117
114
 
118
115
    def set_from_file(self,filename):
119
 
        inputimage = open(filename)
120
 
        imagebuf = inputimage.read()
121
116
        try:
122
 
            pixbufloader = gtk.gdk.PixbufLoader()
123
 
            pixbufloader.write(imagebuf)
124
 
            pixbufloader.close()
125
 
        except:
 
117
            pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
 
118
        except Exception, e:
 
119
            print "AvatarHolder:", e
126
120
            return
127
 
        pixbuf = pixbufloader.get_pixbuf()
128
121
        self.set_property('pixbuf', pixbuf)
129
122
        self.queue_draw()
130
123
 
149
142
    def __shouldReplace(self,pixbuf):
150
143
        #checkEquivalence
151
144
        if self._pixbuf and pixbuf and \
152
 
          pixbuf.get_pixels() == self._pixbuf.get_pixels():
 
145
           pixbuf.get_pixels() == self._pixbuf.get_pixels():
153
146
            return False
154
147
        else:
155
148
            return True
236
229
 
237
230
gobject.type_register( inputBox )
238
231
 
239
 
 
240
 
class TinyArrow(gtk.DrawingArea):
241
 
    LENGTH = 8
242
 
    WIDTH = 5
243
 
 
244
 
    def __init__(self, arrow_type, shadow=gtk.SHADOW_NONE):
245
 
        gtk.DrawingArea.__init__(self)
246
 
        self.arrow_type = arrow_type
247
 
        self.shadow = shadow
248
 
        self.margin = 0
249
 
 
250
 
        self.set_size_request(*self.get_size())
251
 
        self.connect("expose_event", self.expose)
252
 
 
253
 
    def get_size(self):
254
 
        if self.arrow_type in (gtk.ARROW_LEFT, gtk.ARROW_RIGHT):
255
 
            return (TinyArrow.WIDTH + self.margin*2, \
256
 
                    TinyArrow.LENGTH + self.margin*2)
257
 
        else:
258
 
            return (TinyArrow.LENGTH + self.margin*2, \
259
 
                    TinyArrow.WIDTH + self.margin*2)
260
 
 
261
 
    def expose(self, widget=None, event=None):
262
 
        if self.window is None:
263
 
            return
264
 
        self.window.clear()
265
 
        width, height = self.get_size()
266
 
        self.get_style().paint_arrow(self.window, self.state, \
267
 
            self.shadow, None, self, '', self.arrow_type, True, \
268
 
            0, 0, width, height)
269
 
 
270
 
        return False
271
 
 
272
 
    def set(self, arrow_type, shadow=gtk.SHADOW_NONE, margin=None):
273
 
        self.arrow_type = arrow_type
274
 
        self.shadow = shadow
275
 
        if margin is not None:
276
 
            self.margin = margin
277
 
        self.set_size_request(*self.get_size())
278
 
        self.expose()
279
 
 
280
 
 
281
 
class WidgetToggleBox(gtk.Widget):
 
232
class WidgetToggleBox(gtk.EventBox):
282
233
    '''A box that represents a widget and allows toggling its visibility'''
283
234
 
284
235
    def __init__(self, config, key, description, label):
285
 
        gtk.Widget.__init__(self)
 
236
        gtk.EventBox.__init__(self)
 
237
        self.set_border_width(1)
286
238
        self.description = description
287
239
        self.label = label
288
240
        self.config = config
289
241
        self.key = key
290
242
        self.enabled = False
291
243
        self.inside = False
 
244
        # this colors as no particular reason, I liked them
 
245
        # change them if you want. -arielj
 
246
        self.enabledColor = gtk.gdk.Color(17408, 19200, 51456)
 
247
        self.insideColor = gtk.gdk.Color(31744, 40704, 62208)
 
248
        self.disabledColor = gtk.gdk.Color(51456, 51456, 51456)
292
249
        if self.config and key:
293
250
            self.enabled = self.config.user[key]
294
 
 
295
 
    def do_realize(self):
296
 
        '''Initializes the gtk window'''
297
 
        self.set_flags(gtk.REALIZED)
298
 
 
299
 
        mask = gtk.gdk.EXPOSURE_MASK | gtk.gdk.BUTTON_PRESS_MASK | \
300
 
               gtk.gdk.LEAVE_NOTIFY_MASK | gtk.gdk.ENTER_NOTIFY_MASK
301
 
 
302
 
        self.window = gtk.gdk.Window(
303
 
            self.get_parent_window(),
304
 
            x=self.allocation.x,
305
 
            y=self.allocation.y,
306
 
            width=self.allocation.width,
307
 
            height=self.allocation.height,
308
 
            window_type=gtk.gdk.WINDOW_CHILD,
309
 
            wclass=gtk.gdk.INPUT_OUTPUT,
310
 
            event_mask=self.get_events() | mask)
311
 
 
312
 
        self.window.set_user_data(self)
313
 
        self.style2 = self.style.copy()
314
 
        self.style2.attach(self.window)
315
 
        self.style2.set_background(self.window, self.state)
316
 
        self.window.move_resize(*self.allocation)
317
 
 
318
 
        if gtk.gtk_version >= (2, 12, 0) and \
319
 
           gtk.pygtk_version >= (2, 12, 0) and self.description:
320
 
            self.set_tooltip_text(self.description.replace("_", ""))
321
 
 
322
 
    def do_unrealize(self):
323
 
        '''Destroys the window'''
324
 
        self.window.set_user_data(None)
325
 
        self.window.destroy()
326
 
 
327
 
    def do_size_allocate(self, allocation):
328
 
        '''Resizes the window'''
329
 
        self.allocation = allocation
330
 
        if self.flags() & gtk.REALIZED:
331
 
            self.window.move_resize(*allocation)
332
 
 
333
 
    def do_expose_event(self, event):
 
251
            self.update_color()
 
252
 
 
253
    def update_color(self):
334
254
        '''Renders the box'''
335
255
        if self.enabled:
336
 
            state = gtk.STATE_SELECTED
 
256
            color = self.enabledColor
337
257
        else:
338
 
            if self.inside:
339
 
                state = gtk.STATE_PRELIGHT
340
 
            else:
341
 
                state = gtk.STATE_NORMAL
 
258
            color = self.disabledColor
 
259
            
 
260
        if self.inside:
 
261
            color = self.insideColor
342
262
 
343
 
        self.style2.paint_box(self.window, state,
344
 
            gtk.SHADOW_ETCHED_IN, event.area, self, '', 0, 0,
345
 
            self.allocation.width, self.allocation.height)
 
263
        self.modify_bg(gtk.STATE_NORMAL, color)
 
264
        self.modify_bg(gtk.STATE_ACTIVE, color)
 
265
        self.modify_bg(gtk.STATE_PRELIGHT, color)
 
266
        self.queue_draw()
346
267
 
347
268
    def do_button_press_event(self, event):
348
269
        '''Called when the user clicks the widget'''
349
270
        if self.key:
350
271
            self.enabled = not self.enabled
351
 
            self.queue_draw()
 
272
            self.inside = False
 
273
            self.update_color()
352
274
            if self.config:
353
275
                self.config.user[self.key] = self.enabled
354
276
 
358
280
        if self.description:
359
281
            self.inside = True
360
282
            self.label.set_text_with_mnemonic(self.description)
361
 
            self.queue_draw()
 
283
            self.update_color()
362
284
 
363
285
    def do_leave_notify_event(self, event):
364
286
        '''Called when the mouse pointer leaves the widget'''
365
287
        if self.description:
366
288
            self.inside = False
367
289
            self.label.set_text('')
368
 
            self.queue_draw()
 
290
            self.update_color()
369
291
 
370
 
gobject.type_register(WidgetToggleBox)
 
292
gobject.type_register(WidgetToggleBox)
 
 
b'\\ No newline at end of file'