Exemplo n.º 1
0
 def __init__(self, param, n):
     Element.__init__(self, param)
     self._name = n.find("name")
     self._key = n.find("key")
     self._opts = dict()
     opts = n.findall("opt")
     # test against opts when non enum
     try:
         assert self.get_parent().is_enum() or not opts
     except AssertionError:
         raise Exception, "Options for non-enum types cannot have sub-options"
     # extract opts
     for opt in opts:
         # separate the key:value
         try:
             key, value = opt.split(":")
         except:
             raise Exception, 'Error separating "%s" into key:value' % opt
         # test against repeated keys
         try:
             assert not self._opts.has_key(key)
         except AssertionError:
             raise Exception, 'Key "%s" already exists in option' % key
         # store the option
         self._opts[key] = value
Exemplo n.º 2
0
 def __init__(self):
     """
     Block contructor.
     Add graphics related params to the block.
     """
     self.W = 0
     self.H = 0
     #add the position param
     self.get_params().append(self.get_parent().get_parent().Param(
         block=self,
         n=odict({
             'name': 'GUI Coordinate',
             'key': '_coordinate',
             'type': 'raw',
             'value': '(0, 0)',
             'hide': 'all',
         })
     ))
     self.get_params().append(self.get_parent().get_parent().Param(
         block=self,
         n=odict({
             'name': 'GUI Rotation',
             'key': '_rotation',
             'type': 'raw',
             'value': '0',
             'hide': 'all',
         })
     ))
     Element.__init__(self)
     self._comment_pixmap = None
     self.has_busses = [False, False]  # source, sink
Exemplo n.º 3
0
    def __init__(self, id, name, label, help='', type='text', **kwds):
        Element.__init__(self, tag='input', cls="formfield", id=id, name=name, type=type, **kwds)

        self.label = label
        self.help = help

        return
Exemplo n.º 4
0
	def __init__(self):
		"""
		FlowGraph contructor.
		Create a list for signal blocks and connections. Connect mouse handlers.
		"""
		Element.__init__(self)
		#when is the flow graph selected? (used by keyboard event handler)
		self.is_selected = lambda: bool(self.get_selected_elements())
		#important vars dealing with mouse event tracking
		self.element_moved = False
		self.mouse_pressed = False
		self.unselect()
		self.press_coor = (0, 0)
		#selected ports
		self._old_selected_port = None
		self._new_selected_port = None
		#context menu
		self._context_menu = gtk.Menu()
		for action in [
			Actions.BLOCK_CUT,
			Actions.BLOCK_COPY,
			Actions.BLOCK_PASTE,
			Actions.ELEMENT_DELETE,
			Actions.BLOCK_ROTATE_CCW,
			Actions.BLOCK_ROTATE_CW,
			Actions.BLOCK_ENABLE,
			Actions.BLOCK_DISABLE,
			Actions.BLOCK_PARAM_MODIFY,
		]: self._context_menu.append(action.create_menu_item())
Exemplo n.º 5
0
    def __init__(self):
        """
		Block contructor.
		Add graphics related params to the block.
		"""
        # add the position param
        self.get_params().append(
            self.get_parent()
            .get_parent()
            .Param(
                block=self,
                n=odict(
                    {"name": "GUI Coordinate", "key": "_coordinate", "type": "raw", "value": "(0, 0)", "hide": "all"}
                ),
            )
        )
        self.get_params().append(
            self.get_parent()
            .get_parent()
            .Param(
                block=self,
                n=odict({"name": "GUI Rotation", "key": "_rotation", "type": "raw", "value": "0", "hide": "all"}),
            )
        )
        Element.__init__(self)
Exemplo n.º 6
0
	def __init__(self, flow_graph, porta, portb):
		"""
		Make a new connection given the parent and 2 ports.
		
		Args:
		    flow_graph: the parent of this element
		    porta: a port (any direction)
		    portb: a port (any direction)
		@throws Error cannot make connection
		
		Returns:
		    a new connection
		"""
		Element.__init__(self, flow_graph)
		source = sink = None
		#separate the source and sink
		for port in (porta, portb):
			if port.is_source(): source = port
			if port.is_sink(): sink = port
		if not source: raise ValueError('Connection could not isolate source')
		if not sink: raise ValueError('Connection could not isolate sink')
		#ensure that this connection (source -> sink) is unique
		for connection in self.get_parent().get_connections():
			if connection.get_source() is source and connection.get_sink() is sink:
				raise Exception('This connection between source and sink is not unique.')
		self._source = source
		self._sink = sink
Exemplo n.º 7
0
	def __init__(self, name, version, key,
		block_paths, block_dtd, default_flow_graph, generator,
		license='', website=None, colors=[]):
		"""
		Make a platform from the arguments.
		@param name the platform name
		@param version the version string
		@param key the unique platform key
		@param block_paths the file paths to blocks in this platform
		@param block_dtd the dtd validator for xml block wrappers
		@param default_flow_graph the default flow graph file path
		@param generator the generator class for this platform
		@param colors a list of title, color_spec tuples
		@param license a multi-line license (first line is copyright)
		@param website the website url for this platform
		@return a platform object
		"""
		_Element.__init__(self)
		self._name = name
		self._version = version
		self._key = key
		self._license = license
		self._website = website
		self._block_paths = block_paths
		self._block_dtd = block_dtd
		self._default_flow_graph = default_flow_graph
		self._generator = generator
		self._colors = colors
		#create a dummy flow graph for the blocks
		self._flow_graph = _Element(self)
		#search for *.xml files in the given search path

		self.loadblocks();
Exemplo n.º 8
0
	def __init__(self):
		"""
		Port contructor.
		Create list of connector coordinates.
		"""
		Element.__init__(self)
		self.connector_coordinates = dict()
