~mmcg069/software-center/small-fix

« back to all changes in this revision

Viewing changes to softwarecenter/ui/gtk3/widgets/buttons.py

  • Committer: Matthew McGowan
  • Date: 2011-08-28 11:53:54 UTC
  • Revision ID: matthew.joseph.mcgowan@gmail.com-20110828115354-pdpry08yf8diz74j
make the section sel button paint using the Gtk.Button paint routine

Show diffs side-by-side

added added

removed removed

Lines of Context:
304
304
 
305
305
        self.section_button = section_button
306
306
        self.popup = None
307
 
        self._dark_color = Gdk.RGBA(red=0,green=0,blue=0)
308
 
        self.connect('style-updated', self.on_style_updated)
 
307
        #~ self._dark_color = Gdk.RGBA(red=0,green=0,blue=0)
 
308
        #~ self.connect('style-updated', self.on_style_updated)
309
309
        self.connect("button-press-event", self.on_button_press)
310
310
        return
311
311
 
312
 
    def do_draw(self, cr):
313
 
        a = self.get_allocation()
314
 
        cr.set_line_width(1)
315
 
        cr.rectangle(-0.5, -1.5, a.width, a.height+3)
316
 
        Gdk.cairo_set_source_rgba(cr, self._dark_color)
317
 
        cr.stroke()
318
 
        cr.rectangle(0.5, -1.5, a.width-2, a.height+3)
319
 
        cr.set_source_rgba(1,1,1, 0.07)
320
 
        cr.stroke()
321
 
 
322
 
        for child in self: self.propagate_draw(child, cr)
323
 
        return
324
 
 
 
312
    #~ def do_draw(self, cr):
 
313
        #~ a = self.get_allocation()
 
314
        #~ cr.set_line_width(1)
 
315
        #~ cr.rectangle(-0.5, -1.5, a.width, a.height+3)
 
316
        #~ Gdk.cairo_set_source_rgba(cr, self._dark_color)
 
317
        #~ cr.stroke()
 
318
        #~ cr.rectangle(0.5, -1.5, a.width-2, a.height+3)
 
319
        #~ cr.set_source_rgba(1,1,1, 0.07)
 
320
        #~ cr.stroke()
 
321
#~ 
 
322
        #~ for child in self: self.propagate_draw(child, cr)
 
323
        #~ return
 
324
#~ 
325
325
    def on_button_press(self, button, event):
326
326
        if self.popup is None:
327
327
            self.build_channel_selector()
328
328
        self.show_channel_sel_popup(self, event)
329
329
        return
330
 
 
331
 
    def on_style_updated(self, widget):
332
 
        context = widget.get_style_context()
333
 
        context.save()
334
 
        context.add_class("menu")
335
 
        bgcolor = context.get_background_color(Gtk.StateFlags.NORMAL)
336
 
        context.restore()
337
 
 
338
 
        self._dark_color = darken(bgcolor, 0.5)
339
 
        return
 
330
#~ 
 
331
    #~ def on_style_updated(self, widget):
 
332
        #~ context = widget.get_style_context()
 
333
        #~ context.save()
 
334
        #~ context.add_class("menu")
 
335
        #~ bgcolor = context.get_background_color(Gtk.StateFlags.NORMAL)
 
336
        #~ context.restore()
 
337
#~ 
 
338
        #~ self._dark_color = darken(bgcolor, 0.5)
 
339
        #~ return
340
340
 
341
341
    def show_channel_sel_popup(self, widget, event):
342
342
 
376
376
        self.label.set_name("section-selector")
377
377
        self.set_name("section-selector")
378
378
        self.draw_hint_has_channel_selector = False
379
 
        self._dark_color = Gdk.RGBA(red=0,green=0,blue=0)
380
 
        self.connect('style-updated', self.on_style_updated)
 
379
        #~ self._dark_color = Gdk.RGBA(red=0,green=0,blue=0)
 
380
        #~ self.connect('style-updated', self.on_style_updated)
381
381
        self.label.connect("draw", self.on_label_draw)
382
382
        return
383
383
 
384
384
    def do_draw(self, cr):
385
385
        a = self.get_allocation()
386
386
        if self.get_active():
387
 
            r, g, b = (self._dark_color.red,
388
 
                       self._dark_color.green,
389
 
                       self._dark_color.blue)
390
 
 
391
 
            cr.rectangle(0, -1, a.width, a.height+2)
392
 
            lin = cairo.LinearGradient(0, 0, 0, a.height)
393
 
            lin.add_color_stop_rgba(0.0, r,g,b, 0.0)
394
 
            lin.add_color_stop_rgba(0.25, r,g,b, 0.3)
395
 
            lin.add_color_stop_rgba(0.5, r,g,b, 0.5)
396
 
            lin.add_color_stop_rgba(0.75, r,g,b, 0.3)
397
 
            lin.add_color_stop_rgba(1.0, r,g,b, 0.0)
398
 
            cr.set_source(lin)
399
 
            cr.fill_preserve()
400
 
            cr.set_source_rgba(r,g,b)
401
 
            cr.stroke()
402
 
 
403
 
        elif self.draw_hint_has_channel_selector:
404
 
            cr.set_line_width(1)
405
 
            cr.move_to(a.width-0.5, -1)
406
 
            cr.rel_line_to(0, a.height+2)
407
 
            Gdk.cairo_set_source_rgba(cr, self._dark_color)
408
 
            cr.stroke()
409
 
 
 
387
            context = self.get_style_context()
 
388
            context.save()
 
389
            state = self.get_state_flags()
 
390
            context.set_state(state)
 
391
 
 
392
            a = self.get_allocation()
 
393
 
 
394
            x = 0
 
395
            y = -5
 
396
            width = a.width
 
397
            height = a.height + 10
 
398
            Gtk.render_background(context, cr,
 
399
                                  x, y, width, height)
 
400
            Gtk.render_frame(context, cr,
 
401
                             x, y, width, height)
 
402
 
 
403
            context.restore()
410
404
        for child in self: 
411
405
            self.propagate_draw(child, cr)
412
406
        return
413
 
 
414
 
    def on_style_updated(self, widget):
415
 
        context = widget.get_style_context()
416
 
        context.save()
417
 
        context.add_class("menu")
418
 
        bgcolor = context.get_background_color(Gtk.StateFlags.NORMAL)
419
 
        context.restore()
420
 
 
421
 
        self._dark_color = darken(bgcolor, 0.5)
422
 
        return
 
407
#~ 
 
408
    #~ def on_style_updated(self, widget):
 
409
        #~ context = widget.get_style_context()
 
410
        #~ context.save()
 
411
        #~ context.add_class("menu")
 
412
        #~ bgcolor = context.get_background_color(Gtk.StateFlags.NORMAL)
 
413
        #~ context.restore()
 
414
#~ 
 
415
        #~ self._dark_color = darken(bgcolor, 0.5)
 
416
        #~ return
423
417
 
424
418
    def on_label_draw(self, label, cr):
425
419
        layout = label.get_layout()