diff options
Diffstat (limited to 'grc/gui')
-rw-r--r-- | grc/gui/ActionHandler.py | 19 | ||||
-rw-r--r-- | grc/gui/Actions.py | 10 | ||||
-rw-r--r-- | grc/gui/Bars.py | 1 | ||||
-rw-r--r-- | grc/gui/Block.py | 13 | ||||
-rw-r--r-- | grc/gui/Connection.py | 18 | ||||
-rw-r--r-- | grc/gui/Element.py | 3 | ||||
-rw-r--r-- | grc/gui/FlowGraph.py | 14 | ||||
-rw-r--r-- | grc/gui/Port.py | 25 | ||||
-rw-r--r-- | grc/gui/Utils.py | 6 |
9 files changed, 96 insertions, 13 deletions
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py index add32dbdac..fa3e960d26 100644 --- a/grc/gui/ActionHandler.py +++ b/grc/gui/ActionHandler.py @@ -447,6 +447,23 @@ class ActionHandler: for b in self.get_flow_graph().get_selected_blocks(): if b._grc_source: self.main_window.new_page(b._grc_source, show=True); + elif action == Actions.BUSSIFY_SOURCES: + n = {'name':'bus', 'type':'bus'} + for b in self.get_flow_graph().get_selected_blocks(): + b.bussify(n, 'source'); + self.get_flow_graph()._old_selected_port = None; + self.get_flow_graph()._new_selected_port = None; + Actions.ELEMENT_CREATE(); + + elif action == Actions.BUSSIFY_SINKS: + n = {'name':'bus', 'type':'bus'} + for b in self.get_flow_graph().get_selected_blocks(): + b.bussify(n, 'sink') + self.get_flow_graph()._old_selected_port = None; + self.get_flow_graph()._new_selected_port = None; + Actions.ELEMENT_CREATE(); + + else: print '!!! Action "%s" not handled !!!'%action ################################################## # Global Actions for all States @@ -466,6 +483,8 @@ class ActionHandler: Actions.BLOCK_DISABLE.set_sensitive(bool(self.get_flow_graph().get_selected_blocks())) Actions.BLOCK_CREATE_HIER.set_sensitive(bool(self.get_flow_graph().get_selected_blocks())) Actions.OPEN_HIER.set_sensitive(bool(self.get_flow_graph().get_selected_blocks())) + Actions.BUSSIFY_SOURCES.set_sensitive(bool(self.get_flow_graph().get_selected_blocks())) + Actions.BUSSIFY_SINKS.set_sensitive(bool(self.get_flow_graph().get_selected_blocks())) Actions.RELOAD_BLOCKS.set_sensitive(True) #set the exec and stop buttons self.update_exec_stop() diff --git a/grc/gui/Actions.py b/grc/gui/Actions.py index 9225b0bd52..5832e08bf0 100644 --- a/grc/gui/Actions.py +++ b/grc/gui/Actions.py @@ -295,3 +295,13 @@ OPEN_HIER = Action( tooltip='Open the source of the selected hierarchical block', stock_id=gtk.STOCK_JUMP_TO, ) +BUSSIFY_SOURCES = Action( + label='Toggle So_urce Bus', + tooltip='Gang source ports into a single bus port', + stock_id=gtk.STOCK_JUMP_TO, +) +BUSSIFY_SINKS = Action( + label='Toggle S_ink Bus', + tooltip='Gang sink ports into a single bus port', + stock_id=gtk.STOCK_JUMP_TO, +) diff --git a/grc/gui/Bars.py b/grc/gui/Bars.py index d95d23f1fe..770e705ffc 100644 --- a/grc/gui/Bars.py +++ b/grc/gui/Bars.py @@ -52,6 +52,7 @@ TOOLBAR_LIST = ( None, Actions.RELOAD_BLOCKS, Actions.OPEN_HIER, + Actions.BUSSIFY_SOURCES, ) ##The list of actions and categories for the menu bar. diff --git a/grc/gui/Block.py b/grc/gui/Block.py index 11e66bff85..e69fe1a418 100644 --- a/grc/gui/Block.py +++ b/grc/gui/Block.py @@ -124,6 +124,7 @@ class Block(Element): def create_shapes(self): """Update the block, parameters, and ports when a change occurs.""" + 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)) @@ -173,7 +174,10 @@ class Block(Element): 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())] + for ports in (self.get_sources_gui(), self.get_sinks_gui())] + + [4*PORT_BORDER_SEPARATION + \ + sum([(port.H) + PORT_SEPARATION for port in ports]) - PORT_SEPARATION + for ports in ([i for i in self.get_sources_gui() if i.get_type() == 'bus'], [i for i in self.get_sinks_gui() if i.get_type() == 'bus'])] )) def draw(self, gc, window): @@ -196,7 +200,10 @@ class Block(Element): elif self.is_vertical(): window.draw_drawable(gc, self.vertical_label, 0, 0, x+(self.H-self.label_height)/2, y+BLOCK_LABEL_PADDING, -1, -1) #draw ports - for port in self.get_ports(): port.draw(gc, window) + + + for port in self.get_ports_gui(): + port.draw(gc, window) def what_is_selected(self, coor, coor_m=None): """ @@ -209,7 +216,7 @@ class Block(Element): Returns: this block, a port, or None """ - for port in self.get_ports(): + for port in self.get_ports_gui(): port_selected = port.what_is_selected(coor, coor_m) if port_selected: return port_selected return Element.what_is_selected(self, coor, coor_m) diff --git a/grc/gui/Connection.py b/grc/gui/Connection.py index 5d24fefded..4f46e73ea9 100644 --- a/grc/gui/Connection.py +++ b/grc/gui/Connection.py @@ -62,7 +62,10 @@ class Connection(Element): self._sink_coor = None self._source_coor = None #get the source coordinate - connector_length = self.get_source().get_connector_length() + try: + connector_length = self.get_source().get_connector_length() + except: + return self.x1, self.y1 = Utils.get_rotated_coordinate((connector_length, 0), self.get_source().get_rotation()) #get the sink coordinate connector_length = self.get_sink().get_connector_length() + CONNECTOR_ARROW_HEIGHT @@ -133,7 +136,11 @@ class Connection(Element): source = self.get_source() #check for changes 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() + elif self._sink_coor != sink.get_coordinate() or self._source_coor != source.get_coordinate(): + try: + self._update_after_move() + except: + return #cache values self._sink_rot = sink.get_rotation() self._source_rot = source.get_rotation() @@ -145,5 +152,8 @@ class Connection(Element): else: border_color = Colors.CONNECTION_DISABLED_COLOR Element.draw(self, gc, window, bg_color=None, border_color=border_color) #draw arrow on sink port - gc.set_foreground(self._arrow_color) - window.draw_polygon(gc, True, self._arrow) + try: + gc.set_foreground(self._arrow_color) + window.draw_polygon(gc, True, self._arrow) + except: + return diff --git a/grc/gui/Element.py b/grc/gui/Element.py index eac59d88eb..cd97a3fb21 100644 --- a/grc/gui/Element.py +++ b/grc/gui/Element.py @@ -69,7 +69,7 @@ class Element(object): 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() + for child in self.get_children():child.create_labels() def create_shapes(self): """ @@ -89,6 +89,7 @@ class Element(object): border_color: the color for lines and rectangle borders bg_color: the color for the inside of the rectangle """ + X,Y = self.get_coordinate() for (rX,rY),(W,H) in self._areas_list: aX = X + rX diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py index 3f17c47bc8..a238ed166a 100644 --- a/grc/gui/FlowGraph.py +++ b/grc/gui/FlowGraph.py @@ -65,6 +65,8 @@ class FlowGraph(Element): Actions.BLOCK_PARAM_MODIFY, Actions.BLOCK_CREATE_HIER, Actions.OPEN_HIER, + Actions.BUSSIFY_SOURCES, + Actions.BUSSIFY_SINKS, ]: self._context_menu.append(action.create_menu_item()) ########################################################################### @@ -141,6 +143,7 @@ class FlowGraph(Element): Args: clipboard: the nested data of blocks, connections """ + selected = set() (x_min, y_min), blocks_n, connections_n = clipboard old_id2block = dict() @@ -158,18 +161,23 @@ class FlowGraph(Element): #set params params_n = block_n.findall('param') for param_n in params_n: + param_key = param_n.find('key') param_value = param_n.find('value') #setup id parameter 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 [block.get_id() for block in self.get_blocks()]: + if param_value in [bluck.get_id() for bluck in self.get_blocks()]: param_value = self._get_unique_id(param_value) + + #set value to key + block.get_param(param_key).set_value(param_value) #move block to offset coordinate block.move((x_off, y_off)) + #update before creating connections self.update() #create connections @@ -333,9 +341,13 @@ class FlowGraph(Element): Call the top level rewrite and validate. Call the top level create labels and shapes. """ + self.rewrite() + self.validate() + self.create_labels() + self.create_shapes() ########################################################################## diff --git a/grc/gui/Port.py b/grc/gui/Port.py index 7b4c27dd5f..2ccc394971 100644 --- a/grc/gui/Port.py +++ b/grc/gui/Port.py @@ -45,15 +45,22 @@ class Port(Element): def create_shapes(self): """Create new areas and labels for the port.""" Element.create_shapes(self) + #get current rotation rotation = self.get_rotation() #get all sibling ports - if self.is_source(): ports = self.get_parent().get_sources() - elif self.is_sink(): ports = self.get_parent().get_sinks() + if self.is_source(): ports = self.get_parent().get_sources_gui() + elif self.is_sink(): ports = self.get_parent().get_sinks_gui() #get the max width self.W = max([port.W for port in ports] + [PORT_MIN_WIDTH]) #get a numeric index for this port relative to its sibling ports - index = ports.index(self) + try: + index = ports.index(self) + except: + if hasattr(self, '_connector_length'): + del self._connector_length; + return + length = len(ports) #reverse the order of ports for these rotations if rotation in (180, 270): index = length-index-1 @@ -81,7 +88,15 @@ class Port(Element): self._connector_coordinate = (x+self.H/2, y+1+self.W) #the connector length self._connector_length = CONNECTOR_EXTENSION_MINIMAL + CONNECTOR_EXTENSION_INCREMENT*index - + + def modify_height(self, start_height): + type_dict = {'bus':(lambda a: a * 3)}; + + if self.get_type() in type_dict: + return type_dict[self.get_type()](start_height); + else: + return start_height; + def create_labels(self): """Create the labels for the socket.""" Element.create_labels(self) @@ -91,6 +106,7 @@ class Port(Element): layout.set_markup(Utils.parse_template(PORT_MARKUP_TMPL, port=self)) self.w, self.h = layout.get_pixel_size() self.W, self.H = 2*PORT_LABEL_PADDING+self.w, 2*PORT_LABEL_PADDING+self.h + self.H = self.modify_height(self.H); #create the pixmap pixmap = self.get_parent().get_parent().new_pixmap(self.w, self.h) gc = pixmap.new_gc() @@ -111,6 +127,7 @@ class Port(Element): gc: the graphics context window: the gtk window to draw on """ + Element.draw( self, gc, window, bg_color=self._bg_color, border_color=self.is_highlighted() and Colors.HIGHLIGHT_COLOR or Colors.BORDER_COLOR, diff --git a/grc/gui/Utils.py b/grc/gui/Utils.py index b68c19c4e1..407c875a87 100644 --- a/grc/gui/Utils.py +++ b/grc/gui/Utils.py @@ -101,4 +101,10 @@ def parse_template(tmpl_str, **kwargs): a string of the parsed template """ kwargs['encode'] = gobject.markup_escape_text + #try: + # cat = str(Template(tmpl_str, kwargs)) + #except TypeError: + # print 'guppy' + # print tmpl_str + # print str(kwargs['param'].get_error_messages()) return str(Template(tmpl_str, kwargs)) |