Exemplo n.º 9
0
 def __init__(self):
     """
     Block contructor.
     Add graphics related params to the block.
     """
     #add the position param
     self.get_params().append(self.get_parent().get_parent().Param(
         block=self,
         n=odict({
             'name': 'GUI Coordinate',
             'key': '_coordinate',
             'type': 'raw',
             'value': '(0, 0)',
             'hide': 'all',
         })
     ))
     self.get_params().append(self.get_parent().get_parent().Param(
         block=self,
         n=odict({
             'name': 'GUI Rotation',
             'key': '_rotation',
             'type': 'raw',
             'value': '0',
             'hide': 'all',
         })
     ))
     Element.__init__(self)
Exemplo n.º 10
0
    def __init__(self, flow_graph, n):
        """
		Make a new block from nested data.
		@param flow graph the parent element
		@param n the nested odict
		@return block a new block
		"""
        # build the block
        Element.__init__(self, flow_graph)
        # grab the data
        params = n.findall("param")
        sources = n.findall("source")
        sinks = n.findall("sink")
        self._name = n.find("name")
        self._key = n.find("key")
        self._category = n.find("category") or ""
        self._grc_source = n.find("grc_source") or ""
        self._block_wrapper_path = n.find("block_wrapper_path")
        # create the param objects
        self._params = list()
        # add the id param
        self.get_params().append(
            self.get_parent().get_parent().Param(block=self, n=odict({"name": "ID", "key": "id", "type": "id"}))
        )
        self.get_params().append(
            self.get_parent()
            .get_parent()
            .Param(
                block=self,
                n=odict({"name": "Enabled", "key": "_enabled", "type": "raw", "value": "True", "hide": "all"}),
            )
        )
        for param in map(lambda n: self.get_parent().get_parent().Param(block=self, n=n), params):
            key = param.get_key()
            # test against repeated keys
            if key in self.get_param_keys():
                raise Exception, 'Key "%s" already exists in params' % key
                # store the param
            self.get_params().append(param)
            # create the source objects
        self._sources = list()
        for source in map(lambda n: self.get_parent().get_parent().Port(block=self, n=n, dir="source"), sources):
            key = source.get_key()
            # test against repeated keys
            if key in self.get_source_keys():
                raise Exception, 'Key "%s" already exists in sources' % key
                # store the port
            self.get_sources().append(source)
            # create the sink objects
        self._sinks = list()
        for sink in map(lambda n: self.get_parent().get_parent().Port(block=self, n=n, dir="sink"), sinks):
            key = sink.get_key()
            # test against repeated keys
            if key in self.get_sink_keys():
                raise Exception, 'Key "%s" already exists in sinks' % key
                # store the port
            self.get_sinks().append(sink)
Exemplo n.º 11
0
	def __init__(self, title=u'', subtitle=u'',
				x=0.0, y=0.0, width=100.0, height=50.0,
				id=u'', classes=(),
				titleid=u'', titleclasses=(),
				subtitleid=u'', subtitleclasses=(),
				border=False, borderid=u'', borderclasses=()):
		"""
		@param title: The text of the title
		@type title: string
		@param subtitle: The text of the subtitle
		@type subtitle: string or None
		@param x: The x coordinate to draw the title element at
		@param y: The y coordinate to draw the title element at
		@param width: The width of the title element (used for centering)
		@param height: The height of the title element (used for centering)

		@param id: The unique ID to be used in the SVG document
		@type id: string
		@param classes: Classnames to be used in the SVG document
		@type classes: string or sequence of strings

		@param titleid: The SVG document ID of the title text
		@type titleid: string
		@param titleclasses: Classnames to be applied to the title text
		@type titleclasses: string or sequence of strings

		@param subtitleid: The SVG document ID of the subtitle text
		@type subtitleid: string
		@param subtitleclasses: Classnames to be applied to the subtitle text
		@type subtitleclasses: string or sequence of strings

		@param border: Flag designating whether or not to draw a border
		@type border: boolean
		@param borderid: The SVG document ID of the title element's border
		@type borderid: string
		@param borderclasses: Classnames to be applied to the title element's border
		@type borderclasses: string or sequence of strings
		"""

		Element.__init__(self)

		self.title = title
		self.subtitle = subtitle
		self.x = x
		self.y = y
		self.width = width
		self.height = height
		self.id = id
		self.classes = classes
		self.titleid = titleid
		self.titleclasses = titleclasses
		self.subtitleid = subtitleid
		self.subtitleclasses = subtitleclasses
		self.border = border
		self.borderid = borderid
		self.borderclasses = borderclasses
Exemplo n.º 12
0
 def __init__(self):
     """
     Port contructor.
     Create list of connector coordinates.
     """
     Element.__init__(self)
     self.W = self.H = self.w = self.h = 0
     self._connector_coordinate = (0,0)
     self._connector_length = 0
     self._label_hidden = True
Exemplo n.º 13
0
	def __init__(self, platform):
		"""
		Make a flow graph from the arguments.
		@param platform a platforms with blocks and contrcutors
		@return the flow graph object
		"""
		#initialize
		Element.__init__(self, platform)
		#inital blank import
		self.import_data()
Exemplo n.º 14
0
    def __init__(self, description, type='', target='', tip='', icon='', **kwds):
        Element.__init__(self, 'a', **kwds)

        self.description = description
        self.type = type
        self.target = target
        self.tip = tip
        self.icon = icon

        return
