Ejemplo n.º 1
0
    def _quick_drag_menu ( self, object ):
        """ Displays the quick drag menu for a specified drag object.
        """

        # Get all the features it could be dropped on:
        feature_lists = []
        if isinstance( object, IFeatureTool ):
            msg = 'Apply to'
            for dc in self.dock_control.dock_controls:
                if (dc.visible and
                    (object.feature_can_drop_on( dc.object ) or
                     object.feature_can_drop_on_dock_control( dc ))):
                    from feature_tool import FeatureTool

                    feature_lists.append( [ FeatureTool( dock_control = dc ) ] )
        else:
            msg = 'Send to'
            for dc in self.dock_control.dock_controls:
                if dc.visible:
                    allowed = [ f for f in dc.features
                                if (f.feature_name != '') and
                                    f.can_drop( object ) ]
                    if len( allowed ) > 0:
                        feature_lists.append( allowed )

        # If there are any compatible features:
        if len( feature_lists ) > 0:
            # Create the pop-up menu:
            features = []
            actions  = []
            for list in feature_lists:
                if len( list ) > 1:
                    sub_actions = []
                    for feature in list:
                        sub_actions.append( Action(
                            name   = '%s Feature' % feature.feature_name,
                            action = "self._drop_on(%d)" % len( features ) )
                        )
                        features.append( feature )

                    actions.append( Menu(
                        name = '%s the %s' % ( msg, feature.dock_control.name ),
                        *sub_actions )
                    )
                else:
                    actions.append( Action(
                        name   = '%s %s' % ( msg, list[ 0 ].dock_control.name ),
                        action = "self._drop_on(%d)" % len( features ) )
                    )
                    features.append( list[0] )

            # Display the pop-up menu:
            self._object   = object
            self._features = features
            self.popup_menu( Menu( name = 'popup', *actions ) )
            self._object = self._features = None
Ejemplo n.º 2
0
def add_feature ( feature_class ):
    """ Adds a new DockWindowFeature class to the list of available features.
    """
    global features

    result = (feature_class not in features)
    if result:
        features.append( feature_class )

        # Mark the feature class as having been installed:
        if feature_class.state == 0:
            feature_class.state = 1

    return result