1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
"""
Copyright 2008 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
GNU Radio Companion is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""
from .. platforms.base.Constants import HOME_DIR, FLOW_GRAPH_DTD
from .. utils import ParseXML
import Messages
import os
##Access the loaded preferences in this module
_prefs = list()
def _set_prefs(prefs): _prefs.append(prefs)
def _get_prefs(): return _prefs[0]
def load(platform): _Preferences(platform)
def save(): _get_prefs().save()
def get_preferences(): return _get_prefs().get_preferences()
class _Preferences(object):
def __init__(self, platform):
#make self available to module
_set_prefs(self)
#get prefs block
self._prefs_block = platform.get_prefs_block()
#prefs file path
self._prefs_file_path = os.path.join(HOME_DIR, self._prefs_block.get_param('prefs_file').get_value())
#load
try:
ParseXML.validate_dtd(self._prefs_file_path, FLOW_GRAPH_DTD)
n = ParseXML.from_file(self._prefs_file_path)
self._prefs_block.import_data(n['block'])
except: Messages.send_fail_load_preferences(self._prefs_file_path)
##all params
self.snap_to_grid_param = self._prefs_block.get_param('snap_to_grid')
self.grid_size_param = self._prefs_block.get_param('grid_size')
self.show_grid_param = self._prefs_block.get_param('show_grid')
self.show_reports_param = self._prefs_block.get_param('show_reports')
self.restore_files_param = self._prefs_block.get_param('restore_files')
self.window_size_param = self._prefs_block.get_param('window_size')
self.file_open_param = self._prefs_block.get_param('file_open')
self.files_open_param = self._prefs_block.get_param('files_open')
self.show_params_param = self._prefs_block.get_param('show_params')
def save(self):
try: ParseXML.to_file({'block': self._prefs_block.export_data()}, self._prefs_file_path)
except IOError: Messages.send_fail_save_preferences(self._prefs_file_path)
def get_preferences(self):
##Preferences: title, notes, params
return [
(
'Grid',
'''
Show grid will draw a square grid onto the flow graph with grid points separated by grid size pixels. \
Snap to Grid forces the upper right corner of the signal block to align with a grid point.
''',
[self.snap_to_grid_param, self.grid_size_param, self.show_grid_param],
),
(
'Appearance',
'''
Show or hide the reports window at the bottom of the main window.
Show or hide all paramater labels in the signal blocks.
''',
[self.show_reports_param, self.show_params_param],
),
(
'Misc',
'''
Restore previously opened files on start-up.
''',
[self.restore_files_param],
),
]
###########################################################################
# Special methods for specific program functionalities
###########################################################################
def window_size(size=None):
if size: _get_prefs().window_size_param.set_value(size)
else:
try: return eval(_get_prefs().window_size_param.get_value())
except: return (-1, -1)
def restore_files():
return _get_prefs().restore_files_param.get_value() == 'yes'
def file_open(file=None):
if file is not None: _get_prefs().file_open_param.set_value(file)
else: return _get_prefs().file_open_param.get_value()
def files_open(files=None):
if files is not None: _get_prefs().files_open_param.set_value('\n'.join(files))
else: return _get_prefs().files_open_param.get_value().split('\n')
def show_reports_window():
return _get_prefs().show_reports_param.get_value() == 'show'
def get_grid_size():
return int(_get_prefs().grid_size_param.get_value())
def snap_to_grid():
return _get_prefs().snap_to_grid_param.get_value() == 'on'
def show_grid():
return _get_prefs().show_grid_param.get_value() == 'show'
def show_params():
return _get_prefs().show_params_param.get_value() == 'show'
|