[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 29/101: grc: refactor: block states are no
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 29/101: grc: refactor: block states are no longer hidden params |
Date: |
Thu, 16 Mar 2017 14:58:02 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch python3
in repository gnuradio.
commit 020878e8468d848cebe1bfe5b0dc7c9b557214f7
Author: Sebastian Koslowski <address@hidden>
Date: Sun Jun 19 20:39:22 2016 -0700
grc: refactor: block states are no longer hidden params
---
grc/core/Block.py | 49 ++++++++++++++++++++++++++++++-------------------
grc/gui/Block.py | 31 +++++++++----------------------
grc/gui/FlowGraph.py | 14 ++++++++++----
3 files changed, 49 insertions(+), 45 deletions(-)
diff --git a/grc/core/Block.py b/grc/core/Block.py
index ec65a1a..013f2cd 100644
--- a/grc/core/Block.py
+++ b/grc/core/Block.py
@@ -21,6 +21,7 @@ from __future__ import absolute_import
import collections
import itertools
+import ast
import six
from six.moves import map, range
@@ -31,7 +32,7 @@ from . import utils
from . Constants import (
BLOCK_FLAG_NEED_QT_GUI, BLOCK_FLAG_NEED_WX_GUI,
- ADVANCED_PARAM_TAB, DEFAULT_PARAM_TAB,
+ ADVANCED_PARAM_TAB,
BLOCK_FLAG_THROTTLE, BLOCK_FLAG_DISABLE_BYPASS,
BLOCK_FLAG_DEPRECATED,
)
@@ -101,6 +102,8 @@ class Block(Element):
self.sources = self._init_ports(sources_n, direction='source')
self.sinks = self._init_ports(sinks_n, direction='sink')
+ self.states = {'_enabled': True}
+
self._epy_source_hash = -1 # for epy blocks
self._epy_reload_error = None
@@ -113,7 +116,6 @@ class Block(Element):
def _init_params(self, params_n, has_sources, has_sinks):
self._add_param(key='id', name='ID', type='id')
- self._add_param(key='_enabled', name='Enabled', value='True',
type='raw', hide='all')
# Virtual source/sink and pad source/sink blocks are
# indistinguishable from normal GR blocks. Make explicit
@@ -409,7 +411,7 @@ class Block(Element):
DISABLED - 2
"""
try:
- return self.STATE_LABELS[int(self.params['_enabled'].get_value())]
+ return self.STATE_LABELS[int(self.states['_enabled'])]
except ValueError:
return 'enabled'
@@ -424,10 +426,10 @@ class Block(Element):
DISABLED - 2
"""
try:
- encoded = str(self.STATE_LABELS.index(value))
+ encoded = self.STATE_LABELS.index(value)
except ValueError:
- encoded = str(self.STATE_LABELS.index('enabled'))
- self.params['_enabled'].set_value(encoded)
+ encoded = 1
+ self.states['_enabled'] = encoded
# Enable/Disable Aliases
def get_enabled(self):
@@ -643,11 +645,16 @@ class Block(Element):
"""
n = collections.OrderedDict()
n['key'] = self.key
- n['param'] = [param.export_data() for _, param in
sorted(six.iteritems(self.params))]
- if 'bus' in [a.get_type() for a in self.sinks]:
- n['bus_sink'] = str(1)
- if 'bus' in [a.get_type() for a in self.sources]:
- n['bus_source'] = str(1)
+
+ params = (param.export_data() for param in six.itervalues(self.params))
+ states = (collections.OrderedDict([('key', key), ('value',
repr(value))])
+ for key, value in six.iteritems(self.states))
+ n['param'] = sorted(itertools.chain(states, params), key=lambda p:
p['key'])
+
+ if any('bus' in a.get_type() for a in self.sinks):
+ n['bus_sink'] = '1'
+ if any('bus' in a.get_type() for a in self.sources):
+ n['bus_source'] = '1'
return n
def import_data(self, n):
@@ -662,22 +669,26 @@ class Block(Element):
Args:
n: the nested data odict
"""
- params_n = n.get('param', [])
+ param_data = {p['key']: p['value'] for p in n.get('param', [])}
+
+ for key in self.states:
+ try:
+ self.states[key] = ast.literal_eval(param_data.pop(key))
+ except (KeyError, SyntaxError, ValueError):
+ pass
def get_hash():
- return hash(tuple(map(hash, self.params.values())))
+ return hash(tuple(hash(v) for v in self.params.values()))
- my_hash = 0
- while get_hash() != my_hash:
- for param_n in params_n:
- key = param_n['key']
- value = param_n['value']
+ pre_rewrite_hash = -1
+ while pre_rewrite_hash != get_hash():
+ for key, value in six.iteritems(param_data):
try:
self.params[key].set_value(value)
except KeyError:
continue
# Store hash and call rewrite
- my_hash = get_hash()
+ pre_rewrite_hash = get_hash()
self.rewrite()
self._import_bus_stuff(n)
diff --git a/grc/gui/Block.py b/grc/gui/Block.py
index a38e4cc..94887ee 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 87bd91d..d592242 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
- [Commit-gnuradio] [gnuradio] 09/101: grc-refactor: replace some unnecessary getters, (continued)
- [Commit-gnuradio] [gnuradio] 09/101: grc-refactor: replace some unnecessary getters, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 24/101: grc-refactor: the hopeless cause of bus ports..., git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 25/101: Merge branch 'next_grcwg' into gtk3 (v3.7.10 release), git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 34/101: grc: fix parent getter in rewrite_epy_block, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 13/101: grc-refactor: Connections, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 28/101: grc: refactor: block state handling, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 26/101: grc: gtk3: enable block comments, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 12/101: grc-refactor: remove odict, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 36/101: grc: keep list of active ports in core blocks, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 23/101: grc-refactor: make block.params a dict, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 29/101: grc: refactor: block states are no longer hidden params,
git <=
- [Commit-gnuradio] [gnuradio] 37/101: grc: refactor: fixup selection code and core connection changes, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 22/101: grc-refactor: Block: make more public attribs, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 35/101: grc: gtk3: quick fix for file dialogs, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 41/101: grc: gtk3: fix PythonEditorParam widget, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 02/101: gtk3: add flowgraph draw code and other gtk3 fixes (WIP), git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 21/101: grc-refactor: Block: remove key getters, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 31/101: grc: gtk3: refactor connection draw code, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 14/101: grc-refactor: rewrite tree-api in core, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 42/101: grc: gtk3: update main and checks, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 27/101: grc: gtk3: refactor and update draw code WIP, git, 2017/03/16