Exemplo n.º 15
0
    def __init__(self, block, n):
        """
        Make a new param from nested data.

        Args:
            block: the parent element
            n: the nested odict
        """
        # if the base key is a valid param key, copy its data and overlay this params data
        base_key = n.find('base_key')
        if base_key and base_key in block.get_param_keys():
            n_expanded = block.get_param(base_key)._n.copy()
            n_expanded.update(n)
            n = n_expanded
        # save odict in case this param will be base for another
        self._n = n
        # parse the data
        self._name = n.find('name')
        self._key = n.find('key')
        value = n.find('value') or ''
        self._type = n.find('type') or 'raw'
        self._hide = n.find('hide') or ''
        self._tab_label = n.find('tab') or block.get_param_tab_labels()[0]
        if not self._tab_label in block.get_param_tab_labels():
            block.get_param_tab_labels().append(self._tab_label)
        #build the param
        Element.__init__(self, block)
        #create the Option objects from the n data
        self._options = list()
        for option in map(lambda o: Option(param=self, n=o), n.findall('option')):
            key = option.get_key()
            #test against repeated keys
            if key in self.get_option_keys():
                raise Exception, 'Key "%s" already exists in options'%key
            #store the option
            self.get_options().append(option)
        #test the enum options
        if self.is_enum():
            #test against options with identical keys
            if len(set(self.get_option_keys())) != len(self.get_options()):
                raise Exception, 'Options keys "%s" are not unique.'%self.get_option_keys()
            #test against inconsistent keys in options
            opt_keys = self.get_options()[0].get_opt_keys()
            for option in self.get_options():
                if set(opt_keys) != set(option.get_opt_keys()):
                    raise Exception, 'Opt keys "%s" are not identical across all options.'%opt_keys
            #if a value is specified, it must be in the options keys
            self._value = value if value or value in self.get_option_keys() else self.get_option_keys()[0]
            if self.get_value() not in self.get_option_keys():
                raise Exception, 'The value "%s" is not in the possible values of "%s".'%(self.get_value(), self.get_option_keys())
        else: self._value = value or ''
        self._default = value
Exemplo n.º 16
0
	def __init__(self, entries=(), x=0.0, y=0.0,
				width=1.0, height=1.0, entryheight=12.0,
				title=u'Legend', titlesize=12.0,
				id=u'', classes=(),
				titleid=u'', titleclasses=(),
				border=False, borderid=u'', borderclasses=()):
		"""
		@param entries: The legend entries. A sequence of dictionaries in the format {'shape': Shape, 'text': string}
		@param x: The x coordinate of the legend
		@param y: The y coordinate of the legend
		@param width: The width of the legend
		@param height: The height of the legend
		@param entryheight: The height of each legend entry
		@param title: The title of the legend
		@type title: string or None
		@param titlesize: The size of the title text

		@param id: The unique ID to be used in the SVG document
		@type id: string
		@param classes: Classnames to be used in the SVG document
		@type classes: string or sequence of strings

		@param titleid: The SVG document ID of the title element
		@type titleid: string
		@param titleclasses: Classnames to be applied to the title element
		@type titleclasses: string or sequence of strings

		@param border: Flag designating whether or not to draw a border
		@type border: boolean
		@param borderid: The SVG document ID of the border element
		@type borderid: string
		@param borderclasses: Classnames to be applied to the border element
		@type borderclasses: string or sequence of strings
		"""

		Element.__init__(self, id=id, classes=classes)

		self.entries = entries
		self.x = x
		self.y = y
		self.width = width
		self.height = height
		self.title = title
		self.titlesize = titlesize
		self.entryheight = entryheight
		self.titleid = titleid
		self.titleclasses = titleclasses
		self.border = border
		self.borderid = borderid
		self.borderclasses = borderclasses
		self.entrymargin = 2.0
Exemplo n.º 17
0
    def __init__(self, block, n):
        """
		Make a new param from nested data.
		@param block the parent element
		@param n the nested odict
		"""
        # grab the data
        self._name = n.find("name")
        self._key = n.find("key")
        value = n.find("value") or ""
        self._type = n.find("type")
        self._hide = n.find("hide") or ""
        # build the param
        Element.__init__(self, block)
        # create the Option objects from the n data
        self._options = list()
        for option in map(lambda o: Option(param=self, n=o), n.findall("option")):
            key = option.get_key()
            # test against repeated keys
            try:
                assert key not in self.get_option_keys()
            except AssertionError:
                raise Exception, 'Key "%s" already exists in options' % key
            # store the option
            self.get_options().append(option)
            # test the enum options
        if self.is_enum():
            # test against options with identical keys
            try:
                assert len(set(self.get_option_keys())) == len(self.get_options())
            except AssertionError:
                raise Exception, 'Options keys "%s" are not unique.' % self.get_option_keys()
            # test against inconsistent keys in options
            opt_keys = self.get_options()[0].get_opt_keys()
            for option in self.get_options():
                try:
                    assert set(opt_keys) == set(option.get_opt_keys())
                except AssertionError:
                    raise Exception, 'Opt keys "%s" are not identical across all options.' % opt_keys
                # if a value is specified, it must be in the options keys
            self._value = value if value or value in self.get_option_keys() else self.get_option_keys()[0]
            try:
                assert self.get_value() in self.get_option_keys()
            except AssertionError:
                raise Exception, 'The value "%s" is not in the possible values of "%s".' % (
                    self.get_value(),
                    self.get_option_keys(),
                )
        else:
            self._value = value or ""
Exemplo n.º 18
0
	def __init__(self, block, n, dir):
		"""
		Make a new port from nested data.
		@param block the parent element
		@param n the nested odict
		@param dir the direction source or sink
		"""
		#build the port
		Element.__init__(self, block)
		#grab the data
		self._name = n['name']
		self._key = n['key']
		self._type = n['type']
		self._dir = dir
Exemplo n.º 19
0
    def __init__(self, platform):
        """
        Make a flow graph from the arguments.

        Args:
            platform: a platforms with blocks and contrcutors

        Returns:
            the flow graph object
        """
        # initialize
        Element.__init__(self, platform)
        self._elements = []
        self._timestamp = time.ctime()
        # inital blank import
        self.import_data()
Exemplo n.º 20
0
	def __init__(self, block, n):
		"""
		Make a new port from nested data.
		@param block the parent element
		@param n the nested odict
		@return a new port
		"""
		#grab the data
		name = n['name']
		key = n['key']
		type = n['type']
		#build the port
		Element.__init__(self, block)
		self._name = name
		self._key = key
		self._type = type
Exemplo n.º 21
0
    def __init__(self, *args, **kwargs):
        """
		FlowGraph contructor.
		Create a list for signal blocks and connections. Connect mouse handlers.
		"""
        Element.__init__(self)
        # when is the flow graph selected? (used by keyboard event handler)
        self.is_selected = lambda: bool(self.get_selected_elements())
        # important vars dealing with mouse event tracking
        self.element_moved = False
        self.mouse_pressed = False
        self.unselect()
        self.press_coor = (0, 0)
        # selected ports
        self._old_selected_port = None
        self._new_selected_port = None
