commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 02/09: grc: one preferences handler for all


From: git
Subject: [Commit-gnuradio] [gnuradio] 02/09: grc: one preferences handler for all bools
Date: Wed, 20 Aug 2014 20:18:46 +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 17766c2077ab6120d565a26552e09c37b8277d0a
Author: Sebastian Koslowski <address@hidden>
Date:   Wed Aug 20 17:51:17 2014 +0200

    grc: one preferences handler for all bools
---
 grc/gui/ActionHandler.py | 30 +++++++++++++++---------------
 grc/gui/Actions.py       | 17 ++++++++++++++++-
 grc/gui/Preferences.py   | 29 +++++++----------------------
 3 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index 18b7c9a..b68fa60 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -134,10 +134,12 @@ class ActionHandler:
             if not self.get_page(): self.main_window.new_page() #ensure that 
at least a blank page exists
 
             self.main_window.btwin.search_entry.hide()
-            
Actions.TOGGLE_REPORTS_WINDOW.set_active(Preferences.reports_window_visibility())
-            
Actions.TOGGLE_BLOCKS_WINDOW.set_active(Preferences.blocks_window_visibility())
-            Actions.TOGGLE_SCROLL_LOCK.set_active(Preferences.scroll_lock())
-            
Actions.TOGGLE_AUTO_HIDE_PORT_LABELS.set_active(Preferences.auto_hide_port_labels())
+            for action in (
+                Actions.TOGGLE_REPORTS_WINDOW,
+                Actions.TOGGLE_BLOCKS_WINDOW,
+                Actions.TOGGLE_AUTO_HIDE_PORT_LABELS,
+                Actions.TOGGLE_SCROLL_LOCK,
+            ): action.load_from_preferences()
         elif action == Actions.APPLICATION_QUIT:
             if self.main_window.close_pages():
                 gtk.main_quit()
@@ -363,30 +365,29 @@ class ActionHandler:
         elif action == Actions.ERRORS_WINDOW_DISPLAY:
             Dialogs.ErrorsDialog(self.get_flow_graph())
         elif action == Actions.TOGGLE_REPORTS_WINDOW:
-            visible = action.get_active()
-            if visible:
+            if action.get_active():
                 self.main_window.reports_scrolled_window.show()
             else:
                 self.main_window.reports_scrolled_window.hide()
-            Preferences.reports_window_visibility(visible)
+            action.save_to_preferences()
         elif action == Actions.TOGGLE_BLOCKS_WINDOW:
-            visible = action.get_active()
-            if visible:
+            if action.get_active():
                 self.main_window.btwin.show()
             else:
                 self.main_window.btwin.hide()
-            Preferences.blocks_window_visibility(visible)
+            action.save_to_preferences()
         elif action == Actions.TOGGLE_SCROLL_LOCK:
-            visible = action.get_active()
-            self.main_window.text_display.scroll_lock = visible
-            if visible:
+            active = action.get_active()
+            self.main_window.text_display.scroll_lock = active
+            if active:
                 self.main_window.text_display.scroll_to_end()
+            action.save_to_preferences()
         elif action == Actions.CLEAR_REPORTS:
             self.main_window.text_display.clear()
         elif action == Actions.TOGGLE_HIDE_DISABLED_BLOCKS:
             Actions.NOTHING_SELECT()
         elif action == Actions.TOGGLE_AUTO_HIDE_PORT_LABELS:
-            Preferences.auto_hide_port_labels(action.get_active())
+            action.save_to_preferences()
             self.main_window.get_flow_graph().create_shapes()
         ##################################################
         # Param Modifications
@@ -497,7 +498,6 @@ class ActionHandler:
             self.main_window.btwin.search_entry.show()
             self.main_window.btwin.search_entry.grab_focus()
         elif action == Actions.OPEN_HIER:
-            bn = [];
             for b in self.get_flow_graph().get_selected_blocks():
                 if b._grc_source:
                     self.main_window.new_page(b._grc_source, show=True)
diff --git a/grc/gui/Actions.py b/grc/gui/Actions.py
index 484952b..f4191a4 100644
--- a/grc/gui/Actions.py
+++ b/grc/gui/Actions.py
@@ -21,6 +21,8 @@ import pygtk
 pygtk.require('2.0')
 import gtk
 
