Пример #1
0
    def insert(self, index, item):
        """ Inserts an item into the group at the specified index.

        1) An 'ActionManagerItem' instance.

            In which case the item is simply inserted into the group.

        2) An 'Action' instance.
        
            In which case an 'ActionItem' instance is created with the action
            and then inserted into the group.

        3) A Python callable (ie.'callable(item)' returns True).

            In which case an 'Action' is created that calls the callable when
            it is performed, and the action is then wrapped as in 2).
        
        """

        if isinstance(item, Action):
            item = ActionItem(action=item)

        elif callable(item):
            text = user_name_for(item.func_name)
            item = ActionItem(action=Action(text=text, on_perform=item))
            
        item.parent = self
        self._items.insert(index, item)

        return item
Пример #2
0
    def insert(self, index, item):
        """ Inserts an item into the group at the specified index.

        1) An 'ActionManagerItem' instance.

            In which case the item is simply inserted into the group.

        2) An 'Action' instance.
        
            In which case an 'ActionItem' instance is created with the action
            and then inserted into the group.

        3) A Python callable (ie.'callable(item)' returns True).

            In which case an 'Action' is created that calls the callable when
            it is performed, and the action is then wrapped as in 2).
        
        """

        if isinstance(item, Action):
            item = ActionItem(action=item)

        elif callable(item):
            text = user_name_for(item.func_name)
            item = ActionItem(action=Action(text=text, on_perform=item))

        item.parent = self
        self._items.insert(index, item)

        return item
Пример #3
0
    def get_label ( self, ui ):
        """ Gets the label to use for a specified Item.
        """
        # Return 'None' if the Item is a separator or spacer:
        if self.is_spacer():
            return None

        label = self.label
        if label != '':
            return label

        name   = self.name
        object = ui.context[ self.object ]
        trait  = object.base_trait( name )
        label  = user_name_for( name )
        tlabel = trait.label
        if tlabel is None:
            return label
        if isinstance(tlabel, basestring):
            if tlabel[0:3] == '...':
                return label + tlabel[3:]
            if tlabel[-3:] == '...':
                return tlabel[:-3] + label
            if self.label != '':
                return self.label
            return tlabel
        return tlabel( object, name, label )
Пример #4
0
 def init ( self, parent ):
     """ Finishes initializing the editor by creating the underlying toolkit
         widget.
     """
     label = self.factory.label
     if label == '':
         label = user_name_for( self.name )
     self.control = tk.Button( parent, text    = label, 
                                       command = self.update_object )
Пример #5
0
 def init(self, parent):
     """ Finishes initializing the editor by creating the underlying toolkit
         widget.
     """
     label = self.factory.label
     if label == '':
         label = user_name_for(self.name)
     self.control = tk.Button(parent,
                              text=label,
                              command=self.update_object)
Пример #6
0
 def init(self, parent):
     """ Finishes initialising the editor by creating the underlying toolkit
         widget.
     """
     label = self.factory.label
     if label == "":
         label = user_name_for(self.name)
     #            label = self.item.get_label( self.ui )
     self.sync_value(self.factory.label_value, "label", "from")
     self.control = control = Button(label, getattr(self, "update_object"))
     #        parent.add( control )
     self.set_tooltip()
Пример #7
0
    def get_label ( self, ui ):
        """ Gets the label to use for a specified Item.
        """
        # Return 'None' if the Item is a separator or spacer:
        if self.is_spacer():
            return None

        label = self.label
        if label != '':
            return label
        name   = self.name
        object = eval( self.object_, globals(), ui.context )
        trait  = object.base_trait( name )

        # --------------------------------
        # append metadata 'unit' to the label string if it exists: 
        dict = trait.__dict__
        if dict.has_key( 'unit' ):
            unit_str = ' [' + dict['unit'] +']'
        else:
            unit_str = ' '
        label  = user_name_for( name ) + unit_str 
        #---------------------------------

        tlabel = trait.label
        if tlabel is None:
            return label
            
        if isinstance( tlabel, basestring ):
            if tlabel[0:3] == '...':
                return label + tlabel[3:]
            if tlabel[-3:] == '...':
                return tlabel[:-3] + label
            if self.label != '':
                return self.label
            return tlabel
            
        return tlabel( object, name, label )
Пример #8
0
 def _get_label(self):
     """ Gets the label of the column.
     """
     if self._label is not None:
         return self._label
     return user_name_for(self.name)
Пример #9
0
 def _get_label ( self ):
     """ Gets the label of the column.
     """
     if self._label is not None:
         return self._label
     return user_name_for( self.name )