plotter/qgpib_plotter.py

Mon, 04 Feb 2008 19:49:48 +0100

author
David Douard <david.douard@logilab.fr>
date
Mon, 04 Feb 2008 19:49:48 +0100
changeset 39
8becd52c2171
parent 38
73bd2fe81005
permissions
-rw-r--r--

refactoring in progress

22
b2f4646161be Begin of a HPGL plotter application (PyQt4)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
1 #
b2f4646161be Begin of a HPGL plotter application (PyQt4)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
2
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: 22
diff changeset
3 import os, sys
27
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
4 import time
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 import glob
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: 22
diff changeset
6
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: 22
diff changeset
7 from PyQt4 import QtGui, QtCore, uic
22
b2f4646161be Begin of a HPGL plotter application (PyQt4)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
8 from PyQt4.QtCore import SIGNAL, Qt
b2f4646161be Begin of a HPGL plotter application (PyQt4)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
9
28
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
10 if "-m" in sys.argv:
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
11 from gpib_plotter_mockup import GPIBplotter
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
12 else:
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
13 from gpib_plotter import GPIBplotter
22
b2f4646161be Begin of a HPGL plotter application (PyQt4)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
14 from hpgl_qt import QHPGLPlotterWidget
34
022e881b758e moved some files & one bugfix
David Douard <david.douard@logilab.fr>
parents: 32
diff changeset
15 import hpgl_plotter_rc
22
b2f4646161be Begin of a HPGL plotter application (PyQt4)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
16
34
022e881b758e moved some files & one bugfix
David Douard <david.douard@logilab.fr>
parents: 32
diff changeset
17 ldir = os.path.abspath(os.path.dirname(__file__))
022e881b758e moved some files & one bugfix
David Douard <david.douard@logilab.fr>
parents: 32
diff changeset
18 sys.path.append(ldir)
022e881b758e moved some files & one bugfix
David Douard <david.douard@logilab.fr>
parents: 32
diff changeset
19 form_class, base_class = uic.loadUiType(os.path.join(ldir, "qhpgl_plotter.ui"))
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: 22
diff changeset
20
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: 34
diff changeset
21 from qpreferences import BaseItem, IntItem, UnicodeItem, ColorItem
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: 34
diff changeset
22 from qpreferences import PointItem, SizeItem, ByteArrayItem
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: 34
diff changeset
23 from qpreferences import AbstractPreferences
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: 34
diff changeset
24 from qpreferenceseditor import PreferencesEditor
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: 22
diff changeset
25
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
26 from tools import str_num_cmp
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
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: 22
diff changeset
28 class Preferences(AbstractPreferences):
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: 22
diff changeset
29 ORGANISATION="Logilab"
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: 22
diff changeset
30 APPLICATION="qgpib_plotter"
22
b2f4646161be Begin of a HPGL plotter application (PyQt4)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
31
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: 34
diff changeset
32 _pos = PointItem()
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: 34
diff changeset
33 _size = SizeItem()
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: 34
diff changeset
34 _appState = ByteArrayItem()
27
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
35
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: 34
diff changeset
36 device = UnicodeItem(default='/dev/ttyUSB0',
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: 34
diff changeset
37 name=u'device',
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: 34
diff changeset
38 description=u'GPIB device',
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: 34
diff changeset
39 group="GPIB settings")
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: 34
diff changeset
40 address = IntItem(default=5, min=0, max=16,
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: 34
diff changeset
41 name=u'GPIB address',
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: 34
diff changeset
42 group="GPIB settings")
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: 34
diff changeset
43
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: 34
diff changeset
44 background = ColorItem(default=QtGui.QColor("white"),
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: 34
diff changeset
45 name="Background",
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: 34
diff changeset
46 group="Colors")
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: 34
diff changeset
47 color0 = ColorItem(default=QtGui.QColor("black"),
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: 34
diff changeset
48 name="Pen #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: 34
diff changeset
49 group="Colors")
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: 34
diff changeset
50 color1 = ColorItem(default=QtGui.QColor("green"),
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: 34
diff changeset
51 name="Pen #1",
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: 34
diff changeset
52 group="Colors")
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: 34
diff changeset
53 color2 = ColorItem(default=QtGui.QColor("red"),
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: 34
diff changeset
54 name="Pen #2",
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: 34
diff changeset
55 group="Colors")
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: 34
diff changeset
56 color3 = ColorItem(default=QtGui.QColor("blue"),
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: 34
diff changeset
57 name="Pen #3",
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: 34
diff changeset
58 group="Colors")
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: 34
diff changeset
59 color4 = ColorItem(default=QtGui.QColor("yellow"),
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: 34
diff changeset
60 name="Pen #4",
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: 34
diff changeset
61 group="Colors")
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: 34
diff changeset
62 color5 = ColorItem(default=QtGui.QColor("cyan"),
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: 34
diff changeset
63 name="Pen #5",
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: 34
diff changeset
64 group="Colors")
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: 34
diff changeset
65 color6 = ColorItem(default=QtGui.QColor("magenta"),
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: 34
diff changeset
66 name="Pen #6",
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: 34
diff changeset
67 group="Colors")
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: 34
diff changeset
68 color7 = ColorItem(default=QtGui.QColor("darkred"),
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: 34
diff changeset
69 name="Pen #7",
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: 34
diff changeset
70 group="Colors")
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: 22
diff changeset
71
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: 22
diff changeset
72 class QtHPGLPlotter(QtGui.QMainWindow, form_class):
22
b2f4646161be Begin of a HPGL plotter application (PyQt4)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
73 def __init__(self, parent=None):
b2f4646161be Begin of a HPGL plotter application (PyQt4)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
74 QtGui.QMainWindow.__init__(self, parent)
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: 22
diff changeset
75 self._plots = {}
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: 22
diff changeset
76 self._prefs = Preferences()
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: 22
diff changeset
77 self.setupUi()
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: 22
diff changeset
78 self.initializeGPIB()
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: 22
diff changeset
79 if self._prefs._pos:
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: 22
diff changeset
80 self.move(self._prefs._pos)
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: 22
diff changeset
81 if self._prefs._size:
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: 22
diff changeset
82 self.resize(self._prefs._size)
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: 22
diff changeset
83 if self._prefs._appState:
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: 22
diff changeset
84 self.restoreState(self._prefs._appState)
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: 34
diff changeset
85 self.readPreferences()
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: 22
diff changeset
86
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: 34
diff changeset
87 def readPreferences(self):
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: 34
diff changeset
88 bg = self._prefs.background
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: 34
diff changeset
89 if bg and bg.isValid():
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: 34
diff changeset
90 self.plotterWidget.qview.setBackgroundBrush(QtGui.QBrush(bg))
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: 34
diff changeset
91 pen_colors = [self._prefs["color%d"%i] for i in range(8)]
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: 34
diff changeset
92 self.plotterWidget.pen_colors = pen_colors
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: 34
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: 34
diff changeset
94 def replotCurrent(self):
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: 34
diff changeset
95 self.currentPlotChanged(self.plotsView.currentIndex())
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: 34
diff changeset
96
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: 22
diff changeset
97 def setupUi(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: 22
diff changeset
98 form_class.setupUi(self, self) # call qtdesigner generated form creation
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: 22
diff changeset
99 # actions defined in designer
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: 22
diff changeset
100 self.connect(self.actionPreferences, SIGNAL('triggered(bool)'),
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: 22
diff changeset
101 self.preferencesTriggered)
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: 22
diff changeset
102 self.connect(self.actionQuit, SIGNAL('triggered(bool)'),
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: 22
diff changeset
103 self.quitTriggered)
25
32d0d1cd44c3 add main menu shotcuts and make first openened file displayed
David Douard <david.douard@logilab.fr>
parents: 23
diff changeset
104 self.actionQuit.setShortcut(QtGui.QKeySequence(u'Ctrl+Q'))
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: 22
diff changeset
105 self.connect(self.actionOpen, SIGNAL('triggered(bool)'),
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: 22
diff changeset
106 self.openTriggered)
25
32d0d1cd44c3 add main menu shotcuts and make first openened file displayed
David Douard <david.douard@logilab.fr>
parents: 23
diff changeset
107 self.actionOpen.setShortcut(QtGui.QKeySequence(u'Ctrl+O'))
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: 22
diff changeset
108 self.connect(self.actionSave, SIGNAL('triggered(bool)'),
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: 22
diff changeset
109 self.saveTriggered)
25
32d0d1cd44c3 add main menu shotcuts and make first openened file displayed
David Douard <david.douard@logilab.fr>
parents: 23
diff changeset
110 self.actionSave.setShortcut(QtGui.QKeySequence(u'Ctrl+S'))
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: 22
diff changeset
111 self.connect(self.actionSaveAs, SIGNAL('triggered(bool)'),
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: 22
diff changeset
112 self.saveAsTriggered)
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: 22
diff changeset
113
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: 22
diff changeset
114 self.plotterWidget = QHPGLPlotterWidget(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: 22
diff changeset
115 self.setCentralWidget(self.plotterWidget)
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: 22
diff changeset
116
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: 22
diff changeset
117 self.connect(self.captureButton, SIGNAL("toggled(bool)"),
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: 22
diff changeset
118 self.captureToggled)
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: 22
diff changeset
119
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: 22
diff changeset
120 self._plots_list = QtGui.QStringListModel()
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: 22
diff changeset
121 self.plotsView.setModel(self._plots_list)
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: 22
diff changeset
122 self.connect(self.plotsView, SIGNAL('activated(const QModelIndex&)'),
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: 22
diff changeset
123 self.currentPlotChanged)
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: 22
diff changeset
124 self.connect(self.plotsView.selectionModel(),
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: 22
diff changeset
125 SIGNAL('currentChanged(const QModelIndex&, const QModelIndex&)'),
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: 22
diff changeset
126 self.currentPlotChanged)
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: 22
diff changeset
127
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: 22
diff changeset
128 def currentPlotChanged(self, index, old_index=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: 22
diff changeset
129 if index.isValid():
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: 22
diff changeset
130 value = unicode(self.plotsView.model().data(index, Qt.DisplayRole).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: 22
diff changeset
131
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: 22
diff changeset
132 self.plotterWidget.clear()
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: 22
diff changeset
133 self.plotterWidget.parse(self._plots[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: 22
diff changeset
134
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: 22
diff changeset
135 def preferencesTriggered(self, checked=False):
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: 22
diff changeset
136 PreferencesEditor(self._prefs, self).exec_()
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: 34
diff changeset
137 self.readPreferences()
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: 34
diff changeset
138 self.replotCurrent()
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: 22
diff changeset
139
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: 22
diff changeset
140 def quitTriggered(self, checked=False):
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: 22
diff changeset
141 self.close()
22
b2f4646161be Begin of a HPGL plotter application (PyQt4)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
142
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: 22
diff changeset
143 def closeEvent(self, event):
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: 22
diff changeset
144 if 1:
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: 22
diff changeset
145 #if self.promptForSave():
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: 22
diff changeset
146 self._prefs._pos = self.pos()
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: 22
diff changeset
147 self._prefs._size = self.size()
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: 22
diff changeset
148 self._prefs._appState = self.saveState()
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: 22
diff changeset
149 event.accept()
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: 22
diff changeset
150 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: 22
diff changeset
151 event.ignore()
22
b2f4646161be Begin of a HPGL plotter application (PyQt4)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
152
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: 22
diff changeset
153 def openTriggered(self, checked=False):
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: 22
diff changeset
154 filenames = QtGui.QFileDialog.getOpenFileNames(self, "Open a HPGL file to display", '.', 'HPGL files (*.plt)\nAll files (*)')
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
155 self.openFiles(filenames)
38
73bd2fe81005 small improvement; display first plot at startup
David Douard <david.douard@logilab.fr>
parents: 36
diff changeset
156 self.displayFirst()
73bd2fe81005 small improvement; display first plot at startup
David Douard <david.douard@logilab.fr>
parents: 36
diff changeset
157
73bd2fe81005 small improvement; display first plot at startup
David Douard <david.douard@logilab.fr>
parents: 36
diff changeset
158 def displayFirst(self):
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
159 if not self.plotsView.currentIndex().isValid():
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
160 self.plotsView.setCurrentIndex(self.plotsView.model().index(0, 0))
38
73bd2fe81005 small improvement; display first plot at startup
David Douard <david.douard@logilab.fr>
parents: 36
diff changeset
161
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
162 def openFiles(self, filenames):
38
73bd2fe81005 small improvement; display first plot at startup
David Douard <david.douard@logilab.fr>
parents: 36
diff changeset
163 ok = False
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: 22
diff changeset
164 for filename in filenames:
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: 22
diff changeset
165 filename = str(filename)
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: 22
diff changeset
166 if os.path.exists(filename):
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: 22
diff changeset
167 data = open(filename).read()
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: 22
diff changeset
168 name = os.path.basename(filename)
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: 22
diff changeset
169 name = os.path.splitext(name)[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: 22
diff changeset
170 lst = self.plotsView.model().stringList()
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: 22
diff changeset
171 lst.append(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: 22
diff changeset
172 self._plots[name] = data
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: 22
diff changeset
173 self.plotsView.model().setStringList(lst)
38
73bd2fe81005 small improvement; display first plot at startup
David Douard <david.douard@logilab.fr>
parents: 36
diff changeset
174 ok = True
73bd2fe81005 small improvement; display first plot at startup
David Douard <david.douard@logilab.fr>
parents: 36
diff changeset
175 return ok
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
176
27
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
177 def plotReceived(self, num):
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
178 self._receiving = False
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
179 self.setReceivingLed()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
180 plot, timestamp = self.captureThread.getPlot(num)
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
181 name = "plot_%s"%(num)
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
182 lst = self.plotsView.model().stringList()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
183 lst.append(name)
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
184 self._plots[name] = plot
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
185 self.plotsView.model().setStringList(lst)
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
186
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
187 def plotStarted(self):
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
188 self._receiving = True
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
189 self.setReceivingLed()
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: 22
diff changeset
190
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: 22
diff changeset
191 def saveTriggered(self, checked=False):
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: 22
diff changeset
192 print "save"
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
193
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: 22
diff changeset
194 def saveAsTriggered(self, checked=False):
34
022e881b758e moved some files & one bugfix
David Douard <david.douard@logilab.fr>
parents: 32
diff changeset
195 index = self.plotsView.selectionModel().currentIndex()
022e881b758e moved some files & one bugfix
David Douard <david.douard@logilab.fr>
parents: 32
diff changeset
196 if index.isValid():
022e881b758e moved some files & one bugfix
David Douard <david.douard@logilab.fr>
parents: 32
diff changeset
197 filename = QtGui.QFileDialog.getSaveFileName(self, "Selecte a file name to save HPGL file", '.', 'HPGL files (*.plt)\nAll files (*)')
022e881b758e moved some files & one bugfix
David Douard <david.douard@logilab.fr>
parents: 32
diff changeset
198 n = index.row()
022e881b758e moved some files & one bugfix
David Douard <david.douard@logilab.fr>
parents: 32
diff changeset
199 value = unicode(self.plotsView.model().data(index, Qt.DisplayRole).toString())
022e881b758e moved some files & one bugfix
David Douard <david.douard@logilab.fr>
parents: 32
diff changeset
200 open(filename, 'w').write(self._plots[value])
022e881b758e moved some files & one bugfix
David Douard <david.douard@logilab.fr>
parents: 32
diff changeset
201
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: 22
diff changeset
202
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: 22
diff changeset
203 def initializeGPIB(self):
27
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
204 self._online = False
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: 22
diff changeset
205 try:
27
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
206 self.gpib_plotter = QGPIBplotter(device=self._prefs.device,
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: 22
diff changeset
207 address=self._prefs.address,
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: 22
diff changeset
208 )
27
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
209 self.captureThread = GPIBReceiver(self.gpib_plotter)
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
210 self.connect(self.captureThread, SIGNAL('plotReceived(int)'),
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
211 self.plotReceived)
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
212 self.connect(self.captureThread, SIGNAL('plotStarted()'),
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
213 self.plotStarted)
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
214 self.captureThread.start()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
215 except Exception, e:
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
216 #print e
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: 22
diff changeset
217 self.gpib_plotter = 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: 22
diff changeset
218 self.setCaptureLed()
27
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
219
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: 22
diff changeset
220 def captureToggled(self, state):
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: 22
diff changeset
221 if state:
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: 22
diff changeset
222 if self.gpib_plotter is 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: 22
diff changeset
223 self.initializeGPIB()
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: 22
diff changeset
224 if self.gpib_plotter is 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: 22
diff changeset
225 QtGui.QMessageBox.critical(self, self.tr("GPIB error"),
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: 22
diff changeset
226 self.tr("<b>Unable to initialize GPIB connection</b>.<br>Please check your GPIB dongle and settings."))
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: 22
diff changeset
227 self._online = False
27
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
228 self.setCaptureLed()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
229 return
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
230 self._online = True
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
231 self.captureThread.startCapture()
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: 22
diff changeset
232 else:
27
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
233 if self.captureThread:
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
234 self.captureThread.stopCapture()
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: 22
diff changeset
235 self._online = False
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: 22
diff changeset
236 self.setCaptureLed()
27
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
237
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: 22
diff changeset
238 def setCaptureLed(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: 22
diff changeset
239 if self._online:
27
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
240 icn = QtGui.QIcon(':/icons/led_green.svg')
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: 22
diff changeset
241 else:
27
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
242 icn = QtGui.QIcon(':/icons/led_green_off.svg')
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: 22
diff changeset
243 self.captureButton.setIcon(icn)
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: 22
diff changeset
244 self.captureButton.setChecked(self._online)
27
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
245
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
246 def setReceivingLed(self):
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
247 if self._receiving:
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
248 icn = QtGui.QIcon(':/icons/led_red.svg')
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
249 else:
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
250 icn = QtGui.QIcon(':/icons/led_red_off.svg')
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
251 self.receivingButton.setIcon(icn)
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
252
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
253 class QGPIBplotter(GPIBplotter):
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
254 def __init__(self, device="/dev/ttyUSB0", baudrate=115200, timeout=0.1,
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
255 address=5):
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
256 GPIBplotter.__init__(self, device, baudrate, timeout, address)
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
257 self.emitter = None
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
258
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
259 def plotStarted(self):
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
260 if self.emitter:
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
261 self.emitter.emit(SIGNAL('plotStarted()'))
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
262 #self.emitter.msleep(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: 22
diff changeset
263
27
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
264 class GPIBReceiver(QtCore.QThread):
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
265 def __init__(self, cnx):
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
266 QtCore.QThread.__init__(self)
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
267 self.gpibplotter = cnx
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
268 self.gpibplotter.emitter = self
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
269
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
270 self._cancelmutex = QtCore.QMutex()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
271 self._cancel = False
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
272 #self._nreceived = 0
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
273 self._plotsmutex = QtCore.QMutex()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
274 self._plots = []
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
275 self._startstopmutex = QtCore.QMutex()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
276 self._startstop = QtCore.QWaitCondition()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
277 self._capturing = False
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
278
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
279 def cancel(self):
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
280 self._cancelmutex.lock()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
281 self._cancel = True
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
282 self._cancelmutex.unlock()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
283
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
284 def startCapture(self):
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
285 self._startstop.wakeOne()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
286
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
287 def stopCapture(self):
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
288 self._startstopmutex.lock()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
289 self._capturing = False
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
290 self._startstopmutex.unlock()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
291
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
292 def run(self):
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
293 while 1:
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
294 self._cancelmutex.lock()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
295 if self._cancel:
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
296 return
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
297 self._cancelmutex.unlock()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
298 self._startstopmutex.lock()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
299 if not self._capturing:
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
300 self._startstop.wait(self._startstopmutex)
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
301 self._capturing = True
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
302 self._startstopmutex.unlock()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
303
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
304 plot = self.gpibplotter.load_plot(wait_timeout=0.1)
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
305 timestamp = time.time()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
306 if plot:
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
307 self._plotsmutex.lock()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
308 self._plots.append((plot, timestamp))
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
309 n = len(self._plots)
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
310 self._plotsmutex.unlock()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
311 self.emit(SIGNAL('plotReceived(int)'), n-1)
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
312 self.msleep(10)
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
313
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
314 def getPlot(self, num):
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
315 self._plotsmutex.lock()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
316 try:
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
317 return self._plots[num]
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
318 finally:
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
319 self._plotsmutex.unlock()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents: 26
diff changeset
320
28
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
321 def main():
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
322 import optparse
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
323 opt = optparse.OptionParser('A simple PyQt4 HP7470A GPIB plotter emulator for USB-GPIB bundle (ProLogix)')
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
324 opt.add_option('-m', '--mockup', default=False,
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
325 action="store_true",
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
326 dest='mockup',
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
327 help='Use a pseudo GPIB connection (for test purpose)',
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
328 )
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
329 opt.add_option('-v', '--verbose', default=False,
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
330 action="store_true",
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
331 dest="verbose",
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
332 help="Verbose mode",)
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
333
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
334 options, argv = opt.parse_args(sys.argv)
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
335
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
336 a = QtGui.QApplication(argv)
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: 22
diff changeset
337 w = QtHPGLPlotter()
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
338 files = [f for f in argv[1:] if os.path.isfile(f)]
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
339 files.sort(cmp=str_num_cmp)
38
73bd2fe81005 small improvement; display first plot at startup
David Douard <david.douard@logilab.fr>
parents: 36
diff changeset
340 if w.openFiles(files):
73bd2fe81005 small improvement; display first plot at startup
David Douard <david.douard@logilab.fr>
parents: 36
diff changeset
341 w.displayFirst()
73bd2fe81005 small improvement; display first plot at startup
David Douard <david.douard@logilab.fr>
parents: 36
diff changeset
342
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: 22
diff changeset
343 w.show()
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: 22
diff changeset
344 a.exec_()
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: 22
diff changeset
345
28
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
346 if __name__ == '__main__':
0a7270d439d0 added a start scrip & cleanups
David Douard <david.douard@logilab.fr>
parents: 27
diff changeset
347 main()

mercurial