Exemplo n.º 22
0
    def __init__(self, name, version, key,
                 block_paths, block_dtd, default_flow_graph, generator,
                 license='', website=None, colors=None):
        """
        Make a platform from the arguments.

        Args:
            name: the platform name
            version: the version string
            key: the unique platform key
            block_paths: the file paths to blocks in this platform
            block_dtd: the dtd validator for xml block wrappers
            default_flow_graph: the default flow graph file path
            generator: the generator class for this platform
            colors: a list of title, color_spec tuples
            license: a multi-line license (first line is copyright)
            website: the website url for this platform

        Returns:
            a platform object
        """
        _Element.__init__(self)
        self._name = name
        # Save the verion string to the first
        self._version = version[0]
        self._version_major = version[1]
        self._version_api = version[2]
        self._version_minor = version[3]
        self._version_short = version[1] + "." + version[2] + "." + version[3]

        self._key = key
        self._license = license
        self._website = website
        self._block_paths = list(set(block_paths))
        self._block_dtd = block_dtd
        self._default_flow_graph = default_flow_graph
        self._generator = generator
        self._colors = colors or []
        #create a dummy flow graph for the blocks
        self._flow_graph = _Element(self)

        self._blocks = None
        self._blocks_n = None
        self._category_trees_n = None
        self._domains = dict()
        self._connection_templates = dict()
        self.load_blocks()
    def __init__( self, name, shape = None, children = None,
                  **attributes):
        Element.__init__(self, name, shape, **attributes)

        from IdGenerator import IdGenerator
        self._idGenerator = IdGenerator()

        #containers
        self._elements = []
        self._id2element = {}
        self._name2element = {}
        self._name2id = {}

        #add children
        if children is None: children = []
        for child in children: self.addElement( child )
        return
Exemplo n.º 24
0
    def __init__(self, block, n, dir):
        """
        Make a new port from nested data.

        Args:
            block: the parent element
            n: the nested odict
            dir: the direction source or sink
        """
        #build the port
        Element.__init__(self, block)
        #grab the data
        self._name = n['name']
        self._key = n['key']
        self._type = n['type']
        self._hide = n.find('hide') or ''
        self._dir = dir
Exemplo n.º 25
0
	def __init__(self, flow_graph, porta, portb):
		"""
		Make a new connection given the parent and 2 ports.
		
		Args:
		    flow_graph: the parent of this element
		    porta: a port (any direction)
		    portb: a port (any direction)
		@throws Error cannot make connection
		
		Returns:
		    a new connection
		"""
		Element.__init__(self, flow_graph)
		source = sink = None
		#separate the source and sink
		for port in (porta, portb):
			if port.is_source(): source = port
			if port.is_sink(): sink = port
		if not source: raise ValueError('Connection could not isolate source')
		if not sink: raise ValueError('Connection could not isolate sink')

		busses = len(filter(lambda a: a.get_type() == 'bus', [source, sink]))%2
		if not busses == 0: raise ValueError('busses must get with busses')

		if not len(source.get_associated_ports()) == len(sink.get_associated_ports()):
			raise ValueError('port connections must have same cardinality');
		#ensure that this connection (source -> sink) is unique
		for connection in self.get_parent().get_connections():
			if connection.get_source() is source and connection.get_sink() is sink:
				raise Exception('This connection between source and sink is not unique.')
		self._source = source
		self._sink = sink
		
		if source.get_type() == 'bus':
			
			sources = source.get_associated_ports();
			sinks = sink.get_associated_ports();
			
			for i in range(len(sources)):
				try:
					flow_graph.connect(sources[i], sinks[i]);
				except:
					pass
Exemplo n.º 26
0
    def __init__(self, block, n, dir):
        """
        Make a new port from nested data.

        Args:
            block: the parent element
            n: the nested odict
            dir: the direction source or sink
        """
        # build the port
        Element.__init__(self, block)
        # grab the data
        self._name = n["name"]
        self._key = n["key"]
        self._type = n["type"]
        self._domain = n["domain"]
        self._hide = n.find("hide") or ""
        self._dir = dir
        self._hide_evaluated = False  # updated on rewrite()
Exemplo n.º 27
0
 def __init__(self, param, n):
     Element.__init__(self, param)
     self._name = n.find('name')
     self._key = n.find('key')
     self._opts = dict()
     opts = n.findall('opt')
     #test against opts when non enum
     if not self.get_parent().is_enum() and opts:
         raise Exception, 'Options for non-enum types cannot have sub-options'
     #extract opts
     for opt in opts:
         #separate the key:value
         try: key, value = opt.split(':')
         except: raise Exception, 'Error separating "%s" into key:value'%opt
         #test against repeated keys
         if self._opts.has_key(key):
             raise Exception, 'Key "%s" already exists in option'%key
         #store the option
         self._opts[key] = value
Exemplo n.º 28
0
    def __init__(self, block, n, dir):
        """
        Make a new port from nested data.

        Args:
            block: the parent element
            n: the nested odict
            dir: the direction source or sink
        """
        #build the port
        Element.__init__(self, block)
        #grab the data
        self._name = n['name']
        self._key = n['key']
        self._type = n['type']
        self._domain = n['domain']
        self._hide = n.find('hide') or ''
        self._dir = dir
        self._type_evaluated = None  # updated on rewrite()
        self._hide_evaluated = False  # updated on rewrite()
Exemplo n.º 29
0
 def __init__(self, param, n):
     Element.__init__(self, param)
     self._name = n.find('name')
     self._key = n.find('key')
     self._opts = dict()
     opts = n.findall('opt')
     #test against opts when non enum
     if not self.get_parent().is_enum() and opts:
         raise Exception, 'Options for non-enum types cannot have sub-options'
     #extract opts
     for opt in opts:
         #separate the key:value
         try:
             key, value = opt.split(':')
         except:
             raise Exception, 'Error separating "%s" into key:value' % opt
         #test against repeated keys
         if self._opts.has_key(key):
             raise Exception, 'Key "%s" already exists in option' % key
         #store the option
         self._opts[key] = value
