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/Param.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'grc/gui/Param.py') 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. -- 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 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 33 deletions(-) (limited to 'grc/gui/Param.py') 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): """ -- 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 --------------- 1 file changed, 15 deletions(-) (limited to 'grc/gui/Param.py') 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. -- 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 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'grc/gui/Param.py') 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): """ -- 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 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'grc/gui/Param.py') 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): """ -- 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 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'grc/gui/Param.py') 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.""" -- cgit