summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Blum2009-09-05 02:21:37 -0700
committerJosh Blum2009-09-05 02:21:37 -0700
commitfa465d160b0c53fae3ad7876cf429263157dd60a (patch)
tree12c1b47840f0f4af32ab43d9878fa725d092decf
parent5bb2a70a94be9c0f83712ee259b7125e3a582b08 (diff)
downloadgnuradio-fa465d160b0c53fae3ad7876cf429263157dd60a.tar.gz
gnuradio-fa465d160b0c53fae3ad7876cf429263157dd60a.tar.bz2
gnuradio-fa465d160b0c53fae3ad7876cf429263157dd60a.zip
Created recursive create labels and shapes method for gui element.
Replaces update methods in the gui classes and simplifies calls. The master update method in flow graph calls create labels and shapes.
-rw-r--r--grc/gui/Block.py25
-rw-r--r--grc/gui/Connection.py7
-rw-r--r--grc/gui/Element.py19
-rw-r--r--grc/gui/FlowGraph.py7
-rw-r--r--grc/gui/Port.py7
5 files changed, 39 insertions, 26 deletions
diff --git a/grc/gui/Block.py b/grc/gui/Block.py
index 68c4da9c3..fd8cfc226 100644
--- a/grc/gui/Block.py
+++ b/grc/gui/Block.py
@@ -113,23 +113,16 @@ class Block(Element):
"""
self.get_param('_rotation').set_value(str(rot))
- def update(self):
+ def create_shapes(self):
"""Update the block, parameters, and ports when a change occurs."""
- self._bg_color = self.get_enabled() and Colors.BLOCK_ENABLED_COLOR or Colors.BLOCK_DISABLED_COLOR
- self.clear()
- self._create_labels()
- self.W = self.label_width + 2*BLOCK_LABEL_PADDING
- self.H = max(*(
- [self.label_height+2*BLOCK_LABEL_PADDING] + [2*PORT_BORDER_SEPARATION + \
- sum([port.H + PORT_SEPARATION for port in ports]) - PORT_SEPARATION
- for ports in (self.get_sources(), self.get_sinks())]
- ))
+ Element.create_shapes(self)
if self.is_horizontal(): self.add_area((0, 0), (self.W, self.H))
elif self.is_vertical(): self.add_area((0, 0), (self.H, self.W))
- map(lambda p: p.update(), self.get_ports())
- def _create_labels(self):
+ def create_labels(self):
"""Create the labels for the signal block."""
+ Element.create_labels(self)
+ self._bg_color = self.get_enabled() and Colors.BLOCK_ENABLED_COLOR or Colors.BLOCK_DISABLED_COLOR
layouts = list()
#create the main layout
layout = gtk.DrawingArea().create_pango_layout('')
@@ -164,7 +157,13 @@ class Block(Element):
self.vertical_label = vimage = gtk.gdk.Image(gtk.gdk.IMAGE_NORMAL, pixmap.get_visual(), height, width)
for i in range(width):
for j in range(height): vimage.put_pixel(j, width-i-1, image.get_pixel(i, j))
- map(lambda p: p._create_labels(), self.get_ports())
+ #calculate width and height needed
+ self.W = self.label_width + 2*BLOCK_LABEL_PADDING
+ self.H = max(*(
+ [self.label_height+2*BLOCK_LABEL_PADDING] + [2*PORT_BORDER_SEPARATION + \
+ sum([port.H + PORT_SEPARATION for port in ports]) - PORT_SEPARATION
+ for ports in (self.get_sources(), self.get_sinks())]
+ ))
def draw(self, gc, window):
"""
diff --git a/grc/gui/Connection.py b/grc/gui/Connection.py
index a85650ee2..45f8a689a 100644
--- a/grc/gui/Connection.py
+++ b/grc/gui/Connection.py
@@ -50,8 +50,9 @@ class Connection(Element):
"""
return 0
- def update(self):
+ def create_shapes(self):
"""Precalculate relative coordinates."""
+ Element.create_shapes(self)
self._sink_rot = None
self._source_rot = None
self._sink_coor = None
@@ -74,7 +75,7 @@ class Connection(Element):
def _update_after_move(self):
"""Calculate coordinates."""
- self.clear()
+ self.clear() #FIXME do i want this here?
#source connector
source = self.get_source()
X, Y = source.get_connector_coordinate()
@@ -125,7 +126,7 @@ class Connection(Element):
sink = self.get_sink()
source = self.get_source()
#check for changes
- if self._sink_rot != sink.get_rotation() or self._source_rot != source.get_rotation(): self.update()
+ if self._sink_rot != sink.get_rotation() or self._source_rot != source.get_rotation(): self.create_shapes()
elif self._sink_coor != sink.get_coordinate() or self._source_coor != source.get_coordinate(): self._update_after_move()
#cache values
self._sink_rot = sink.get_rotation()
diff --git a/grc/gui/Element.py b/grc/gui/Element.py
index bda187059..2e20b9a22 100644
--- a/grc/gui/Element.py
+++ b/grc/gui/Element.py
@@ -61,6 +61,21 @@ class Element(object):
rotation = rotation or self.get_rotation()
return rotation in (90, 270)
+ def create_labels(self):
+ """
+ Create labels (if applicable) and call on all children.
+ Call this base method before creating labels in the element.
+ """
+ for child in self.get_children(): child.create_labels()
+
+ def create_shapes(self):
+ """
+ Create shapes (if applicable) and call on all children.
+ Call this base method before creating shapes in the element.
+ """
+ self.clear()
+ for child in self.get_children(): child.create_shapes()
+
def draw(self, gc, window, border_color, bg_color):
"""
Draw in the given window.
@@ -216,7 +231,3 @@ class Element(object):
if rotation not in POSSIBLE_ROTATIONS:
raise Exception('"%s" is not one of the possible rotations: (%s)'%(rotation, POSSIBLE_ROTATIONS))
self.rotation = rotation
-
- def update(self):
- """Do nothing for the update. Dummy method."""
- pass
diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py
index 8a908ff50..35ccf5e27 100644
--- a/grc/gui/FlowGraph.py
+++ b/grc/gui/FlowGraph.py
@@ -291,12 +291,13 @@ class FlowGraph(Element):
def update(self):
"""
- Do a global rewrite and validate.
- Call update on all elements.
+ Call the top level rewrite and validate.
+ Call the top level create labels and shapes.
"""
self.rewrite()
self.validate()
- for element in self.get_elements(): element.update()
+ self.create_labels()
+ self.create_shapes()
##########################################################################
## Get Selected
diff --git a/grc/gui/Port.py b/grc/gui/Port.py
index f8bfefee6..6763f6cbd 100644
--- a/grc/gui/Port.py
+++ b/grc/gui/Port.py
@@ -42,9 +42,9 @@ class Port(Element):
Element.__init__(self)
self.connector_coordinates = dict()
- def update(self):
+ def create_shapes(self):
"""Create new areas and labels for the port."""
- self.clear()
+ Element.create_shapes(self)
#get current rotation
rotation = self.get_rotation()
#get all sibling ports
@@ -82,8 +82,9 @@ class Port(Element):
#the connector length
self._connector_length = CONNECTOR_EXTENSION_MINIMAL + CONNECTOR_EXTENSION_INCREMENT*index
- def _create_labels(self):
+ def create_labels(self):
"""Create the labels for the socket."""
+ Element.create_labels(self)
self._bg_color = Colors.get_color(self.get_color())
#create the layout
layout = gtk.DrawingArea().create_pango_layout('')