[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 01/01: grc: fix apply button, on enable it
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 01/01: grc: fix apply button, on enable it if needed, update main window on apply |
Date: |
Fri, 3 Apr 2015 20:29:07 +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 6afc40e80f05a6cc2dbdebcc037ed40c5f5921f1
Author: Sebastian Koslowski <address@hidden>
Date: Fri Apr 3 18:16:18 2015 +0200
grc: fix apply button, on enable it if needed, update main window on apply
---
grc/gui/ActionHandler.py | 26 ++++++++++++++++----------
grc/gui/Param.py | 35 +++++++++++++++++++++++++++--------
grc/gui/PropsDialog.py | 33 +++++++++++++++++++--------------
3 files changed, 62 insertions(+), 32 deletions(-)
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index 116dff1..6dc088c 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -407,16 +407,22 @@ class ActionHandler:
elif action == Actions.BLOCK_PARAM_MODIFY:
selected_block = self.get_flow_graph().get_selected_block()
if selected_block:
- if PropsDialog(selected_block).run():
- #save the new state
- 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)
- else:
- #restore the current state
- n = self.get_page().get_state_cache().get_current_state()
- self.get_flow_graph().import_data(n)
- self.get_flow_graph().update()
+ dialog = PropsDialog(selected_block)
+ response = gtk.RESPONSE_APPLY
+ while response == gtk.RESPONSE_APPLY: # do while construct:
rerun the dialog if Apply was hit
+ response = dialog.run()
+ if response == gtk.RESPONSE_APPLY:
+ self.get_flow_graph().update()
+ Actions.ELEMENT_SELECT() # empty action, that updates
the main window and flowgraph
+ elif response == gtk.RESPONSE_ACCEPT:
+ 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)
+ else: # restore the current state
+ n =
self.get_page().get_state_cache().get_current_state()
+ self.get_flow_graph().import_data(n)
+ self.get_flow_graph().update()
+ dialog.destroy()
##################################################
# View Parser Errors
##################################################
diff --git a/grc/gui/Param.py b/grc/gui/Param.py
index 2ef8603..3ea1e4d 100644
--- a/grc/gui/Param.py
+++ b/grc/gui/Param.py
@@ -29,16 +29,17 @@ import os
class InputParam(gtk.HBox):
"""The base class for an input parameter inside the input parameters
dialog."""
- def __init__(self, param, callback=None):
+ def __init__(self, param, changed_callback=None, editing_callback=None):
gtk.HBox.__init__(self)
self.param = param
- self._callback = callback
+ self._changed_callback = changed_callback
+ self._editing_callback = editing_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
- self._changed_but_unchecked = False
+ self._have_pending_changes = False
#connect events
self.connect('show', self._update_gui)
def set_color(self, color): pass
@@ -54,7 +55,7 @@ class InputParam(gtk.HBox):
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,
- modified=self._changed_but_unchecked))
+ modified=self._have_pending_changes))
#set the color
self.set_color(self.param.get_color())
#set the tooltip
@@ -69,8 +70,10 @@ class InputParam(gtk.HBox):
"""
Mark this param as modified on change, but validate only on focus-lost
"""
- self._changed_but_unchecked = True
+ self._have_pending_changes = True
self._update_gui()
+ if self._editing_callback:
+ self._editing_callback()
def _apply_change(self, *args):
"""
@@ -80,12 +83,25 @@ class InputParam(gtk.HBox):
#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._changed_callback:
+ self._changed_callback(*args)
+ else:
+ self.param.validate()
#gui update
- self._changed_but_unchecked = False
+ self._have_pending_changes = 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(widget, event)
+ return True
+ return False
+
+ def apply_pending_changes(self):
+ if self._have_pending_changes:
+ self._apply_change()
+
+
class EntryParam(InputParam):
"""Provide an entry box for strings and numbers."""
@@ -95,6 +111,7 @@ class EntryParam(InputParam):
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('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):
@@ -123,6 +140,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."""
@@ -137,6 +155,7 @@ class EnumEntryParam(InputParam):
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('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()
diff --git a/grc/gui/PropsDialog.py b/grc/gui/PropsDialog.py
index d7ba8c5..1045cfb 100644
--- a/grc/gui/PropsDialog.py
+++ b/grc/gui/PropsDialog.py
@@ -65,10 +65,13 @@ 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_response_sensitive(gtk.RESPONSE_APPLY, False)
self.set_size_request(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT)
+ self._block = block
vpaned = gtk.VPaned()
self.vbox.pack_start(vpaned)
@@ -109,6 +112,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):
@@ -138,6 +142,10 @@ class PropsDialog(gtk.Dialog):
self._block.rewrite()
self._block.validate()
self._update_gui()
+ self._activate_apply()
+
+ def _activate_apply(self):
+ self.set_response_sensitive(gtk.RESPONSE_APPLY, True)
def _update_gui(self, *args):
"""
@@ -161,7 +169,7 @@ class PropsDialog(gtk.Dialog):
if param.get_hide() == 'all':
continue
box_all_valid = box_all_valid and param.is_valid()
- vbox.pack_start(param.get_input(self._handle_changed),
False)
+ vbox.pack_start(param.get_input(self._handle_changed,
self._activate_apply), False)
label.set_markup(Utils.parse_template(TAB_LABEL_MARKUP_TMPL,
valid=box_all_valid, tab=tab))
#show params box with new params
vbox.show_all()
@@ -183,18 +191,15 @@ 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 run(self):
- """
- Run the dialog and get its response.
-
- Returns:
- true if the response was accept
- """
- response = gtk.Dialog.run(self)
- self.destroy()
- return response == gtk.RESPONSE_ACCEPT
+ 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_pending_changes())
+ self.set_response_sensitive(gtk.RESPONSE_APPLY, False)
+ return True
+ return False