def Create(self): """ Create CMD from constructor """ from Container import ContainerBlock, iPort, oPort # new containerBlock model self.__m = ContainerBlock(self._label, self._inputs, self._outputs) print range(self._inputs) # input and output ports for id in xrange(self._inputs): iport = iPort(label='IPort %d'%(id)) iport.id = id self.__m.AddShape(iport) self.__m.nbiPort = id for id in xrange(self._outputs): oport = oPort(label='OPort %d'%(id)) oport.id = id self.__m.AddShape(oport) self.__m.nboPort = id self.__m.python_path = self._python_file self.__m.model_path = self._model_file return self.__m
def Load(filename, label): """ Load CMD from filename """ from Container import ContainerBlock, iPort, oPort assert(filename.endswith('.cmd')) ### new ContainerBlock instance m = ContainerBlock() load_file_result = m.LoadFile(filename) if isinstance(load_file_result, Exception): wx.MessageBox(_('Error loading %s model : %s'%(label, str(load_file_result))), _('Error'), wx.OK | wx.ICON_ERROR) return None else: ### mandatory due to the LoadFile call before m.label = label # coupled input ports m.input=0 ; m.output=0 for s in m.shapes: if isinstance(s, iPort): m.input +=1 elif isinstance(s, oPort): m.output +=1 return CMDComponent.ChekFilename(filename, m)
class CMDComponent(GenericComponent): """ Return labeled block from filename at (x,y) position in canvas @filename: filename for loading block @label: label of block @x: horizontal position @y: vertical position @canvas: canvas accepting block """ def __init__(self, *argv, **kwargs): """ Constructor """ GenericComponent.__init__(self, *argv, **kwargs) def Create(self): """ Create CMD from constructor """ from Container import ContainerBlock, iPort, oPort # new containerBlock model self.__m = ContainerBlock(self._label, self._inputs, self._outputs) print range(self._inputs) # input and output ports for id in xrange(self._inputs): iport = iPort(label='IPort %d'%(id)) iport.id = id self.__m.AddShape(iport) self.__m.nbiPort = id for id in xrange(self._outputs): oport = oPort(label='OPort %d'%(id)) oport.id = id self.__m.AddShape(oport) self.__m.nboPort = id self.__m.python_path = self._python_file self.__m.model_path = self._model_file return self.__m @staticmethod def Load(filename, label): """ Load CMD from filename """ from Container import ContainerBlock, iPort, oPort assert(filename.endswith('.cmd')) ### new ContainerBlock instance m = ContainerBlock() load_file_result = m.LoadFile(filename) if isinstance(load_file_result, Exception): wx.MessageBox(_('Error loading %s model : %s'%(label, str(load_file_result))), _('Error'), wx.OK | wx.ICON_ERROR) return None else: ### mandatory due to the LoadFile call before m.label = label # coupled input ports m.input=0 ; m.output=0 for s in m.shapes: if isinstance(s, iPort): m.input +=1 elif isinstance(s, oPort): m.output +=1 return CMDComponent.ChekFilename(filename, m)