Exemplo n.º 30
0
 def __init__(self):
     """
     FlowGraph constructor.
     Create a list for signal blocks and connections. Connect mouse handlers.
     """
     Element.__init__(self)
     #when is the flow graph selected? (used by keyboard event handler)
     self.is_selected = lambda: bool(self.get_selected_elements())
     #important vars dealing with mouse event tracking
     self.element_moved = False
     self.mouse_pressed = False
     self.unselect()
     self.press_coor = (0, 0)
     #selected ports
     self._old_selected_port = None
     self._new_selected_port = None
     # current mouse hover element
     self.element_under_mouse = None
     #context menu
     self._context_menu = Bars.ContextMenu()
     self.get_context_menu = lambda: self._context_menu
Exemplo n.º 31
0
 def __init__(self, block, n):
     """
     Make a new param from nested data.
     
     Args:
         block: the parent element
         n: the nested odict
     """
     #grab the data
     self._name = n.find('name')
     self._key = n.find('key')
     value = n.find('value') or ''
     self._type = n.find('type')
     self._hide = n.find('hide') or ''
     #build the param
     Element.__init__(self, block)
     #create the Option objects from the n data
     self._options = list()
     for option in map(lambda o: Option(param=self, n=o), n.findall('option')):
         key = option.get_key()
         #test against repeated keys
         if key in self.get_option_keys():
             raise Exception, 'Key "%s" already exists in options'%key
         #store the option
         self.get_options().append(option)
     #test the enum options
     if self.is_enum():
         #test against options with identical keys
         if len(set(self.get_option_keys())) != len(self.get_options()):
             raise Exception, 'Options keys "%s" are not unique.'%self.get_option_keys()
         #test against inconsistent keys in options
         opt_keys = self.get_options()[0].get_opt_keys()
         for option in self.get_options():
             if set(opt_keys) != set(option.get_opt_keys()):
                 raise Exception, 'Opt keys "%s" are not identical across all options.'%opt_keys
         #if a value is specified, it must be in the options keys
         self._value = value if value or value in self.get_option_keys() else self.get_option_keys()[0]
         if self.get_value() not in self.get_option_keys():
             raise Exception, 'The value "%s" is not in the possible values of "%s".'%(self.get_value(), self.get_option_keys())
     else: self._value = value or ''
Exemplo n.º 32
0
    def __init__(self, n, d, p, c, nb):
        """
		:param n	: name
		:param d	: depth
		:param p	: parent
		:param c	: model container
		:param nb	: nb_instances
		"""
        Element.__init__(self, n, d)

        if nb.values[0] is not None:
            self.__check_nb_instances(nb.values[0])
        self.__nb_instances = nb
        self.__constraints = {}
        self.__parent = p
        self.__is_done = False

        self.__containers = []
        if c is None:
            self.__containers.append(Container())
        else:
            self.__containers.append(c)
Exemplo n.º 33
0
    def __init__(self, flow_graph, porta, portb):
        """
		Make a new connection given the parent and 2 ports.
		@param flow_graph the parent of this element
		@param porta a port (any direction)
		@param portb a port (any direction)
		@throws Error cannot make connection
		@return a new connection
		"""
        Element.__init__(self, flow_graph)
        source = sink = None
        #separate the source and sink
        for port in (porta, portb):
            if port.is_source(): source = port
            if port.is_sink(): sink = port
        assert (source and sink)
        #ensure that this connection (source -> sink) is unique
        for connection in self.get_parent().get_connections():
            assert not (connection.get_source() is source
                        and connection.get_sink() is sink)
        self._source = source
        self._sink = sink
Exemplo n.º 34
0
 def __init__(self):
     """
     FlowGraph constructor.
     Create a list for signal blocks and connections. Connect mouse handlers.
     """
     Element.__init__(self)
     #when is the flow graph selected? (used by keyboard event handler)
     self.is_selected = lambda: bool(self.get_selected_elements())
     #important vars dealing with mouse event tracking
     self.element_moved = False
     self.mouse_pressed = False
     self.unselect()
     self.press_coor = (0, 0)
     #selected ports
     self._old_selected_port = None
     self._new_selected_port = None
     # current mouse hover element
     self.element_under_mouse = None
     #context menu
     self._context_menu = gtk.Menu()
     for action in [
         Actions.BLOCK_CUT,
         Actions.BLOCK_COPY,
         Actions.BLOCK_PASTE,
         Actions.ELEMENT_DELETE,
         None,
         Actions.BLOCK_ROTATE_CCW,
         Actions.BLOCK_ROTATE_CW,
         Actions.BLOCK_ENABLE,
         Actions.BLOCK_DISABLE,
         None,
         Actions.BLOCK_CREATE_HIER,
         Actions.OPEN_HIER,
         Actions.BUSSIFY_SOURCES,
         Actions.BUSSIFY_SINKS,
         None,
         Actions.BLOCK_PARAM_MODIFY
     ]: self._context_menu.append(action.create_menu_item() if action else gtk.SeparatorMenuItem())
     self.get_context_menu = lambda: self._context_menu
Exemplo n.º 35
0
    def __init__(self, name, version, key,
                 block_paths, block_dtd, default_flow_graph, generator,
                 license='', website=None, colors=None):
        """
        Make a platform from the arguments.

        Args:
            name: the platform name
            version: the version string
            key: the unique platform key
            block_paths: the file paths to blocks in this platform
            block_dtd: the dtd validator for xml block wrappers
            default_flow_graph: the default flow graph file path
            generator: the generator class for this platform
            colors: a list of title, color_spec tuples
            license: a multi-line license (first line is copyright)
            website: the website url for this platform

        Returns:
            a platform object
        """
        _Element.__init__(self)
        self._name = name
        self._version = version
        self._key = key
        self._license = license
        self._website = website
        self._block_paths = block_paths
        self._block_dtd = block_dtd
        self._default_flow_graph = default_flow_graph
        self._generator = generator
        self._colors = colors or []
        #create a dummy flow graph for the blocks
        self._flow_graph = _Element(self)

        self._blocks = None
        self._blocks_n = None
        self._category_trees_n = None
        self.load_blocks()