+import Preferences
+
 NO_MODS_MASK = 0
 
 ########################################################################
@@ -127,7 +129,7 @@ class ToggleAction(gtk.ToggleAction, _ActionBase):
     Pass additional arguments such as keypresses.
     """
 
-    def __init__(self, keypresses=(), name=None, label=None, tooltip=None, 
stock_id=None):
+    def __init__(self, keypresses=(), name=None, label=None, tooltip=None, 
stock_id=None, preference_name=None):
         """
         Create a new ToggleAction instance.
 
@@ -142,6 +144,15 @@ class ToggleAction(gtk.ToggleAction, _ActionBase):
         )
         #register this action
         _ActionBase.__init__(self, label, keypresses)
+        self.preference_name = preference_name
+
+    def load_from_preferences(self):
+        if self.preference_name is not None:
+            self.set_active(Preferences.bool_entry(self.preference_name))
+
+    def save_to_preferences(self):
+        if self.preference_name is not None:
+            Preferences.bool_entry(self.preference_name, self.get_active())
 
 ########################################################################
 # Actions
@@ -245,6 +256,7 @@ TOGGLE_HIDE_DISABLED_BLOCKS = ToggleAction(
 TOGGLE_AUTO_HIDE_PORT_LABELS = ToggleAction(
     label='Auto-hide port _labels',
     tooltip='Automatically hide port labels',
+    preference_name='auto_hide_port_labels'
 )
 BLOCK_CREATE_HIER = Action(
     label='C_reate Hier',
@@ -279,15 +291,18 @@ TOGGLE_REPORTS_WINDOW = ToggleAction(
     label='Show _Reports',
     tooltip='Toggle visibility of the Report widget',
     keypresses=(gtk.keysyms.r, gtk.gdk.CONTROL_MASK),
+    preference_name='reports_window_visible'
 )
 TOGGLE_BLOCKS_WINDOW = ToggleAction(
     label='Show _Block Tree',
     tooltip='Toggle visibility of the block tree widget',
     keypresses=(gtk.keysyms.b, gtk.gdk.CONTROL_MASK),
+    preference_name='blocks_window_visible'
 )
 TOGGLE_SCROLL_LOCK = ToggleAction(
     label='_Reports Scroll Lock',
     tooltip='Toggle scroll lock for the report window',
+    preference_name='scroll_lock'
 )
 ABOUT_WINDOW_DISPLAY = Action(
     label='_About',
diff --git a/grc/gui/Preferences.py b/grc/gui/Preferences.py
index d2ffc71..1d6675d 100644
--- a/grc/gui/Preferences.py
+++ b/grc/gui/Preferences.py
@@ -84,26 +84,11 @@ def blocks_window_position(pos=None):
         try: return _config_parser.getint('main', 'blocks_window_position') or 
1 #greater than 0
         except: return -1
 
-def reports_window_visibility(visible=None):
-    if visible is not None: _config_parser.set('main', 
'reports_window_visible', visible)
+def bool_entry(key, active=None, default=True):
+    if active is not None:
+        _config_parser.set('main', key, active)
     else:
-        try: return _config_parser.getboolean('main', 'reports_window_visible')
-        except: return True
-
-def blocks_window_visibility(visible=None):
-    if visible is not None: _config_parser.set('main', 
'blocks_window_visible', visible)
-    else:
-        try: return _config_parser.getboolean('main', 'blocks_window_visible')
-        except: return True
-
-def scroll_lock(visible=None):
-    if visible is not None: _config_parser.set('main', 'scroll_lock', visible)
-    else:
-        try: return _config_parser.getboolean('main', 'scroll_lock')
-        except: return True
-
-def auto_hide_port_labels(hide=None):
-    if hide is not None: _config_parser.set('main', 'auto_hide_port_labels', 
hide)
-    else:
-        try: return _config_parser.getboolean('main', 'auto_hide_port_labels')
-        except: return True
+        try:
+            return _config_parser.getboolean('main', key)
+        except:
+            return default
\ No newline at end of file



reply via email to

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