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