Exemplo n.º 36
0
	def __init__(self, block, n):
		"""
		Make a new param from nested data.
		@param block the parent element
		@param n the nested odict
		"""
		#grab the data
		self._name = n.find('name')
		self._key = n.find('key')
		value = n.find('value') or ''
		self._type = n.find('type')
		self._hide = n.find('hide') or ''
		#build the param
		Element.__init__(self, block)
		#create the Option objects from the n data
		self._options = list()
		for option in map(lambda o: Option(param=self, n=o), n.findall('option')):
			key = option.get_key()
			#test against repeated keys
			if key in self.get_option_keys():
				raise Exception, 'Key "%s" already exists in options'%key
			#store the option
			self.get_options().append(option)
		#test the enum options
		if self.is_enum():
			#test against options with identical keys
			if len(set(self.get_option_keys())) != len(self.get_options()):
				raise Exception, 'Options keys "%s" are not unique.'%self.get_option_keys()
			#test against inconsistent keys in options
			opt_keys = self.get_options()[0].get_opt_keys()
			for option in self.get_options():
				if set(opt_keys) != set(option.get_opt_keys()):
					raise Exception, 'Opt keys "%s" are not identical across all options.'%opt_keys
			#if a value is specified, it must be in the options keys
			self._value = value if value or value in self.get_option_keys() else self.get_option_keys()[0]
			if self.get_value() not in self.get_option_keys():
				raise Exception, 'The value "%s" is not in the possible values of "%s".'%(self.get_value(), self.get_option_keys())
		else: self._value = value or ''
Exemplo n.º 37
0
    def __init__(self, n, d, p, e, t=[], q=[], r=[]):
        """
		:param n		: name
		:param d		: depth
		:param p		: parent
		:param e		: expressions
		:param t		: types
		:param q		: quantifiers
		:param r		: ranges
		"""
        Element.__init__(self, n, d)

        self.__parent = p
        self.__var_depth = -1

        self.__basic_checks(e)
        self.__raw_expressions = e
        self.__quantifiers = []
        for i, n in enumerate(q):
            self.__quantifiers.append(Quantifier(n, r[i][0], r[i][1], t[i]))

        self.__expressions = []
        self.__variables = {}
Exemplo n.º 38
0
    def __init__(self,
                 id,
                 name,
                 label,
                 value='',
                 embeddedText='',
                 help='',
                 error='',
                 type='button',
                 **kwds):
        Element.__init__(self,
                         tag='button',
                         id=id,
                         name=name,
                         type=type,
                         value=value,
                         **kwds)

        self.label = label
        self.embeddedText = embeddedText
        self.help = help
        self.error = error

        return
Exemplo n.º 39
0
    def __init__(self, flow_graph, n):
        """
		Make a new block from nested data.
		@param flow graph the parent element
		@param n the nested odict
		@return block a new block
		"""
        #build the block
        Element.__init__(self, flow_graph)
        #grab the data
        params = n.findall('param')
        sources = n.findall('source')
        sinks = n.findall('sink')
        self._name = n.find('name')
        self._key = n.find('key')
        self._category = n.find('category') or ''
        self._block_wrapper_path = n.find('block_wrapper_path')
        #create the param objects
        self._params = list()
        #add the id param
        self.get_params().append(self.get_parent().get_parent().Param(
            block=self, n=odict({
                'name': 'ID',
                'key': 'id',
                'type': 'id',
            })))
        self.get_params().append(self.get_parent().get_parent().Param(
            block=self,
            n=odict({
                'name': 'Enabled',
                'key': '_enabled',
                'type': 'raw',
                'value': 'True',
                'hide': 'all',
            })))
        for param in map(
                lambda n: self.get_parent().get_parent().Param(block=self, n=n
                                                               ), params):
            key = param.get_key()
            #test against repeated keys
            if key in self.get_param_keys():
                raise Exception, 'Key "%s" already exists in params' % key
            #store the param
            self.get_params().append(param)
        #create the source objects
        self._sources = list()
        for source in map(
                lambda n: self.get_parent().get_parent().Port(
                    block=self, n=n, dir='source'), sources):
            key = source.get_key()
            #test against repeated keys
            if key in self.get_source_keys():
                raise Exception, 'Key "%s" already exists in sources' % key
            #store the port
            self.get_sources().append(source)
        #create the sink objects
        self._sinks = list()
        for sink in map(
                lambda n: self.get_parent().get_parent().Port(
                    block=self, n=n, dir='sink'), sinks):
            key = sink.get_key()
            #test against repeated keys
            if key in self.get_sink_keys():
                raise Exception, 'Key "%s" already exists in sinks' % key
            #store the port
            self.get_sinks().append(sink)
Exemplo n.º 40
0
    def __init__(self):
        Element.__init__(self, 'div', cls='portletContent')

        self.content = None

        return
