def new(self, _type, name=None, script=None): """ desc: Creates a new item. arguments: _type: desc: The item type. type: unicode keywords: name: desc: The item name, or None to choose a unique name based on the item type. type: [unicode, NoneType] script: desc: A definition script, or None to start with a blank item. type: [unicode, NoneType] returns: desc: The newly generated item. type: item example: | items.new(u'sketchpad', name=u'my_sketchpad') items[u'my_sketchpad'].prepare() items[u'my_sketchpad'].run() """ debug.msg(u'creating %s' % _type) name = self.valid_name(_type, suggestion=name) if plugins.is_plugin(_type): # Load a plug-in try: item = plugins.load_plugin(_type, name, self.experiment, script, self.experiment.item_prefix()) except Exception as e: raise osexception( u"Failed to load plugin '%s'" % _type, exception=e) self.__items__[name] = item else: # Load one of the core items debug.msg(u"loading core item '%s' from '%s'" % (_type, self.experiment.module_container())) item_module = __import__(u'%s.%s' % ( self.experiment.module_container(), _type), fromlist=[u'dummy']) item_class = getattr(item_module, _type) item = item_class(name, self.experiment, script) self.__items__[name] = item return item
def new(self, _type, name=None, script=None): """ desc: Creates a new item. arguments: _type: desc: The item type. type: unicode keywords: name: desc: The item name, or None to choose a unique name based on the item type. type: [unicode, NoneType] script: desc: A definition script, or None to start with a blank item. type: [unicode, NoneType] returns: desc: The newly generated item. type: item example: | items.new(u'sketchpad', name=u'my_sketchpad') items[u'my_sketchpad'].prepare() items[u'my_sketchpad'].run() """ debug.msg(u'creating %s' % _type) name = self.valid_name(_type, suggestion=name) if plugins.is_plugin(_type): # Load a plug-in try: item = plugins.load_plugin(_type, name, self.experiment, script, self.experiment.item_prefix()) except Exception as e: raise osexception(u"Failed to load plugin '%s'" % _type, exception=e) self.__items__[name] = item else: # Load one of the core items debug.msg(u"loading core item '%s' from '%s'" % (_type, self.experiment.module_container())) item_module = __import__( u'%s.%s' % (self.experiment.module_container(), _type), fromlist=[u'dummy']) item_class = getattr(item_module, _type) item = item_class(name, self.experiment, script) self.__items__[name] = item return item