summaryrefslogtreecommitdiff
path: root/grc/gui
diff options
context:
space:
mode:
Diffstat (limited to 'grc/gui')
-rw-r--r--grc/gui/ActionHandler.py2
-rw-r--r--grc/gui/Block.py19
-rw-r--r--grc/gui/FlowGraph.py46
-rw-r--r--grc/gui/Port.py18
4 files changed, 52 insertions, 33 deletions
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index 170247557a..b219ed2363 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -232,7 +232,7 @@ class ActionHandler:
if y < y_min:
y_min = y
- for connection in block.get_connections():
+ for connection in block.connections:
# Get id of connected blocks
source_id = connection.get_source().get_parent().get_id()
diff --git a/grc/gui/Block.py b/grc/gui/Block.py
index 97b4e96c91..2439c32d22 100644
--- a/grc/gui/Block.py
+++ b/grc/gui/Block.py
@@ -32,7 +32,7 @@ from .Constants import (
from . Element import Element
from ..model.odict import odict
from ..model.Param import num_to_str
-
+from ..model.utils.complexity import calculate_flowgraph_complexity
from ..model.Block import Block as _Block
BLOCK_MARKUP_TMPL="""\
@@ -138,10 +138,10 @@ class Block(Element, _Block):
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()
@@ -150,7 +150,7 @@ class Block(Element, _Block):
sW, sH = self.W, self.H
else:
sW, sH = self.H, self.W
-
+
if x + dX < 0:
dX = -x
elif dX + x + sW >= fgW:
@@ -162,7 +162,7 @@ class Block(Element, _Block):
except:
pass
- return ( dX, dY )
+ return ( dX, dY )
def get_rotation(self):
"""
@@ -196,7 +196,7 @@ class Block(Element, _Block):
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
@@ -207,7 +207,7 @@ class Block(Element, _Block):
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)
]
@@ -274,7 +274,8 @@ class Block(Element, _Block):
# 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,
@@ -314,7 +315,7 @@ class Block(Element, _Block):
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():
diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py
index e975595c11..0c66a7e5ad 100644
--- a/grc/gui/FlowGraph.py
+++ b/grc/gui/FlowGraph.py
@@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
import random
import functools
-from itertools import chain
+from itertools import chain, count
from operator import methodcaller
from distutils.spawn import find_executable
@@ -65,6 +65,22 @@ class FlowGraph(Element, _Flowgraph):
self._external_updaters = {}
+ def _get_unique_id(self, base_id=''):
+ """
+ Get a unique id starting with the base id.
+
+ Args:
+ base_id: the id starts with this and appends a count
+
+ Returns:
+ a unique id
+ """
+ for index in count():
+ block_id = '{}_{}'.format(base_id, index)
+ if block_id not in (b.get_id() for b in self.blocks):
+ break
+ return block_id
+
def install_external_editor(self, param):
target = (param.get_parent().get_id(), param.get_key())
@@ -163,7 +179,7 @@ class FlowGraph(Element, _Flowgraph):
#get connections between selected blocks
connections = filter(
lambda c: c.get_source().get_parent() in blocks and c.get_sink().get_parent() in blocks,
- self.get_connections(),
+ self.connections,
)
clipboard = (
(x_min, y_min),
@@ -202,7 +218,7 @@ class FlowGraph(Element, _Flowgraph):
if param_key == 'id':
old_id2block[param_value] = block
#if the block id is not unique, get a new block id
- if param_value in [bluck.get_id() for bluck in self.get_blocks()]:
+ if param_value in (blk.get_id() for blk in self.blocks):
param_value = self._get_unique_id(param_value)
#set value to key
block.get_param(param_key).set_value(param_value)
@@ -284,7 +300,7 @@ class FlowGraph(Element, _Flowgraph):
"""
for selected_block in self.get_selected_blocks():
delta_coordinate = selected_block.bound_move_delta(delta_coordinate)
-
+
for selected_block in self.get_selected_blocks():
selected_block.move(delta_coordinate)
self.element_moved = True
@@ -346,7 +362,7 @@ class FlowGraph(Element, _Flowgraph):
# draw comments first
if Actions.TOGGLE_SHOW_BLOCK_COMMENTS.get_active():
- for block in self.iter_blocks():
+ for block in self.blocks:
if block.get_enabled():
block.draw_comment(gc, window)
#draw multi select rectangle
@@ -364,8 +380,8 @@ class FlowGraph(Element, _Flowgraph):
window.draw_rectangle(gc, False, x, y, w, h)
#draw blocks on top of connections
hide_disabled_blocks = Actions.TOGGLE_HIDE_DISABLED_BLOCKS.get_active()
- blocks = sorted(self.iter_blocks(), key=methodcaller('get_enabled'))
- for element in chain(self.iter_connections(), blocks):
+ blocks = sorted(self.blocks, key=methodcaller('get_enabled'))
+ for element in chain(self.connections, blocks):
if hide_disabled_blocks and not element.get_enabled():
continue # skip hidden disabled blocks and connections
element.draw(gc, window)
@@ -452,13 +468,13 @@ class FlowGraph(Element, _Flowgraph):
if not selected_element: continue
# hidden disabled connections, blocks and their ports can not be selected
if Actions.TOGGLE_HIDE_DISABLED_BLOCKS.get_active() and (
- selected_element.is_block() and not selected_element.get_enabled() or
- selected_element.is_connection() and not selected_element.get_enabled() or
- selected_element.is_port() and not selected_element.get_parent().get_enabled()
+ selected_element.is_block and not selected_element.get_enabled() or
+ selected_element.is_connection and not selected_element.get_enabled() or
+ selected_element.is_port and not selected_element.get_parent().get_enabled()
):
continue
#update the selected port information
- if selected_element.is_port():
+ if selected_element.is_port:
if not coor_m: selected_port = selected_element
selected_element = selected_element.get_parent()
selected.add(selected_element)
@@ -482,7 +498,8 @@ class FlowGraph(Element, _Flowgraph):
"""
selected = set()
for selected_element in self.get_selected_elements():
- if selected_element.is_connection(): selected.add(selected_element)
+ if selected_element.is_connection:
+ selected.add(selected_element)
return list(selected)
def get_selected_blocks(self):
@@ -494,7 +511,8 @@ class FlowGraph(Element, _Flowgraph):
"""
selected = set()
for selected_element in self.get_selected_elements():
- if selected_element.is_block(): selected.add(selected_element)
+ if selected_element.is_block:
+ selected.add(selected_element)
return list(selected)
def get_selected_block(self):
@@ -669,7 +687,7 @@ class FlowGraph(Element, _Flowgraph):
adj.set_value(adj_val-SCROLL_DISTANCE)
adj.emit('changed')
#remove the connection if selected in drag event
- if len(self.get_selected_elements()) == 1 and self.get_selected_element().is_connection():
+ if len(self.get_selected_elements()) == 1 and self.get_selected_element().is_connection:
Actions.ELEMENT_DELETE()
#move the selected elements and record the new coordinate
if not self.get_ctrl_mask():
diff --git a/grc/gui/Port.py b/grc/gui/Port.py
index 28d3b4d915..c281cbdeeb 100644
--- a/grc/gui/Port.py
+++ b/grc/gui/Port.py
@@ -64,7 +64,7 @@ class Port(_Port, Element):
rotation = self.get_rotation()
#get all sibling ports
ports = self.get_parent().get_sources_gui() \
- if self.is_source() else self.get_parent().get_sinks_gui()
+ if self.is_source else self.get_parent().get_sinks_gui()
ports = filter(lambda p: not p.get_hide(), ports)
#get the max width
self.W = max([port.W for port in ports] + [PORT_MIN_WIDTH])
@@ -82,27 +82,27 @@ class Port(_Port, Element):
index = length-index-1
port_separation = PORT_SEPARATION \
- if not self.get_parent().has_busses[self.is_source()] \
+ if not self.get_parent().has_busses[self.is_source] \
else max([port.H for port in ports]) + PORT_SPACING
offset = (self.get_parent().H - (length-1)*port_separation - self.H)/2
#create areas and connector coordinates
- if (self.is_sink() and rotation == 0) or (self.is_source() and rotation == 180):
+ if (self.is_sink and rotation == 0) or (self.is_source and rotation == 180):
x = -W
y = port_separation*index+offset
self.add_area((x, y), (W, self.H))
self._connector_coordinate = (x-1, y+self.H/2)
- elif (self.is_source() and rotation == 0) or (self.is_sink() and rotation == 180):
+ elif (self.is_source and rotation == 0) or (self.is_sink and rotation == 180):
x = self.get_parent().W
y = port_separation*index+offset
self.add_area((x, y), (W, self.H))
self._connector_coordinate = (x+1+W, y+self.H/2)
- elif (self.is_source() and rotation == 90) or (self.is_sink() and rotation == 270):
+ elif (self.is_source and rotation == 90) or (self.is_sink and rotation == 270):
y = -W
x = port_separation*index+offset
self.add_area((x, y), (self.H, W))
self._connector_coordinate = (x+self.H/2, y-1)
- elif (self.is_sink() and rotation == 90) or (self.is_source() and rotation == 270):
+ elif (self.is_sink and rotation == 90) or (self.is_source and rotation == 270):
y = self.get_parent().W
x = port_separation*index+offset
self.add_area((x, y), (self.H, W))
@@ -145,7 +145,7 @@ class Port(_Port, Element):
Element.draw(
self, gc, window, bg_color=self._bg_color,
border_color=self.is_highlighted() and Colors.HIGHLIGHT_COLOR or
- self.get_parent().is_dummy_block() and Colors.MISSING_BLOCK_BORDER_COLOR or
+ self.get_parent().is_dummy_block and Colors.MISSING_BLOCK_BORDER_COLOR or
Colors.BORDER_COLOR,
)
if not self._areas_list or self._label_hidden():
@@ -177,8 +177,8 @@ class Port(_Port, Element):
Returns:
the direction in degrees
"""
- if self.is_source(): return self.get_rotation()
- elif self.is_sink(): return (self.get_rotation() + 180)%360
+ if self.is_source: return self.get_rotation()
+ elif self.is_sink: return (self.get_rotation() + 180)%360
def get_connector_length(self):
"""