def empty_list ( self ): """ Creates an empty list entry (so the user can add a new item). """ def handler ( ): self.popup_empty_menu( control ) ic = ImageControl( image = self.image, selectable = True ) control = ic.create_control( self.control ).control ic.on_facet_set( handler, 'clicked' ) 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 facet changes externally to the editor. """ # Disconnect the editor from any control about to be destroyed: self._dispose_items() # Get rid of any previous contents: list_pane = self.control list_pane.SetSizer( None ) list_pane.DestroyChildren() # Create all of the list item facet editors: facet_handler = self._facet_handler resizable = ((facet_handler.minlen != facet_handler.maxlen) and self.mutable) item_facet = facet_handler.item_facet factory = self.factory list_sizer = wx.FlexGridSizer( 0, (1 + resizable) * factory.columns, 0, 0 ) j = resizable for i in range( factory.columns ): list_sizer.AddGrowableCol( j ) j += ( 1 + resizable ) values = self.value index = 0 width, height = 0, 0 is_fake = (resizable and (len( values ) == 0)) if is_fake: values = [ item_facet.default_value()[1] ] editor = self._editor for value in values: width1 = height = 0 if resizable: ic = ImageControl( image = self.image, selectable = True ) control = ic.create_control( list_pane ).control def handler ( ): self.popup_menu( control ) ic.on_facet_set( handler, 'clicked' ) width1, height = control.GetSize() width1 += 4 try: proxy = ListItemProxy( self.object, self.name, index, item_facet, value ) if resizable: control.proxy = proxy peditor = editor( self.ui, proxy, 'value', self.description ).set( object_name = '' ) peditor.prepare( list_pane ) pcontrol = peditor.control pcontrol.proxy = proxy except: if not is_fake: raise pcontrol = wx.Button( list_pane, -1, 'sample' ) pcontrol.Fit() width2, height2 = size = pcontrol.GetSize() pcontrol.SetMinSize( size ) width = max( width, width1 + width2 ) height = max( height, height2 ) if resizable: list_sizer.Add( control, 0, wx.LEFT | wx.RIGHT, 2 ) list_sizer.Add( pcontrol, 0, wx.EXPAND ) index += 1 list_pane.SetSizer( list_sizer ) if is_fake: self._cur_control = control self.empty_list() control.Destroy() pcontrol.Destroy() rows = 1 if not self.single_row: rows = self.factory.rows # Make sure we have valid values set for width and height (in case there # was no data to base them on): if width == 0: width = 100 if height == 0: height = 20 list_pane.SetMinSize( wx.Size( width + ((facet_handler.maxlen > rows) * scrollbar_dx), height * rows ) ) list_pane.SetupScrolling() list_pane.GetParent().Layout()