Sun, 03 Feb 2008 23:39:27 +0100
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
23
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
1 | import os |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
2 | from PyQt4 import QtCore, QtGui, uic |
35
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
3 | from tools import AbstractRegister |
23
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
4 | |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
5 | def fromVariant(v): |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
6 | _cvrts = {0: lambda x:None, |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
7 | 1: lambda x:x.toBool(), |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
8 | 2: lambda x:x.toInt()[0], |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
9 | 6: lambda x:x.toDouble()[0], |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
10 | 10: lambda x:unicode(x.toString()), |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
11 | 12: lambda x:x.toByteArray(), |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
12 | 21: lambda x:x.toSize(), |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
13 | 22: lambda x:x.toSizeF(), |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
14 | 25: lambda x:x.toPoint(), |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
15 | 26: lambda x:x.toPointF(), |
35
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
16 | 64: lambda x:QtGui.QFont(x), |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
17 | 67: lambda x:QtGui.QColor(x), |
23
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
18 | } |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
19 | t = v.userType() |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
20 | return _cvrts[t](v) |
35
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
21 | |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
22 | class PreferenceMetaclass(type): |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
23 | _widgets = {} |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
24 | def __init__(cls, name, bases, dct): |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
25 | # called at class creation |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
26 | super(type, cls).__init__(name, bases, dct) |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
27 | if name != "BaseItem": |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
28 | ItemRegister().add(cls) |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
29 | |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
30 | class BaseItem(object): |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
31 | #__metaclass__ = PreferenceMetaclass |
23
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
32 | _id = 0 |
35
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
33 | def __init__(self, default=None, name=None, description=None, group=None): |
23
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
34 | self._default = default |
35
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
35 | self._id = BaseItem._id |
23
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
36 | self._name = name |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
37 | self._description = description |
35
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
38 | self._group = group |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
39 | BaseItem._id += 1 |
23
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
40 | |
35
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
41 | def validate(self, value): |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
42 | return True |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
43 | |
23
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
44 | def __get__(self, obj, cls): |
35
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
45 | if obj is None: #when called from the class, return the Item itself |
23
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
46 | return self |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
47 | try: |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
48 | return obj.getPref(self._id) |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
49 | except Exception, e: |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
50 | return None |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
51 | |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
52 | def __set__(self, obj, value): |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
53 | obj.setPref(self._id, value) |
35
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
54 | |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
55 | class ItemRegister(AbstractRegister): |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
56 | _registered_type = BaseItem |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
57 | getItem = AbstractRegister.get_class |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
58 | |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
59 | class PointItem(BaseItem): |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
60 | _type = QtCore.QPoint |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
61 | |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
62 | class SizeItem(BaseItem): |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
63 | _type = QtCore.QSize |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
64 | |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
65 | class ByteArrayItem(BaseItem): |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
66 | _type = QtCore.QByteArray |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
67 | |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
68 | class UnicodeItem(BaseItem): |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
69 | _type = unicode |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
70 | def validate(self, value): |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
71 | return isinstance(value, basestring) |
23
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
72 | |
35
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
73 | class IntItem(BaseItem): |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
74 | _type = int |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
75 | def __init__(self, default=None, name=None, description=None, group=None, min=None, max=None): |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
76 | BaseItem.__init__(self, default, name, description, group) |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
77 | self._min = min |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
78 | self._max = max |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
79 | |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
80 | def validate(self, value): |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
81 | try: |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
82 | value = self._type(value) |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
83 | except: |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
84 | return False |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
85 | if self._min is not None and value<self._min: |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
86 | return False |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
87 | if self._max is not None and value>self._max: |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
88 | return False |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
89 | return True |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
90 | |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
91 | class ColorItem(BaseItem): |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
92 | _type = QtGui.QColor |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
93 | |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
94 | def validate(self, value): |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
95 | try: |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
96 | self._type(value) |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
97 | return True |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
98 | except: |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
99 | return False |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
100 | |
23
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
101 | class AbstractPreferences(QtCore.QObject): |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
102 | def __init__(self): |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
103 | QtCore.QObject.__init__(self) |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
104 | self._settings = QtCore.QSettings(QtCore.QSettings.UserScope, |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
105 | self.ORGANISATION, self.APPLICATION) |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
106 | self._prefs = {} |
35
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
107 | self.groups = [] |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
108 | keys = [] |
23
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
109 | for k in dir(self.__class__): |
35
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
110 | item = self.getItem(k) |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
111 | if isinstance(item, BaseItem): |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
112 | keys.append((k,item)) |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
113 | keys.sort(key=lambda x: x[1]._id) |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
114 | print [x[1]._id for x in keys] |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
115 | for k, item in keys: |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
116 | self._prefs[item._id] = k |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
117 | if item._group not in self.groups: |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
118 | self.groups.append(item._group) |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
119 | |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
120 | def getItem(self, key): |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
121 | return getattr(self.__class__, key) |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
122 | #return self._prefs.get(key, None) |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
123 | |
23
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
124 | def getPref(self, key): |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
125 | key = self._prefs.get(key, key) |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
126 | default = getattr(self.__class__, key)._default |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
127 | if default is not None: |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
128 | default = QtCore.QVariant(default) |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
129 | else: |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
130 | default = QtCore.QVariant() |
35
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
131 | val = fromVariant(self._settings.value(key, default)) |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
132 | return val |
23
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
133 | |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
134 | def setPref(self, key, value): |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
135 | key = self._prefs.get(key, key) |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
136 | self._settings.setValue(key, QtCore.QVariant(value)) |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
137 | |
35
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
138 | def keys(self, group=None): |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
139 | return [k for k in self._prefs.values() if not k.startswith('_') and self.getItem(k)._group == group] |
23
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
140 | |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
141 | def getName(self, key): |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
142 | item = getattr(self.__class__, key) |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
143 | return item._name |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
144 | |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
145 | def getDescription(self, key): |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
146 | item = getattr(self.__class__, key) |
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
147 | return item._description |
35
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
148 | |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
149 | def __getitem__(self, key): |
3b7a38af5c42
Refactored the preference system for the qt gpib plotter app. One can now set the colors for plotting pens.
David Douard <david.douard@logilab.fr>
parents:
32
diff
changeset
|
150 | return getattr(self, key) |
23
cb97962a1ae9
make qplotter a working app: can new load several hpgl files à display them; have a preference system
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
151 |