Delete sub-widgets clearly
This commit is contained in:
		
							parent
							
								
									4c8c845e6c
								
							
						
					
					
						commit
						f9de29f539
					
				@ -9,23 +9,27 @@ window.add(box)
 | 
				
			|||||||
toolbar = Toolbar()
 | 
					toolbar = Toolbar()
 | 
				
			||||||
box.pack_start(toolbar, False)
 | 
					box.pack_start(toolbar, False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
tollbarbutton_1 = ToolbarButton(toolbar, gtk.Button('1'),
 | 
					tollbarbutton_1 = ToolbarButton(toolbar, gtk.Button('sub-widget #1'),
 | 
				
			||||||
        icon_name='computer-xo',
 | 
					        icon_name='computer-xo',
 | 
				
			||||||
        tooltip='foo')
 | 
					        tooltip='foo')
 | 
				
			||||||
toolbar.top.insert(tollbarbutton_1, -1)
 | 
					toolbar.top.insert(tollbarbutton_1, -1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
toolbar.top.insert(gtk.SeparatorToolItem(), -1)
 | 
					toolbar.top.insert(gtk.SeparatorToolItem(), -1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
tollbarbutton_2 = ToolbarButton(toolbar, gtk.Button('1'),
 | 
					tollbarbutton_2 = ToolbarButton(toolbar, gtk.Button('sub-widget #2'),
 | 
				
			||||||
        icon_name='button_cancel',
 | 
					        icon_name='button_cancel',
 | 
				
			||||||
        tooltip='foo')
 | 
					        tooltip='foo')
 | 
				
			||||||
toolbar.top.insert(tollbarbutton_2, -1)
 | 
					toolbar.top.insert(tollbarbutton_2, -1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
toolbar.top.insert(gtk.SeparatorToolItem(), -1)
 | 
					toolbar.top.insert(gtk.SeparatorToolItem(), -1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
tollbarbutton_3 = ToolbarButton(toolbar, gtk.Button('3'),
 | 
					def del_cb(widget):
 | 
				
			||||||
 | 
					    toolbar.top.remove(tollbarbutton_3)
 | 
				
			||||||
 | 
					del_b = gtk.Button('delete sub-widget #3')
 | 
				
			||||||
 | 
					del_b.connect('clicked', del_cb)
 | 
				
			||||||
 | 
					tollbarbutton_3 = ToolbarButton(toolbar, del_b,
 | 
				
			||||||
        icon_name='activity-journal',
 | 
					        icon_name='activity-journal',
 | 
				
			||||||
        tooltip='foo')
 | 
					        tooltip='del')
 | 
				
			||||||
toolbar.top.insert(tollbarbutton_3, -1)
 | 
					toolbar.top.insert(tollbarbutton_3, -1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
window.show_all()
 | 
					window.show_all()
 | 
				
			||||||
 | 
				
			|||||||
@ -50,7 +50,7 @@ class ToolbarButton(ToolButton):
 | 
				
			|||||||
            return
 | 
					            return
 | 
				
			||||||
        if value:
 | 
					        if value:
 | 
				
			||||||
            expanded = self._bar._expanded_page()
 | 
					            expanded = self._bar._expanded_page()
 | 
				
			||||||
            if expanded:
 | 
					            if expanded and expanded._toolitem.window:
 | 
				
			||||||
                expanded._toolitem.window.invalidate_rect(None, True)
 | 
					                expanded._toolitem.window.invalidate_rect(None, True)
 | 
				
			||||||
            self._page._toolitem_alloc = self.allocation
 | 
					            self._page._toolitem_alloc = self.allocation
 | 
				
			||||||
            self._bar._expand_page(self._page)
 | 
					            self._bar._expand_page(self._page)
 | 
				
			||||||
@ -104,8 +104,15 @@ class Toolbar(gtk.VBox):
 | 
				
			|||||||
        self._notebook.connect('notify::page', lambda notebook, pspec:
 | 
					        self._notebook.connect('notify::page', lambda notebook, pspec:
 | 
				
			||||||
                self.emit('current-toolbar-changed', notebook.props.page))
 | 
					                self.emit('current-toolbar-changed', notebook.props.page))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self._bar.connect('remove', self._remove_cb)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    top = property(lambda self: self._bar)
 | 
					    top = property(lambda self: self._bar)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def _remove_cb(self, sender, widget):
 | 
				
			||||||
 | 
					        if not isinstance(widget, ToolbarButton):
 | 
				
			||||||
 | 
					            return
 | 
				
			||||||
 | 
					        widget.expanded = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _remove_page(self, page):
 | 
					    def _remove_page(self, page):
 | 
				
			||||||
        page = self._notebook.page_num(page)
 | 
					        page = self._notebook.page_num(page)
 | 
				
			||||||
        self._notebook.remove_page(page)
 | 
					        self._notebook.remove_page(page)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user