def __init__(self, place, position, **kwds): self.pos = position if position in ['left', 'right']: orientation = 'vertical' tbo = 'horizontal' elif position in ['top', 'bottom']: orientation = 'horizontal' tbo = 'vertical' self.orientation = orientation Box.__init__(self, place, tbo, **kwds) self.contents = [] self.toolbar = Toolbar(self.place(stretch=0), orientation) self.splitter = place[0] self.Bind(wx.EVT_PAINT, self.on_paint) self._shown = False self._width = place[1].get('width', 100)
class Panel(Box): def __init__(self, place, position, **kwds): self.pos = position if position in ['left', 'right']: orientation = 'vertical' tbo = 'horizontal' elif position in ['top', 'bottom']: orientation = 'horizontal' tbo = 'vertical' self.orientation = orientation Box.__init__(self, place, tbo, **kwds) self.contents = [] self.toolbar = Toolbar(self.place(stretch=0), orientation) self.splitter = place[0] self.Bind(wx.EVT_PAINT, self.on_paint) self._shown = False self._width = place[1].get('width', 100) def on_paint(self, evt): # The first time we are shown, # set the correct size if not self._shown: self._shown = True sz = self.toolbar.size[self.orientation == 'horizontal'] self.splitter.resize_child(self, sz) for w in self.contents: if w._command.state: w._command(True) evt.Skip() def _add(self, widget, label=None, image=None, **opts): if image is not None: self.contents.append(widget) widget._command = self.callback(widget, label, image) self.toolbar.append(widget._command) opts['prepend'] = self.pos in ['bottom', 'right'] Box._add(self, widget, **opts) if image is not None: self.layout.Hide(widget) def open(self, widget): widget._command.state = True def close(self, widget): widget._command.state = False def callback(self, widget, label, image): if label is None: label = "" image = _text_img_wxbitmap(label, images[image][16, 16], rotate=self.orientation == 'vertical') @Command.from_function('callable', 'callit', image, type='check') def callable(on): sz = self.toolbar.size[self.orientation == 'horizontal'] if on: for win in self.contents: if win != widget: win._command.state = False self.layout.Show(widget) self.splitter.resize_child(self, self._width + sz) else: self._width = self.size[self.orientation == 'horizontal'] - sz self.layout.Hide(widget) self.splitter.resize_child(self, sz) return callable
class Panel(Box): def __init__(self, place, position, **kwds): self.pos = position if position in ['left', 'right']: orientation = 'vertical' tbo = 'horizontal' elif position in ['top', 'bottom']: orientation = 'horizontal' tbo = 'vertical' self.orientation = orientation Box.__init__(self, place, tbo, **kwds) self.contents = [] self.toolbar = Toolbar(self.place(stretch=0), orientation) self.splitter = place[0] self.Bind(wx.EVT_PAINT, self.on_paint) self._shown = False self._width = place[1].get('width', 100) def on_paint(self, evt): # The first time we are shown, # set the correct size if not self._shown: self._shown = True sz = self.toolbar.size[self.orientation=='horizontal'] self.splitter.resize_child(self, sz) for w in self.contents: if w._command.state: w._command(True) evt.Skip() def _add(self, widget, label=None, image=None, **opts): if image is not None: self.contents.append(widget) widget._command = self.callback(widget, label, image) self.toolbar.append(widget._command) opts['prepend'] = self.pos in ['bottom', 'right'] Box._add(self, widget, **opts) if image is not None: self.layout.Hide(widget) def open(self, widget): widget._command.state = True def close(self, widget): widget._command.state = False def callback(self, widget, label, image): if label is None: label = "" image = _text_img_wxbitmap(label, images[image][16,16], rotate=self.orientation == 'vertical') @Command.from_function('callable', 'callit', image, type='check') def callable(on): sz = self.toolbar.size[self.orientation=='horizontal'] if on: for win in self.contents: if win!=widget: win._command.state = False self.layout.Show(widget) self.splitter.resize_child(self, self._width+sz) else: self._width = self.size[self.orientation=='horizontal']-sz self.layout.Hide(widget) self.splitter.resize_child(self, sz) return callable