Ticket #3987: 0001-Set-correct-background-for-subtoolbars-SL-3987.2.patch

File 0001-Set-correct-background-for-subtoolbars-SL-3987.2.patch, 7.3 KB (added by manuq, 12 years ago)

Better patch, that does the styling in the theme

  • src/sugar3/graphics/toolbarbox.py

    From 2afa5398a281b5d3b52020445ee8629c0ce5f5c3 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
    Date: Wed, 31 Oct 2012 13:18:46 -0300
    Subject: [PATCH toolkit-gtk3] Set correct background for subtoolbars - SL
     #3987
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    Mail-Followup-To: <sugar-devel@lists.sugarlabs.org>
    
    - remove set_app_paintable from _SubtoolbarContainer (previously _Box)
      to fix the bad coloring of subtoolbars.  The documentation say we
      can't rely on it to paint the themed background when this is set
      [1].
    
    - remove all calls to modify_bg from the code.  Do all the styling in
      the theme.  Needs the artwork patch accompanied in the ticket.  Note
      the code removal in _setup_page function, which was iterating the
      toolbar children to modify their background.
    
    - add new class _ToolbarContainer with a __gtype_name__ to style it.
      Primary toolbar is embedded in it.
    
    - rename _Box class for _SubtoolbarContainer, make it inherit
      _ToolbarContainer.  Subtoolbars are embedded in these.
    
    - call show() in the proper order, after widgets are packed.  See
      changes in _embed_page function.
    
    - call the parent class __init__ insted of GObject.GObject.
    
    - long lines fixed.
    
    [1] http://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-set-app-paintable
    
    Signed-off-by: Manuel Quiñones <manuq@laptop.org>
    ---
     src/sugar3/graphics/toolbarbox.py | 76 +++++++++++++++------------------------
     1 file changed, 29 insertions(+), 47 deletions(-)
    
    diff --git a/src/sugar3/graphics/toolbarbox.py b/src/sugar3/graphics/toolbarbox.py
    index ee709dd..d5b3a63 100644
    a b class ToolbarButton(ToolButton): 
    6666        if page is None:
    6767            self.page_widget = None
    6868            return
    69         self.page_widget, alignment_ = _embed_page(_Box(self), page)
     69        self.page_widget, alignment_ = _embed_page(_SubToolbarContainer(self),
     70                                                   page)
    7071        self.page_widget.set_size_request(-1, style.GRID_CELL_SIZE)
    71         page.show()
     72        self.page_widget.show()
    7273        if self.props.palette is None:
    7374            self.props.palette = _ToolbarPalette(invoker=ToolInvoker(self))
    7475        self._move_page_to_palette()
    class ToolbarButton(ToolButton): 
    9798            self._move_page_to_palette()
    9899            return
    99100
    100         box = self.toolbar_box
    101 
    102         if box.expanded_button is not None:
    103             box.expanded_button.queue_draw()
    104             box.expanded_button.set_expanded(False)
    105         box.expanded_button = self
     101        if self.toolbar_box.expanded_button is not None:
     102            self.toolbar_box.expanded_button.queue_draw()
     103            self.toolbar_box.expanded_button.set_expanded(False)
     104        self.toolbar_box.expanded_button = self
    106105
    107106        self._unparent()
    108107
    109         self.modify_bg(Gtk.StateType.NORMAL, box.background)
    110         _setup_page(self.page_widget, box.background, box.props.padding)
    111         box.pack_start(self.page_widget, True, True, 0)
     108        _setup_page(self.page_widget, self.toolbar_box.props.padding)
     109        self.toolbar_box.pack_start(self.page_widget, True, True, 0)
    112110
    113111    def _move_page_to_palette(self):
    114112        if self.is_in_palette():
    class ToolbarButton(ToolButton): 
    143141class ToolbarBox(Gtk.VBox):
    144142
    145143    def __init__(self, padding=style.TOOLBOX_HORIZONTAL_PADDING):
    146         GObject.GObject.__init__(self)
     144        Gtk.VBox.__init__(self)
    147145        self._expanded_button_index = -1
    148         self.background = None
    149146
    150147        self._toolbar = Gtk.Toolbar()
    151148        self._toolbar.owner = self
    152149        self._toolbar.connect('remove', self.__remove_cb)
    153150
    154151        self._toolbar_widget, self._toolbar_alignment = \
    155                 _embed_page(Gtk.EventBox(), self._toolbar)
     152                _embed_page(_ToolbarContainer(), self._toolbar)
    156153        self.pack_start(self._toolbar_widget, True, True, 0)
     154        self._toolbar_widget.show()
    157155
    158156        self.props.padding = padding
    159         self.modify_bg(Gtk.StateType.NORMAL,
    160                 style.COLOR_TOOLBAR_GREY.get_gdk_color())
    161157
    162158    def get_toolbar(self):
    163159        return self._toolbar
    class ToolbarBox(Gtk.VBox): 
    186182    padding = GObject.property(type=object,
    187183            getter=get_padding, setter=set_padding)
    188184
    189     def modify_bg(self, state, color):
    190         if state == Gtk.StateType.NORMAL:
    191             self.background = color
    192         self._toolbar_widget.modify_bg(state, color)
    193         self.toolbar.modify_bg(state, color)
    194 
    195185    def __remove_cb(self, sender, button):
    196186        if not isinstance(button, ToolbarButton):
    197187            return
    class _ToolbarPalette(PaletteWindow): 
    255245        if button.is_expanded():
    256246            return
    257247        box = button.toolbar_box
    258         _setup_page(button.page_widget, style.COLOR_BLACK.get_gdk_color(),
    259                 box.props.padding)
     248        _setup_page(button.page_widget, box.props.padding)
    260249        PaletteWindow.popup(self, immediate)
    261250
    262251    def __group_popdown_cb(self, group):
    class _ToolbarPalette(PaletteWindow): 
    264253            self.popdown(immediate=True)
    265254
    266255
    267 class _Box(Gtk.EventBox):
     256class _ToolbarContainer(Gtk.EventBox):
     257
     258    __gtype_name__ = 'SugarToolbarContainer'
     259
     260    def __init__(self):
     261        Gtk.EventBox.__init__(self)
     262
     263
     264class _SubToolbarContainer(_ToolbarContainer):
    268265
    269266    def __init__(self, toolbar_button):
    270         GObject.GObject.__init__(self)
    271         self.set_app_paintable(True)
     267        _ToolbarContainer.__init__(self)
    272268        self._toolbar_button = toolbar_button
    273         self.modify_bg(Gtk.StateType.NORMAL,
    274                        style.COLOR_TOOLBAR_GREY.get_gdk_color())
    275269
    276270    def do_draw(self, cr):
    277271        button_alloc = self._toolbar_button.get_allocation()
    class _Box(Gtk.EventBox): 
    280274        cr.set_source_rgba(*style.COLOR_BUTTON_GREY.get_rgba())
    281275        cr.move_to(0, 0)
    282276        cr.line_to(button_alloc.x + style.FOCUS_LINE_WIDTH, 0)
    283         cr.move_to(button_alloc.x + button_alloc.width - style.FOCUS_LINE_WIDTH, 0)
     277        cr.move_to(button_alloc.x + button_alloc.width - style.FOCUS_LINE_WIDTH,
     278                   0)
    284279        cr.line_to(self.get_allocation().width, 0)
    285280        cr.stroke()
    286281
    287         Gtk.EventBox.do_draw(self, cr)
     282        self.get_child().do_draw(self, cr)
    288283
    289284
    290 def _setup_page(page_widget, color, hpad):
     285def _setup_page(page_widget, hpad):
    291286    vpad = style.FOCUS_LINE_WIDTH
    292287    page_widget.get_child().set_padding(vpad, vpad, hpad, hpad)
    293288
    294     page = _get_embedded_page(page_widget)
    295     page.modify_bg(Gtk.StateType.NORMAL, color)
    296     if isinstance(page, Gtk.Container):
    297         for i in page.get_children():
    298             i.modify_bg(Gtk.StateType.INSENSITIVE, color)
    299 
    300     page_widget.modify_bg(Gtk.StateType.NORMAL, color)
    301     page_widget.modify_bg(Gtk.StateType.PRELIGHT, color)
    302 
    303289
    304290def _embed_page(page_widget, page):
    305     page.show()
    306 
    307291    alignment = Gtk.Alignment(xscale=1.0, yscale=1.0)
    308292    alignment.add(page)
    309     alignment.show()
     293    page.show()
    310294
    311     page_widget.modify_bg(Gtk.StateType.ACTIVE,
    312             style.COLOR_BUTTON_GREY.get_gdk_color())
    313295    page_widget.add(alignment)
    314     page_widget.show()
     296    alignment.show()
    315297
    316298    return (page_widget, alignment)
    317299