commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 43/101: grc: refactor: minor clean-up and f


From: git
Subject: [Commit-gnuradio] [gnuradio] 43/101: grc: refactor: minor clean-up and fixes
Date: Thu, 16 Mar 2017 14:58:04 +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 fb81e9b463d8e0c1f6f2aa5739a290a00fcab207
Author: Sebastian Koslowski <address@hidden>
Date:   Thu Jul 14 14:22:43 2016 +0200

    grc: refactor: minor clean-up and fixes
---
 grc/core/Param.py                                | 29 +++------------------
 grc/core/__init__.py                             |  3 +++
 grc/core/utils/__init__.py                       |  2 ++
 grc/core/utils/{complexity.py => _complexity.py} |  0
 grc/core/utils/_num_to_str.py                    | 30 ++++++++++++++++++++++
 grc/gui/Block.py                                 | 22 ++++++++--------
 grc/gui/Connection.py                            | 11 ++++----
 grc/gui/Element.py                               |  3 +--
 grc/gui/Param.py                                 |  7 +-----
 grc/gui/Platform.py                              | 32 +++++++++++-------------
 grc/gui/Utils.py                                 |  2 +-
 11 files changed, 73 insertions(+), 68 deletions(-)

diff --git a/grc/core/Param.py b/grc/core/Param.py
index c35d593..841f85e 100644
--- a/grc/core/Param.py
+++ b/grc/core/Param.py
@@ -26,7 +26,7 @@ import collections
 
 from six.moves import builtins, filter, map, range, zip
 
-from . import Constants
+from . import Constants, utils
 from .Element import Element
 
 # Blacklist certain ids, its not complete, but should help
@@ -41,29 +41,6 @@ _check_id_matcher = re.compile('^[a-z|A-Z]\w*$')
 _show_id_matcher = re.compile('^(variable\w*|parameter|options|notebook)$')
 
 
-def num_to_str(num):
-    """ Display logic for numbers """
-    def eng_notation(value, fmt='g'):
-        """Convert a number to a string in engineering notation.  E.g., 5e-9 
-> 5n"""
-        template = '{:' + fmt + '}{}'
-        magnitude = abs(value)
-        for exp, symbol in zip(range(9, -15-1, -3), 'GMk munpf'):
-            factor = 10 ** exp
-            if magnitude >= factor:
-                return template.format(value / factor, symbol.strip())
-        return template.format(value, '')
-
-    if isinstance(num, Constants.COMPLEX_TYPES):
-        num = complex(num)  # Cast to python complex
-        if num == 0:
-            return '0'
-        output = eng_notation(num.real) if num.real else ''
-        output += eng_notation(num.imag, '+g' if output else 'g') + 'j' if 
num.imag else ''
-        return output
-    else:
-        return str(num)
-
-
 class Option(Element):
 
     def __init__(self, param, n):
@@ -246,7 +223,7 @@ class Param(Element):
         if isinstance(e, bool):
             return str(e)
         elif isinstance(e, Constants.COMPLEX_TYPES):
-            dt_str = num_to_str(e)
+            dt_str = utils.num_to_str(e)
         elif isinstance(e, Constants.VECTOR_TYPES):
             # Vector types
             if len(e) > 8:
@@ -255,7 +232,7 @@ class Param(Element):
                 truncate = 1
             else:
                 # Small vectors use eval
-                dt_str = ', '.join(map(num_to_str, e))
+                dt_str = ', '.join(map(utils.num_to_str, e))
         elif t in ('file_open', 'file_save'):
             dt_str = self.get_value()
             truncate = -1
diff --git a/grc/core/__init__.py b/grc/core/__init__.py
index 8b13789..3e38807 100644
--- a/grc/core/__init__.py
+++ b/grc/core/__init__.py
@@ -1 +1,4 @@
 
+from .Param import Param
+from .Port import Port
+from .Block import Block
diff --git a/grc/core/utils/__init__.py b/grc/core/utils/__init__.py
index 66393fd..4b1717b 100644
--- a/grc/core/utils/__init__.py
+++ b/grc/core/utils/__init__.py
@@ -21,3 +21,5 @@ from . import expr_utils
 from . import epy_block_io
 from . import extract_docs
 
