示例#1
0
    def __init__( self, func, optionmodel=None, view=views.OptionBoxView, name=None, label=None, category=None, annotation=None, args=(), kwargs={} ):

        if name is None:
            ( filename, line_number, function_name, text ) = traceback.extract_stack()[-2]
            try:
                name = text[:text.find( '=' )].strip()
            except AttributeError:
                name = 'perform' + utils.pascalCase( func.__name__ )
                pm.mel.warning( "'name' not provided and could not be extrapolated. Assuming: '%s'" % name )

        if label is None:
            label = utils.pascalCase( func.__name__ )

        super( PerformCommand, self ).__init__( func, name, label, category, annotation, False, args, kwargs )

        self.view = view

        if optionmodel is not None:
            if not isinstance( optionmodel, models.OptionModel ) and not issubclass( optionmodel, models.OptionModel ):
                raise TypeError( "`optionmodel` must subclass of %s" % models.OptionModel )
            elif not hasattr( optionmodel, 'options' ):
                optionmodel = optionmodel()

        self.optionmodel = optionmodel

        self.register()
示例#2
0
    def __init__( self, func, name=None, label=None, category=None, annotation=None, register=True, args=(), kwargs={} ):

        self.func = func
        self.args = args
        self.kwargs = kwargs

        self.__doc__ = self.func.__doc__

        if name is None:
            ( filename, line_number, function_name, text ) = traceback.extract_stack()[-2]
            try:
                name = text[:text.find( '=' )].strip()
            except AttributeError:
                assert False, "'name' not provided and could not be extrapolated."

        self.__name__ = self.name = name

        if label is None:
            label = utils.pascalCase( self.name )
        self.label = label

        if category is None:
            if self.func.__module__ != '__main__':
                category = ' '.join( [ utils.pascalCase( c ) for c in self.func.__module__.split( '.' )[:2]] )
        self.category = category

        if annotation is None:
            try:
                annotation = self.func.__doc__.strip().splitlines()[0].split( '.' )[0]
            except:
                annotation = self.label
        self.annotation = annotation

        if register:
            self.register()