19 |
20 |
20 from qpreferences import BaseItem, IntItem, UnicodeItem, ColorItem |
21 from qpreferences import BaseItem, IntItem, UnicodeItem, ColorItem |
21 from qpreferences import PointItem, SizeItem, ByteArrayItem |
22 from qpreferences import PointItem, SizeItem, ByteArrayItem |
22 from qpreferences import AbstractPreferences |
23 from qpreferences import AbstractPreferences |
23 from qpreferenceseditor import PreferencesEditor |
24 from qpreferenceseditor import PreferencesEditor |
|
25 |
|
26 from tools import str_num_cmp |
24 |
27 |
25 class Preferences(AbstractPreferences): |
28 class Preferences(AbstractPreferences): |
26 ORGANISATION="Logilab" |
29 ORGANISATION="Logilab" |
27 APPLICATION="qgpib_plotter" |
30 APPLICATION="qgpib_plotter" |
28 |
31 |
84 def readPreferences(self): |
87 def readPreferences(self): |
85 bg = self._prefs.background |
88 bg = self._prefs.background |
86 if bg and bg.isValid(): |
89 if bg and bg.isValid(): |
87 self.plotterWidget.qview.setBackgroundBrush(QtGui.QBrush(bg)) |
90 self.plotterWidget.qview.setBackgroundBrush(QtGui.QBrush(bg)) |
88 pen_colors = [self._prefs["color%d"%i] for i in range(8)] |
91 pen_colors = [self._prefs["color%d"%i] for i in range(8)] |
89 print |
|
90 self.plotterWidget.pen_colors = pen_colors |
92 self.plotterWidget.pen_colors = pen_colors |
91 |
93 |
92 def replotCurrent(self): |
94 def replotCurrent(self): |
93 self.currentPlotChanged(self.plotsView.currentIndex()) |
95 self.currentPlotChanged(self.plotsView.currentIndex()) |
94 |
96 |
148 else: |
150 else: |
149 event.ignore() |
151 event.ignore() |
150 |
152 |
151 def openTriggered(self, checked=False): |
153 def openTriggered(self, checked=False): |
152 filenames = QtGui.QFileDialog.getOpenFileNames(self, "Open a HPGL file to display", '.', 'HPGL files (*.plt)\nAll files (*)') |
154 filenames = QtGui.QFileDialog.getOpenFileNames(self, "Open a HPGL file to display", '.', 'HPGL files (*.plt)\nAll files (*)') |
|
155 self.openFiles(filenames) |
|
156 if not self.plotsView.currentIndex().isValid(): |
|
157 self.plotsView.setCurrentIndex(self.plotsView.model().index(0, 0)) |
|
158 |
|
159 def openFiles(self, filenames): |
153 for filename in filenames: |
160 for filename in filenames: |
154 filename = str(filename) |
161 filename = str(filename) |
155 if os.path.exists(filename): |
162 if os.path.exists(filename): |
156 data = open(filename).read() |
163 data = open(filename).read() |
157 name = os.path.basename(filename) |
164 name = os.path.basename(filename) |
158 name = os.path.splitext(name)[0] |
165 name = os.path.splitext(name)[0] |
159 lst = self.plotsView.model().stringList() |
166 lst = self.plotsView.model().stringList() |
160 lst.append(name) |
167 lst.append(name) |
161 self._plots[name] = data |
168 self._plots[name] = data |
162 self.plotsView.model().setStringList(lst) |
169 self.plotsView.model().setStringList(lst) |
163 |
170 |
164 if not self.plotsView.currentIndex().isValid(): |
|
165 self.plotsView.setCurrentIndex(self.plotsView.model().index(0, 0)) |
|
166 |
|
167 def plotReceived(self, num): |
171 def plotReceived(self, num): |
168 self._receiving = False |
172 self._receiving = False |
169 self.setReceivingLed() |
173 self.setReceivingLed() |
170 plot, timestamp = self.captureThread.getPlot(num) |
174 plot, timestamp = self.captureThread.getPlot(num) |
171 name = "plot_%s"%(num) |
175 name = "plot_%s"%(num) |
178 self._receiving = True |
182 self._receiving = True |
179 self.setReceivingLed() |
183 self.setReceivingLed() |
180 |
184 |
181 def saveTriggered(self, checked=False): |
185 def saveTriggered(self, checked=False): |
182 print "save" |
186 print "save" |
|
187 |
183 def saveAsTriggered(self, checked=False): |
188 def saveAsTriggered(self, checked=False): |
184 index = self.plotsView.selectionModel().currentIndex() |
189 index = self.plotsView.selectionModel().currentIndex() |
185 if index.isValid(): |
190 if index.isValid(): |
186 filename = QtGui.QFileDialog.getSaveFileName(self, "Selecte a file name to save HPGL file", '.', 'HPGL files (*.plt)\nAll files (*)') |
191 filename = QtGui.QFileDialog.getSaveFileName(self, "Selecte a file name to save HPGL file", '.', 'HPGL files (*.plt)\nAll files (*)') |
187 n = index.row() |
192 n = index.row() |
304 self._plotsmutex.lock() |
309 self._plotsmutex.lock() |
305 try: |
310 try: |
306 return self._plots[num] |
311 return self._plots[num] |
307 finally: |
312 finally: |
308 self._plotsmutex.unlock() |
313 self._plotsmutex.unlock() |
309 |
|
310 |
|
311 |
|
312 |
314 |
313 def main(): |
315 def main(): |
314 import optparse |
316 import optparse |
315 opt = optparse.OptionParser('A simple PyQt4 HP7470A GPIB plotter emulator for USB-GPIB bundle (ProLogix)') |
317 opt = optparse.OptionParser('A simple PyQt4 HP7470A GPIB plotter emulator for USB-GPIB bundle (ProLogix)') |
316 opt.add_option('-m', '--mockup', default=False, |
318 opt.add_option('-m', '--mockup', default=False, |