[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 01/13: grc: refactor Preferences.py
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 01/13: grc: refactor Preferences.py |
Date: |
Fri, 24 Jul 2015 15:33:48 +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 2aad7187ddab012dd21f60e0d346add03869a20d
Author: Sebastian Koslowski <address@hidden>
Date: Fri Jul 17 09:56:50 2015 +0200
grc: refactor Preferences.py
---
grc/gui/Preferences.py | 98 +++++++++++++++++++++++++++++++-------------------
1 file changed, 61 insertions(+), 37 deletions(-)
diff --git a/grc/gui/Preferences.py b/grc/gui/Preferences.py
index e7b0551..109fe5e 100644
--- a/grc/gui/Preferences.py
+++ b/grc/gui/Preferences.py
@@ -18,24 +18,34 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA
"""
import ConfigParser
-import os
+
_platform = None
_config_parser = ConfigParser.ConfigParser()
-def file_extension(): return '.'+_platform.get_key()
+
+def file_extension():
+ return '.'+_platform.get_key()
+
def load(platform):
global _platform
_platform = platform
- #create sections
+ # create sections
_config_parser.add_section('main')
_config_parser.add_section('files_open')
- try: _config_parser.read(_platform.get_prefs_file())
- except: pass
+ try:
+ _config_parser.read(_platform.get_prefs_file())
+ except:
+ pass
+
+
def save():
- try: _config_parser.write(open(_platform.get_prefs_file(), 'w'))
- except: pass
+ try:
+ _config_parser.write(open(_platform.get_prefs_file(), 'w'))
+ except:
+ pass
+
###########################################################################
# Special methods for specific program functionalities
@@ -46,49 +56,63 @@ def main_window_size(size=None):
_config_parser.set('main', 'main_window_width', size[0])
_config_parser.set('main', 'main_window_height', size[1])
else:
- try: return (
- _config_parser.getint('main', 'main_window_width'),
- _config_parser.getint('main', 'main_window_height'),
- )
- except: return (1, 1)
-
-def file_open(file=None):
- if file is not None: _config_parser.set('main', 'file_open', file)
+ 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
+
+
+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 ''
+ try:
+ return _config_parser.get('main', 'file_open')
+ except:
+ return ''
+
def files_open(files=None):
if files is not None:
- _config_parser.remove_section('files_open') #clear section
+ _config_parser.remove_section('files_open') # clear section
_config_parser.add_section('files_open')
- for i, file in enumerate(files):
- _config_parser.set('files_open', 'file_open_%d'%i, file)
+ for i, filename in enumerate(files):
+ _config_parser.set('files_open', 'file_open_%d' % i, filename)
+
else:
- files = list()
- i = 0
- while True:
- try:
- files.append(_config_parser.get('files_open',
'file_open_%d'%i))
- except:
- return files
- i += 1
+ try:
+ files = [value for name, value in
_config_parser.items('files_open')
+ if name.startswith('file_open_')]
+ except:
+ files = []
+ return files
+
def reports_window_position(pos=None):
- if pos is not None: _config_parser.set('main', 'reports_window_position',
pos)
+ 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
+ try:
+ return _config_parser.getint('main', 'reports_window_position') or
1 #greater than 0
+ except:
+ return -1
+
def blocks_window_position(pos=None):
- if pos is not None: _config_parser.set('main', 'blocks_window_position',
pos)
+ 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
+ try:
+ return _config_parser.getint('main', 'blocks_window_position') or
1 #greater than 0
+ except:
+ return -1
+
-def bool_entry(key, active=None, default=True):
- if active is not None:
- _config_parser.set('main', key, active)
+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)
- [Commit-gnuradio] [gnuradio] branch master updated (cc973de -> 65d6523), git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 12/13: Merge branch 'maint', git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 13/13: Merge remote-tracking branch 'gnuradio-wg-grc/master_grcwg', git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 06/13: grc: align default flowgraph block with canvas grid, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 11/13: grc: clean-up Block port counters, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 02/13: grc: show preview of generated code in each blocks properties dialog, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 07/13: grc: fix bus ports spacing in gui, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 03/13: grc: add default value to ToggleActions, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 04/13: grc: only show code preview tab after user enables it, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 01/13: grc: refactor Preferences.py,
git <=
- [Commit-gnuradio] [gnuradio] 05/13: grc: add user settings for canvas default size and canvas font size (+ clean-ups), git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 08/13: grc: add QT GUI hier blocks (#727), git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 09/13: grc: add support for dynamic param names, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 10/13: grc: add struct variable block, git, 2015/07/24