From b8f69ad7ba49aa85239f6de611ddfd040344f66b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 8 Sep 2009 23:04:38 -0700 Subject: [PATCH] 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 7fabb667..4464a57a 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 34fd7ec1..49650041 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 33426d90..6965371d 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 689d41ec..38c8f655 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 985d481c..d2e92e75 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): -- 2.30.2