diff options
-rw-r--r-- | grc/base/Block.py | 23 | ||||
-rw-r--r-- | grc/base/Element.py | 48 | ||||
-rw-r--r-- | grc/base/FlowGraph.py | 21 | ||||
-rw-r--r-- | grc/gui/ActionHandler.py | 4 | ||||
-rw-r--r-- | grc/gui/Block.py | 29 | ||||
-rw-r--r-- | grc/gui/Connection.py | 11 | ||||
-rw-r--r-- | grc/gui/Element.py | 53 | ||||
-rw-r--r-- | grc/gui/FlowGraph.py | 9 | ||||
-rw-r--r-- | grc/gui/Makefile.am | 2 | ||||
-rw-r--r-- | grc/gui/Param.py | 95 | ||||
-rw-r--r-- | grc/gui/Platform.py | 3 | ||||
-rw-r--r-- | grc/gui/Port.py | 11 | ||||
-rw-r--r-- | grc/gui/PropsDialog.py (renamed from grc/gui/ParamsDialog.py) | 113 | ||||
-rw-r--r-- | grc/python/FlowGraph.py | 1 | ||||
-rw-r--r-- | grc/python/Param.py | 6 | ||||
-rw-r--r-- | grc/python/Port.py | 2 | ||||
-rwxr-xr-x | grc/scripts/usrp2_probe | 12 | ||||
-rwxr-xr-x | grc/scripts/usrp_probe | 12 | ||||
-rw-r--r-- | grc/todo.txt | 7 |
19 files changed, 246 insertions, 216 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 ############################################## 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/Block.py b/grc/gui/Block.py index 0f3e511d8..8c65bf06f 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. @@ -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('') @@ -142,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 @@ -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 013bcb00f..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 @@ -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. @@ -48,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 @@ -72,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() @@ -123,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 315191723..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 @@ -32,7 +30,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. """ @@ -61,6 +59,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. @@ -70,14 +83,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 +103,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 +149,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 +157,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 +192,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 @@ -220,7 +229,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 5e645be72..35ccf5e27 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. @@ -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/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/Param.py b/grc/gui/Param.py index 4955d3336..4464a57ab 100644 --- a/grc/gui/Param.py +++ b/grc/gui/Param.py @@ -26,17 +26,52 @@ 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.label = gtk.Label('') #no label, markup is added by set_markup + 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) 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_gui(self, *args): + """ + Set the markup, color, tooltip, show/hide. + """ + #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(), + ) + #show/hide + if self.param.get_hide() == 'all': self.hide_all() + else: self.show_all() + + 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(*args) + else: self.param.validate() + #gui update + self._update_gui() + class EntryParam(InputParam): """Provide an entry box for strings and numbers.""" @@ -114,7 +149,9 @@ Error: class Param(Element): """The graphical parameter.""" - def get_input_class(self): + def __init__(self): Element.__init__(self) + + def get_input(self, *args, **kwargs): """ Get the graphical gtk class to represent this parameter. An enum requires and combo parameter. @@ -122,53 +159,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 - - 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. - 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 - @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) + 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/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..6763f6cbd 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. @@ -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('') @@ -114,7 +115,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(): diff --git a/grc/gui/ParamsDialog.py b/grc/gui/PropsDialog.py index ccf19d1a2..496500416 100644 --- a/grc/gui/ParamsDialog.py +++ b/grc/gui/PropsDialog.py @@ -37,70 +37,116 @@ def get_title_label(title): hbox.pack_start(label, False, False, padding=11) return hbox -class ParamsDialog(gtk.Dialog): - """A dialog box to set block parameters.""" +class PropsDialog(gtk.Dialog): + """ + 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 = 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() - #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 events self.connect('key_press_event', self._handle_key_press) + self.connect('show', self._update_gui) + #show all (performs initial gui update) self.show_all() - #initial update - for param in self.block.get_params(): param.update() - self._update() - def _update(self): + def _params_changed(self): + """ + Have the params in this dialog changed? + Ex: Added, removed, type change, hide change... + Make a hash that uniquely represents the params state. + @return true if changed + """ + old_hash = self._hash + self._hash = 0 + 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 _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. 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 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): + 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(self._handle_changed) + self._input_object_params.append(io_param) + self._params_box.pack_start(io_param, False) + #show params box with new params + self._params_box.show_all() #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): """ @@ -112,34 +158,17 @@ class ParamsDialog(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(). @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/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/python/Param.py b/grc/python/Param.py index e61779136..387fab548 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(self, *args, **kwargs) + return _GUIParam.get_input(self, *args, **kwargs) def get_color(self): """ 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 00d4366dd..38c8f655c 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,11 @@ 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() + return input + class USRP2ProbeWindow(gtk.Window): """ The main window for USRP Dignostics. @@ -69,8 +71,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..d2e92e753 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,11 @@ 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() + return input + class USRPProbeWindow(gtk.Window): """ The main window for USRP Dignostics. @@ -66,8 +68,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 ffc9d64db..b4e3af39d 100644 --- a/grc/todo.txt +++ b/grc/todo.txt @@ -67,13 +67,8 @@ * 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 -* better error for blank string params +* 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 ################################################## # Future |