示例#1
0
 def empty_list ( self ):
     """ Creates an empty list entry (so the user can add a new item).
     """
     control          = IconButton( '@facets:list_editor', self.popup_menu )
     control.is_empty = True
     proxy          = ListItemProxy( self.object, self.name, -1, None, None )
     pcontrol       = QLabel( '   (Empty List)' )
     pcontrol.proxy = control.proxy = proxy
     self.reload_sizer( [ ( control, pcontrol ) ] )
示例#2
0
    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()

        list_pane = self._list_pane
        layout    = list_pane.layout()

        # 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
        values        = self.value
        index         = 0

        is_fake       = (resizable and (len( values ) == 0))
        if is_fake:
            values = [ item_facet.default_value()[1] ]

        editor = self._editor
        # FIXME: Add support for more than one column.
        for value in values:
            if resizable:
                control = IconButton( '@facets:list_editor', self.popup_menu )
                layout.addWidget( control, index, 0 )

            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 = QPushButton( 'sample', list_pane )

            if isinstance( pcontrol, QWidget ):
                layout.addWidget( pcontrol, index, 1 )
            else:
                layout.addLayout( pcontrol, index, 1 )

            index += 1

        if is_fake:
           self._cur_control = control
           self.empty_list()
           control.setParent( None )

        if self.single_row:
            rows = 1
        else:
            rows = self.factory.rows

        #list_pane.SetSize( wx.Size(
        #     width + ((facet_handler.maxlen > rows) * scrollbar_dx),
        #     height * rows ) )

        # QScrollArea can have problems if the widget being scrolled is set too
        # early (ie. before it contains something).
        if self.control.widget() is None:
            self.control.setWidget( list_pane )