36c0da485c631fa419e40277ce07ce23d49551f6
[debian/gnuradio] / gr-utils / src / python / gr_plot_qt.py
1 #!/usr/bin/env python
2
3 try:
4     import scipy
5     from scipy import fftpack
6 except ImportError:
7     print "Please install SciPy to run this script (http://www.scipy.org/)"
8     raise SystemExit, 1
9
10 try:
11     from matplotlib import mlab
12 except ImportError:
13     print "Please install Matplotlib to run this script (http://matplotlib.sourceforge.net)"
14     raise SystemExit, 1
15
16 try:
17     from PyQt4 import Qt, QtCore, QtGui
18 except ImportError:
19     print "Please install PyQt4 to run this script (http://www.riverbankcomputing.co.uk/software/pyqt/download)"
20     raise SystemExit, 1
21
22 try:
23     import PyQt4.Qwt5 as Qwt
24 except ImportError:
25     print "Please install PyQwt5 to run this script (http://pyqwt.sourceforge.net/)"
26     raise SystemExit, 1
27
28 try:
29     # FIXME: reenable this before committing
30     #from gnuradio.pyqt_plot import Ui_MainWindow
31     from pyqt_plot import Ui_MainWindow
32 except ImportError:
33     print "Could not import from pyqt_plot. Please build with \"pyuic4 pyqt_plot.ui -o pyqt_plot.py\""
34     raise SystemExit, 1
35
36 import sys, os
37 from optparse import OptionParser
38 from gnuradio import eng_notation
39
40
41 class SpectrogramData(Qwt.QwtRasterData):
42
43     def __init__(self, f, t):
44         Qwt.QwtArrayData.__init__(self, Qt.QRectF(0, 0, 0, 0))
45         self.sp = scipy.array([[0], [0]])
46
47     def set_data(self, xfreq, ytime, data):
48         self.sp = data
49         self.freq = xfreq
50         self.time = ytime
51         boundingBox = Qt.QRectF(self.freq.min(), self.time.min(),
52                                 self.freq.max() - self.freq.min(),
53                                 self.time.max() - self.time.min())
54         self.setBoundingRect(boundingBox)
55
56     def rasterHint(self, rect):
57         return Qt.QSize(self.sp.shape[0], self.sp.shape[1])
58         
59     def copy(self):
60         return self
61
62     def range(self):
63         
64         return Qwt.QwtDoubleInterval(self.sp.min(), self.sp.max())
65
66     def value(self, x, y):
67         f = int(self.freq.searchsorted(x))
68         t = int(self.time.searchsorted(y))
69         return self.sp[f][t-1]
70
71
72 class gr_plot_qt(QtGui.QMainWindow):
73     def __init__(self, qapp, filename, options, parent=None):
74         QtGui.QWidget.__init__(self, parent)
75         self.gui = Ui_MainWindow()
76         self.gui.setupUi(self)
77                        
78         self.filename = None
79         self.block_length = options.block_length
80         self.start = options.start
81         self.sample_rate = options.sample_rate
82         self.psdfftsize = options.psd_size
83         self.specfftsize = options.spec_size
84         self.winfunc = scipy.blackman
85         self.sizeof_data = 8
86         self.datatype = scipy.complex64
87         self.iq = list()
88         self.time = list()
89
90         # Set up basic plot attributes
91         self.gui.timePlot.setAxisTitle(self.gui.timePlot.xBottom, "Time (sec)")
92         self.gui.timePlot.setAxisTitle(self.gui.timePlot.yLeft, "Amplitude (V)")
93         self.gui.freqPlot.setAxisTitle(self.gui.freqPlot.xBottom, "Frequency (Hz)")
94         self.gui.freqPlot.setAxisTitle(self.gui.freqPlot.yLeft, "Magnitude (dB)")
95         self.gui.specPlot.setAxisTitle(self.gui.specPlot.xBottom, "Frequency (Hz)")
96         self.gui.specPlot.setAxisTitle(self.gui.specPlot.yLeft, "Time (sec)")
97
98         # Set up FFT size combo box
99         self.fftsizes = ["128", "256", "512", "1024", "2048",
100                          "4096", "8192", "16384", "32768"]
101         self.gui.psdFFTComboBox.addItems(self.fftsizes)
102         self.gui.specFFTComboBox.addItems(self.fftsizes)
103         pos = self.gui.psdFFTComboBox.findText(Qt.QString("%1").arg(self.psdfftsize))
104         self.gui.psdFFTComboBox.setCurrentIndex(pos)
105         pos = self.gui.specFFTComboBox.findText(Qt.QString("%1").arg(self.specfftsize))
106         self.gui.specFFTComboBox.setCurrentIndex(pos)
107
108         self.connect(self.gui.psdFFTComboBox,
109                      Qt.SIGNAL("activated (const QString&)"),
110                      self.psdFFTComboBoxEdit)
111         self.connect(self.gui.specFFTComboBox,
112                      Qt.SIGNAL("activated (const QString&)"),
113                      self.specFFTComboBoxEdit)
114
115         # Set up color scheme box
116         self.color_modes = {"Black on White" : self.color_black_on_white,
117                             "White on Black" : self.color_white_on_black,
118                             "Blue on Black"  : self.color_blue_on_black,
119                             "Green on Black" : self.color_green_on_black}
120         self.gui.colorComboBox.addItems(self.color_modes.keys())
121         pos = self.gui.colorComboBox.findText("Blue on Black")
122         self.gui.colorComboBox.setCurrentIndex(pos)
123         self.connect(self.gui.colorComboBox,
124                      Qt.SIGNAL("activated (const QString&)"),
125                      self.colorComboBoxEdit)
126         
127         
128         # Create zoom functionality for the plots
129         self.timeZoomer = Qwt.QwtPlotZoomer(self.gui.timePlot.xBottom,
130                                             self.gui.timePlot.yLeft,
131                                             Qwt.QwtPicker.PointSelection,
132                                             Qwt.QwtPicker.AlwaysOn,
133                                             self.gui.timePlot.canvas())
134
135         self.freqZoomer = Qwt.QwtPlotZoomer(self.gui.freqPlot.xBottom,
136                                             self.gui.freqPlot.yLeft,
137                                             Qwt.QwtPicker.PointSelection,
138                                             Qwt.QwtPicker.AlwaysOn,
139                                             self.gui.freqPlot.canvas())
140
141         self.specZoomer = Qwt.QwtPlotZoomer(self.gui.specPlot.xBottom,
142                                             self.gui.specPlot.yLeft,
143                                             Qwt.QwtPicker.PointSelection,
144                                             Qwt.QwtPicker.AlwaysOn,
145                                             self.gui.specPlot.canvas())
146
147         #self.picker = Qwt.QwtPlotPicker(self.gui.timePlot.xBottom,
148         #                                self.gui.timePlot.yLeft,
149         #                                Qwt.QwtPicker.PointSelection,
150         #                                Qwt.QwtPlotPicker.CrossRubberBand,
151         #                                Qwt.QwtPicker.AlwaysOn,
152         #                                self.gui.timePlot.canvas())
153         #self.picker.connect(self.picker,
154         #                    Qt.SIGNAL('selected(const QwtDoublePoint&)'),
155         #                    self.clickMe)
156
157         # Set up action when tab is changed
158         self.connect(self.gui.tabGroup,
159                      Qt.SIGNAL("currentChanged (int)"),
160                      self.tabChanged)
161
162         # Add a legend to the Time plot
163         legend_real = Qwt.QwtLegend()
164         self.gui.timePlot.insertLegend(legend_real)
165
166         # Set up slider
167         self.gui.plotHBar.setSingleStep(1)
168         self.gui.plotHBar.setPageStep(self.block_length)
169         self.gui.plotHBar.setMinimum(0)
170         self.gui.plotHBar.setMaximum(self.block_length)
171         self.connect(self.gui.plotHBar,
172                      Qt.SIGNAL("valueChanged(int)"),
173                      self.sliderMoved)
174
175         # Connect Open action to Open Dialog box
176         self.connect(self.gui.action_open,
177                      Qt.SIGNAL("activated()"),
178                      self.open_file)
179
180         # Connect Reload action to reload the file
181         self.connect(self.gui.action_reload,
182                      Qt.SIGNAL("activated()"),
183                      self.reload_file)
184         self.gui.action_reload.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+R",
185                                                                         None, QtGui.QApplication.UnicodeUTF8))
186
187         # Set up file position boxes to update current figure
188         self.connect(self.gui.filePosStartLineEdit,
189                      Qt.SIGNAL("editingFinished()"),
190                      self.file_position_changed)
191         self.connect(self.gui.filePosStopLineEdit,
192                      Qt.SIGNAL("editingFinished()"),
193                      self.file_position_changed)
194         self.connect(self.gui.filePosLengthLineEdit,
195                      Qt.SIGNAL("editingFinished()"),
196                      self.file_length_changed)
197
198         self.connect(self.gui.fileTimeStartLineEdit,
199                      Qt.SIGNAL("editingFinished()"),
200                      self.file_time_changed)
201         self.connect(self.gui.fileTimeStopLineEdit,
202                      Qt.SIGNAL("editingFinished()"),
203                      self.file_time_changed)
204         self.connect(self.gui.fileTimeLengthLineEdit,
205                      Qt.SIGNAL("editingFinished()"),
206                      self.file_time_length_changed)
207
208         self.rcurve = Qwt.QwtPlotCurve("Real")
209         self.icurve = Qwt.QwtPlotCurve("Imaginary")
210
211         self.icurve.attach(self.gui.timePlot)
212         self.rcurve.attach(self.gui.timePlot)
213
214         self.psdcurve = Qwt.QwtPlotCurve("PSD")
215         self.psdcurve.attach(self.gui.freqPlot)
216
217         # Set up specTab plot as a spectrogram
218         self.specdata = SpectrogramData(range(0, 10), range(0, 10))
219
220         colorMap = Qwt.QwtLinearColorMap(Qt.Qt.darkCyan, Qt.Qt.red)
221         colorMap.addColorStop(0.1, Qt.Qt.cyan)
222         colorMap.addColorStop(0.6, Qt.Qt.green)
223         colorMap.addColorStop(0.95, Qt.Qt.yellow)
224
225         self.spec = Qwt.QwtPlotSpectrogram()
226         self.spec.setColorMap(colorMap)
227         self.spec.attach(self.gui.specPlot)
228         self.spec.setDisplayMode(Qwt.QwtPlotSpectrogram.ImageMode, True)
229         self.spec.setData(self.specdata)
230
231         self.rightAxis = self.gui.specPlot.axisWidget(Qwt.QwtPlot.yRight)
232         self.rightAxis.setTitle("Magnitude (dBm)")
233         self.rightAxis.setColorBarEnabled(True)
234         self.rightAxis.setColorMap(self.spec.data().range(),
235                                    self.spec.colorMap())
236         self.gui.specPlot.enableAxis(Qwt.QwtPlot.yRight)
237
238         # Set up initial color scheme
239         self.color_modes["Blue on Black"]()
240
241         # Connect a signal for when the sample rate changes
242         self.set_sample_rate(self.sample_rate)
243         self.connect(self.gui.sampleRateLineEdit,
244                      Qt.SIGNAL("editingFinished()"),
245                      self.sample_rate_changed)
246
247         if(filename is not None):
248             self.initialize(filename)
249
250         self.show()
251
252     def open_file(self):
253         filename = Qt.QFileDialog.getOpenFileName(self, "Open", ".")
254         if(filename != ""):
255             #print filename
256             self.initialize(filename)
257
258     def reload_file(self):
259         if(self.filename):
260             self.initialize(self.filename)
261         
262     def initialize(self, filename):
263         self.filename = filename
264         self.hfile = open(filename, "r")
265
266         self.setWindowTitle(("GNU Radio File Plot Utility: %s" % filename))
267
268         self.gui.filePosStartLineEdit.setText("0")
269         self.gui.filePosStopLineEdit.setText("0")
270         self.gui.fileTimeStartLineEdit.setText("0")
271         self.gui.fileTimeStopLineEdit.setText("0")
272
273         self.cur_start = 0
274         self.cur_stop = self.block_length
275
276         self.init_data_input()
277         self.get_data(self.cur_start, self.cur_stop)
278         self.get_psd()
279         self.get_specgram() 
280         self.gui.plotHBar.setSliderPosition(0)
281         self.gui.plotHBar.setMaximum(self.signal_size)
282
283
284         self.update_time_curves()
285         self.update_psd_curves()
286         self.update_specgram_curves()
287
288     def init_data_input(self):
289         self.hfile.seek(0, os.SEEK_END)
290         self.signal_size = self.hfile.tell()/self.sizeof_data
291         #print "Sizeof File: ", self.signal_size
292         self.hfile.seek(0, os.SEEK_SET)
293         
294     def get_data(self, start, end):
295         if(end > start):
296             self.hfile.seek(start*self.sizeof_data, os.SEEK_SET)
297             self.position = start
298             try:
299                 iq = scipy.fromfile(self.hfile, dtype=self.datatype,
300                                     count=end-start)
301
302                 if(len(iq) < (end-start)):
303                     end = len(iq)
304                     self.gui.filePosLengthLineEdit.setText(Qt.QString("%1").arg(end))
305                     self.gui.plotHBar.setMaximum(end)
306                     self.gui.plotHBar.setSingleStep(end)
307                     self.file_length_changed()
308
309                 tstep = 1.0 / self.sample_rate
310                 self.iq = iq
311                 self.time = [tstep*(self.position + i) for i in xrange(len(self.iq))]
312
313                 self.set_file_pos_box(start, end)
314             except MemoryError:
315                 pass
316         else:
317             # Do we want to do anything about this?
318             pass
319
320     def get_psd(self):
321         winpoints = self.winfunc(self.psdfftsize)
322         iq_psd, freq = mlab.psd(self.iq, Fs=self.sample_rate,
323                                 NFFT=self.psdfftsize,
324                                 noverlap=self.psdfftsize/4.0,
325                                 window=winpoints,
326                                 scale_by_freq=False)
327
328         self.iq_psd = 10.0*scipy.log10(abs(fftpack.fftshift(iq_psd)))
329         self.freq = freq - self.sample_rate/2.0
330
331     def get_specgram(self):
332         winpoints = self.winfunc(self.specfftsize)
333         iq_spec, f, t = mlab.specgram(self.iq, Fs=self.sample_rate,
334                                       NFFT=self.specfftsize,
335                                       noverlap=self.specfftsize/4.0,
336                                       window=winpoints,
337                                       scale_by_freq=False)
338         
339         self.iq_spec = 10.0*scipy.log10(abs(iq_spec))
340         self.spec_f = f
341         self.spec_t = t
342
343     def clickMe(self, qPoint):
344         print qPoint.x()
345
346     def psdFFTComboBoxEdit(self, fftSize):
347         self.psdfftsize = fftSize.toInt()[0]
348         self.get_psd()
349         self.update_psd_curves()
350
351     def specFFTComboBoxEdit(self, fftSize):
352         self.specfftsize = fftSize.toInt()[0]
353         self.get_specgram()
354         self.update_specgram_curves()
355         
356     def colorComboBoxEdit(self, colorSelection):
357         colorstr = str(colorSelection.toAscii())
358         color_func = self.color_modes[colorstr]
359         color_func()
360
361     def sliderMoved(self, value):
362         pos_start = value
363         pos_end = value + self.gui.plotHBar.pageStep()
364
365         self.get_data(pos_start, pos_end)
366         self.get_psd()
367         self.get_specgram()
368         self.update_time_curves()
369         self.update_psd_curves()
370         self.update_specgram_curves()
371
372     def set_sample_rate(self, sr):
373         self.sample_rate = sr
374         srstr = eng_notation.num_to_str(self.sample_rate)
375         self.gui.sampleRateLineEdit.setText(Qt.QString("%1").arg(srstr))
376
377     def sample_rate_changed(self):
378         srstr = self.gui.sampleRateLineEdit.text().toAscii()
379         self.sample_rate = eng_notation.str_to_num(srstr)
380         self.set_file_pos_box(self.cur_start, self.cur_stop)
381         self.get_data(self.cur_start, self.cur_stop)
382         self.get_psd()
383         self.get_specgram()
384         self.update_time_curves()
385         self.update_psd_curves()
386         self.update_specgram_curves()
387
388     def set_file_pos_box(self, start, end):
389         tstart = start / self.sample_rate
390         tend = end / self.sample_rate
391
392         self.gui.filePosStartLineEdit.setText(Qt.QString("%1").arg(start))
393         self.gui.filePosStopLineEdit.setText(Qt.QString("%1").arg(end))
394         self.gui.filePosLengthLineEdit.setText(Qt.QString("%1").arg(end-start))
395
396         self.gui.fileTimeStartLineEdit.setText(Qt.QString("%1").arg(tstart))
397         self.gui.fileTimeStopLineEdit.setText(Qt.QString("%1").arg(tend))
398         self.gui.fileTimeLengthLineEdit.setText(Qt.QString("%1").arg(tend-tstart))
399
400     def file_position_changed(self):
401         start  = self.gui.filePosStartLineEdit.text().toInt()
402         end    = self.gui.filePosStopLineEdit.text().toInt()
403         if((start[1] == True) and (end[1] == True)):
404             self.cur_start = start[0]
405             self.cur_stop = end[0]
406
407             tstart = self.cur_start / self.sample_rate
408             tend = self.cur_stop / self.sample_rate
409             self.gui.fileTimeStartLineEdit.setText(Qt.QString("%1").arg(tstart))
410             self.gui.fileTimeStopLineEdit.setText(Qt.QString("%1").arg(tend))
411             
412             self.get_data(self.cur_start, self.cur_stop)
413
414             self.update_time_curves()
415             self.update_psd_curves()
416             self.update_specgram_curves()
417
418         # If there's a non-digit character, reset box
419         else:
420             self.set_file_pos_box(self.cur_start, self.cur_stop)
421
422     def file_time_changed(self):
423         tstart = self.gui.fileTimeStartLineEdit.text().toDouble()
424         tstop  = self.gui.fileTimeStopLineEdit.text().toDouble()
425         if((tstart[1] == True) and (tstop[1] == True)):
426             self.cur_start = int(tstart[0] * self.sample_rate)
427             self.cur_stop = int(tstop[0] * self.sample_rate)
428             self.get_data(self.cur_start, self.cur_stop)
429
430             self.gui.filePosStartLineEdit.setText(Qt.QString("%1").arg(self.cur_start))
431             self.gui.filePosStopLineEdit.setText(Qt.QString("%1").arg(self.cur_stop))
432
433             self.update_time_curves()
434             self.update_psd_curves()
435             self.update_specgram_curves()
436         # If there's a non-digit character, reset box
437         else:
438             self.set_file_pos_box(self.cur_start, self.cur_stop)
439
440     def file_length_changed(self):
441         start = self.gui.filePosStartLineEdit.text().toInt()
442         length = self.gui.filePosLengthLineEdit.text().toInt()
443
444         if((start[1] == True) and (length[1] == True)):
445             self.cur_start = start[0]
446             self.block_length = length[0]
447             self.cur_stop = self.cur_start + self.block_length
448
449             tstart = self.cur_start / self.sample_rate
450             tend = self.cur_stop / self.sample_rate
451             tlen = self.block_length / self.sample_rate
452             self.gui.fileTimeStartLineEdit.setText(Qt.QString("%1").arg(tstart))
453             self.gui.fileTimeStopLineEdit.setText(Qt.QString("%1").arg(tend))
454             self.gui.fileTimeLengthLineEdit.setText(Qt.QString("%1").arg(tlen))
455
456             self.gui.plotHBar.setPageStep(self.block_length)
457
458             self.get_data(self.cur_start, self.cur_stop)
459             self.get_psd()
460             self.get_specgram()
461
462             self.update_time_curves()
463             self.update_psd_curves()
464             self.update_specgram_curves()
465         # If there's a non-digit character, reset box
466         else:
467             self.set_file_pos_box(self.cur_start, self.cur_stop)
468
469     def file_time_length_changed(self):
470         tstart = self.gui.fileTimeStartLineEdit.text().toDouble()
471         tlength = self.gui.fileTimeLengthLineEdit.text().toDouble()
472         if((tstart[1] == True) and (tlength[1] == True)):
473             self.cur_start = int(tstart[0] * self.sample_rate)
474             self.block_length = int(tlength[0] * self.sample_rate)
475             self.cur_stop = self.cur_start + self.block_length
476
477             tstart = self.cur_start / self.sample_rate
478             tend = self.cur_stop / self.sample_rate
479             tlen = self.block_length / self.sample_rate
480             self.gui.fileTimeStartLineEdit.setText(Qt.QString("%1").arg(tstart))
481             self.gui.fileTimeStopLineEdit.setText(Qt.QString("%1").arg(tend))
482             self.gui.fileTimeLengthLineEdit.setText(Qt.QString("%1").arg(tlen))
483
484             self.get_data(self.cur_start, self.cur_stop)
485             self.get_psd()
486             self.get_specgram()
487
488             self.update_time_curves()
489             self.update_psd_curves()
490             self.update_specgram_curves()
491         # If there's a non-digit character, reset box
492         else:
493             self.set_file_pos_box(self.cur_start, self.cur_stop)
494
495
496     def update_time_curves(self):
497         self.icurve.setData(self.time, self.iq.imag)
498         self.rcurve.setData(self.time, self.iq.real)
499
500         # Reset the x-axis to the new time scale
501         iqmax = 1.5 * max(max(self.iq.real), max(self.iq.imag))
502         iqmin = 1.5 * min(min(self.iq.real), min(self.iq.imag))
503         self.gui.timePlot.setAxisScale(self.gui.timePlot.xBottom,
504                                        min(self.time),
505                                        max(self.time))
506         self.gui.timePlot.setAxisScale(self.gui.timePlot.yLeft,
507                                        iqmin,
508                                        iqmax)
509
510         # Set the zoomer base to unzoom to the new axis
511         self.timeZoomer.setZoomBase()
512     
513         self.gui.timePlot.replot()
514         
515     def update_psd_curves(self):
516         self.psdcurve.setData(self.freq, self.iq_psd)
517
518         self.gui.freqPlot.setAxisScale(self.gui.freqPlot.xBottom,
519                                        min(self.freq),
520                                        max(self.freq))
521                                        
522         # Set the zoomer base to unzoom to the new axis
523         self.freqZoomer.setZoomBase()
524
525         self.gui.freqPlot.replot()
526
527     def update_specgram_curves(self):
528         # We don't have to reset the data for the speccurve here
529         # since this is taken care of in the SpectrogramData class
530         self.specdata.set_data(self.spec_f, self.spec_t, self.iq_spec)
531
532         # Set the color map based on the new data
533         self.rightAxis.setColorMap(self.spec.data().range(),
534                                    self.spec.colorMap())
535
536         # Set the new axis base; include right axis for the intenisty color bar
537         self.gui.specPlot.setAxisScale(self.gui.specPlot.xBottom,
538                                        min(self.spec_f),
539                                        max(self.spec_f))
540         self.gui.specPlot.setAxisScale(self.gui.specPlot.yLeft,
541                                        min(self.spec_t),
542                                        max(self.spec_t))
543         self.gui.specPlot.setAxisScale(self.gui.specPlot.yRight, 
544                                        self.iq_spec.min(),
545                                        self.iq_spec.max())
546  
547         # Set the zoomer base to unzoom to the new axis
548         self.specZoomer.setZoomBase()
549
550         self.gui.specPlot.replot()
551
552     def tabChanged(self, index):
553         self.gui.timePlot.replot()
554         self.gui.freqPlot.replot()
555
556     def color_black_on_white(self):
557         blue = QtGui.qRgb(0x00, 0x00, 0xFF)
558         red = QtGui.qRgb(0xFF, 0x00, 0x00)
559
560         blackBrush = Qt.QBrush(Qt.QColor("black"))
561         blueBrush = Qt.QBrush(Qt.QColor(blue))
562         redBrush = Qt.QBrush(Qt.QColor(red))
563
564         self.gui.timePlot.setCanvasBackground(Qt.QColor("white"))
565         self.gui.freqPlot.setCanvasBackground(Qt.QColor("white"))
566         #self.picker.setTrackerPen(Qt.QPen(blackBrush, 2))
567         self.timeZoomer.setTrackerPen(Qt.QPen(blackBrush, 2))
568         self.timeZoomer.setRubberBandPen(Qt.QPen(blackBrush, 2))
569         self.freqZoomer.setTrackerPen(Qt.QPen(blackBrush, 2))
570         self.freqZoomer.setRubberBandPen(Qt.QPen(blackBrush, 2))
571         self.psdcurve.setPen(Qt.QPen(blueBrush, 1))
572         self.rcurve.setPen(Qt.QPen(blueBrush, 2))
573         self.icurve.setPen(Qt.QPen(redBrush, 2))
574
575         self.gui.timePlot.replot()
576         self.gui.freqPlot.replot()
577
578     def color_white_on_black(self):
579         white = QtGui.qRgb(0xFF, 0xFF, 0xFF)
580         red = QtGui.qRgb(0xFF, 0x00, 0x00)
581
582         whiteBrush = Qt.QBrush(Qt.QColor("white"))
583         whiteBrush = Qt.QBrush(Qt.QColor(white))
584         redBrush = Qt.QBrush(Qt.QColor(red))
585         
586         self.gui.timePlot.setCanvasBackground(QtGui.QColor("black"))
587         self.gui.freqPlot.setCanvasBackground(QtGui.QColor("black"))
588         #self.picker.setTrackerPen(Qt.QPen(whiteBrush, 2))
589         self.timeZoomer.setTrackerPen(Qt.QPen(whiteBrush, 2))
590         self.timeZoomer.setRubberBandPen(Qt.QPen(whiteBrush, 2))
591         self.freqZoomer.setTrackerPen(Qt.QPen(whiteBrush, 2))
592         self.freqZoomer.setRubberBandPen(Qt.QPen(whiteBrush, 2))
593         self.psdcurve.setPen(Qt.QPen(whiteBrush, 1))
594         self.rcurve.setPen(Qt.QPen(whiteBrush, 2))
595         self.icurve.setPen(Qt.QPen(redBrush, 2))
596
597         self.gui.timePlot.replot()
598         self.gui.freqPlot.replot()
599
600
601     def color_green_on_black(self):
602         green = QtGui.qRgb(0x00, 0xFF, 0x00)
603         red = QtGui.qRgb(0xFF, 0x00, 0x50)
604
605         whiteBrush = Qt.QBrush(Qt.QColor("white"))
606         greenBrush = Qt.QBrush(Qt.QColor(green))
607         redBrush = Qt.QBrush(Qt.QColor(red))
608         
609         self.gui.timePlot.setCanvasBackground(QtGui.QColor("black"))
610         self.gui.freqPlot.setCanvasBackground(QtGui.QColor("black"))
611         #self.picker.setTrackerPen(Qt.QPen(whiteBrush, 2))
612         self.timeZoomer.setTrackerPen(Qt.QPen(whiteBrush, 2))
613         self.timeZoomer.setRubberBandPen(Qt.QPen(whiteBrush, 2))
614         self.freqZoomer.setTrackerPen(Qt.QPen(whiteBrush, 2))
615         self.freqZoomer.setRubberBandPen(Qt.QPen(whiteBrush, 2))
616         self.psdcurve.setPen(Qt.QPen(greenBrush, 1))
617         self.rcurve.setPen(Qt.QPen(greenBrush, 2))
618         self.icurve.setPen(Qt.QPen(redBrush, 2))
619
620         self.gui.timePlot.replot()
621         self.gui.freqPlot.replot()
622
623     def color_blue_on_black(self):
624         blue = QtGui.qRgb(0x00, 0x00, 0xFF)
625         red = QtGui.qRgb(0xFF, 0x00, 0x00)
626
627         whiteBrush = Qt.QBrush(Qt.QColor("white"))
628         blueBrush = Qt.QBrush(Qt.QColor(blue))
629         redBrush = Qt.QBrush(Qt.QColor(red))
630         
631         self.gui.timePlot.setCanvasBackground(QtGui.QColor("black"))
632         self.gui.freqPlot.setCanvasBackground(QtGui.QColor("black"))
633         #self.picker.setTrackerPen(Qt.QPen(whiteBrush, 2))
634         self.timeZoomer.setTrackerPen(Qt.QPen(whiteBrush, 2))
635         self.timeZoomer.setRubberBandPen(Qt.QPen(whiteBrush, 2))
636         self.freqZoomer.setTrackerPen(Qt.QPen(whiteBrush, 2))
637         self.freqZoomer.setRubberBandPen(Qt.QPen(whiteBrush, 2))
638         self.psdcurve.setPen(Qt.QPen(blueBrush, 1))
639         self.rcurve.setPen(Qt.QPen(blueBrush, 2))
640         self.icurve.setPen(Qt.QPen(redBrush, 2))
641
642         self.gui.timePlot.replot()
643         self.gui.freqPlot.replot()
644
645 def setup_options():
646     usage="%prog: [options] (input_filename)"
647     description = ""
648
649     parser = OptionParser(conflict_handler="resolve", usage=usage, description=description)
650     parser.add_option("-B", "--block-length", type="int", default=8192,
651                       help="Specify the block size [default=%default]")
652     parser.add_option("-s", "--start", type="int", default=0,
653                       help="Specify where to start in the file [default=%default]")
654     parser.add_option("-R", "--sample-rate", type="float", default=1.0,
655                       help="Set the sampler rate of the data [default=%default]")
656     parser.add_option("", "--psd-size", type="int", default=2048,
657                       help="Set the size of the PSD FFT [default=%default]")
658     parser.add_option("", "--spec-size", type="int", default=2048,
659                       help="Set the size of the spectrogram FFT [default=%default]")
660
661     return parser
662
663 def main(args):
664     parser = setup_options()
665     (options, args) = parser.parse_args ()
666
667     if(len(args) == 1):
668         filename = args[0]
669     else:
670         filename = None
671
672     app = Qt.QApplication(args)
673     gplt = gr_plot_qt(app, filename, options)
674     app.exec_()
675
676 if __name__ == '__main__':
677     main(sys.argv)
678