Debian Codegraph @

manual/plugin_examples/interface_demo/config.py

raw
1 #!/usr/bin/env python
2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
3
4
5 __license__ = 'GPL v3'
6 __copyright__ = '2011, Kovid Goyal <[email protected]>'
7 __docformat__ = 'restructuredtext en'
8
9 from qt.core import QHBoxLayout, QLabel, QLineEdit, QWidget
10
11 from calibre.utils.config import JSONConfig
12
13 # This is where all preferences for this plugin will be stored
14 # Remember that this name (i.e. plugins/interface_demo) is also
15 # in a global namespace, so make it as unique as possible.
16 # You should always prefix your config file name with plugins/,
17 # so as to ensure you don't accidentally clobber a calibre config file
18 prefs = JSONConfig('plugins/interface_demo')
19
20 # Set defaults
21 prefs.defaults['hello_world_msg'] = 'Hello, World!'
22
23
24 class ConfigWidget(QWidget):
25 def __init__(self):
26 QWidget.__init__(self)
27 self.l = QHBoxLayout()
28 self.setLayout(self.l)
29
30 self.label = QLabel('Hello world &message:')
31 self.l.addWidget(self.label)
32
33 self.msg = QLineEdit(self)
34 self.msg.setText(prefs['hello_world_msg'])
35 self.l.addWidget(self.msg)
36 self.label.setBuddy(self.msg)
37
38 def save_settings(self):
39 prefs['hello_world_msg'] = self.msg.text()