2 ## This file is part of the sigrok-meter project.
4 ## Copyright (C) 2015 Jens Steinhauser <jens.steinhauser@gmail.com>
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 2 of the License, or
9 ## (at your option) any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program; if not, write to the Free Software
18 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 QtCore = qtcompat.QtCore
24 QtGui = qtcompat.QtGui
26 class Setting(QtCore.QObject):
27 '''Wrapper class around the raw 'QSettings' class that emits signals
28 when the value of the setting changes.'''
30 '''Signal emitted when the setting has changed.'''
31 changed = QtCore.Signal(object)
33 def __init__(self, key, default=None):
34 super(self.__class__, self).__init__()
37 self._default = default
41 s = QtCore.QSettings()
42 self._value = s.value(self._key, self._default)
46 def setValue(self, value):
47 if value != self._value:
48 s = QtCore.QSettings()
49 s.setValue(self._key, value)
52 self.changed.emit(self._value)
54 class _SettingsGroup(object):
55 '''Dummy class to group multiple 'Setting' objects together.'''
59 '''Creates the 'Settings' objects for all known settings and places them
60 into the module's namespace.
62 A QApplication must have been created before this function can be called.
65 app = QtGui.QApplication.instance()
66 app.setApplicationName('sigrok-meter')
67 app.setOrganizationName('sigrok')
68 app.setOrganizationDomain('sigrok.org')
70 mainwindow = _SettingsGroup()
71 mainwindow.size = Setting('mainwindow/size', QtCore.QSize(900, 550))
72 mainwindow.pos = Setting('mainwindow/pos')
73 globals()['mainwindow'] = mainwindow