+from ._complexity import calculate_flowgraph_complexity
+from ._num_to_str import num_to_str
diff --git a/grc/core/utils/complexity.py b/grc/core/utils/_complexity.py
similarity index 100%
rename from grc/core/utils/complexity.py
rename to grc/core/utils/_complexity.py
diff --git a/grc/core/utils/_num_to_str.py b/grc/core/utils/_num_to_str.py
new file mode 100644
index 0000000..92b2167
--- /dev/null
+++ b/grc/core/utils/_num_to_str.py
@@ -0,0 +1,30 @@
+# -*- coding: utf-8 -*-
+"""${FILE_NAME}"""
+from grc.core import Constants
+
+__author__ = "Sebastian Koslowski"
+__email__ = "address@hidden"
+__copyright__ = "Copyright 2016, Sebastian Koslowski"
+
+
+def num_to_str(num):
+    """ Display logic for numbers """
+    def eng_notation(value, fmt='g'):
+        """Convert a number to a string in engineering notation.  E.g., 5e-9 
-> 5n"""
+        template = '{:' + fmt + '}{}'
+        magnitude = abs(value)
+        for exp, symbol in zip(range(9, -15-1, -3), 'GMk munpf'):
+            factor = 10 ** exp
+            if magnitude >= factor:
+                return template.format(value / factor, symbol.strip())
+        return template.format(value, '')
+
+    if isinstance(num, Constants.COMPLEX_TYPES):
+        num = complex(num)  # Cast to python complex
+        if num == 0:
+            return '0'
+        output = eng_notation(num.real) if num.real else ''
+        output += eng_notation(num.imag, '+g' if output else 'g') + 'j' if 
num.imag else ''
+        return output
+    else:
+        return str(num)
diff --git a/grc/gui/Block.py b/grc/gui/Block.py
index 25435e9..8d0c65c 100644
--- a/grc/gui/Block.py
+++ b/grc/gui/Block.py
@@ -29,12 +29,11 @@ from .Constants import (
     PORT_BORDER_SEPARATION, BLOCK_FONT, PARAM_FONT
 )
 from . Element import Element
-from ..core.Param import num_to_str
-from ..core.utils.complexity import calculate_flowgraph_complexity
-from ..core.Block import Block as _Block
+from ..core import utils
+from ..core.Block import Block as CoreBlock
 
 
-class Block(_Block, Element):
+class Block(CoreBlock, Element):
     """The graphical signal block."""
 
     def __init__(self, flow_graph, n):
@@ -134,10 +133,12 @@ class Block(_Block, Element):
 
     def create_labels(self):
         """Create the labels for the signal block."""
-        self._bg_color = Colors.MISSING_BLOCK_BACKGROUND_COLOR if 
self.is_dummy_block else \
-                         Colors.BLOCK_BYPASSED_COLOR if self.get_bypassed() 
else \
-                         Colors.BLOCK_ENABLED_COLOR if self.get_enabled() else 
\
-                         Colors.BLOCK_DISABLED_COLOR
+        self._bg_color = (
+            Colors.MISSING_BLOCK_BACKGROUND_COLOR if self.is_dummy_block else
+            Colors.BLOCK_BYPASSED_COLOR if self.get_bypassed() else
+            Colors.BLOCK_ENABLED_COLOR if self.get_enabled() else
+            Colors.BLOCK_DISABLED_COLOR
+        )
 
         # update the title layout
         title_layout, params_layout = self._surface_layouts
@@ -180,6 +181,7 @@ class Block(_Block, Element):
             if ports:
                 min_height -= ports[-1].height
             return min_height