Exemplo n.º 41
0
    def __init__(self,
                 name,
                 version,
                 key,
                 block_paths,
                 block_dtd,
                 default_flow_graph,
                 generator,
                 license='',
                 website=None,
                 colors=[]):
        """
		Make a platform from the arguments.
		@param name the platform name
		@param version the version string
		@param key the unique platform key
		@param block_paths the file paths to blocks in this platform
		@param block_dtd the dtd validator for xml block wrappers
		@param default_flow_graph the default flow graph file path
		@param generator the generator class for this platform
		@param colors a list of title, color_spec tuples
		@param license a multi-line license (first line is copyright)
		@param website the website url for this platform
		@return a platform object
		"""
        _Element.__init__(self)
        self._name = name
        self._version = version
        self._key = key
        self._license = license
        self._website = website
        self._block_paths = block_paths
        self._block_dtd = block_dtd
        self._default_flow_graph = default_flow_graph
        self._generator = generator
        self._colors = colors
        #create a dummy flow graph for the blocks
        self._flow_graph = _Element(self)
        #search for *.xml files in the given search path
        xml_files = list()
        for block_path in self._block_paths:
            if os.path.isfile(block_path): xml_files.append(block_path)
            elif os.path.isdir(block_path):
                for dirpath, dirnames, filenames in os.walk(block_path):
                    for filename in sorted(
                            filter(lambda f: f.endswith('.xml'), filenames)):
                        xml_files.append(os.path.join(dirpath, filename))
        #load the blocks
        self._blocks = odict()
        self._blocks_n = odict()
        self._block_tree_files = list()
        for xml_file in xml_files:
            try:  #try to add the xml file as a block wrapper
                ParseXML.validate_dtd(xml_file, self._block_dtd)
                n = ParseXML.from_file(xml_file).find('block')
                #inject block wrapper path
                n['block_wrapper_path'] = xml_file
                block = self.Block(self._flow_graph, n)
                key = block.get_key()
                #test against repeated keys
                if key in self.get_block_keys():
                    print >> sys.stderr, 'Warning: Block with key "%s" already exists.\n\tIgnoring: %s' % (
                        key, xml_file)
                #store the block
                else:
                    self._blocks[key] = block
                    self._blocks_n[key] = n
            except ParseXML.XMLSyntaxError, e:
                try:  #try to add the xml file as a block tree
                    ParseXML.validate_dtd(xml_file, BLOCK_TREE_DTD)
                    self._block_tree_files.append(xml_file)
                except ParseXML.XMLSyntaxError, e:
                    print >> sys.stderr, 'Warning: Block validation failed:\n\t%s\n\tIgnoring: %s' % (
                        e, xml_file)
Exemplo n.º 42
0
 def __init__(self, value):
     Element.__init__(self)
     self.value = int(value)
     self.symbol = str(value)
Exemplo n.º 43
0
    def __init__(self): Element.__init__(self)

    def get_input(self, *args, **kwargs):
Exemplo n.º 44
0
 def __init__(self, **kwds):
     Element.__init__(self, 'link', **kwds)
     return
Exemplo n.º 45
0
 def __init__(self, title):
     Element.__init__(self, 'title')
     self.title = title
     return
Exemplo n.º 46
0
 def __init__(self, **kwds):
     Element.__init__(self, 'style', **kwds)
     self.style = []
     return
Exemplo n.º 47
0
    def __init__(self, **kwds):
        Element.__init__(self, 'pre', **kwds)

        self.text = []
        return
Exemplo n.º 48
0
 def __init__(self):
     Element.__init__(self)
Exemplo n.º 49
0
 def __init__(self, control=None):
     Element.__init__(self, tag='div', cls="formfield")
     self.control = control
     return
Exemplo n.º 50
0
 def __init__(self, url):
     Element.__init__(self, 'base', href=url)
     return
Exemplo n.º 51
0
 def __init__(self, symbol, value=None):
     Element.__init__(self)
     self.value = value
     self.symbol = str(symbol)
Exemplo n.º 52
0
    def __init__(self, prefs_file):
        Element.__init__(self)

        self._prefs_file = prefs_file
Exemplo n.º 53
0
    def __init__(self, flow_graph, n):
        """
        Make a new block from nested data.

        Args:
            flow: graph the parent element
            n: the nested odict

        Returns:
            block a new block
        """
        #build the block
        Element.__init__(self, flow_graph)
        #grab the data
        params = n.findall('param')
        sources = n.findall('source')
        sinks = n.findall('sink')
        self._name = n.find('name')
        self._key = n.find('key')
        self._category = n.find('category') or ''
        self._grc_source = n.find('grc_source') or ''
        self._block_wrapper_path = n.find('block_wrapper_path')
        self._bussify_sink = n.find('bus_sink')
        self._bussify_source = n.find('bus_source')
        self._var_value = n.find('var_value') or '$value'

        # get list of param tabs
        n_tabs = n.find('param_tab_order') or None
        self._param_tab_labels = n_tabs.findall('tab') if n_tabs is not None else [DEFAULT_PARAM_TAB]

        #create the param objects
        self._params = list()
        #add the id param
        self.get_params().append(self.get_parent().get_parent().Param(
            block=self,
            n=odict({
                'name': 'ID',
                'key': 'id',
                'type': 'id',
            })
        ))
        self.get_params().append(self.get_parent().get_parent().Param(
            block=self,
            n=odict({
                'name': 'Enabled',
                'key': '_enabled',
                'type': 'raw',
                'value': 'True',
                'hide': 'all',
            })
        ))
        for param in imap(lambda n: self.get_parent().get_parent().Param(block=self, n=n), params):
            key = param.get_key()
            #test against repeated keys
            if key in self.get_param_keys():
                raise Exception, 'Key "%s" already exists in params'%key
            #store the param
            self.get_params().append(param)
        #create the source objects
        self._sources = list()
        for source in map(lambda n: self.get_parent().get_parent().Port(block=self, n=n, dir='source'), sources):
            key = source.get_key()
            #test against repeated keys
            if key in self.get_source_keys():
                raise Exception, 'Key "%s" already exists in sources'%key
            #store the port
            self.get_sources().append(source)
        self.back_ofthe_bus(self.get_sources())
        #create the sink objects
        self._sinks = list()
        for sink in map(lambda n: self.get_parent().get_parent().Port(block=self, n=n, dir='sink'), sinks):
            key = sink.get_key()
            #test against repeated keys
            if key in self.get_sink_keys():
                raise Exception, 'Key "%s" already exists in sinks'%key
            #store the port
            self.get_sinks().append(sink)
        self.back_ofthe_bus(self.get_sinks())
        self.current_bus_structure = {'source':'','sink':''};

        # Virtual source/sink and pad source/sink blocks are
        # indistinguishable from normal GR blocks. Make explicit
        # checks for them here since they have no work function or
        # buffers to manage.
        is_not_virtual_or_pad = ((self._key != "virtual_source") \
                                     and (self._key != "virtual_sink") \
                                     and (self._key != "pad_source") \
                                     and (self._key != "pad_sink"))
        is_variable = self._key.startswith('variable')

        if is_not_virtual_or_pad and not is_variable:
            self.get_params().append(self.get_parent().get_parent().Param(
                block=self,
                n=odict({'name': 'Block Alias',
                         'key': 'alias',
                         'type': 'string',
                         'hide': 'part',
                         'tab': ADVANCED_PARAM_TAB
                     })
            ))

        if (len(sources) or len(sinks)) and is_not_virtual_or_pad:
            self.get_params().append(self.get_parent().get_parent().Param(
                    block=self,
                    n=odict({'name': 'Core Affinity',
                             'key': 'affinity',
                             'type': 'int_vector',
                             'hide': 'part',
                             'tab': ADVANCED_PARAM_TAB
                             })
                    ))
        if len(sources) and is_not_virtual_or_pad:
            self.get_params().append(self.get_parent().get_parent().Param(
                    block=self,
                    n=odict({'name': 'Min Output Buffer',
                             'key': 'minoutbuf',
                             'type': 'int',
                             'hide': 'part',
                             'value': '0',
                             'tab': ADVANCED_PARAM_TAB
                             })
                    ))
            self.get_params().append(self.get_parent().get_parent().Param(
                    block=self,
                    n=odict({'name': 'Max Output Buffer',
                             'key': 'maxoutbuf',
                             'type': 'int',
                             'hide': 'part',
                             'value': '0',
                             'tab': ADVANCED_PARAM_TAB
                             })
                    ))

        self.get_params().append(self.get_parent().get_parent().Param(
                block=self,
                n=odict({'name': 'Comment',
                         'key': 'comment',
                         'type': 'multiline',
                         'hide': 'part',
                         'value': '',
                         'tab': ADVANCED_PARAM_TAB
                         })
                ))
