Circular dependecy in ToolbarBox #1389
This commit is contained in:
parent
33ea5bdee4
commit
ac586e5a85
@ -46,13 +46,13 @@ class ToolbarButton(ToolButton):
|
|||||||
def get_page(self):
|
def get_page(self):
|
||||||
if self.page_widget is None:
|
if self.page_widget is None:
|
||||||
return None
|
return None
|
||||||
return self.page_widget.child.child
|
return _unembed_page(self.page_widget)
|
||||||
|
|
||||||
def set_page(self, page):
|
def set_page(self, page):
|
||||||
if page is None:
|
if page is None:
|
||||||
self.page_widget = None
|
self.page_widget = None
|
||||||
return
|
return
|
||||||
self.page_widget = _embody_page(_Box, page)
|
self.page_widget, alignment_ = _embed_page(_Box, page)
|
||||||
self.page_widget.set_size_request(-1, style.GRID_CELL_SIZE)
|
self.page_widget.set_size_request(-1, style.GRID_CELL_SIZE)
|
||||||
page.show()
|
page.show()
|
||||||
if self.props.palette is None:
|
if self.props.palette is None:
|
||||||
@ -61,21 +61,13 @@ class ToolbarButton(ToolButton):
|
|||||||
|
|
||||||
page = gobject.property(type=object, getter=get_page, setter=set_page)
|
page = gobject.property(type=object, getter=get_page, setter=set_page)
|
||||||
|
|
||||||
def _move_page_to_palette(self):
|
def is_paletted(self):
|
||||||
if self.page_widget is None or \
|
return self.page is not None and \
|
||||||
self.page_widget.parent == self.props.palette:
|
self.page_widget.parent == self.props.palette
|
||||||
return
|
|
||||||
|
|
||||||
if self.page_widget.parent is not None:
|
|
||||||
self.page_widget.parent.remove(self.page_widget)
|
|
||||||
|
|
||||||
if isinstance(self.props.palette, _ToolbarPalette):
|
|
||||||
self.props.palette.add(self.page_widget)
|
|
||||||
|
|
||||||
def is_expanded(self):
|
def is_expanded(self):
|
||||||
return self.page_widget is not None and \
|
return self.page is not None and \
|
||||||
self.page_widget.parent is not None and \
|
not self.is_paletted()
|
||||||
self.page_widget.parent != self.props.palette
|
|
||||||
|
|
||||||
def popdown(self):
|
def popdown(self):
|
||||||
if self.props.palette is not None:
|
if self.props.palette is not None:
|
||||||
@ -84,7 +76,7 @@ class ToolbarButton(ToolButton):
|
|||||||
def set_expanded(self, expanded):
|
def set_expanded(self, expanded):
|
||||||
self.popdown()
|
self.popdown()
|
||||||
|
|
||||||
if self.page_widget is None or self.is_expanded() == expanded:
|
if self.page is None or self.is_expanded() == expanded:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not expanded:
|
if not expanded:
|
||||||
@ -100,13 +92,26 @@ class ToolbarButton(ToolButton):
|
|||||||
box.expanded_button.set_expanded(False)
|
box.expanded_button.set_expanded(False)
|
||||||
box.expanded_button = self
|
box.expanded_button = self
|
||||||
|
|
||||||
if self.page_widget.parent is not None:
|
self._unparent()
|
||||||
self.props.palette.remove(self.page_widget)
|
|
||||||
|
|
||||||
self.modify_bg(gtk.STATE_NORMAL, box.background)
|
self.modify_bg(gtk.STATE_NORMAL, box.background)
|
||||||
_setup_page(self.page_widget, box.background, box.props.padding)
|
_setup_page(self.page_widget, box.background, box.props.padding)
|
||||||
box.pack_start(self.page_widget)
|
box.pack_start(self.page_widget)
|
||||||
|
|
||||||
|
def _move_page_to_palette(self):
|
||||||
|
if self.is_paletted():
|
||||||
|
return
|
||||||
|
|
||||||
|
self._unparent()
|
||||||
|
|
||||||
|
if isinstance(self.props.palette, _ToolbarPalette):
|
||||||
|
self.props.palette.add(self.page_widget)
|
||||||
|
|
||||||
|
def _unparent(self):
|
||||||
|
if self.page_widget.parent is None:
|
||||||
|
return
|
||||||
|
self.page_widget.parent.remove(self.page_widget)
|
||||||
|
|
||||||
def do_expose_event(self, event):
|
def do_expose_event(self, event):
|
||||||
if not self.is_expanded() or self.props.palette is not None and \
|
if not self.is_expanded() or self.props.palette is not None and \
|
||||||
self.props.palette.is_up():
|
self.props.palette.is_up():
|
||||||
@ -142,26 +147,47 @@ class ToolbarBox(gtk.VBox):
|
|||||||
self._toolbar.owner = self
|
self._toolbar.owner = self
|
||||||
self._toolbar.connect('remove', self.__remove_cb)
|
self._toolbar.connect('remove', self.__remove_cb)
|
||||||
|
|
||||||
top_widget = _embody_page(gtk.EventBox, self._toolbar)
|
self._toolbar_widget, self._toolbar_alignment = \
|
||||||
self.pack_start(top_widget)
|
_embed_page(gtk.EventBox, self._toolbar)
|
||||||
|
self.pack_start(self._toolbar_widget)
|
||||||
|
|
||||||
self.props.padding = padding
|
self.props.padding = padding
|
||||||
self.modify_bg(gtk.STATE_NORMAL,
|
self.modify_bg(gtk.STATE_NORMAL,
|
||||||
style.COLOR_TOOLBAR_GREY.get_gdk_color())
|
style.COLOR_TOOLBAR_GREY.get_gdk_color())
|
||||||
|
|
||||||
|
def get_toolbar(self):
|
||||||
|
return self._toolbar
|
||||||
|
|
||||||
|
toolbar = property(get_toolbar)
|
||||||
|
|
||||||
def get_expanded_button(self):
|
def get_expanded_button(self):
|
||||||
if self._expanded_button_index == -1:
|
if self._expanded_button_index == -1:
|
||||||
return None
|
return None
|
||||||
return self._toolbar.get_nth_item(self._expanded_button_index)
|
return self.toolbar.get_nth_item(self._expanded_button_index)
|
||||||
|
|
||||||
def set_expanded_button(self, button):
|
def set_expanded_button(self, button):
|
||||||
if not button in self._toolbar:
|
if not button in self.toolbar:
|
||||||
self._expanded_button_index = -1
|
self._expanded_button_index = -1
|
||||||
return
|
return
|
||||||
self._expanded_button_index = self._toolbar.get_item_index(button)
|
self._expanded_button_index = self.toolbar.get_item_index(button)
|
||||||
|
|
||||||
expanded_button = property(get_expanded_button, set_expanded_button)
|
expanded_button = property(get_expanded_button, set_expanded_button)
|
||||||
|
|
||||||
|
def get_padding(self):
|
||||||
|
return self._toolbar_alignment.props.left_padding
|
||||||
|
|
||||||
|
def set_padding(self, pad):
|
||||||
|
self._toolbar_alignment.set_padding(0, 0, pad, pad)
|
||||||
|
|
||||||
|
padding = gobject.property(type=object,
|
||||||
|
getter=get_padding, setter=set_padding)
|
||||||
|
|
||||||
|
def modify_bg(self, state, color):
|
||||||
|
if state == gtk.STATE_NORMAL:
|
||||||
|
self.background = color
|
||||||
|
self._toolbar_widget.modify_bg(state, color)
|
||||||
|
self.toolbar.modify_bg(state, color)
|
||||||
|
|
||||||
def __remove_cb(self, sender, button):
|
def __remove_cb(self, sender, button):
|
||||||
if not isinstance(button, ToolbarButton):
|
if not isinstance(button, ToolbarButton):
|
||||||
return
|
return
|
||||||
@ -170,26 +196,6 @@ class ToolbarBox(gtk.VBox):
|
|||||||
self.remove(button.page_widget)
|
self.remove(button.page_widget)
|
||||||
self._expanded_button_index = -1
|
self._expanded_button_index = -1
|
||||||
|
|
||||||
def get_toolbar(self):
|
|
||||||
return self._toolbar
|
|
||||||
|
|
||||||
toolbar = property(get_toolbar)
|
|
||||||
|
|
||||||
def get_padding(self):
|
|
||||||
return self.toolbar.parent.props.left_padding
|
|
||||||
|
|
||||||
def set_padding(self, pad):
|
|
||||||
self.toolbar.parent.set_padding(0, 0, pad, pad)
|
|
||||||
|
|
||||||
padding = gobject.property(type=object,
|
|
||||||
getter=get_padding, setter=set_padding)
|
|
||||||
|
|
||||||
def modify_bg(self, state, color):
|
|
||||||
if state == gtk.STATE_NORMAL:
|
|
||||||
self.background = color
|
|
||||||
self.toolbar.parent.parent.modify_bg(state, color)
|
|
||||||
self.toolbar.modify_bg(state, color)
|
|
||||||
|
|
||||||
|
|
||||||
class _ToolbarPalette(PaletteWindow):
|
class _ToolbarPalette(PaletteWindow):
|
||||||
|
|
||||||
@ -276,7 +282,7 @@ def _setup_page(page_widget, color, hpad):
|
|||||||
vpad = style.FOCUS_LINE_WIDTH
|
vpad = style.FOCUS_LINE_WIDTH
|
||||||
page_widget.child.set_padding(vpad, vpad, hpad, hpad)
|
page_widget.child.set_padding(vpad, vpad, hpad, hpad)
|
||||||
|
|
||||||
page = page_widget.child.child
|
page = _unembed_page(page_widget)
|
||||||
page.modify_bg(gtk.STATE_NORMAL, color)
|
page.modify_bg(gtk.STATE_NORMAL, color)
|
||||||
if isinstance(page, gtk.Container):
|
if isinstance(page, gtk.Container):
|
||||||
for i in page.get_children():
|
for i in page.get_children():
|
||||||
@ -286,7 +292,7 @@ def _setup_page(page_widget, color, hpad):
|
|||||||
page_widget.modify_bg(gtk.STATE_PRELIGHT, color)
|
page_widget.modify_bg(gtk.STATE_PRELIGHT, color)
|
||||||
|
|
||||||
|
|
||||||
def _embody_page(box_class, page):
|
def _embed_page(box_class, page):
|
||||||
page.show()
|
page.show()
|
||||||
|
|
||||||
alignment = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
|
alignment = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
|
||||||
@ -299,7 +305,11 @@ def _embody_page(box_class, page):
|
|||||||
page_widget.add(alignment)
|
page_widget.add(alignment)
|
||||||
page_widget.show()
|
page_widget.show()
|
||||||
|
|
||||||
return page_widget
|
return (page_widget, alignment)
|
||||||
|
|
||||||
|
|
||||||
|
def _unembed_page(page_widget):
|
||||||
|
return page_widget.child.child
|
||||||
|
|
||||||
|
|
||||||
def _paint_arrow(widget, event, arrow_type):
|
def _paint_arrow(widget, event, arrow_type):
|
||||||
|
Loading…
Reference in New Issue
Block a user