+
         height = max(
             [  # labels
                 height
@@ -220,10 +222,10 @@ class Block(_Block, Element):
 
         # Show the flow graph complexity on the top block if enabled
         if Actions.TOGGLE_SHOW_FLOWGRAPH_COMPLEXITY.get_active() and self.key 
== "options":
-            complexity = calculate_flowgraph_complexity(self.parent)
+            complexity = utils.calculate_flowgraph_complexity(self.parent)
             markups.append(
                 '<span foreground="#444" size="medium" font_desc="{font}">'
-                '<b>Complexity: 
{num}bal</b></span>'.format(num=num_to_str(complexity), font=BLOCK_FONT)
+                '<b>Complexity: 
{num}bal</b></span>'.format(num=utils.num_to_str(complexity), font=BLOCK_FONT)
             )
         comment = self.get_comment()  # Returns None if there are no comments
         if comment:
diff --git a/grc/gui/Connection.py b/grc/gui/Connection.py
index 33fe104..5362bc0 100644
--- a/grc/gui/Connection.py
+++ b/grc/gui/Connection.py
@@ -41,7 +41,7 @@ class Connection(Element, _Connection):
         Element.__init__(self)
         _Connection.__init__(self, **kwargs)
 
-        self._color =self._color2 = self._arrow_color =  None
+        self._color = self._color2 = self._arrow_color = None
 
         self._sink_rot = self._source_rot = None
         self._sink_coor = self._source_coor = None
@@ -138,7 +138,7 @@ class Connection(Element, _Connection):
         else:
             # 2 possible points to create a right-angled connector
             point, alt = [(x1, y2), (x2, y1)]
-            # source connector -> points[0] should be in the direction of 
source (if possible)
+            # source connector -> point should be in the direction of source 
(if possible)
             if Utils.get_angle_from_coordinates(p1, point) != source_dir:
                 point, alt = alt, point
             # point -> sink connector should not be in the direction of sink
@@ -156,7 +156,7 @@ class Connection(Element, _Connection):
         """
         sink = self.sink_port
         source = self.source_port
-        #check for changes
+        # check for changes
         if self._sink_rot != sink.rotation or self._source_rot != 
source.rotation:
             self.create_shapes()
             self._sink_rot = sink.rotation
@@ -183,8 +183,7 @@ class Connection(Element, _Connection):
             cr.restore()
         # draw arrow on sink port
         cr.set_source_rgb(*self._arrow_color)
-        cr.move_to(*self._arrow[0])
-        cr.line_to(*self._arrow[1])
-        cr.line_to(*self._arrow[2])
+        for p in self._arrow:
+            cr.move_to(*p)
         cr.close_path()
         cr.fill()
diff --git a/grc/gui/Element.py b/grc/gui/Element.py
index 3b077dc..b51a647 100644
--- a/grc/gui/Element.py
+++ b/grc/gui/Element.py
@@ -112,8 +112,7 @@ class Element(object):
 
         cr.set_source_rgb(*border_color)
         for line in self.lines:
-            cr.move_to(*line[0])
-            for point in line[1:]:
+            for point in line:
                 cr.line_to(*point)
             cr.stroke()
 
diff --git a/grc/gui/Param.py b/grc/gui/Param.py
index c888b9e..9d5b55f 100644
--- a/grc/gui/Param.py
+++ b/grc/gui/Param.py
@@ -19,18 +19,13 @@ from __future__ import absolute_import
 from . import Utils, Constants
 
 from . import ParamWidgets
-from .Element import Element
 
 from ..core.Param import Param as _Param
 
 
-class Param(Element, _Param):
+class Param(_Param):
     """The graphical parameter."""
 
-    def __init__(self, **kwargs):
-        Element.__init__(self)
-        _Param.__init__(self, **kwargs)
-
     def get_input(self, *args, **kwargs):
         """
         Get the graphical gtk class to represent this parameter.
diff --git a/grc/gui/Platform.py b/grc/gui/Platform.py
index 997e96a..25c7556 100644
--- a/grc/gui/Platform.py
+++ b/grc/gui/Platform.py
@@ -22,22 +22,20 @@ from __future__ import absolute_import, print_function
 import os
 import sys
 
-from ..core.Platform import Platform as _Platform
+from ..core.Platform import Platform as CorePlatform
 
-from .Config import Config as _Config
-from .Block import Block as _Block
-from .Connection import Connection as _Connection
-from .Element import Element
-from .FlowGraph import FlowGraph as _FlowGraph
-from .Param import Param as _Param
-from .Port import Port as _Port
+from .Config import Config
+from .Block import Block
+from .Connection import Connection
+from .FlowGraph import FlowGraph
+from .Param import Param
+from .Port import Port
 
 
-class Platform(Element, _Platform):
+class Platform(CorePlatform):
 
     def __init__(self, *args, **kwargs):
-        Element.__init__(self)
-        _Platform.__init__(self, *args, **kwargs)
+        CorePlatform.__init__(self, *args, **kwargs)
 
         # Ensure conf directories
         gui_prefs_file = self.config.gui_prefs_file
@@ -65,9 +63,9 @@ class Platform(Element, _Platform):
     ##############################################
     # Constructors
     ##############################################
-    FlowGraph = _FlowGraph
-    Connection = _Connection
-    Block = _Block
-    Port = _Port
-    Param = _Param
-    Config = _Config
+    Config = Config
+    FlowGraph = FlowGraph
+    Connection = Connection
+    Block = Block
+    Port = Port
+    Param = Param
diff --git a/grc/gui/Utils.py b/grc/gui/Utils.py
index 70adede..304c8b8 100644
--- a/grc/gui/Utils.py
+++ b/grc/gui/Utils.py
@@ -36,7 +36,7 @@ def get_rotated_coordinate(coor, rotation):
         the rotated coordinates
     """
     # handles negative angles
-    rotation = (rotation + 360)%360
+    rotation = (rotation + 360) % 360
     if rotation not in POSSIBLE_ROTATIONS:
         raise ValueError('unusable rotation angle "%s"'%str(rotation))
     # determine the number of degrees to rotate



reply via email to

[Prev in Thread] Current Thread [Next in Thread]