commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 31/43: grc: PropsDialog: apply button and h


From: git
Subject: [Commit-gnuradio] [gnuradio] 31/43: grc: PropsDialog: apply button and hotkey (Ctrl+Enter)
Date: Thu, 2 Apr 2015 19:15:52 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit 9b57c33393dda48933fd5968070a4a7cac1290ca
Author: Sebastian Koslowski <address@hidden>
Date:   Thu Apr 2 15:52:18 2015 +0200

    grc: PropsDialog: apply button and hotkey (Ctrl+Enter)
---
 grc/gui/Param.py       | 30 ++++++++++++++++++++++--------
 grc/gui/PropsDialog.py | 19 ++++++++++++++++---
 2 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/grc/gui/Param.py b/grc/gui/Param.py
index 2ef8603..1efa563 100644
--- a/grc/gui/Param.py
+++ b/grc/gui/Param.py
@@ -72,20 +72,31 @@ class InputParam(gtk.HBox):
         self._changed_but_unchecked = True
         self._update_gui()
 
-    def _apply_change(self, *args):
+    def apply_change(self, *args):
         """
         Handle a gui change by setting the new param value,
         calling the callback (if applicable), and updating.
         """
+        if not self._changed_but_unchecked:
+            return
         #set the new value
         self.param.set_value(self.get_text())
         #call the callback
-        if self._callback: self._callback(*args)
-        else: self.param.validate()
+        if self._callback:
+            self._callback(*args)
+        else:
+            self.param.validate()
         #gui update
         self._changed_but_unchecked = False
         self._update_gui()
 
+    def _handle_key_press(self, widget, event):
+        if event.keyval == gtk.keysyms.Return and event.state & 
gtk.gdk.CONTROL_MASK:
+            self.apply_change()
+            return True
+        return False
+
+
 class EntryParam(InputParam):
     """Provide an entry box for strings and numbers."""
 
@@ -94,7 +105,8 @@ class EntryParam(InputParam):
         self._input = gtk.Entry()
         self._input.set_text(self.param.get_value())
         self._input.connect('changed', self._mark_changed)
-        self._input.connect('focus-out-event', self._apply_change)
+        self._input.connect('focus-out-event', self.apply_change)
+        self._input.connect('key-press-event', self._handle_key_press)
         self.pack_start(self._input, True)
     def get_text(self): return self._input.get_text()
     def set_color(self, color):
@@ -114,7 +126,7 @@ class EnumParam(InputParam):
         self._input = gtk.combo_box_new_text()
         for option in self.param.get_options(): 
self._input.append_text(option.get_name())
         
self._input.set_active(self.param.get_option_keys().index(self.param.get_value()))
-        self._input.connect('changed', self._apply_change)
+        self._input.connect('changed', self.apply_change)
         self.pack_start(self._input, False)
     def get_text(self): return 
self.param.get_option_keys()[self._input.get_active()]
     def set_tooltip_text(self, text):
@@ -123,6 +135,7 @@ class EnumParam(InputParam):
         except AttributeError:
             pass  # no tooltips for old GTK
 
+
 class EnumEntryParam(InputParam):
     """Provide an entry box and drop down menu for Raw Enum types."""
 
@@ -134,9 +147,10 @@ class EnumEntryParam(InputParam):
         except:
             self._input.set_active(-1)
             self._input.get_child().set_text(self.param.get_value())
-        self._input.connect('changed', self._apply_change)
+        self._input.connect('changed', self.apply_change)
         self._input.get_child().connect('changed', self._mark_changed)
-        self._input.get_child().connect('focus-out-event', self._apply_change)
+        self._input.get_child().connect('focus-out-event', self.apply_change)
+        self._input.get_child().connect('key-press-event', 
self._handle_key_press)
         self.pack_start(self._input, False)
     def get_text(self):
         if self._input.get_active() == -1: return 
self._input.get_child().get_text()
@@ -191,7 +205,7 @@ class FileParam(EntryParam):
         if gtk.RESPONSE_OK == file_dialog.run(): #run the dialog
             file_path = file_dialog.get_filename() #get the file path
             self._input.set_text(file_path)
-            self._apply_change()
+            self.apply_change()
         file_dialog.destroy() #destroy the dialog
 
 
diff --git a/grc/gui/PropsDialog.py b/grc/gui/PropsDialog.py
index d7ba8c5..d172175 100644
--- a/grc/gui/PropsDialog.py
+++ b/grc/gui/PropsDialog.py
@@ -65,7 +65,9 @@ class PropsDialog(gtk.Dialog):
         gtk.Dialog.__init__(
             self,
             title='Properties: %s' % block.get_name(),
-            buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, 
gtk.RESPONSE_ACCEPT),
+            buttons=(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT,
+                     gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
+                     gtk.STOCK_APPLY, gtk.RESPONSE_APPLY)
         )
         self._block = block
         self.set_size_request(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT)
@@ -109,6 +111,7 @@ class PropsDialog(gtk.Dialog):
         # Connect events
         self.connect('key-press-event', self._handle_key_press)
         self.connect('show', self._update_gui)
+        self.connect('response', self._handle_response)
         self.show_all()  # show all (performs initial gui update)
 
     def _params_changed(self):
@@ -183,11 +186,18 @@ class PropsDialog(gtk.Dialog):
         Returns:
             false to forward the keypress
         """
-        if event.keyval == gtk.keysyms.Return:
+        if event.keyval == gtk.keysyms.Return and event.state & 
gtk.gdk.CONTROL_MASK == 0:
             self.response(gtk.RESPONSE_ACCEPT)
             return True  # handled here
         return False  # forward the keypress
 
+    def _handle_response(self, widget, response):
+        if response == gtk.RESPONSE_APPLY:
+            for tab, label, vbox in self._params_boxes:
+                vbox.forall(lambda c: c.apply_change())
+            return True
+        return False
+
     def run(self):
         """
         Run the dialog and get its response.
@@ -195,6 +205,9 @@ class PropsDialog(gtk.Dialog):
         Returns:
             true if the response was accept
         """
-        response = gtk.Dialog.run(self)
+        response = gtk.RESPONSE_APPLY
+        # don't close dialog on apply click
+        while response == gtk.RESPONSE_APPLY:
+            response = gtk.Dialog.run(self)
         self.destroy()
         return response == gtk.RESPONSE_ACCEPT



reply via email to

[Prev in Thread] Current Thread [Next in Thread]