Mon, 04 Jun 2018 22:28:05 +0200
[plotter] add a --mockup option to the demo main function
66
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
40
diff
changeset
|
1 | # This program is free software; you can redistribute it and/or modify it under |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
40
diff
changeset
|
2 | # the terms of the GNU General Public License as published by the Free Software |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
40
diff
changeset
|
3 | # Foundation; either version 2 of the License, or (at your option) any later |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
40
diff
changeset
|
4 | # version. |
36
cb4124e3e75b
some improvements; can now give a bunch of files to open on cmd line; removed print statements
David Douard <david.douard@logilab.fr>
parents:
35
diff
changeset
|
5 | # |
66
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
40
diff
changeset
|
6 | # This program is distributed in the hope that it will be useful, but WITHOUT |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
40
diff
changeset
|
7 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
40
diff
changeset
|
8 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
40
diff
changeset
|
9 | # |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
40
diff
changeset
|
10 | # You should have received a copy of the GNU General Public License along with |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
40
diff
changeset
|
11 | # this program; if not, write to the Free Software Foundation, Inc., |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
40
diff
changeset
|
12 | # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
86
96e30b092f70
[py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents:
66
diff
changeset
|
13 | """ Copyright (c) 2007-2018 David Douard (Paris, FRANCE). |
91
f2a8f688dbc0
project moved to bitbucket
David Douard <david.douard@logilab.fr>
parents:
89
diff
changeset
|
14 | https://bitbucket.org/dddouard/pygpibtoolkit -- mailto:david.douard@sdfa3.org |
66
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
40
diff
changeset
|
15 | |
36
cb4124e3e75b
some improvements; can now give a bunch of files to open on cmd line; removed print statements
David Douard <david.douard@logilab.fr>
parents:
35
diff
changeset
|
16 | Helper functions and classes |
cb4124e3e75b
some improvements; can now give a bunch of files to open on cmd line; removed print statements
David Douard <david.douard@logilab.fr>
parents:
35
diff
changeset
|
17 | """ |
cb4124e3e75b
some improvements; can now give a bunch of files to open on cmd line; removed print statements
David Douard <david.douard@logilab.fr>
parents:
35
diff
changeset
|
18 | import re |
cb4124e3e75b
some improvements; can now give a bunch of files to open on cmd line; removed print statements
David Douard <david.douard@logilab.fr>
parents:
35
diff
changeset
|
19 | |
86
96e30b092f70
[py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents:
66
diff
changeset
|
20 | |
96e30b092f70
[py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents:
66
diff
changeset
|
21 | def cmp(a, b): |
96e30b092f70
[py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents:
66
diff
changeset
|
22 | return (a > b) - (a < b) |
96e30b092f70
[py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents:
66
diff
changeset
|
23 | |
96e30b092f70
[py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents:
66
diff
changeset
|
24 | |
89
61074a32808a
[HP3562A] port HP3562A app to Py3k/Qt5
David Douard <david.douard@logilab.fr>
parents:
87
diff
changeset
|
25 | def str_num_key(s1): |
61074a32808a
[HP3562A] port HP3562A app to Py3k/Qt5
David Douard <david.douard@logilab.fr>
parents:
87
diff
changeset
|
26 | """string comparator function that will allow to put 'toto_10' after 'toto_2' |
36
cb4124e3e75b
some improvements; can now give a bunch of files to open on cmd line; removed print statements
David Douard <david.douard@logilab.fr>
parents:
35
diff
changeset
|
27 | Also works for strings like 'toto_1_et_23er25'. |
cb4124e3e75b
some improvements; can now give a bunch of files to open on cmd line; removed print statements
David Douard <david.douard@logilab.fr>
parents:
35
diff
changeset
|
28 | """ |
cb4124e3e75b
some improvements; can now give a bunch of files to open on cmd line; removed print statements
David Douard <david.douard@logilab.fr>
parents:
35
diff
changeset
|
29 | r = re.compile(r'((?<=\d)\D+|(?<=\D)\d+)') |
89
61074a32808a
[HP3562A] port HP3562A app to Py3k/Qt5
David Douard <david.douard@logilab.fr>
parents:
87
diff
changeset
|
30 | return [not x.isdigit() and x or int(x) for x in r.split(s1) if x] |
36
cb4124e3e75b
some improvements; can now give a bunch of files to open on cmd line; removed print statements
David Douard <david.douard@logilab.fr>
parents:
35
diff
changeset
|
31 | |
cb4124e3e75b
some improvements; can now give a bunch of files to open on cmd line; removed print statements
David Douard <david.douard@logilab.fr>
parents:
35
diff
changeset
|
32 | |
86
96e30b092f70
[py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents:
66
diff
changeset
|
33 | class AbstractRegister: |
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:
diff
changeset
|
34 | _instance = 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:
diff
changeset
|
35 | _registered_type = None |
86
96e30b092f70
[py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents:
66
diff
changeset
|
36 | |
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:
diff
changeset
|
37 | def __new__(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:
diff
changeset
|
38 | # implements a singleton |
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:
diff
changeset
|
39 | if cls._instance is None: |
86
96e30b092f70
[py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents:
66
diff
changeset
|
40 | # debug('Instanciating %s', cls.__name__) |
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:
diff
changeset
|
41 | cls._instance = super(AbstractRegister, cls).__new__(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:
diff
changeset
|
42 | cls._instance.registered = {} |
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:
diff
changeset
|
43 | cls._instance.accepts = set() |
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:
diff
changeset
|
44 | return cls._instance |
86
96e30b092f70
[py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents:
66
diff
changeset
|
45 | |
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:
diff
changeset
|
46 | def add(self, 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:
diff
changeset
|
47 | assert issubclass(cls, self._registered_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:
diff
changeset
|
48 | if cls is self._registered_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:
diff
changeset
|
49 | return |
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:
diff
changeset
|
50 | if cls._accepts is 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:
diff
changeset
|
51 | return |
86
96e30b092f70
[py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents:
66
diff
changeset
|
52 | # assert isinstance(cls._accepts, (basestring, tuple)) |
96e30b092f70
[py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents:
66
diff
changeset
|
53 | |
96e30b092f70
[py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents:
66
diff
changeset
|
54 | # debug("Registerered %s for %s", cls.__name__) |
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:
diff
changeset
|
55 | if not isinstance(cls._accepts, tuple): |
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:
diff
changeset
|
56 | cls._accepts = (cls._accepts,) |
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:
diff
changeset
|
57 | for key in cls._accepts: |
87
59a0946aa3d1
port HPGL plotter emulator to PyQt5
David Douard <david.douard@logilab.fr>
parents:
86
diff
changeset
|
58 | print('Accept ', key, 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:
diff
changeset
|
59 | key = self._get_typ(key) |
86
96e30b092f70
[py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents:
66
diff
changeset
|
60 | # debug(" new key = %s", key) |
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:
diff
changeset
|
61 | self.registered.setdefault(key, []).append(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:
diff
changeset
|
62 | self.accepts.add(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:
diff
changeset
|
63 | |
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:
diff
changeset
|
64 | def _get_typ(self, typ): |
86
96e30b092f70
[py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents:
66
diff
changeset
|
65 | if not isinstance(typ, str): |
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:
diff
changeset
|
66 | if not isinstance(typ, 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:
diff
changeset
|
67 | return 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:
diff
changeset
|
68 | typ = typ.__name__ |
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:
diff
changeset
|
69 | return typ |
86
96e30b092f70
[py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents:
66
diff
changeset
|
70 | |
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:
diff
changeset
|
71 | def __contains__(self, val): |
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:
diff
changeset
|
72 | val = self._get_typ(val) |
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:
diff
changeset
|
73 | return val in self.accepts |
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:
diff
changeset
|
74 | |
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:
diff
changeset
|
75 | def get_class(self, typ): |
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:
diff
changeset
|
76 | item = typ |
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:
diff
changeset
|
77 | if not isinstance(typ, 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:
diff
changeset
|
78 | typ = typ.__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:
diff
changeset
|
79 | name = typ.__name__ |
86
96e30b092f70
[py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents:
66
diff
changeset
|
80 | # debug("Looking a widget for %s", typ.__name__) |
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:
diff
changeset
|
81 | orig_typ = typ |
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:
diff
changeset
|
82 | while typ is not 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:
diff
changeset
|
83 | if typ.__name__ in self.registered: |
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:
diff
changeset
|
84 | for w in self.registered[typ.__name__]: |
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:
diff
changeset
|
85 | if w._filter is None or w._filter(item): |
86
96e30b092f70
[py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents:
66
diff
changeset
|
86 | # debug("Widget for %s is %s", typ.__name__, w) |
96e30b092f70
[py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents:
66
diff
changeset
|
87 | return w # self.registered[typ.__name__] |
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:
diff
changeset
|
88 | if typ.__bases__: |
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:
diff
changeset
|
89 | typ = typ.__bases__[0] |
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:
diff
changeset
|
90 | if typ == 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:
diff
changeset
|
91 | typ = 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:
diff
changeset
|
92 | elif typ.__name__ in ("ObjectItem_", "AbstractListItem_"): |
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:
diff
changeset
|
93 | typ = orig_typ._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:
diff
changeset
|
94 | else: |
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:
diff
changeset
|
95 | typ = 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:
diff
changeset
|
96 | raise ValueError('No registered class for %s' % (name)) |