[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 18/101: grc-refactor: block state handling
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 18/101: grc-refactor: block state handling |
Date: |
Thu, 16 Mar 2017 14:57:59 +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 310af9cd32b42e9ad5324fb1dca9bff25ccaca96
Author: Sebastian Koslowski <address@hidden>
Date: Wed Jun 15 11:25:31 2016 -0700
grc-refactor: block state handling
---
grc/core/Block.py | 44 ++++++++++++++++++++++++--------------------
grc/core/Constants.py | 5 -----
grc/gui/ActionHandler.py | 10 ++++++----
grc/gui/Element.py | 1 -
4 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/grc/core/Block.py b/grc/core/Block.py
index 9fff5af..8296659 100644
--- a/grc/core/Block.py
+++ b/grc/core/Block.py
@@ -26,13 +26,13 @@ from six.moves import map, range
from Cheetah.Template import Template
-from .utils import epy_block_io
+from . import utils
+
from . Constants import (
BLOCK_FLAG_NEED_QT_GUI, BLOCK_FLAG_NEED_WX_GUI,
ADVANCED_PARAM_TAB, DEFAULT_PARAM_TAB,
BLOCK_FLAG_THROTTLE, BLOCK_FLAG_DISABLE_BYPASS,
BLOCK_FLAG_DEPRECATED,
- BLOCK_ENABLED, BLOCK_BYPASSED, BLOCK_DISABLED
)
from . Element import Element
@@ -52,6 +52,9 @@ class Block(Element):
is_block = True
+ # block states
+ DISABLED, ENABLED, BYPASSED = range(3)
+
def __init__(self, flow_graph, n):
"""
Make a new block from nested data.
@@ -318,7 +321,7 @@ class Block(Element):
return
try:
- blk_io = epy_block_io.extract(src)
+ blk_io = utils.epy_block_io.extract(src)
except Exception as e:
self._epy_reload_error = ValueError(str(e))
@@ -326,7 +329,7 @@ class Block(Element):
blk_io_args = eval(param_blk.get_value())
if len(blk_io_args) == 6:
blk_io_args += ([],) # add empty callbacks
- blk_io = epy_block_io.BlockIO(*blk_io_args)
+ blk_io = utils.epy_block_io.BlockIO(*blk_io_args)
except Exception:
return
else:
@@ -395,7 +398,8 @@ class Block(Element):
# Main functions to get and set the block state
# Also kept get_enabled and set_enabled to keep compatibility
- def get_state(self):
+ @property
+ def state(self):
"""
Gets the block's current state.
@@ -405,11 +409,12 @@ class Block(Element):
DISABLED - 2
"""
try:
- return int(eval(self.get_param('_enabled').get_value()))
- except:
- return BLOCK_ENABLED
+ return int(self.get_param('_enabled').get_value())
+ except ValueError:
+ return self.ENABLED
- def set_state(self, state):
+ @state.setter
+ def state(self, value):
"""
Sets the state for the block.
@@ -418,10 +423,9 @@ class Block(Element):
BYPASSED - 1
DISABLED - 2
"""
- if state in [BLOCK_ENABLED, BLOCK_BYPASSED, BLOCK_DISABLED]:
- self.get_param('_enabled').set_value(str(state))
- else:
- self.get_param('_enabled').set_value(str(BLOCK_ENABLED))
+ if value not in [self.ENABLED, self.BYPASSED, self.DISABLED]:
+ value = self.ENABLED
+ self.get_param('_enabled').set_value(str(value))
# Enable/Disable Aliases
def get_enabled(self):
@@ -431,7 +435,7 @@ class Block(Element):
Returns:
true for enabled
"""
- return not (self.get_state() == BLOCK_DISABLED)
+ return self.state != self.DISABLED
def set_enabled(self, enabled):
"""
@@ -443,9 +447,9 @@ class Block(Element):
Returns:
True if block changed state
"""
- old_state = self.get_state()
- new_state = BLOCK_ENABLED if enabled else BLOCK_DISABLED
- self.set_state(new_state)
+ old_state = self.state
+ new_state = self.ENABLED if enabled else self.DISABLED
+ self.state = new_state
return old_state != new_state
# Block bypassing
@@ -453,7 +457,7 @@ class Block(Element):
"""
Check if the block is bypassed
"""
- return self.get_state() == BLOCK_BYPASSED
+ return self.state == self.BYPASSED
def set_bypassed(self):
"""
@@ -462,8 +466,8 @@ class Block(Element):
Returns:
True if block chagnes state
"""
- if self.get_state() != BLOCK_BYPASSED and self.can_bypass():
- self.set_state(BLOCK_BYPASSED)
+ if self.state != self.BYPASSED and self.can_bypass():
+ self.state = self.BYPASSED
return True
return False
diff --git a/grc/core/Constants.py b/grc/core/Constants.py
index 9953148..40fe69d 100644
--- a/grc/core/Constants.py
+++ b/grc/core/Constants.py
@@ -54,11 +54,6 @@ BLOCK_FLAG_NEED_QT_GUI = 'need_qt_gui'
BLOCK_FLAG_NEED_WX_GUI = 'need_wx_gui'
BLOCK_FLAG_DEPRECATED = 'deprecated'
-# Block States
-BLOCK_DISABLED = 0
-BLOCK_ENABLED = 1
-BLOCK_BYPASSED = 2
-
# File creation modes
TOP_BLOCK_FILE_MODE = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
stat.S_IRGRP | \
stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index 25c779b..d188030 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -670,12 +670,14 @@ class ActionHandler:
Actions.BLOCK_COPY.set_sensitive(bool(selected_blocks))
Actions.BLOCK_PASTE.set_sensitive(bool(self.clipboard))
#update enable/disable/bypass
- can_enable = any(block.get_state() != Constants.BLOCK_ENABLED
+ can_enable = any(block.state != block.ENABLED
for block in selected_blocks)
- can_disable = any(block.get_state() != Constants.BLOCK_DISABLED
+ can_disable = any(block.state != block.DISABLED
for block in selected_blocks)
- can_bypass_all = all(block.can_bypass() for block in selected_blocks) \
- and any(not block.get_bypassed() for block in
selected_blocks)
+ can_bypass_all = (
+ all(block.can_bypass() for block in selected_blocks) and
+ any(not block.get_bypassed() for block in selected_blocks)
+ )
Actions.BLOCK_ENABLE.set_sensitive(can_enable)
Actions.BLOCK_DISABLE.set_sensitive(can_disable)
Actions.BLOCK_BYPASS.set_sensitive(can_bypass_all)
diff --git a/grc/gui/Element.py b/grc/gui/Element.py
index 4e88df3..48fdf62 100644
--- a/grc/gui/Element.py
+++ b/grc/gui/Element.py
@@ -48,7 +48,6 @@ class Element(object):
0, Gdk.LINE_SOLID, Gdk.CAP_BUTT, Gdk.JOIN_MITER
]"""
-
def is_horizontal(self, rotation=None):
"""
Is this element horizontal?
- [Commit-gnuradio] [gnuradio] branch python3 updated (50bfc3d -> 00e775f), git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 07/101: grc-refactor: move param input widgets to separate file, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 04/101: grc: remove all Cheetah templates from GUI, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 03/101: grc-refactor: start clean-up Block.py, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 05/101: grc-refactor: move param entry colors spec in gui package, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 10/101: grc: gtk3: remove some deprecated warnings, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 19/101: grc-refactor: block documentation prop, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 18/101: grc-refactor: block state handling,
git <=
- [Commit-gnuradio] [gnuradio] 20/101: grc-refactor: Block: remove name getter, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 15/101: grc: gtk3: fix paste and domain color settings, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 08/101: grc: gtk3: remove canvas size and enable zooming, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 06/101: grc: gtk3: update props dialog, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 17/101: grc-refactor: move more port type color stuff to gui, git, 2017/03/16
- [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