Exemplo n.º 54
0
 def __init__(self, url, **kwds):
     Element.__init__(self, 'style', **kwds)
     self.url = url
     return
Exemplo n.º 55
0
    def __init__(self,
                 title=u'',
                 subtitle=u'',
                 x=0.0,
                 y=0.0,
                 width=100.0,
                 height=50.0,
                 id=u'',
                 classes=(),
                 titleid=u'',
                 titleclasses=(),
                 subtitleid=u'',
                 subtitleclasses=(),
                 border=False,
                 borderid=u'',
                 borderclasses=()):
        """
		@param title: The text of the title
		@type title: string
		@param subtitle: The text of the subtitle
		@type subtitle: string or None
		@param x: The x coordinate to draw the title element at
		@param y: The y coordinate to draw the title element at
		@param width: The width of the title element (used for centering)
		@param height: The height of the title element (used for centering)

		@param id: The unique ID to be used in the SVG document
		@type id: string
		@param classes: Classnames to be used in the SVG document
		@type classes: string or sequence of strings

		@param titleid: The SVG document ID of the title text
		@type titleid: string
		@param titleclasses: Classnames to be applied to the title text
		@type titleclasses: string or sequence of strings

		@param subtitleid: The SVG document ID of the subtitle text
		@type subtitleid: string
		@param subtitleclasses: Classnames to be applied to the subtitle text
		@type subtitleclasses: string or sequence of strings

		@param border: Flag designating whether or not to draw a border
		@type border: boolean
		@param borderid: The SVG document ID of the title element's border
		@type borderid: string
		@param borderclasses: Classnames to be applied to the title element's border
		@type borderclasses: string or sequence of strings
		"""

        Element.__init__(self)

        self.title = title
        self.subtitle = subtitle
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.id = id
        self.classes = classes
        self.titleid = titleid
        self.titleclasses = titleclasses
        self.subtitleid = subtitleid
        self.subtitleclasses = subtitleclasses
        self.border = border
        self.borderid = borderid
        self.borderclasses = borderclasses
Exemplo n.º 56
0
 def __init__(self, tag, **attributes):
     Element.__init__(self, tag, **attributes)
     self.contents = []
     return
Exemplo n.º 57
0
 def __init__(self, **kwds):
     Element.__init__(self, 'script', **kwds)
     self.script = []
     return
Exemplo n.º 58
0
    def __init__(self,
                 name=_defaults['name'],
                 value=_defaults['value'],
                 scale=_defaults['scale'],
                 min=_defaults['min'],
                 max=_defaults['max'],
                 free=_defaults['free'],
                 dom=None,
                 *args,
                 **kwargs):
        """Initialize this Parameter.

        Parameters:

        self: This object.

        name: (string) Name of the Parameter.

        value: (float) Value of the Parameter.

        scale: (float) Scale factor for the Parameter value.

        min: (float) Minimum valid value of the Parameter. If None, no
        minimum checking is performed.

        max: (float) Maximum valid value of the Parameter. If None, no
        maximum checking is performed.

        free: (Boolean) True if the Parameter value can be adjusted by
        the likelihood estimator, False otherwise.

        dom (xml.dom.minidom.Element): DOM element to convert to this
        Parameter. If this parameter is specified, the other
        parameters are ignored.

        Return value:

        None.

        Description:

        Initialize this Parameter. All data attributes are set from
        the corresponding parameters. If a DOM element is provided,
        use the attribute nodes of that DOM element to set the data
        attributes of this Parameter.
        """

        # Initialize the parent class. Do not pass the dom parameter,
        # since it will be used if needed when fromDom() is called
        # below.
        Element.__init__(self, Parameter._tagName, *args, **kwargs)

        # Set attributes.
        if dom:
            if isinstance(dom, xml.dom.minidom.Element):
                self.fromDom(dom)
            else:
                raise TypeError('Not a DOM element (%s)!' % dom)
        else:
            self.setName(name)
            self.setMin(min)  # Set min, max before value to allow
            self.setMax(max)  # range checking when setValue() is called.
            self.setValue(value)
            self.setScale(scale)
            self.setFree(free)
Exemplo n.º 59
0
 def __init__(self):
     Element.__init__(self)
     # can't use Colors.CONNECTION_ENABLED_COLOR here, might not be defined (grcc)
     self._bg_color = self._arrow_color = self._color = None