def _create_image_grid(self, parent): """ Populates a specified window with a grid of image buttons. """ # Create the panel to hold the ImageControl buttons: self.control = panel = TraitsUIPanel(parent, -1) # Create the main sizer: if self.factory.cols > 1: sizer = wx.GridSizer(0, self.factory.cols, 0, 0) else: sizer = wx.BoxSizer(wx.VERTICAL) # Add the set of all possible choices: factory = self.factory mapping = factory._mapping cur_value = self.value for name in self.factory._names: value = mapping[name] control = ImageControl( panel, bitmap_cache('%s%s%s' % (factory.prefix, name, factory.suffix), False, factory._image_path), value == cur_value, self.update_object) control.value = value sizer.Add(control, 0, wx.ALL, 2) self.set_tooltip(control) # Finish setting up the control layout: panel.SetSizerAndFit(sizer)
def init ( self, parent ): """ Finishes initializing the editor by creating the underlying toolkit widget. """ self.control = ImageControl( parent, bitmap_cache( self.str_value + self.factory.suffix, False, self.factory._image_path ) )
def _create_image_grid ( self, parent ): """ Populates a specified window with a grid of image buttons. """ # Create the panel to hold the ImageControl buttons: self.control = panel = wx.Panel( parent, -1 ) # Create the main sizer: if self.factory.cols > 1: sizer = wx.GridSizer( 0, self.factory.cols, 0, 0 ) else: sizer = wx.BoxSizer( wx.VERTICAL ) # Add the set of all possible choices: cur_value = self.str_value for value in self.factory._names: control = ImageControl( panel, bitmap_cache( value + self.factory.suffix, False, self.factory._image_path ), value == cur_value, self.update_object ) control.value = value sizer.Add( control, 0, wx.ALL, 2 ) self.set_tooltip( control ) # Finish setting up the control layout: panel.SetAutoLayout( True ) panel.SetSizer( sizer ) sizer.Fit( panel )
def _create_image_grid ( self, parent ): """ Populates a specified window with a grid of image buttons. """ # Create the panel to hold the ImageControl buttons: self.control = panel = TraitsUIPanel( parent, -1 ) # Create the main sizer: if self.factory.cols > 1: sizer = wx.GridSizer( 0, self.factory.cols, 0, 0 ) else: sizer = wx.BoxSizer( wx.VERTICAL ) # Add the set of all possible choices: factory = self.factory mapping = factory._mapping cur_value = self.value for name in self.factory._names: value = mapping[ name ] control = ImageControl( panel, bitmap_cache( '%s%s%s' % ( factory.prefix, name, factory.suffix ), False, factory._image_path ), value == cur_value, self.update_object ) control.value = value sizer.Add( control, 0, wx.ALL, 2 ) self.set_tooltip( control ) # Finish setting up the control layout: panel.SetSizerAndFit( sizer )
def update_editor ( self ): """ Updates the editor when the object trait changes externally to the editor. """ self.control.Bitmap( bitmap_cache( '%s%s%s' % ( self.factory.prefix, self.str_value, self.factory.suffix ), False, self.factory._image_path ) )
def _create_image_grid(self, parent): """ Populates a specified window with a grid of image buttons. """ # Create the panel to hold the ImageControl buttons: self.control = panel = wx.Panel(parent, -1) # Create the main sizer: if self.factory.cols > 1: sizer = wx.GridSizer(0, self.factory.cols, 0, 0) else: sizer = wx.BoxSizer(wx.VERTICAL) # Add the set of all possible choices: cur_value = self.str_value for value in self.factory._names: control = ImageControl( panel, bitmap_cache(value + self.factory.suffix, False, self.factory._image_path), value == cur_value, self.update_object) control.value = value sizer.Add(control, 0, wx.ALL, 2) self.set_tooltip(control) # Finish setting up the control layout: panel.SetAutoLayout(True) panel.SetSizer(sizer) sizer.Fit(panel)
def update_editor(self): """ Updates the editor when the object trait changes external to the editor. """ self.control.Bitmap( bitmap_cache(self.str_value + self.factory.suffix, False, self.factory._image_path))
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ self.control = ImageControl( parent, bitmap_cache(self.str_value + self.factory.suffix, False, self.factory._image_path))
def empty_list(self): """ Creates an empty list entry (so the user can add a new item). """ control = ImageControl(self.control, bitmap_cache('list_editor', False), -1, self.popup_empty_menu) control.is_empty = True proxy = ListItemProxy(self.object, self.name, -1, None, None) pcontrol = wx.StaticText(self.control, -1, ' (Empty List)') pcontrol.proxy = control.proxy = proxy self.reload_sizer([(control, pcontrol)])
def empty_list ( self ): """ Creates an empty list entry (so the user can add a new item). """ control = ImageControl( self.control, bitmap_cache( 'list_editor', False ), -1, self.popup_empty_menu ) control.is_empty = True proxy = ListItemProxy( self.object, self.name, -1, None, None ) pcontrol = wx.StaticText( self.control, -1, ' (Empty List)' ) pcontrol.proxy = control.proxy = proxy self.reload_sizer( [ ( control, pcontrol ) ] )
def update_editor(self): """ Updates the editor when the object trait changes external to the editor. """ list_pane = self.control editor = self._editor # Disconnext the editor from any control about to be destroyed: for control in list_pane.GetChildren(): if hasattr(control, '_editor'): control._editor.control = None # Get rid of any previous contents: list_pane.SetSizer(None) list_pane.DestroyChildren() # Create all of the list item trait editors: trait_handler = self.factory.trait_handler resizable = ((trait_handler.minlen != trait_handler.maxlen) and (self.kind != 'readonly_editor')) item_trait = trait_handler.item_trait list_sizer = wx.FlexGridSizer(0, 1 + resizable, 0, 0) list_sizer.AddGrowableCol(resizable) values = self.value index = 0 width, height = 100, 18 is_fake = (resizable and (len(values) == 0)) if is_fake: values = [item_trait.default_value()[1]] for value in values: width = height = 0 if resizable: control = ImageControl(list_pane, bitmap_cache('list_editor', False), -1, self.popup_menu) width, height = control.GetSize() width += 4 try: proxy = ListItemProxy(self.object, self.name, index, item_trait, value) peditor = editor(self.ui, proxy, 'value', self.description, list_pane) pcontrol = peditor.control pcontrol.proxy = proxy if resizable: control.proxy = proxy except: if not is_fake: raise pcontrol = wx.Button(list_pane, -1, 'sample') width2, height2 = pcontrol.GetSize() width += width2 height = max(height, height2) if resizable: list_sizer.Add(control, 0, wx.LEFT | wx.RIGHT, 2) list_sizer.Add(pcontrol, 1, wx.EXPAND) index += 1 list_pane.SetSizer(list_sizer) if is_fake: self._cur_control = control self.empty_list() control.Destroy() pcontrol.Destroy() rows = [self.factory.rows, 1][self.kind == 'simple_editor'] list_pane.SetSize( wx.Size(width + ((trait_handler.maxlen > rows) * scrollbar_dx), height * rows)) list_pane.SetScrollRate(16, height) list_pane.SetVirtualSize(list_sizer.GetMinSize()) list_pane.GetParent().Layout()
def update_editor ( self ): """ Updates the editor when the object trait changes external to the editor. """ list_pane = self.control editor = self._editor # Disconnext the editor from any control about to be destroyed: for control in list_pane.GetChildren(): if hasattr( control, '_editor' ): control._editor.control = None # Get rid of any previous contents: list_pane.SetSizer( None ) list_pane.DestroyChildren() # Create all of the list item trait editors: trait_handler = self.factory.trait_handler resizable = ((trait_handler.minlen != trait_handler.maxlen) and (self.kind != 'readonly_editor')) item_trait = trait_handler.item_trait list_sizer = wx.FlexGridSizer( 0, 1 + resizable, 0, 0 ) list_sizer.AddGrowableCol( resizable ) values = self.value index = 0 width, height = 100, 18 is_fake = (resizable and (len( values ) == 0)) if is_fake: values = [ item_trait.default_value()[1] ] for value in values: width = height = 0 if resizable: control = ImageControl( list_pane, bitmap_cache( 'list_editor', False ), -1, self.popup_menu ) width, height = control.GetSize() width += 4 try: proxy = ListItemProxy( self.object, self.name, index, item_trait, value ) peditor = editor( self.ui, proxy, 'value', self.description, list_pane ) pcontrol = peditor.control pcontrol.proxy = proxy if resizable: control.proxy = proxy except: if not is_fake: raise pcontrol = wx.Button( list_pane, -1, 'sample' ) width2, height2 = pcontrol.GetSize() width += width2 height = max( height, height2 ) if resizable: list_sizer.Add( control, 0, wx.LEFT | wx.RIGHT, 2 ) list_sizer.Add( pcontrol, 1, wx.EXPAND ) index += 1 list_pane.SetSizer( list_sizer ) if is_fake: self._cur_control = control self.empty_list() control.Destroy() pcontrol.Destroy() rows = [ self.factory.rows, 1 ][ self.kind == 'simple_editor' ] list_pane.SetSize( wx.Size( width + ((trait_handler.maxlen > rows) * scrollbar_dx), height * rows ) ) list_pane.SetScrollRate( 16, height ) list_pane.SetVirtualSize( list_sizer.GetMinSize() ) list_pane.GetParent().Layout()