From 58cebfd63726dc2082ab31681afcd78e25c36132 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 5 Sep 2009 00:45:14 -0700 Subject: Implement a recursive validation api in the base Element class. The rewrite and validate methods will invoke themselves on the child elements. The error messages are now a super-list of element and child error messages. As a side-effect, this cleans up code in base Block and Flowgraph class. --- grc/base/Block.py | 23 +---------------------- grc/base/Element.py | 48 +++++++++++++++++++++++++++++++++++++++++++----- grc/base/FlowGraph.py | 21 +-------------------- 3 files changed, 45 insertions(+), 47 deletions(-) diff --git a/grc/base/Block.py b/grc/base/Block.py index fc501205f..cb21c3958 100644 --- a/grc/base/Block.py +++ b/grc/base/Block.py @@ -132,28 +132,6 @@ class Block(Element): """ self.get_param('_enabled').set_value(str(enabled)) - def rewrite(self): - """ - Rewrite critical structures. - Call rewrite on all sub elements. - """ - Element.rewrite(self) - for elem in self.get_ports() + self.get_params(): elem.rewrite() - - def validate(self): - """ - Validate the block. - All ports and params must be valid. - All checks must evaluate to true. - Validate the params, ports, and the connections to this block. - """ - Element.validate(self) - for c in self.get_params() + self.get_ports() + self.get_connections(): - c.validate() - if not c.is_valid(): - for msg in c.get_error_messages(): - self.add_error_message('>>> %s:\n\t%s'%(c, msg)) - def __str__(self): return 'Block - %s - %s(%s)'%(self.get_id(), self.get_name(), self.get_key()) def get_id(self): return self.get_param('id').get_value() @@ -163,6 +141,7 @@ class Block(Element): def get_category(self): return self._category def get_doc(self): return '' def get_ports(self): return self.get_sources() + self.get_sinks() + def get_children(self): return self.get_ports() + self.get_params() def get_block_wrapper_path(self): return self._block_wrapper_path ############################################## diff --git a/grc/base/Element.py b/grc/base/Element.py index 43cee886c..e77e7ce08 100644 --- a/grc/base/Element.py +++ b/grc/base/Element.py @@ -25,16 +25,54 @@ class Element(object): ################################################## # Element Validation API ################################################## - def validate(self): self._error_messages = list() - def is_valid(self): return not self.get_error_messages() or not self.get_enabled() - def add_error_message(self, msg): self._error_messages.append(msg) - def get_error_messages(self): return self._error_messages + def validate(self): + """ + Validate this element and call validate on all children. + Call this base method before adding error messages in the subclass. + """ + self._error_messages = list() + for child in self.get_children(): child.validate() - def rewrite(self): pass + def is_valid(self): + """ + Is this element valid? + @return true when the element is enabled and has no error messages + """ + return not self.get_error_messages() or not self.get_enabled() + + def add_error_message(self, msg): + """ + Add an error message to the list of errors. + @param msg the error message string + """ + self._error_messages.append(msg) + + def get_error_messages(self): + """ + Get the list of error messages from this element and all of its children. + Cleverly indent the children error messages for printing purposes. + @return a list of error message strings + """ + error_messages = list(self._error_messages) #make a copy + for child in self.get_children(): + for msg in child.get_error_messages(): + error_messages.append("%s:\n\t%s"%(child, msg.replace("\n", "\n\t"))) + return error_messages + + def rewrite(self): + """ + Rewrite this element and call rewrite on all children. + Call this base method before rewriting the element. + """ + for child in self.get_children(): child.rewrite() def get_enabled(self): return True + ############################################## + ## Tree-like API + ############################################## def get_parent(self): return self._parent + def get_children(self): return list() ############################################## ## Type testing methods diff --git a/grc/base/FlowGraph.py b/grc/base/FlowGraph.py index b24f13b09..ce370ca24 100644 --- a/grc/base/FlowGraph.py +++ b/grc/base/FlowGraph.py @@ -68,6 +68,7 @@ class FlowGraph(Element): def get_block(self, id): return filter(lambda b: b.get_id() == id, self.get_blocks())[0] def get_blocks(self): return filter(lambda e: e.is_block(), self.get_elements()) def get_connections(self): return filter(lambda e: e.is_connection(), self.get_elements()) + def get_children(self): return self.get_elements() def get_elements(self): """ Get a list of all the elements. @@ -144,26 +145,6 @@ class FlowGraph(Element): """ raise NotImplementedError - def rewrite(self): - """ - Rewrite critical structures. - Call rewrite on all sub elements. - """ - Element.rewrite(self) - for elem in self.get_elements(): elem.rewrite() - - def validate(self): - """ - Validate the flow graph. - Validate only the blocks. - Connections will be validated within the blocks. - """ - Element.validate(self) - for c in self.get_blocks(): - c.validate() - if not c.is_valid(): - self.add_error_message('Element "%s" is not valid.'%c) - ############################################## ## Import/Export Methods ############################################## -- cgit From 4cc3667b348d58ef4fb30f0ecbe494cdb109fc83 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 5 Sep 2009 00:54:56 -0700 Subject: better error msg for empty statements --- grc/python/FlowGraph.py | 1 + grc/todo.txt | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/grc/python/FlowGraph.py b/grc/python/FlowGraph.py index 6b2936c75..4dd18a81f 100644 --- a/grc/python/FlowGraph.py +++ b/grc/python/FlowGraph.py @@ -42,6 +42,7 @@ class FlowGraph(_FlowGraph, _GUIFlowGraph): @param namespace_hash a unique hash for the namespace @return the resultant object """ + if not code: raise Exception, 'Cannot evaluate empty statement.' my_hash = hash(code) ^ namespace_hash #cache if does not exist if not self._eval_cache.has_key(my_hash): diff --git a/grc/todo.txt b/grc/todo.txt index ffc9d64db..ca9a68180 100644 --- a/grc/todo.txt +++ b/grc/todo.txt @@ -68,7 +68,6 @@ * save/restore cwd * threads dont die on exit in probe and variable sink * align param titles in paramsdialog -* better error for blank string params * weird grid params misbehaving * params dialog needs to dynamically update for all params * will not update for non-enum params -- cgit From 5f54b018b3a84ba4b68009a1c326ba73eaea8cfd Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 5 Sep 2009 01:54:41 -0700 Subject: standardized the Element inheritance __init__ usage in gui --- grc/gui/Block.py | 2 +- grc/gui/Connection.py | 2 ++ grc/gui/Element.py | 2 +- grc/gui/FlowGraph.py | 2 +- grc/gui/Param.py | 2 ++ grc/gui/Platform.py | 3 ++- grc/gui/Port.py | 2 +- 7 files changed, 10 insertions(+), 5 deletions(-) diff --git a/grc/gui/Block.py b/grc/gui/Block.py index 0f3e511d8..68c4da9c3 100644 --- a/grc/gui/Block.py +++ b/grc/gui/Block.py @@ -37,7 +37,7 @@ BLOCK_MARKUP_TMPL="""\ class Block(Element): """The graphical signal block.""" - def __init__(self, *args, **kwargs): + def __init__(self): """ Block contructor. Add graphics related params to the block. diff --git a/grc/gui/Connection.py b/grc/gui/Connection.py index 013bcb00f..a85650ee2 100644 --- a/grc/gui/Connection.py +++ b/grc/gui/Connection.py @@ -32,6 +32,8 @@ class Connection(Element): The arrow coloring exposes the enabled and valid states. """ + def __init__(self): Element.__init__(self) + def get_coordinate(self): """ Get the 0,0 coordinate. diff --git a/grc/gui/Element.py b/grc/gui/Element.py index 315191723..ecf1de1ca 100644 --- a/grc/gui/Element.py +++ b/grc/gui/Element.py @@ -32,7 +32,7 @@ class Element(object): and methods to detect selection of those areas. """ - def __init__(self, *args, **kwargs): + def __init__(self): """ Make a new list of rectangular areas and lines, and set the coordinate and the rotation. """ diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py index 5e645be72..8a908ff50 100644 --- a/grc/gui/FlowGraph.py +++ b/grc/gui/FlowGraph.py @@ -39,7 +39,7 @@ class FlowGraph(Element): and the connections between inputs and outputs. """ - def __init__(self, *args, **kwargs): + def __init__(self): """ FlowGraph contructor. Create a list for signal blocks and connections. Connect mouse handlers. diff --git a/grc/gui/Param.py b/grc/gui/Param.py index 4955d3336..5cc8d9c7f 100644 --- a/grc/gui/Param.py +++ b/grc/gui/Param.py @@ -114,6 +114,8 @@ Error: class Param(Element): """The graphical parameter.""" + def __init__(self): Element.__init__(self) + def get_input_class(self): """ Get the graphical gtk class to represent this parameter. diff --git a/grc/gui/Platform.py b/grc/gui/Platform.py index 8f0aa533d..8bbfaca23 100644 --- a/grc/gui/Platform.py +++ b/grc/gui/Platform.py @@ -19,4 +19,5 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA from Element import Element -class Platform(Element): pass +class Platform(Element): + def __init__(self): Element.__init__(self) diff --git a/grc/gui/Port.py b/grc/gui/Port.py index 6fc2c4b15..9c8d87a16 100644 --- a/grc/gui/Port.py +++ b/grc/gui/Port.py @@ -34,7 +34,7 @@ PORT_MARKUP_TMPL="""\ class Port(Element): """The graphical port.""" - def __init__(self, *args, **kwargs): + def __init__(self): """ Port contructor. Create list of connector coordinates. -- cgit From 5bb2a70a94be9c0f83712ee259b7125e3a582b08 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 5 Sep 2009 02:01:41 -0700 Subject: replaced dict[rot] storage of areas and lines with a single list for the current rotation --- grc/gui/Element.py | 28 ++++++++++++---------------- grc/gui/Port.py | 2 +- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/grc/gui/Element.py b/grc/gui/Element.py index ecf1de1ca..bda187059 100644 --- a/grc/gui/Element.py +++ b/grc/gui/Element.py @@ -70,14 +70,14 @@ class Element(object): @param bg_color the color for the inside of the rectangle """ X,Y = self.get_coordinate() - for (rX,rY),(W,H) in self.areas_dict[self.get_rotation()]: + for (rX,rY),(W,H) in self._areas_list: aX = X + rX aY = Y + rY gc.set_foreground(bg_color) window.draw_rectangle(gc, True, aX, aY, W, H) gc.set_foreground(border_color) window.draw_rectangle(gc, False, aX, aY, W, H) - for (x1, y1),(x2, y2) in self.lines_dict[self.get_rotation()]: + for (x1, y1),(x2, y2) in self._lines_list: gc.set_foreground(border_color) window.draw_line(gc, X+x1, Y+y1, X+x2, Y+y2) @@ -90,8 +90,8 @@ class Element(object): def clear(self): """Empty the lines and areas.""" - self.areas_dict = dict((rotation, list()) for rotation in POSSIBLE_ROTATIONS) - self.lines_dict = dict((rotation, list()) for rotation in POSSIBLE_ROTATIONS) + self._areas_list = list() + self._lines_list = list() def set_coordinate(self, coor): """ @@ -136,7 +136,7 @@ class Element(object): X, Y = self.get_coordinate() self.set_coordinate((X+deltaX, Y+deltaY)) - def add_area(self, rel_coor, area, rotation=None): + def add_area(self, rel_coor, area): """ Add an area to the area list. An area is actually a coordinate relative to the main coordinate @@ -144,25 +144,21 @@ class Element(object): A positive width is to the right of the coordinate. A positive height is above the coordinate. The area is associated with a rotation. - If rotation is not specified, the element's current rotation is used. @param rel_coor (x,y) offset from this element's coordinate @param area (width,height) tuple - @param rotation rotation in degrees """ - self.areas_dict[rotation or self.get_rotation()].append((rel_coor, area)) + self._areas_list.append((rel_coor, area)) - def add_line(self, rel_coor1, rel_coor2, rotation=None): + def add_line(self, rel_coor1, rel_coor2): """ Add a line to the line list. A line is defined by 2 relative coordinates. Lines must be horizontal or vertical. The line is associated with a rotation. - If rotation is not specified, the element's current rotation is used. @param rel_coor1 relative (x1,y1) tuple @param rel_coor2 relative (x2,y2) tuple - @param rotation rotation in degrees """ - self.lines_dict[rotation or self.get_rotation()].append((rel_coor1, rel_coor2)) + self._lines_list.append((rel_coor1, rel_coor2)) def what_is_selected(self, coor, coor_m=None): """ @@ -183,24 +179,24 @@ class Element(object): if coor_m: x_m, y_m = [a-b for a,b in zip(coor_m, self.get_coordinate())] #handle rectangular areas - for (x1,y1), (w,h) in self.areas_dict[self.get_rotation()]: + for (x1,y1), (w,h) in self._areas_list: if in_between(x1, x, x_m) and in_between(y1, y, y_m) or \ in_between(x1+w, x, x_m) and in_between(y1, y, y_m) or \ in_between(x1, x, x_m) and in_between(y1+h, y, y_m) or \ in_between(x1+w, x, x_m) and in_between(y1+h, y, y_m): return self #handle horizontal or vertical lines - for (x1, y1), (x2, y2) in self.lines_dict[self.get_rotation()]: + for (x1, y1), (x2, y2) in self._lines_list: if in_between(x1, x, x_m) and in_between(y1, y, y_m) or \ in_between(x2, x, x_m) and in_between(y2, y, y_m): return self return None else: #handle rectangular areas - for (x1,y1), (w,h) in self.areas_dict[self.get_rotation()]: + for (x1,y1), (w,h) in self._areas_list: if in_between(x, x1, x1+w) and in_between(y, y1, y1+h): return self #handle horizontal or vertical lines - for (x1, y1), (x2, y2) in self.lines_dict[self.get_rotation()]: + for (x1, y1), (x2, y2) in self._lines_list: if x1 == x2: x1, x2 = x1-LINE_SELECT_SENSITIVITY, x2+LINE_SELECT_SENSITIVITY if y1 == y2: y1, y2 = y1-LINE_SELECT_SENSITIVITY, y2+LINE_SELECT_SENSITIVITY if in_between(x, x1, x2) and in_between(y, y1, y2): return self diff --git a/grc/gui/Port.py b/grc/gui/Port.py index 9c8d87a16..f8bfefee6 100644 --- a/grc/gui/Port.py +++ b/grc/gui/Port.py @@ -114,7 +114,7 @@ class Port(Element): border_color=self.is_highlighted() and Colors.HIGHLIGHT_COLOR or Colors.BORDER_COLOR, ) X,Y = self.get_coordinate() - (x,y),(w,h) = self.areas_dict[self.get_rotation()][0] #use the first area's sizes to place the labels + (x,y),(w,h) = self._areas_list[0] #use the first area's sizes to place the labels if self.is_horizontal(): window.draw_image(gc, self.horizontal_label, 0, 0, x+X+(self.W-self.w)/2, y+Y+(self.H-self.h)/2, -1, -1) elif self.is_vertical(): -- cgit From fa465d160b0c53fae3ad7876cf429263157dd60a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 5 Sep 2009 02:21:37 -0700 Subject: 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. --- grc/gui/Block.py | 25 ++++++++++++------------- grc/gui/Connection.py | 7 ++++--- grc/gui/Element.py | 19 +++++++++++++++---- grc/gui/FlowGraph.py | 7 ++++--- grc/gui/Port.py | 7 ++++--- 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('') -- cgit From caf93a02068e8379ffa7f553deabb62cfc42b9a7 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 5 Sep 2009 02:38:46 -0700 Subject: remove unused imports, copyright date update, tweak --- grc/gui/Block.py | 2 +- grc/gui/Connection.py | 2 +- grc/gui/Element.py | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/grc/gui/Block.py b/grc/gui/Block.py index fd8cfc226..8c65bf06f 100644 --- a/grc/gui/Block.py +++ b/grc/gui/Block.py @@ -135,7 +135,7 @@ class Block(Element): layouts.append(layout) w,h = layout.get_pixel_size() self.label_width = max(w, self.label_width) - self.label_height = self.label_height + h + LABEL_SEPARATION + self.label_height += h + LABEL_SEPARATION width = self.label_width height = self.label_height #setup the pixmap diff --git a/grc/gui/Connection.py b/grc/gui/Connection.py index 45f8a689a..fabf34ee7 100644 --- a/grc/gui/Connection.py +++ b/grc/gui/Connection.py @@ -1,5 +1,5 @@ """ -Copyright 2007, 2008 Free Software Foundation, Inc. +Copyright 2007, 2008, 2009 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or diff --git a/grc/gui/Element.py b/grc/gui/Element.py index 2e20b9a22..f0518ee12 100644 --- a/grc/gui/Element.py +++ b/grc/gui/Element.py @@ -1,5 +1,5 @@ """ -Copyright 2007 Free Software Foundation, Inc. +Copyright 2007, 2008, 2009 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or @@ -17,11 +17,9 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA """ -import Colors import pygtk pygtk.require('2.0') import gtk -import pango from Constants import LINE_SELECT_SENSITIVITY from Constants import POSSIBLE_ROTATIONS -- cgit From 79bace9eb9e441405535e082f3f0ee1a26740fe0 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 5 Sep 2009 21:11:51 -0700 Subject: renamed params dialog to props dialog --- grc/gui/ActionHandler.py | 4 +- grc/gui/Makefile.am | 2 +- grc/gui/ParamsDialog.py | 145 ----------------------------------------------- grc/gui/PropsDialog.py | 145 +++++++++++++++++++++++++++++++++++++++++++++++ grc/todo.txt | 2 + 5 files changed, 150 insertions(+), 148 deletions(-) delete mode 100644 grc/gui/ParamsDialog.py create mode 100644 grc/gui/PropsDialog.py diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py index 8f317d6a8..f12893579 100644 --- a/grc/gui/ActionHandler.py +++ b/grc/gui/ActionHandler.py @@ -31,7 +31,7 @@ import Messages from .. base import ParseXML import random from MainWindow import MainWindow -from ParamsDialog import ParamsDialog +from PropsDialog import PropsDialog import Dialogs from FileDialogs import OpenFlowGraphFileDialog, SaveFlowGraphFileDialog, SaveImageFileDialog @@ -240,7 +240,7 @@ class ActionHandler: ################################################## elif state == Actions.BLOCK_PARAM_MODIFY: selected_block = self.get_flow_graph().get_selected_block() - if selected_block and ParamsDialog(selected_block).run(): + if selected_block and PropsDialog(selected_block).run(): self.get_flow_graph().update() self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data()) self.get_page().set_saved(False) diff --git a/grc/gui/Makefile.am b/grc/gui/Makefile.am index cb45d5359..b14817d04 100644 --- a/grc/gui/Makefile.am +++ b/grc/gui/Makefile.am @@ -43,7 +43,7 @@ ourpython_PYTHON = \ MainWindow.py \ Messages.py \ NotebookPage.py \ - ParamsDialog.py \ + PropsDialog.py \ Preferences.py \ StateCache.py \ __init__.py diff --git a/grc/gui/ParamsDialog.py b/grc/gui/ParamsDialog.py deleted file mode 100644 index ccf19d1a2..000000000 --- a/grc/gui/ParamsDialog.py +++ /dev/null @@ -1,145 +0,0 @@ -""" -Copyright 2007, 2008, 2009 Free Software Foundation, Inc. -This file is part of GNU Radio - -GNU Radio Companion is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -GNU Radio Companion is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -""" - -import pygtk -pygtk.require('2.0') -import gtk - -from Dialogs import TextDisplay -from Constants import MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT - -def get_title_label(title): - """ - Get a title label for the params window. - The title will be bold, underlined, and left justified. - @param title the text of the title - @return a gtk object - """ - label = gtk.Label() - label.set_markup('\n%s:\n'%title) - hbox = gtk.HBox() - hbox.pack_start(label, False, False, padding=11) - return hbox - -class ParamsDialog(gtk.Dialog): - """A dialog box to set block parameters.""" - - def __init__(self, block): - """ - SignalBlockParamsDialog contructor. - @param block the signal block - """ - gtk.Dialog.__init__(self, - title='Properties: %s'%block.get_name(), - buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE), - ) - self.block = block - self.set_size_request(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT) - vbox = gtk.VBox() - #Add the title label - vbox.pack_start(get_title_label('Parameters'), False) - #Create the scrolled window to hold all the parameters - scrolled_window = gtk.ScrolledWindow() - scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) - scrolled_window.add_with_viewport(vbox) - self.vbox.pack_start(scrolled_window, True) - #Error Messages for the block - self._error_box = gtk.VBox() - self._error_messages_text_display = TextDisplay() - self._error_box.pack_start(gtk.Label(), False, False, 7) #spacing - self._error_box.pack_start(get_title_label('Error Messages'), False) - self._error_box.pack_start(self._error_messages_text_display, False) - #Docs for the block - self._docs_box = err_box = gtk.VBox() - self._docs_text_display = TextDisplay() - self._docs_box.pack_start(gtk.Label(), False, False, 7) #spacing - self._docs_box.pack_start(get_title_label('Documentation'), False) - self._docs_box.pack_start(self._docs_text_display, False) - #Add all the parameters - for param in self.block.get_params(): - vbox.pack_start(param.get_input_object(self._handle_changed), False) - #Add the error and docs box - vbox.pack_start(self._error_box, False) - vbox.pack_start(self._docs_box, False) - #connect and show - self.connect('key_press_event', self._handle_key_press) - self.show_all() - #initial update - for param in self.block.get_params(): param.update() - self._update() - - def _update(self): - """ - Update the error messages box. - Hide the box if there are no errors. - Update the documentation block. - Hide the box if there are no docs. - """ - self.block.validate() - #update the errors box - if self.block.is_valid(): self._error_box.hide() - else: self._error_box.show() - messages = '\n\n'.join(self.block.get_error_messages()) - self._error_messages_text_display.set_text(messages) - #update the docs box - if self.block.get_doc(): self._docs_box.show() - else: self._docs_box.hide() - self._docs_text_display.set_text(self.block.get_doc()) - - def _handle_key_press(self, widget, event): - """ - Handle key presses from the keyboard. - Call the ok response when enter is pressed. - @return false to forward the keypress - """ - keyname = gtk.gdk.keyval_name(event.keyval) - if keyname == 'Return': self.response(gtk.RESPONSE_OK) - return False #forward the keypress - - def _handle_changed(self, param): - """ - A change occured, update any dependent parameters: - The enum inside the variable type may have changed and, - the variable param will need an external update. - @param param the graphical parameter that initiated the callback - """ - #update dependent params - if param.is_enum(): - for other_param in param.get_parent().get_params(): - if param.get_key() is not other_param.get_key() and ( - param.get_key() in other_param._type or \ - param.get_key() in other_param._hide): other_param.update() - #update - self._update() - return True - - def run(self): - """ - Call run(). - @return true if a change occured. - """ - original_data = list() - for param in self.block.get_params(): - original_data.append(param.get_value()) - gtk.Dialog.run(self) - self.destroy() - new_data = list() - for param in self.block.get_params(): - new_data.append(param.get_value()) - return original_data != new_data diff --git a/grc/gui/PropsDialog.py b/grc/gui/PropsDialog.py new file mode 100644 index 000000000..200cff1f5 --- /dev/null +++ b/grc/gui/PropsDialog.py @@ -0,0 +1,145 @@ +""" +Copyright 2007, 2008, 2009 Free Software Foundation, Inc. +This file is part of GNU Radio + +GNU Radio Companion is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +GNU Radio Companion is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +""" + +import pygtk +pygtk.require('2.0') +import gtk + +from Dialogs import TextDisplay +from Constants import MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT + +def get_title_label(title): + """ + Get a title label for the params window. + The title will be bold, underlined, and left justified. + @param title the text of the title + @return a gtk object + """ + label = gtk.Label() + label.set_markup('\n%s:\n'%title) + hbox = gtk.HBox() + hbox.pack_start(label, False, False, padding=11) + return hbox + +class PropsDialog(gtk.Dialog): + """A dialog box to set block parameters.""" + + def __init__(self, block): + """ + SignalBlockParamsDialog contructor. + @param block the signal block + """ + gtk.Dialog.__init__(self, + title='Properties: %s'%block.get_name(), + buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE), + ) + self.block = block + self.set_size_request(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT) + vbox = gtk.VBox() + #Add the title label + vbox.pack_start(get_title_label('Parameters'), False) + #Create the scrolled window to hold all the parameters + scrolled_window = gtk.ScrolledWindow() + scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) + scrolled_window.add_with_viewport(vbox) + self.vbox.pack_start(scrolled_window, True) + #Error Messages for the block + self._error_box = gtk.VBox() + self._error_messages_text_display = TextDisplay() + self._error_box.pack_start(gtk.Label(), False, False, 7) #spacing + self._error_box.pack_start(get_title_label('Error Messages'), False) + self._error_box.pack_start(self._error_messages_text_display, False) + #Docs for the block + self._docs_box = err_box = gtk.VBox() + self._docs_text_display = TextDisplay() + self._docs_box.pack_start(gtk.Label(), False, False, 7) #spacing + self._docs_box.pack_start(get_title_label('Documentation'), False) + self._docs_box.pack_start(self._docs_text_display, False) + #Add all the parameters + for param in self.block.get_params(): + vbox.pack_start(param.get_input_object(self._handle_changed), False) + #Add the error and docs box + vbox.pack_start(self._error_box, False) + vbox.pack_start(self._docs_box, False) + #connect and show + self.connect('key_press_event', self._handle_key_press) + self.show_all() + #initial update + for param in self.block.get_params(): param.update() + self._update() + + def _update(self): + """ + Update the error messages box. + Hide the box if there are no errors. + Update the documentation block. + Hide the box if there are no docs. + """ + self.block.validate() + #update the errors box + if self.block.is_valid(): self._error_box.hide() + else: self._error_box.show() + messages = '\n\n'.join(self.block.get_error_messages()) + self._error_messages_text_display.set_text(messages) + #update the docs box + if self.block.get_doc(): self._docs_box.show() + else: self._docs_box.hide() + self._docs_text_display.set_text(self.block.get_doc()) + + def _handle_key_press(self, widget, event): + """ + Handle key presses from the keyboard. + Call the ok response when enter is pressed. + @return false to forward the keypress + """ + keyname = gtk.gdk.keyval_name(event.keyval) + if keyname == 'Return': self.response(gtk.RESPONSE_OK) + return False #forward the keypress + + def _handle_changed(self, param): + """ + A change occured, update any dependent parameters: + The enum inside the variable type may have changed and, + the variable param will need an external update. + @param param the graphical parameter that initiated the callback + """ + #update dependent params + if param.is_enum(): + for other_param in param.get_parent().get_params(): + if param.get_key() is not other_param.get_key() and ( + param.get_key() in other_param._type or \ + param.get_key() in other_param._hide): other_param.update() + #update + self._update() + return True + + def run(self): + """ + Call run(). + @return true if a change occured. + """ + original_data = list() + for param in self.block.get_params(): + original_data.append(param.get_value()) + gtk.Dialog.run(self) + self.destroy() + new_data = list() + for param in self.block.get_params(): + new_data.append(param.get_value()) + return original_data != new_data diff --git a/grc/todo.txt b/grc/todo.txt index ca9a68180..8afd2f145 100644 --- a/grc/todo.txt +++ b/grc/todo.txt @@ -73,6 +73,8 @@ * will not update for non-enum params * needs to account for added or removed params * example with grid params need update after notebook change + * idea: hash the current param keys list and types, + if changed, redo the whole dialog (params part) ################################################## # Future -- cgit From 49b8dd0586241f59df4b74679349718cbe946fde Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 5 Sep 2009 23:41:49 -0700 Subject: Rework the params/properties dialog and param gui class: Better handles dynamic changes and subsequent code cleanup. --- grc/gui/Param.py | 65 +++++++++++++++++++------------------- grc/gui/PropsDialog.py | 84 +++++++++++++++++++++++++++++++------------------- grc/todo.txt | 9 ++---- 3 files changed, 87 insertions(+), 71 deletions(-) diff --git a/grc/gui/Param.py b/grc/gui/Param.py index 5cc8d9c7f..3c5e99e9e 100644 --- a/grc/gui/Param.py +++ b/grc/gui/Param.py @@ -26,10 +26,10 @@ import gtk class InputParam(gtk.HBox): """The base class for an input parameter inside the input parameters dialog.""" - def __init__(self, param, _handle_changed): + def __init__(self, param, callback=None): gtk.HBox.__init__(self) self.param = param - self._handle_changed = _handle_changed + self._callback = callback self.label = gtk.Label('') #no label, markup is added by set_markup self.label.set_size_request(150, -1) self.pack_start(self.label, False) @@ -37,6 +37,34 @@ class InputParam(gtk.HBox): self.tp = None def set_color(self, color): pass + def update(self): + """ + Set the markup, color, and tooltip. + """ + #set the markup + has_cb = \ + hasattr(self.param.get_parent(), 'get_callbacks') and \ + filter(lambda c: self.param.get_key() in c, self.param.get_parent()._callbacks) + self.set_markup(Utils.parse_template(PARAM_LABEL_MARKUP_TMPL, param=self.param, has_cb=has_cb)) + #set the color + self.set_color(self.param.get_color()) + #set the tooltip + if self.tp: self.tp.set_tip( + self.entry, + Utils.parse_template(TIP_MARKUP_TMPL, param=self.param).strip(), + ) + + def _handle_changed(self, *args): + """ + Handle a gui change by setting the new param value, + calling the callback (if applicable), and updating. + """ + #set the new value + self.param.set_value(self.get_text()) + #call the callback + if self._callback: self._callback() + #self.update() #dont update here, parent will update + class EntryParam(InputParam): """Provide an entry box for strings and numbers.""" @@ -138,39 +166,10 @@ class Param(Element): def get_input_object(self, callback=None): """ Get the graphical gtk object to represent this parameter. - Create the input object with this data type and the handle changed method. - @param callback a function of one argument(this param) to be called from the change handler + @param callback a function to be called from the input object. @return gtk input object """ - self._callback = callback - self._input = self.get_input_class()(self, self._handle_changed) - if not self._callback: self.update() - return self._input - - def _handle_changed(self, widget=None): - """ - When the input changes, write the inputs to the data type. - Finish by calling the exteral callback. - """ - self.set_value(self._input.get_text()) - self.validate() - #is param is involved in a callback? #FIXME: messy - has_cb = \ - hasattr(self.get_parent(), 'get_callbacks') and \ - filter(lambda c: self.get_key() in c, self.get_parent()._callbacks) - self._input.set_markup(Utils.parse_template(PARAM_LABEL_MARKUP_TMPL, param=self, has_cb=has_cb)) - #hide/show - if self.get_hide() == 'all': self._input.hide_all() - else: self._input.show_all() - #set the color - self._input.set_color(self.get_color()) - #set the tooltip - if self._input.tp: self._input.tp.set_tip( - self._input.entry, - Utils.parse_template(TIP_MARKUP_TMPL, param=self).strip(), - ) - #execute the external callback - if self._callback: self._callback(self) + return self.get_input_class()(self, callback=callback) def get_layout(self): """ diff --git a/grc/gui/PropsDialog.py b/grc/gui/PropsDialog.py index 200cff1f5..bd66b1178 100644 --- a/grc/gui/PropsDialog.py +++ b/grc/gui/PropsDialog.py @@ -38,13 +38,17 @@ def get_title_label(title): return hbox class PropsDialog(gtk.Dialog): - """A dialog box to set block parameters.""" + """ + A dialog to set block parameters, view errors, and view documentation. + """ def __init__(self, block): """ - SignalBlockParamsDialog contructor. - @param block the signal block + Properties dialog contructor. + @param block a block instance """ + self._hash = '' + LABEL_SPACING = 7 gtk.Dialog.__init__(self, title='Properties: %s'%block.get_name(), buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE), @@ -52,46 +56,81 @@ class PropsDialog(gtk.Dialog): self.block = block self.set_size_request(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT) vbox = gtk.VBox() - #Add the title label - vbox.pack_start(get_title_label('Parameters'), False) #Create the scrolled window to hold all the parameters scrolled_window = gtk.ScrolledWindow() scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrolled_window.add_with_viewport(vbox) self.vbox.pack_start(scrolled_window, True) + #Params box for block parameters + self._params_box = gtk.VBox() + self._params_box.pack_start(get_title_label('Parameters'), False) + self._input_object_params = list() #Error Messages for the block self._error_box = gtk.VBox() self._error_messages_text_display = TextDisplay() - self._error_box.pack_start(gtk.Label(), False, False, 7) #spacing + self._error_box.pack_start(gtk.Label(), False, False, LABEL_SPACING) self._error_box.pack_start(get_title_label('Error Messages'), False) self._error_box.pack_start(self._error_messages_text_display, False) #Docs for the block self._docs_box = err_box = gtk.VBox() self._docs_text_display = TextDisplay() - self._docs_box.pack_start(gtk.Label(), False, False, 7) #spacing + self._docs_box.pack_start(gtk.Label(), False, False, LABEL_SPACING) self._docs_box.pack_start(get_title_label('Documentation'), False) self._docs_box.pack_start(self._docs_text_display, False) - #Add all the parameters - for param in self.block.get_params(): - vbox.pack_start(param.get_input_object(self._handle_changed), False) - #Add the error and docs box + #Add the boxes + vbox.pack_start(self._params_box, False) vbox.pack_start(self._error_box, False) vbox.pack_start(self._docs_box, False) - #connect and show + #connect key press event self.connect('key_press_event', self._handle_key_press) + #initial update to populate the params self.show_all() - #initial update - for param in self.block.get_params(): param.update() self._update() + def _params_changed(self): + """ + Have the params in this dialog changed? + Ex: Added, removed, type change, hidden, shown? + Make a hash that uniquely represents the params state. + @return true if changed + """ + old_hash = self._hash + str_accum = '' + for param in self.block.get_params(): + str_accum += param.get_key() + str_accum += param.get_type() + str_accum += param.get_hide() + self._hash = hash(str_accum) + return self._hash != old_hash + def _update(self): """ + Repopulate the parameters box (if changed). + Update all the input parameters. Update the error messages box. Hide the box if there are no errors. Update the documentation block. Hide the box if there are no docs. """ + #update for the block + self.block.rewrite() self.block.validate() + #update the params box + if self._params_changed(): + #empty the params box + for io_param in list(self._input_object_params): + self._params_box.remove(io_param) + self._input_object_params.remove(io_param) + io_param.destroy() + #repopulate the params box + for param in self.block.get_params(): + if param.get_hide() == 'all': continue + io_param = param.get_input_object(self._update) + self._input_object_params.append(io_param) + self._params_box.pack_start(io_param, False) + self._params_box.show_all() + #update the gui inputs + for io_param in self._input_object_params: io_param.update() #update the errors box if self.block.is_valid(): self._error_box.hide() else: self._error_box.show() @@ -112,23 +151,6 @@ class PropsDialog(gtk.Dialog): if keyname == 'Return': self.response(gtk.RESPONSE_OK) return False #forward the keypress - def _handle_changed(self, param): - """ - A change occured, update any dependent parameters: - The enum inside the variable type may have changed and, - the variable param will need an external update. - @param param the graphical parameter that initiated the callback - """ - #update dependent params - if param.is_enum(): - for other_param in param.get_parent().get_params(): - if param.get_key() is not other_param.get_key() and ( - param.get_key() in other_param._type or \ - param.get_key() in other_param._hide): other_param.update() - #update - self._update() - return True - def run(self): """ Call run(). diff --git a/grc/todo.txt b/grc/todo.txt index 8afd2f145..99351a912 100644 --- a/grc/todo.txt +++ b/grc/todo.txt @@ -67,14 +67,9 @@ * dont generate py files in saved flowgraph dir * save/restore cwd * threads dont die on exit in probe and variable sink -* align param titles in paramsdialog +* align param titles in properties dialog * weird grid params misbehaving -* params dialog needs to dynamically update for all params - * will not update for non-enum params - * needs to account for added or removed params - * example with grid params need update after notebook change - * idea: hash the current param keys list and types, - if changed, redo the whole dialog (params part) +* properties dialog needs to show connection errors ################################################## # Future -- cgit From a6cb9eceeb62593e852b6dea0f640436381ec947 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 5 Sep 2009 23:49:34 -0700 Subject: more code cleanup for properties dialog --- grc/gui/Param.py | 15 --------------- grc/gui/PropsDialog.py | 2 +- grc/todo.txt | 1 + 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/grc/gui/Param.py b/grc/gui/Param.py index 3c5e99e9e..9cd31b8a4 100644 --- a/grc/gui/Param.py +++ b/grc/gui/Param.py @@ -156,21 +156,6 @@ class Param(Element): if self.get_options(): return EnumEntryParam return EntryParam - def update(self): - """ - Called when an external change occurs. - Update the graphical input by calling the change handler. - """ - if hasattr(self, '_input'): self._handle_changed() - - def get_input_object(self, callback=None): - """ - Get the graphical gtk object to represent this parameter. - @param callback a function to be called from the input object. - @return gtk input object - """ - return self.get_input_class()(self, callback=callback) - def get_layout(self): """ Create a layout based on the current markup. diff --git a/grc/gui/PropsDialog.py b/grc/gui/PropsDialog.py index bd66b1178..9be0400fe 100644 --- a/grc/gui/PropsDialog.py +++ b/grc/gui/PropsDialog.py @@ -125,7 +125,7 @@ class PropsDialog(gtk.Dialog): #repopulate the params box for param in self.block.get_params(): if param.get_hide() == 'all': continue - io_param = param.get_input_object(self._update) + io_param = param.get_input_class()(param, callback=self._update) self._input_object_params.append(io_param) self._params_box.pack_start(io_param, False) self._params_box.show_all() diff --git a/grc/todo.txt b/grc/todo.txt index 99351a912..2735ff2af 100644 --- a/grc/todo.txt +++ b/grc/todo.txt @@ -70,6 +70,7 @@ * align param titles in properties dialog * weird grid params misbehaving * properties dialog needs to show connection errors +* fix param input stuff for usrp probes ################################################## # Future -- cgit From e39507bf32666f9b17d2249106aac0d6cbcacc58 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 6 Sep 2009 01:17:35 -0700 Subject: propsdialog tweaks --- grc/gui/Param.py | 13 ++++++++----- grc/gui/PropsDialog.py | 39 ++++++++++++++++++--------------------- grc/python/Param.py | 6 +++--- grc/todo.txt | 1 - 4 files changed, 29 insertions(+), 30 deletions(-) diff --git a/grc/gui/Param.py b/grc/gui/Param.py index 9cd31b8a4..b84598e61 100644 --- a/grc/gui/Param.py +++ b/grc/gui/Param.py @@ -39,7 +39,7 @@ class InputParam(gtk.HBox): def update(self): """ - Set the markup, color, and tooltip. + Set the markup, color, tooltip, show/hide. """ #set the markup has_cb = \ @@ -53,6 +53,9 @@ class InputParam(gtk.HBox): self.entry, Utils.parse_template(TIP_MARKUP_TMPL, param=self.param).strip(), ) + #show/hide + if self.param.get_hide() == 'all': self.hide_all() + else: self.show_all() def _handle_changed(self, *args): """ @@ -144,7 +147,7 @@ class Param(Element): def __init__(self): Element.__init__(self) - def get_input_class(self): + def get_input(self, *args, **kwargs): """ Get the graphical gtk class to represent this parameter. An enum requires and combo parameter. @@ -152,9 +155,9 @@ class Param(Element): All others get a standard entry parameter. @return gtk input class """ - if self.is_enum(): return EnumParam - if self.get_options(): return EnumEntryParam - return EntryParam + if self.is_enum(): return EnumParam(*args, **kwargs) + if self.get_options(): return EnumEntryParam(*args, **kwargs) + return EntryParam(*args, **kwargs) def get_layout(self): """ diff --git a/grc/gui/PropsDialog.py b/grc/gui/PropsDialog.py index 9be0400fe..aa86f7214 100644 --- a/grc/gui/PropsDialog.py +++ b/grc/gui/PropsDialog.py @@ -47,13 +47,13 @@ class PropsDialog(gtk.Dialog): Properties dialog contructor. @param block a block instance """ - self._hash = '' + self._hash = 0 LABEL_SPACING = 7 gtk.Dialog.__init__(self, title='Properties: %s'%block.get_name(), buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE), ) - self.block = block + self._block = block self.set_size_request(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT) vbox = gtk.VBox() #Create the scrolled window to hold all the parameters @@ -90,17 +90,15 @@ class PropsDialog(gtk.Dialog): def _params_changed(self): """ Have the params in this dialog changed? - Ex: Added, removed, type change, hidden, shown? + Ex: Added, removed, type change... Make a hash that uniquely represents the params state. @return true if changed """ old_hash = self._hash - str_accum = '' - for param in self.block.get_params(): - str_accum += param.get_key() - str_accum += param.get_type() - str_accum += param.get_hide() - self._hash = hash(str_accum) + self._hash = 0 + for param in self._block.get_params(): + self._hash ^= hash(param) + self._hash ^= hash(param.get_type()) return self._hash != old_hash def _update(self): @@ -113,33 +111,32 @@ class PropsDialog(gtk.Dialog): Hide the box if there are no docs. """ #update for the block - self.block.rewrite() - self.block.validate() + self._block.rewrite() + self._block.validate() #update the params box if self._params_changed(): #empty the params box for io_param in list(self._input_object_params): + io_param.hide_all() self._params_box.remove(io_param) self._input_object_params.remove(io_param) io_param.destroy() #repopulate the params box - for param in self.block.get_params(): - if param.get_hide() == 'all': continue - io_param = param.get_input_class()(param, callback=self._update) + for param in self._block.get_params(): + io_param = param.get_input(param, callback=self._update) self._input_object_params.append(io_param) self._params_box.pack_start(io_param, False) - self._params_box.show_all() #update the gui inputs for io_param in self._input_object_params: io_param.update() #update the errors box - if self.block.is_valid(): self._error_box.hide() + if self._block.is_valid(): self._error_box.hide() else: self._error_box.show() - messages = '\n\n'.join(self.block.get_error_messages()) + messages = '\n\n'.join(self._block.get_error_messages()) self._error_messages_text_display.set_text(messages) #update the docs box - if self.block.get_doc(): self._docs_box.show() + if self._block.get_doc(): self._docs_box.show() else: self._docs_box.hide() - self._docs_text_display.set_text(self.block.get_doc()) + self._docs_text_display.set_text(self._block.get_doc()) def _handle_key_press(self, widget, event): """ @@ -157,11 +154,11 @@ class PropsDialog(gtk.Dialog): @return true if a change occured. """ original_data = list() - for param in self.block.get_params(): + for param in self._block.get_params(): original_data.append(param.get_value()) gtk.Dialog.run(self) self.destroy() new_data = list() - for param in self.block.get_params(): + for param in self._block.get_params(): new_data.append(param.get_value()) return original_data != new_data diff --git a/grc/python/Param.py b/grc/python/Param.py index e61779136..c64659a08 100644 --- a/grc/python/Param.py +++ b/grc/python/Param.py @@ -153,9 +153,9 @@ class Param(_Param, _GUIParam): dt_str = dt_str[:max_len-3] + '...' return dt_str - def get_input_class(self): - if self.get_type() in ('file_open', 'file_save'): return FileParam - return _GUIParam.get_input_class(self) + def get_input(self, *args, **kwargs): + if self.get_type() in ('file_open', 'file_save'): return FileParam(*args, **kwargs) + return _GUIParam.get_input(self, *args, **kwargs) def get_color(self): """ diff --git a/grc/todo.txt b/grc/todo.txt index 2735ff2af..c675859d1 100644 --- a/grc/todo.txt +++ b/grc/todo.txt @@ -69,7 +69,6 @@ * threads dont die on exit in probe and variable sink * align param titles in properties dialog * weird grid params misbehaving -* properties dialog needs to show connection errors * fix param input stuff for usrp probes ################################################## -- cgit From 6b1d8817a7fc6dd99a770cb11fac7ca48a3c81b0 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 6 Sep 2009 01:58:25 -0700 Subject: Fixed the usrp and usrp2 probe scripts to work with the new gui param api. Also fixed the scripts to work since they were broken by previous changes. Get input in param class now pases a param instance (self) into the object. --- grc/gui/Param.py | 14 +++++++++----- grc/gui/PropsDialog.py | 2 +- grc/python/Param.py | 2 +- grc/scripts/usrp2_probe | 13 ++++++++----- grc/scripts/usrp_probe | 13 ++++++++----- grc/todo.txt | 1 - 6 files changed, 27 insertions(+), 18 deletions(-) diff --git a/grc/gui/Param.py b/grc/gui/Param.py index b84598e61..7fabb6671 100644 --- a/grc/gui/Param.py +++ b/grc/gui/Param.py @@ -30,7 +30,7 @@ class InputParam(gtk.HBox): gtk.HBox.__init__(self) self.param = param self._callback = callback - self.label = gtk.Label('') #no label, markup is added by set_markup + self.label = gtk.Label() #no label, markup is added by set_markup self.label.set_size_request(150, -1) self.pack_start(self.label, False) self.set_markup = lambda m: self.label.set_markup(m) @@ -66,7 +66,11 @@ class InputParam(gtk.HBox): self.param.set_value(self.get_text()) #call the callback if self._callback: self._callback() - #self.update() #dont update here, parent will update + else: + #no callback mode (used in supporting gui scripts) + #internally re-validate the param and update the gui + self.param.validate() + self.update() class EntryParam(InputParam): """Provide an entry box for strings and numbers.""" @@ -155,9 +159,9 @@ class Param(Element): All others get a standard entry parameter. @return gtk input class """ - if self.is_enum(): return EnumParam(*args, **kwargs) - if self.get_options(): return EnumEntryParam(*args, **kwargs) - return EntryParam(*args, **kwargs) + if self.is_enum(): return EnumParam(self, *args, **kwargs) + if self.get_options(): return EnumEntryParam(self, *args, **kwargs) + return EntryParam(self, *args, **kwargs) def get_layout(self): """ diff --git a/grc/gui/PropsDialog.py b/grc/gui/PropsDialog.py index aa86f7214..34fd7ec17 100644 --- a/grc/gui/PropsDialog.py +++ b/grc/gui/PropsDialog.py @@ -123,7 +123,7 @@ class PropsDialog(gtk.Dialog): io_param.destroy() #repopulate the params box for param in self._block.get_params(): - io_param = param.get_input(param, callback=self._update) + io_param = param.get_input(self._update) self._input_object_params.append(io_param) self._params_box.pack_start(io_param, False) #update the gui inputs diff --git a/grc/python/Param.py b/grc/python/Param.py index c64659a08..387fab548 100644 --- a/grc/python/Param.py +++ b/grc/python/Param.py @@ -154,7 +154,7 @@ class Param(_Param, _GUIParam): return dt_str def get_input(self, *args, **kwargs): - if self.get_type() in ('file_open', 'file_save'): return FileParam(*args, **kwargs) + if self.get_type() in ('file_open', 'file_save'): return FileParam(self, *args, **kwargs) return _GUIParam.get_input(self, *args, **kwargs) def get_color(self): diff --git a/grc/scripts/usrp2_probe b/grc/scripts/usrp2_probe index 00d4366dd..689d41ecb 100755 --- a/grc/scripts/usrp2_probe +++ b/grc/scripts/usrp2_probe @@ -32,9 +32,6 @@ from gnuradio.grc.gui.Dialogs import TextDisplay from gnuradio.grc.python.Platform import Platform platform = Platform() -from gnuradio.grc.gui.Platform import Platform -platform = Platform(platform) - flow_graph = platform.get_new_flow_graph() block = flow_graph.get_new_block('usrp2_probe') @@ -42,6 +39,12 @@ block = flow_graph.get_new_block('usrp2_probe') usrp_interface_param = block.get_param('interface') usrp_type_param = block.get_param('type') +def get_input(param): + param.validate() + input = param.get_input() + input.update() + return input + class USRP2ProbeWindow(gtk.Window): """ The main window for USRP Dignostics. @@ -69,8 +72,8 @@ class USRP2ProbeWindow(gtk.Window): #create vbox for storage vbox = gtk.VBox() frame.add(vbox) - vbox.pack_start(usrp_interface_param.get_input_object(), False) - vbox.pack_start(usrp_type_param.get_input_object(), False) + vbox.pack_start(get_input(usrp_interface_param), False) + vbox.pack_start(get_input(usrp_type_param), False) #make the tree model for holding mac addrs self.treestore = gtk.TreeStore(gobject.TYPE_STRING) self.treeview = gtk.TreeView(self.treestore) diff --git a/grc/scripts/usrp_probe b/grc/scripts/usrp_probe index 6565612c1..985d481ce 100755 --- a/grc/scripts/usrp_probe +++ b/grc/scripts/usrp_probe @@ -30,9 +30,6 @@ from gnuradio.grc.gui.Dialogs import TextDisplay from gnuradio.grc.python.Platform import Platform platform = Platform() -from gnuradio.grc.gui.Platform import Platform -platform = Platform(platform) - flow_graph = platform.get_new_flow_graph() block = flow_graph.get_new_block('usrp_probe') @@ -40,6 +37,12 @@ block = flow_graph.get_new_block('usrp_probe') usrp_which_param = block.get_param('which') usrp_dboard_param = block.get_param('dboard') +def get_input(param): + param.validate() + input = param.get_input() + input.update() + return input + class USRPProbeWindow(gtk.Window): """ The main window for USRP Dignostics. @@ -66,8 +69,8 @@ class USRPProbeWindow(gtk.Window): #create vbox for storage vbox = gtk.VBox() frame.add(vbox) - vbox.pack_start(usrp_which_param.get_input_object(), False) - vbox.pack_start(usrp_dboard_param.get_input_object(), False) + vbox.pack_start(get_input(usrp_which_param), False) + vbox.pack_start(get_input(usrp_dboard_param), False) self.probe_button = gtk.Button('Probe') self.probe_button.connect('clicked', self._probe_usrp) vbox.pack_start(self.probe_button, False) diff --git a/grc/todo.txt b/grc/todo.txt index c675859d1..b4e3af39d 100644 --- a/grc/todo.txt +++ b/grc/todo.txt @@ -69,7 +69,6 @@ * threads dont die on exit in probe and variable sink * align param titles in properties dialog * weird grid params misbehaving -* fix param input stuff for usrp probes ################################################## # Future -- cgit From b8f69ad7ba49aa85239f6de611ddfd040344f66b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 8 Sep 2009 23:04:38 -0700 Subject: use show signal to perform initial gui update --- grc/gui/Param.py | 14 +++++++------- grc/gui/PropsDialog.py | 34 ++++++++++++++++++++++------------ grc/python/Port.py | 2 +- grc/scripts/usrp2_probe | 1 - grc/scripts/usrp_probe | 1 - 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/grc/gui/Param.py b/grc/gui/Param.py index 7fabb6671..4464a57ab 100644 --- a/grc/gui/Param.py +++ b/grc/gui/Param.py @@ -35,9 +35,11 @@ class InputParam(gtk.HBox): self.pack_start(self.label, False) self.set_markup = lambda m: self.label.set_markup(m) self.tp = None + #connect events + self.connect('show', self._update_gui) def set_color(self, color): pass - def update(self): + def _update_gui(self, *args): """ Set the markup, color, tooltip, show/hide. """ @@ -65,12 +67,10 @@ class InputParam(gtk.HBox): #set the new value self.param.set_value(self.get_text()) #call the callback - if self._callback: self._callback() - else: - #no callback mode (used in supporting gui scripts) - #internally re-validate the param and update the gui - self.param.validate() - self.update() + if self._callback: self._callback(*args) + else: self.param.validate() + #gui update + self._update_gui() class EntryParam(InputParam): """Provide an entry box for strings and numbers.""" diff --git a/grc/gui/PropsDialog.py b/grc/gui/PropsDialog.py index 34fd7ec17..496500416 100644 --- a/grc/gui/PropsDialog.py +++ b/grc/gui/PropsDialog.py @@ -81,16 +81,16 @@ class PropsDialog(gtk.Dialog): vbox.pack_start(self._params_box, False) vbox.pack_start(self._error_box, False) vbox.pack_start(self._docs_box, False) - #connect key press event + #connect events self.connect('key_press_event', self._handle_key_press) - #initial update to populate the params + self.connect('show', self._update_gui) + #show all (performs initial gui update) self.show_all() - self._update() def _params_changed(self): """ Have the params in this dialog changed? - Ex: Added, removed, type change... + Ex: Added, removed, type change, hide change... Make a hash that uniquely represents the params state. @return true if changed """ @@ -99,9 +99,20 @@ class PropsDialog(gtk.Dialog): for param in self._block.get_params(): self._hash ^= hash(param) self._hash ^= hash(param.get_type()) + self._hash ^= hash(param.get_hide()) return self._hash != old_hash - def _update(self): + def _handle_changed(self, *args): + """ + A change occured within a param: + Rewrite/validate the block and update the gui. + """ + #update for the block + self._block.rewrite() + self._block.validate() + self._update_gui() + + def _update_gui(self, *args): """ Repopulate the parameters box (if changed). Update all the input parameters. @@ -110,24 +121,23 @@ class PropsDialog(gtk.Dialog): Update the documentation block. Hide the box if there are no docs. """ - #update for the block - self._block.rewrite() - self._block.validate() #update the params box if self._params_changed(): + #hide params box before changing + self._params_box.hide_all() #empty the params box for io_param in list(self._input_object_params): - io_param.hide_all() self._params_box.remove(io_param) self._input_object_params.remove(io_param) io_param.destroy() #repopulate the params box for param in self._block.get_params(): - io_param = param.get_input(self._update) + if param.get_hide() == 'all': continue + io_param = param.get_input(self._handle_changed) self._input_object_params.append(io_param) self._params_box.pack_start(io_param, False) - #update the gui inputs - for io_param in self._input_object_params: io_param.update() + #show params box with new params + self._params_box.show_all() #update the errors box if self._block.is_valid(): self._error_box.hide() else: self._error_box.show() diff --git a/grc/python/Port.py b/grc/python/Port.py index 33426d905..6965371df 100644 --- a/grc/python/Port.py +++ b/grc/python/Port.py @@ -45,7 +45,7 @@ def _get_source_from_virtual_source_port(vsp, traversed=[]): lambda b: b.is_virtual_sink(), vsp.get_parent().get_parent().get_enabled_blocks(), ), - )[0].get_sink(vsp.get_key()) + )[0].get_sinks()[0] ), traversed + [vsp], ) except: raise Exception, 'Could not resolve source for virtual source port %s'%vsp diff --git a/grc/scripts/usrp2_probe b/grc/scripts/usrp2_probe index 689d41ecb..38c8f655c 100755 --- a/grc/scripts/usrp2_probe +++ b/grc/scripts/usrp2_probe @@ -42,7 +42,6 @@ usrp_type_param = block.get_param('type') def get_input(param): param.validate() input = param.get_input() - input.update() return input class USRP2ProbeWindow(gtk.Window): diff --git a/grc/scripts/usrp_probe b/grc/scripts/usrp_probe index 985d481ce..d2e92e753 100755 --- a/grc/scripts/usrp_probe +++ b/grc/scripts/usrp_probe @@ -40,7 +40,6 @@ usrp_dboard_param = block.get_param('dboard') def get_input(param): param.validate() input = param.get_input() - input.update() return input class USRPProbeWindow(gtk.Window): -- cgit