[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 05/20: grc: rewrite Preferences.py
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 05/20: grc: rewrite Preferences.py |
Date: |
Fri, 28 Aug 2015 19:19:51 +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 d3d6a40ce979d8dc2dff1dbb23aa1873bad45695
Author: Sebastian Koslowski <address@hidden>
Date: Thu Aug 13 11:08:02 2015 +0200
grc: rewrite Preferences.py
---
grc/gui/Actions.py | 7 ++--
grc/gui/Preferences.py | 90 ++++++++++++++++++++++++--------------------------
2 files changed, 46 insertions(+), 51 deletions(-)
diff --git a/grc/gui/Actions.py b/grc/gui/Actions.py
index d864db7..ce1f2cf 100644
--- a/grc/gui/Actions.py
+++ b/grc/gui/Actions.py
@@ -150,13 +150,12 @@ class ToggleAction(gtk.ToggleAction, _ActionBase):
def load_from_preferences(self):
if self.preference_name is not None:
- self.set_active(Preferences.bool_entry(self.preference_name,
- default=self.default))
+ self.set_active(Preferences.entry(
+ self.preference_name, default=bool(self.default)))
def save_to_preferences(self):
if self.preference_name is not None:
- Preferences.bool_entry(self.preference_name,
- value=self.get_active())
+ Preferences.entry(self.preference_name, value=self.get_active())
########################################################################
# Actions
diff --git a/grc/gui/Preferences.py b/grc/gui/Preferences.py
index 109fe5e..ddffe88 100644
--- a/grc/gui/Preferences.py
+++ b/grc/gui/Preferences.py
@@ -17,11 +17,20 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""
+import sys
import ConfigParser
+HEADER = """\
+# This contains only GUI settings for GRC and is not meant for users to edit.
+#
+# GRC settings not accessible through the GUI are in gnuradio.conf under
+# section [grc].
+
+"""
+
_platform = None
-_config_parser = ConfigParser.ConfigParser()
+_config_parser = ConfigParser.SafeConfigParser()
def file_extension():
@@ -36,15 +45,34 @@ def load(platform):
_config_parser.add_section('files_open')
try:
_config_parser.read(_platform.get_prefs_file())
- except:
- pass
+ except Exception as err:
+ print >> sys.stderr, err
def save():
try:
- _config_parser.write(open(_platform.get_prefs_file(), 'w'))
- except:
- pass
+ with open(_platform.get_prefs_file(), 'w') as fp:
+ fp.write(HEADER)
+ _config_parser.write(fp)
+ except Exception as err:
+ print >> sys.stderr, err
+
+
+def entry(key, value=None, default=None):
+ if value is not None:
+ _config_parser.set('main', key, str(value))
+ result = value
+ else:
+ _type = type(default) if default is not None else str
+ getter = {
+ bool: _config_parser.getboolean,
+ int: _config_parser.getint,
+ }.get(_type, _config_parser.get)
+ try:
+ result = getter('main', key)
+ except ConfigParser.Error:
+ result = _type() if default is None else default
+ return result
###########################################################################
@@ -52,26 +80,15 @@ def save():
###########################################################################
def main_window_size(size=None):
- if size is not None:
- _config_parser.set('main', 'main_window_width', size[0])
- _config_parser.set('main', 'main_window_height', size[1])
- else:
- try:
- w = _config_parser.getint('main', 'main_window_width')
- h = _config_parser.getint('main', 'main_window_height')
- except:
- w, h = 1, 1
- return w, h
+ if size is None:
+ size = [None, None]
+ w = entry('main_window_width', size[0], default=1)
+ h = entry('main_window_height', size[1], default=1)
+ return w, h
def file_open(filename=None):
- if filename is not None:
- _config_parser.set('main', 'file_open', filename)
- else:
- try:
- return _config_parser.get('main', 'file_open')
- except:
- return ''
+ return entry('file_open', filename, default='')
def files_open(files=None):
@@ -85,36 +102,15 @@ def files_open(files=None):
try:
files = [value for name, value in
_config_parser.items('files_open')
if name.startswith('file_open_')]
- except:
+ except ConfigParser.Error:
files = []
return files
def reports_window_position(pos=None):
- if pos is not None:
- _config_parser.set('main', 'reports_window_position', pos)
- else:
- try:
- return _config_parser.getint('main', 'reports_window_position') or
1 #greater than 0
- except:
- return -1
+ return entry('reports_window_position', pos, default=-1) or 1
def blocks_window_position(pos=None):
- if pos is not None:
- _config_parser.set('main', 'blocks_window_position', pos)
- else:
- try:
- return _config_parser.getint('main', 'blocks_window_position') or
1 #greater than 0
- except:
- return -1
-
+ return entry('blocks_window_position', pos, default=-1) or 1
-def bool_entry(key, value=None, default=True):
- if value is not None:
- _config_parser.set('main', key, value)
- else:
- try:
- return _config_parser.getboolean('main', key)
- except:
- return default
- [Commit-gnuradio] [gnuradio] branch master updated (22e2f1a -> 68c6862), git, 2015/08/28
- [Commit-gnuradio] [gnuradio] 02/20: Merge branch 'maint_grcwg' into master_grcwg, git, 2015/08/28
- [Commit-gnuradio] [gnuradio] 01/20: qtgui: added trigger callbacks to GRC XML files, git, 2015/08/28
- [Commit-gnuradio] [gnuradio] 06/20: grc: add warning for invalid xterm setting (fixes #828), git, 2015/08/28
- [Commit-gnuradio] [gnuradio] 05/20: grc: rewrite Preferences.py,
git <=
- [Commit-gnuradio] [gnuradio] 16/20: Merge remote-tracking branch 'ckuethe/trap_import_errors', git, 2015/08/28
- [Commit-gnuradio] [gnuradio] 17/20: Merge remote-tracking branch 'saikwolf/qt_themeing', git, 2015/08/28
- [Commit-gnuradio] [gnuradio] 11/20: clarify missing module exception., git, 2015/08/28
- [Commit-gnuradio] [gnuradio] 07/20: grc: move gui prefs file to ~/.gnuradio/grc.conf, git, 2015/08/28
- [Commit-gnuradio] [gnuradio] 20/20: Merge branch 'maint', git, 2015/08/28
- [Commit-gnuradio] [gnuradio] 19/20: Merge remote-tracking branch 'gnuradio-wg-grc/master_grcwg', git, 2015/08/28
- [Commit-gnuradio] [gnuradio] 04/20: grc: clean-up ActionHandler.py imports, git, 2015/08/28
- [Commit-gnuradio] [gnuradio] 14/20: Merge remote-tracking branch 'estatz/qtgui_trigger_callbacks', git, 2015/08/28
- [Commit-gnuradio] [gnuradio] 13/20: grc: super-secret, git, 2015/08/28
- [Commit-gnuradio] [gnuradio] 10/20: grc: show cmdline when xterm is used, git, 2015/08/28