diff options
Diffstat (limited to 'grc/gui')
-rw-r--r-- | grc/gui/Block.py | 31 | ||||
-rw-r--r-- | grc/gui/FlowGraph.py | 14 |
2 files changed, 19 insertions, 26 deletions
diff --git a/grc/gui/Block.py b/grc/gui/Block.py index a38e4cc59a..94887eeb89 100644 --- a/grc/gui/Block.py +++ b/grc/gui/Block.py @@ -45,13 +45,11 @@ class Block(Element, _Block): Add graphics related params to the block. """ _Block.__init__(self, flow_graph, n) - self.W = self.H = 0 - self._add_param(key='_coordinate', name='GUI Coordinate', value='(0, 0)', - hide='all') - self._add_param(key='_rotation', name='GUI Rotation', value='0', - hide='all') - Element.__init__(self) # needs the params + self.states.update(_coordinate=(0, 0), _rotation=0) + Element.__init__(self) # needs the states + + self.W = self.H = 0 self._param_layouts = [] self._comment_layout = None self._bg_color = Colors.BLOCK_ENABLED_COLOR @@ -64,13 +62,7 @@ class Block(Element, _Block): Returns: the coordinate tuple (x, y) or (0, 0) if failure """ - try: - coor = self.params['_coordinate'].get_value() # should evaluate to tuple - coor = tuple(int(x) for x in coor[1:-1].split(',')) - except: - coor = 0, 0 - self.set_coordinate(coor) - return coor + return self.states['_coordinate'] def set_coordinate(self, coor): """ @@ -85,7 +77,7 @@ class Block(Element, _Block): Utils.align_to_grid(coor[0] + offset_x) - offset_x, Utils.align_to_grid(coor[1] + offset_y) - offset_y ) - self.get_param('_coordinate').set_value(repr(coor)) + self.states['_coordinate'] = coor def get_rotation(self): """ @@ -94,21 +86,16 @@ class Block(Element, _Block): Returns: the rotation in degrees or 0 if failure """ - try: #should evaluate to dict - rotation = int(self.get_param('_rotation').get_value()) - except: - rotation = POSSIBLE_ROTATIONS[0] - self.set_rotation(rotation) - return rotation + return self.states['_rotation'] def set_rotation(self, rot): """ Set the rotation into the position param. - +q Args: rot: the rotation in degrees """ - self.get_param('_rotation').set_value(repr(int(rot))) + self.states['_rotation'] = rot def create_shapes(self): """Update the block, parameters, and ports when a change occurs.""" diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py index 87bd91d880..d592242e2e 100644 --- a/grc/gui/FlowGraph.py +++ b/grc/gui/FlowGraph.py @@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA from __future__ import absolute_import import functools +import ast import random from distutils.spawn import find_executable from itertools import count @@ -219,12 +220,17 @@ class FlowGraph(Element, _Flowgraph): continue # unknown block was pasted (e.g. dummy block) selected.add(block) #set params - params = {n['key']: n['value'] for n in block_n.get('param', [])} + param_data = {n['key']: n['value'] for n in block_n.get('param', [])} + for key in block.states: + try: + block.states[key] = ast.literal_eval(param_data.pop(key)) + except (KeyError, SyntaxError, ValueError): + pass if block_key == 'epy_block': - block.get_param('_io_cache').set_value(params.pop('_io_cache')) - block.get_param('_source_code').set_value(params.pop('_source_code')) + block.get_param('_io_cache').set_value(param_data.pop('_io_cache')) + block.get_param('_source_code').set_value(param_data.pop('_source_code')) block.rewrite() # this creates the other params - for param_key, param_value in six.iteritems(params): + for param_key, param_value in six.iteritems(param_data): #setup id parameter if param_key == 'id': old_id2block[param_value] = block |