Ticket #1389: sugar-1389.patch

File sugar-1389.patch, 7.0 KB (added by alsroot, 12 years ago)
  • src/sugar/graphics/toolbarbox.py

    From ac586e5a85dc928e4c18a05fb5fe8d8b1ea677e9 Mon Sep 17 00:00:00 2001
    From: Aleksey Lim <alsroot@member.fsf.org>
    Date: Fri, 18 Sep 2009 12:24:48 +0000
    Subject: Circular dependecy in ToolbarBox #1389
    
    ---
     src/sugar/graphics/toolbarbox.py |   94 +++++++++++++++++++++-----------------
     1 files changed, 52 insertions(+), 42 deletions(-)
    
    diff --git a/src/sugar/graphics/toolbarbox.py b/src/sugar/graphics/toolbarbox.py
    index ed33ff0..3f0b4b6 100644
    a b class ToolbarButton(ToolButton): 
    4646    def get_page(self):
    4747        if self.page_widget is None:
    4848            return None
    49         return self.page_widget.child.child
     49        return _unembed_page(self.page_widget)
    5050
    5151    def set_page(self, page):
    5252        if page is None:
    5353            self.page_widget = None
    5454            return
    55         self.page_widget = _embody_page(_Box, page)
     55        self.page_widget, alignment_ = _embed_page(_Box, page)
    5656        self.page_widget.set_size_request(-1, style.GRID_CELL_SIZE)
    5757        page.show()
    5858        if self.props.palette is None:
    class ToolbarButton(ToolButton): 
    6161
    6262    page = gobject.property(type=object, getter=get_page, setter=set_page)
    6363
    64     def _move_page_to_palette(self):
    65         if self.page_widget is None or \
    66                 self.page_widget.parent == self.props.palette:
    67             return
    68 
    69         if self.page_widget.parent is not None:
    70             self.page_widget.parent.remove(self.page_widget)
    71 
    72         if isinstance(self.props.palette, _ToolbarPalette):
    73             self.props.palette.add(self.page_widget)
     64    def is_paletted(self):
     65        return self.page is not None and \
     66                self.page_widget.parent == self.props.palette
    7467
    7568    def is_expanded(self):
    76         return self.page_widget is not None and \
    77                 self.page_widget.parent is not None and \
    78                 self.page_widget.parent != self.props.palette
     69        return self.page is not None and \
     70                not self.is_paletted()
    7971
    8072    def popdown(self):
    8173        if self.props.palette is not None:
    class ToolbarButton(ToolButton): 
    8476    def set_expanded(self, expanded):
    8577        self.popdown()
    8678
    87         if self.page_widget is None or self.is_expanded() == expanded:
     79        if self.page is None or self.is_expanded() == expanded:
    8880            return
    8981
    9082        if not expanded:
    class ToolbarButton(ToolButton): 
    10092            box.expanded_button.set_expanded(False)
    10193        box.expanded_button = self
    10294
    103         if self.page_widget.parent is not None:
    104             self.props.palette.remove(self.page_widget)
     95        self._unparent()
    10596
    10697        self.modify_bg(gtk.STATE_NORMAL, box.background)
    10798        _setup_page(self.page_widget, box.background, box.props.padding)
    10899        box.pack_start(self.page_widget)
    109100
     101    def _move_page_to_palette(self):
     102        if self.is_paletted():
     103            return
     104
     105        self._unparent()
     106
     107        if isinstance(self.props.palette, _ToolbarPalette):
     108            self.props.palette.add(self.page_widget)
     109
     110    def _unparent(self):
     111        if self.page_widget.parent is None:
     112            return
     113        self.page_widget.parent.remove(self.page_widget)
     114
    110115    def do_expose_event(self, event):
    111116        if not self.is_expanded() or self.props.palette is not None and \
    112117                self.props.palette.is_up():
    class ToolbarBox(gtk.VBox): 
    142147        self._toolbar.owner = self
    143148        self._toolbar.connect('remove', self.__remove_cb)
    144149
    145         top_widget = _embody_page(gtk.EventBox, self._toolbar)
    146         self.pack_start(top_widget)
     150        self._toolbar_widget, self._toolbar_alignment = \
     151                _embed_page(gtk.EventBox, self._toolbar)
     152        self.pack_start(self._toolbar_widget)
    147153
    148154        self.props.padding = padding
    149155        self.modify_bg(gtk.STATE_NORMAL,
    150156                style.COLOR_TOOLBAR_GREY.get_gdk_color())
    151157
     158    def get_toolbar(self):
     159        return self._toolbar
     160
     161    toolbar = property(get_toolbar)
     162
    152163    def get_expanded_button(self):
    153164        if self._expanded_button_index == -1:
    154165            return None
    155         return self._toolbar.get_nth_item(self._expanded_button_index)
     166        return self.toolbar.get_nth_item(self._expanded_button_index)
    156167
    157168    def set_expanded_button(self, button):
    158         if not button in self._toolbar:
     169        if not button in self.toolbar:
    159170            self._expanded_button_index = -1
    160171            return
    161         self._expanded_button_index = self._toolbar.get_item_index(button)
     172        self._expanded_button_index = self.toolbar.get_item_index(button)
    162173
    163174    expanded_button = property(get_expanded_button, set_expanded_button)
    164175
    165     def __remove_cb(self, sender, button):
    166         if not isinstance(button, ToolbarButton):
    167             return
    168         button.popdown()
    169         if button == self.expanded_button:
    170             self.remove(button.page_widget)
    171             self._expanded_button_index = -1
    172 
    173     def get_toolbar(self):
    174         return self._toolbar
    175 
    176     toolbar = property(get_toolbar)
    177 
    178176    def get_padding(self):
    179         return self.toolbar.parent.props.left_padding
     177        return self._toolbar_alignment.props.left_padding
    180178
    181179    def set_padding(self, pad):
    182         self.toolbar.parent.set_padding(0, 0, pad, pad)
     180        self._toolbar_alignment.set_padding(0, 0, pad, pad)
    183181
    184182    padding = gobject.property(type=object,
    185183            getter=get_padding, setter=set_padding)
    class ToolbarBox(gtk.VBox): 
    187185    def modify_bg(self, state, color):
    188186        if state == gtk.STATE_NORMAL:
    189187            self.background = color
    190         self.toolbar.parent.parent.modify_bg(state, color)
     188        self._toolbar_widget.modify_bg(state, color)
    191189        self.toolbar.modify_bg(state, color)
    192190
     191    def __remove_cb(self, sender, button):
     192        if not isinstance(button, ToolbarButton):
     193            return
     194        button.popdown()
     195        if button == self.expanded_button:
     196            self.remove(button.page_widget)
     197            self._expanded_button_index = -1
     198
    193199
    194200class _ToolbarPalette(PaletteWindow):
    195201
    def _setup_page(page_widget, color, hpad): 
    276282    vpad = style.FOCUS_LINE_WIDTH
    277283    page_widget.child.set_padding(vpad, vpad, hpad, hpad)
    278284
    279     page = page_widget.child.child
     285    page = _unembed_page(page_widget)
    280286    page.modify_bg(gtk.STATE_NORMAL, color)
    281287    if isinstance(page, gtk.Container):
    282288        for i in page.get_children():
    def _setup_page(page_widget, color, hpad): 
    286292    page_widget.modify_bg(gtk.STATE_PRELIGHT, color)
    287293
    288294
    289 def _embody_page(box_class, page):
     295def _embed_page(box_class, page):
    290296    page.show()
    291297
    292298    alignment = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
    def _embody_page(box_class, page): 
    299305    page_widget.add(alignment)
    300306    page_widget.show()
    301307
    302     return page_widget
     308    return (page_widget, alignment)
     309
     310
     311def _unembed_page(page_widget):
     312    return page_widget.child.child
    303313
    304314
    305315def _paint_arrow(widget, event, arrow_type):