diff options
Diffstat (limited to 'grc/gui/Block.py')
-rw-r--r-- | grc/gui/Block.py | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/grc/gui/Block.py b/grc/gui/Block.py index 67b80695fa..95135310b8 100644 --- a/grc/gui/Block.py +++ b/grc/gui/Block.py @@ -17,22 +17,24 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA """ -from Element import Element -import Utils -import Colors -from .. base import odict -from .. python.Param import num_to_str -from Constants import BORDER_PROXIMITY_SENSITIVITY -from Constants import ( - BLOCK_LABEL_PADDING, PORT_SPACING, PORT_SEPARATION, LABEL_SEPARATION, - PORT_BORDER_SEPARATION, POSSIBLE_ROTATIONS, BLOCK_FONT, PARAM_FONT -) -import Actions import pygtk pygtk.require('2.0') import gtk import pango +from . import Actions, Colors, Utils + +from .Constants import ( + BLOCK_LABEL_PADDING, PORT_SPACING, PORT_SEPARATION, LABEL_SEPARATION, + PORT_BORDER_SEPARATION, POSSIBLE_ROTATIONS, BLOCK_FONT, PARAM_FONT, + BORDER_PROXIMITY_SENSITIVITY +) +from . Element import Element +from ..core.Param import num_to_str +from ..core.utils import odict +from ..core.utils.complexity import calculate_flowgraph_complexity +from ..core.Block import Block as _Block + BLOCK_MARKUP_TMPL="""\ #set $foreground = $block.is_valid() and 'black' or 'red' <span foreground="$foreground" font_desc="$font"><b>$encode($block.get_name())</b></span>""" @@ -52,15 +54,16 @@ COMMENT_COMPLEXITY_MARKUP_TMPL="""\ """ - -class Block(Element): +class Block(Element, _Block): """The graphical signal block.""" - def __init__(self): + def __init__(self, flow_graph, n): """ Block contructor. Add graphics related params to the block. """ + _Block.__init__(self, flow_graph, n) + self.W = 0 self.H = 0 #add the position param @@ -135,10 +138,10 @@ class Block(Element): delta_coor: requested delta coordinate (dX, dY) to move Returns: - The delta coordinate possible to move while keeping the block on the canvas + The delta coordinate possible to move while keeping the block on the canvas or the input (dX, dY) on failure """ - dX, dY = delta_coor + dX, dY = delta_coor try: fgW, fgH = self.get_parent().get_size() @@ -147,7 +150,7 @@ class Block(Element): sW, sH = self.W, self.H else: sW, sH = self.H, self.W - + if x + dX < 0: dX = -x elif dX + x + sW >= fgW: @@ -159,7 +162,7 @@ class Block(Element): except: pass - return ( dX, dY ) + return ( dX, dY ) def get_rotation(self): """ @@ -193,7 +196,7 @@ class Block(Element): def create_labels(self): """Create the labels for the signal block.""" Element.create_labels(self) - self._bg_color = self.is_dummy_block() and Colors.MISSING_BLOCK_BACKGROUND_COLOR or \ + self._bg_color = self.is_dummy_block and Colors.MISSING_BLOCK_BACKGROUND_COLOR or \ self.get_bypassed() and Colors.BLOCK_BYPASSED_COLOR or \ self.get_enabled() and Colors.BLOCK_ENABLED_COLOR or Colors.BLOCK_DISABLED_COLOR @@ -204,7 +207,7 @@ class Block(Element): layout.set_markup(Utils.parse_template(BLOCK_MARKUP_TMPL, block=self, font=BLOCK_FONT)) self.label_width, self.label_height = layout.get_pixel_size() #display the params - if self.is_dummy_block(): + if self.is_dummy_block: markups = [ '<span foreground="black" font_desc="{font}"><b>key: </b>{key}</span>'.format(font=PARAM_FONT, key=self._key) ] @@ -271,7 +274,8 @@ class Block(Element): # Show the flowgraph complexity on the top block if enabled if Actions.TOGGLE_SHOW_FLOWGRAPH_COMPLEXITY.get_active() and self.get_key() == "options": - complexity = "Complexity: {}bal".format(num_to_str(self.get_parent().get_complexity())) + complexity = calculate_flowgraph_complexity(self.get_parent()) + complexity = "Complexity: {}bal".format(num_to_str(complexity)) layout = gtk.DrawingArea().create_pango_layout('') layout.set_markup(Utils.parse_template(COMMENT_COMPLEXITY_MARKUP_TMPL, @@ -311,7 +315,7 @@ class Block(Element): Element.draw( self, gc, window, bg_color=self._bg_color, border_color=self.is_highlighted() and Colors.HIGHLIGHT_COLOR or - self.is_dummy_block() and Colors.MISSING_BLOCK_BORDER_COLOR or Colors.BORDER_COLOR, + self.is_dummy_block and Colors.MISSING_BLOCK_BORDER_COLOR or Colors.BORDER_COLOR, ) #draw label image if self.is_horizontal(): |