def register( self ): kwargs = {} for i in range( 1 + self.has_fields ): name = [self.label, self.label + 'Options'][i] if self.has_fields: cmd_str = '%s(%d)' % ( self._perform_func_str, i ) else: cmd_str = '%s()' % ( self._perform_func_str, ) if i == self.has_fields: kwargs['annotation'] = utils.niceName( name ) else: kwargs['annotation'] = self.annotation if not pm.versions.current() >= pm.versions.v2008: kwargs['command'] = 'python("%s")' % cmd_str else: kwargs['command'] = cmd_str kwargs['commandLanguage'] = 'python' if self.category is not None: kwargs['category'] = self.category if not pm.runTimeCommand( name, exists=1 ): pm.runTimeCommand( name, default=True, **kwargs ) print "# Adding runtime:", name, ':', cmd_str
def __init__( self, optionmodel, command ): super(OptionBoxView, self).__init__(optionmodel) self.command = command # -- read Meta data self._title = getattr( self.optionmodel.Meta, 'title', utils.niceName( self.optionmodel.__class__.__name__ ) ) self._help_tag = getattr( self.optionmodel.Meta, 'help_tag', '%sHelp' % self.command.func_name ) self._button_label = getattr( self.optionmodel.Meta, 'button_label', 'Apply/Close' )
def __init__( self, optionmodel ): self.optionmodel = optionmodel self.name = utils.niceName( self.optionmodel.__class__.__name__ + "View" ) if self.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( self.optionmodel, 'fields' ): self.optionmodel = self.optionmodel()
def widget_label( self ): if self.label is not None: return self.label else: return utils.niceName( self.name )
def commandMenuItem( command, args=[], label=None, annotation=None, **kwargs ): """ Creates menuItem from python function objects. 'command' parameter takes a python function object. 'args' can be supplied for the command. If 'label' isn't specified, it will be generated from the function __name__. If 'annotation' isn't specified, it will be taken from the first sentence of the function __doc__. If __doc__ is empty, it will use the 'label'. Setting 'options' to True will build an optionBox menuItem and supply 'True' as the arg to the command. See functions that have OptionBox classes associated with them for the proper structure. """ def _initMenuItem( *args, **kwargs ): keys = kwargs.keys() menuItemName = kwargs.pop( 'menuItemName', False ) if 'command' in keys or 'c' in keys: if 'dragMenuCommand' not in keys or 'dmc' not in keys: kwargs['dmc'] = 'python("%s")' % kwargs['command'] if menuItemName: return pm.menuItem( menuItemName, *args, **kwargs ) else: return pm.menuItem( *args, **kwargs ) argStr = '' if len( args ) > 0: argList = [] for arg in args: if isinstance( arg, str ): argList.append( '\"%s\"' % arg ) else: argList.append( str( arg ) ) argStr = ','.join( argList ) if hasattr( command, 'func' ): command_str = '%s.%s(%s)' % ( command.func.__module__, command.__name__, argStr ) else: command_str = '%s.%s(%s)' % ( command.__module__, command.__name__, argStr ) if command_str.startswith( '__main__' ): command_str = '.'.join( command_str.split( '.' )[1:] ) if label is None: if hasattr( command, 'label' ): label = utils.niceName( command.label ) else: label = utils.niceName( command.__name__ ) if annotation is None: if hasattr( command, 'annotation' ): annotation = command.annotation else: try: annotation = command.__doc__.strip().splitlines()[0].split( '.' )[0] except: annotation = label item = _initMenuItem( command=command_str, label=label, annotation=annotation, **kwargs ) # -- add optionBox menuItem for options -- if hasattr( command, 'optionmodel' ): if command.optionmodel is not None: optCmdStr = command_str.split( '(' )[0] + '(1)' optAnn = label + ' Options' optItem = _initMenuItem( command=optCmdStr, annotation=optAnn, optionBox=True, **kwargs ) return ( item, optItem ) return item