]> git.gag.com Git - debian/gnuradio/blob - gr-utils/src/python/gr_plot_qt.py
Removing plot picker that addd nothing to the interface.
[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         # Set up action when tab is changed
148         self.connect(self.gui.tabGroup,
149                      Qt.SIGNAL("currentChanged (int)"),
150                      self.tabChanged)
151
152         # Add a legend to the Time plot
153         legend_real = Qwt.QwtLegend()
154         self.gui.timePlot.insertLegend(legend_real)
155
156         # Set up slider
157         self.gui.plotHBar.setSingleStep(1)
158         self.gui.plotHBar.setPageStep(self.block_length)
159         self.gui.plotHBar.setMinimum(0)
160         self.gui.plotHBar.setMaximum(self.block_length)
161         self.connect(self.gui.plotHBar,
162                      Qt.SIGNAL("valueChanged(int)"),
163                      self.sliderMoved)
164
165         # Connect Open action to Open Dialog box
166         self.connect(self.gui.action_open,
167                      Qt.SIGNAL("activated()"),
168                      self.open_file)
169
170         # Connect Reload action to reload the file
171         self.connect(self.gui.action_reload,
172                      Qt.SIGNAL("activated()"),
173                      self.reload_file)
174         self.gui.action_reload.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+R",
175                                                                         None, QtGui.QApplication.UnicodeUTF8))
176
177         # Set up file position boxes to update current figure
178         self.connect(self.gui.filePosStartLineEdit,
179                      Qt.SIGNAL("editingFinished()"),
180                      self.file_position_changed)
181         self.connect(self.gui.filePosStopLineEdit,
182                      Qt.SIGNAL("editingFinished()"),
183                      self.file_position_changed)
184         self.connect(self.gui.filePosLengthLineEdit,
185                      Qt.SIGNAL("editingFinished()"),
186                      self.file_length_changed)
187
188         self.connect(self.gui.fileTimeStartLineEdit,
189                      Qt.SIGNAL("editingFinished()"),
190                      self.file_time_changed)
191         self.connect(self.gui.fileTimeStopLineEdit,
192                      Qt.SIGNAL("editingFinished()"),
193                      self.file_time_changed)
194         self.connect(self.gui.fileTimeLengthLineEdit,
195                      Qt.SIGNAL("editingFinished()"),
196                      self.file_time_length_changed)
197
198         self.rcurve = Qwt.QwtPlotCurve("Real")
199         self.icurve = Qwt.QwtPlotCurve("Imaginary")
200
201         self.icurve.attach(self.gui.timePlot)
202         self.rcurve.attach(self.gui.timePlot)
203
204         self.psdcurve = Qwt.QwtPlotCurve("PSD")
205         self.psdcurve.attach(self.gui.freqPlot)
206
207
208         # Set up specTab plot as a spectrogram
209         self.specdata = SpectrogramData(range(0, 10), range(0, 10))
210
211         colorMap = Qwt.QwtLinearColorMap(Qt.Qt.darkCyan, Qt.Qt.red)
212         colorMap.addColorStop(0.1, Qt.Qt.cyan)
213         colorMap.addColorStop(0.6, Qt.Qt.green)
214         colorMap.addColorStop(0.95, Qt.Qt.yellow)
215
216         self.spec = Qwt.QwtPlotSpectrogram()
217         self.spec.setColorMap(colorMap)
218         self.spec.attach(self.gui.specPlot)
219         self.spec.setDisplayMode(Qwt.QwtPlotSpectrogram.ImageMode, True)
220         self.spec.setData(self.specdata)
221
222         self.rightAxis = self.gui.specPlot.axisWidget(Qwt.QwtPlot.yRight)
223         self.rightAxis.setTitle("Magnitude (dBm)")
224         self.rightAxis.setColorBarEnabled(True)
225         self.rightAxis.setColorMap(self.spec.data().range(),
226                                    self.spec.colorMap())
227         self.gui.specPlot.enableAxis(Qwt.QwtPlot.yRight)
228
229         # Set up initial color scheme
230         self.color_modes["Blue on Black"]()
231
232         # Connect a signal for when the sample rate changes
233         self.set_sample_rate(self.sample_rate)
234         self.connect(self.gui.sampleRateLineEdit,
235                      Qt.SIGNAL("editingFinished()"),
236                      self.sample_rate_changed)
237
238         if(filename is not None):
239             self.initialize(filename)
240
241         self.show()
242
243     def open_file(self):
244         filename = Qt.QFileDialog.getOpenFileName(self, "Open", ".")
245         if(filename != ""):
246             #print filename
247             self.initialize(filename)
248
249     def reload_file(self):
250         if(self.filename):
251             self.initialize(self.filename)
252         
253     def initialize(self, filename):
254         self.filename = filename
255         self.hfile = open(filename, "r")
256
257         self.setWindowTitle(("GNU Radio File Plot Utility: %s" % filename))
258
259         self.gui.filePosStartLineEdit.setText("0")
260         self.gui.filePosStopLineEdit.setText("0")
261         self.gui.fileTimeStartLineEdit.setText("0")
262         self.gui.fileTimeStopLineEdit.setText("0")
263
264         self.cur_start = 0
265         self.cur_stop = self.block_length
266
267         self.init_data_input()
268         self.get_data(self.cur_start, self.cur_stop)
269         self.get_psd()
270         self.get_specgram() 
271         self.gui.plotHBar.setSliderPosition(0)
272         self.gui.plotHBar.setMaximum(self.signal_size)
273
274
275         self.update_time_curves()
276         self.update_psd_curves()
277         self.update_specgram_curves()
278
279     def init_data_input(self):
280         self.hfile.seek(0, os.SEEK_END)
281         self.signal_size = self.hfile.tell()/self.sizeof_data
282         #print "Sizeof File: ", self.signal_size
283         self.hfile.seek(0, os.SEEK_SET)
284         
285     def get_data(self, start, end):
286         if(end > start):
287             self.hfile.seek(start*self.sizeof_data, os.SEEK_SET)
288             self.position = start
289             try:
290                 iq = scipy.fromfile(self.hfile, dtype=self.datatype,
291                                     count=end-start)
292
293                 if(len(iq) < (end-start)):
294                     end = len(iq)
295                     self.gui.filePosLengthLineEdit.setText(Qt.QString("%1").arg(end))
296                     self.gui.plotHBar.setMaximum(end)
297                     self.gui.plotHBar.setSingleStep(end)
298                     self.file_length_changed()
299
300                 tstep = 1.0 / self.sample_rate
301                 self.iq = iq
302                 self.time = [tstep*(self.position + i) for i in xrange(len(self.iq))]
303
304                 self.set_file_pos_box(start, end)
305             except MemoryError:
306                 pass
307         else:
308             # Do we want to do anything about this?
309             pass
310
311     def get_psd(self):
312         winpoints = self.winfunc(self.psdfftsize)
313         iq_psd, freq = mlab.psd(self.iq, Fs=self.sample_rate,
314                                 NFFT=self.psdfftsize,
315                                 noverlap=self.psdfftsize/4.0,
316                                 window=winpoints,
317                                 scale_by_freq=False)
318
319         self.iq_psd = 10.0*scipy.log10(abs(fftpack.fftshift(iq_psd)))
320         self.freq = freq - self.sample_rate/2.0
321
322     def get_specgram(self):
323         winpoints = self.winfunc(self.specfftsize)
324         iq_spec, f, t = mlab.specgram(self.iq, Fs=self.sample_rate,
325                                       NFFT=self.specfftsize,
326                                       noverlap=self.specfftsize/4.0,
327                                       window=winpoints,
328                                       scale_by_freq=False)
329         
330         self.iq_spec = 10.0*scipy.log10(abs(iq_spec))
331         self.spec_f = f
332         self.spec_t = t
333
334     def psdFFTComboBoxEdit(self, fftSize):
335         self.psdfftsize = fftSize.toInt()[0]
336         self.get_psd()
337         self.update_psd_curves()
338
339     def specFFTComboBoxEdit(self, fftSize):
340         self.specfftsize = fftSize.toInt()[0]
341         self.get_specgram()
342         self.update_specgram_curves()
343         
344     def colorComboBoxEdit(self, colorSelection):
345         colorstr = str(colorSelection.toAscii())
346         color_func = self.color_modes[colorstr]
347         color_func()
348
349     def sliderMoved(self, value):
350         pos_start = value
351         pos_end = value + self.gui.plotHBar.pageStep()
352
353         self.get_data(pos_start, pos_end)
354         self.get_psd()
355         self.get_specgram()
356         self.update_time_curves()
357         self.update_psd_curves()
358         self.update_specgram_curves()
359
360     def set_sample_rate(self, sr):
361         self.sample_rate = sr
362         srstr = eng_notation.num_to_str(self.sample_rate)
363         self.gui.sampleRateLineEdit.setText(Qt.QString("%1").arg(srstr))
364
365     def sample_rate_changed(self):
366         srstr = self.gui.sampleRateLineEdit.text().toAscii()
367         self.sample_rate = eng_notation.str_to_num(srstr)
368         self.set_file_pos_box(self.cur_start, self.cur_stop)
369         self.get_data(self.cur_start, self.cur_stop)
370         self.get_psd()
371         self.get_specgram()
372         self.update_time_curves()
373         self.update_psd_curves()
374         self.update_specgram_curves()
375
376     def set_file_pos_box(self, start, end):
377         tstart = start / self.sample_rate
378         tend = end / self.sample_rate
379
380         self.gui.filePosStartLineEdit.setText(Qt.QString("%1").arg(start))
381         self.gui.filePosStopLineEdit.setText(Qt.QString("%1").arg(end))
382         self.gui.filePosLengthLineEdit.setText(Qt.QString("%1").arg(end-start))
383
384         self.gui.fileTimeStartLineEdit.setText(Qt.QString("%1").arg(tstart))
385         self.gui.fileTimeStopLineEdit.setText(Qt.QString("%1").arg(tend))
386         self.gui.fileTimeLengthLineEdit.setText(Qt.QString("%1").arg(tend-tstart))
387
388     def file_position_changed(self):
389         start  = self.gui.filePosStartLineEdit.text().toInt()
390         end    = self.gui.filePosStopLineEdit.text().toInt()
391         if((start[1] == True) and (end[1] == True)):
392             self.cur_start = start[0]
393             self.cur_stop = end[0]
394
395             tstart = self.cur_start / self.sample_rate
396             tend = self.cur_stop / self.sample_rate
397             self.gui.fileTimeStartLineEdit.setText(Qt.QString("%1").arg(tstart))
398             self.gui.fileTimeStopLineEdit.setText(Qt.QString("%1").arg(tend))
399             
400             self.get_data(self.cur_start, self.cur_stop)
401
402             self.update_time_curves()
403             self.update_psd_curves()
404             self.update_specgram_curves()
405
406         # If there's a non-digit character, reset box
407         else:
408             self.set_file_pos_box(self.cur_start, self.cur_stop)
409
410     def file_time_changed(self):
411         tstart = self.gui.fileTimeStartLineEdit.text().toDouble()
412         tstop  = self.gui.fileTimeStopLineEdit.text().toDouble()
413         if((tstart[1] == True) and (tstop[1] == True)):
414             self.cur_start = int(tstart[0] * self.sample_rate)
415             self.cur_stop = int(tstop[0] * self.sample_rate)
416             self.get_data(self.cur_start, self.cur_stop)
417
418             self.gui.filePosStartLineEdit.setText(Qt.QString("%1").arg(self.cur_start))
419             self.gui.filePosStopLineEdit.setText(Qt.QString("%1").arg(self.cur_stop))
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_length_changed(self):
429         start = self.gui.filePosStartLineEdit.text().toInt()
430         length = self.gui.filePosLengthLineEdit.text().toInt()
431
432         if((start[1] == True) and (length[1] == True)):
433             self.cur_start = start[0]
434             self.block_length = length[0]
435             self.cur_stop = self.cur_start + self.block_length
436
437             tstart = self.cur_start / self.sample_rate
438             tend = self.cur_stop / self.sample_rate
439             tlen = self.block_length / self.sample_rate
440             self.gui.fileTimeStartLineEdit.setText(Qt.QString("%1").arg(tstart))
441             self.gui.fileTimeStopLineEdit.setText(Qt.QString("%1").arg(tend))
442             self.gui.fileTimeLengthLineEdit.setText(Qt.QString("%1").arg(tlen))
443
444             self.gui.plotHBar.setPageStep(self.block_length)
445
446             self.get_data(self.cur_start, self.cur_stop)
447             self.get_psd()
448             self.get_specgram()
449
450             self.update_time_curves()
451             self.update_psd_curves()
452             self.update_specgram_curves()
453         # If there's a non-digit character, reset box
454         else:
455             self.set_file_pos_box(self.cur_start, self.cur_stop)
456
457     def file_time_length_changed(self):
458         tstart = self.gui.fileTimeStartLineEdit.text().toDouble()
459         tlength = self.gui.fileTimeLengthLineEdit.text().toDouble()
460         if((tstart[1] == True) and (tlength[1] == True)):
461             self.cur_start = int(tstart[0] * self.sample_rate)
462             self.block_length = int(tlength[0] * self.sample_rate)
463             self.cur_stop = self.cur_start + self.block_length
464
465             tstart = self.cur_start / self.sample_rate
466             tend = self.cur_stop / self.sample_rate
467             tlen = self.block_length / self.sample_rate
468             self.gui.fileTimeStartLineEdit.setText(Qt.QString("%1").arg(tstart))
469             self.gui.fileTimeStopLineEdit.setText(Qt.QString("%1").arg(tend))
470             self.gui.fileTimeLengthLineEdit.setText(Qt.QString("%1").arg(tlen))
471
472             self.get_data(self.cur_start, self.cur_stop)
473             self.get_psd()
474             self.get_specgram()
475
476             self.update_time_curves()
477             self.update_psd_curves()
478             self.update_specgram_curves()
479         # If there's a non-digit character, reset box
480         else:
481             self.set_file_pos_box(self.cur_start, self.cur_stop)
482
483
484     def update_time_curves(self):
485         self.icurve.setData(self.time, self.iq.imag)
486         self.rcurve.setData(self.time, self.iq.real)
487
488         # Reset the x-axis to the new time scale
489         iqmax = 1.5 * max(max(self.iq.real), max(self.iq.imag))
490         iqmin = 1.5 * min(min(self.iq.real), min(self.iq.imag))
491         self.gui.timePlot.setAxisScale(self.gui.timePlot.xBottom,
492                                        min(self.time),
493                                        max(self.time))
494         self.gui.timePlot.setAxisScale(self.gui.timePlot.yLeft,
495                                        iqmin,
496                                        iqmax)
497
498         # Set the zoomer base to unzoom to the new axis
499         self.timeZoomer.setZoomBase()
500     
501         self.gui.timePlot.replot()
502         
503     def update_psd_curves(self):
504         self.psdcurve.setData(self.freq, self.iq_psd)
505
506         self.gui.freqPlot.setAxisScale(self.gui.freqPlot.xBottom,
507                                        min(self.freq),
508                                        max(self.freq))
509                                        
510         # Set the zoomer base to unzoom to the new axis
511         self.freqZoomer.setZoomBase()
512
513         self.gui.freqPlot.replot()
514
515     def update_specgram_curves(self):
516         # We don't have to reset the data for the speccurve here
517         # since this is taken care of in the SpectrogramData class
518         self.specdata.set_data(self.spec_f, self.spec_t, self.iq_spec)
519
520         # Set the color map based on the new data
521         self.rightAxis.setColorMap(self.spec.data().range(),
522                                    self.spec.colorMap())
523
524         # Set the new axis base; include right axis for the intenisty color bar
525         self.gui.specPlot.setAxisScale(self.gui.specPlot.xBottom,
526                                        min(self.spec_f),
527                                        max(self.spec_f))
528         self.gui.specPlot.setAxisScale(self.gui.specPlot.yLeft,
529                                        min(self.spec_t),
530                                        max(self.spec_t))
531         self.gui.specPlot.setAxisScale(self.gui.specPlot.yRight, 
532                                        self.iq_spec.min(),
533                                        self.iq_spec.max())
534  
535         # Set the zoomer base to unzoom to the new axis
536         self.specZoomer.setZoomBase()
537
538         self.gui.specPlot.replot()
539
540     def tabChanged(self, index):
541         self.gui.timePlot.replot()
542         self.gui.freqPlot.replot()
543
544     def color_black_on_white(self):
545         blue = QtGui.qRgb(0x00, 0x00, 0xFF)
546         red = QtGui.qRgb(0xFF, 0x00, 0x00)
547
548         blackBrush = Qt.QBrush(Qt.QColor("black"))
549         blueBrush = Qt.QBrush(Qt.QColor(blue))
550         redBrush = Qt.QBrush(Qt.QColor(red))
551
552         self.gui.timePlot.setCanvasBackground(Qt.QColor("white"))
553         self.gui.freqPlot.setCanvasBackground(Qt.QColor("white"))
554         self.timeZoomer.setTrackerPen(Qt.QPen(blackBrush, 2))
555         self.timeZoomer.setRubberBandPen(Qt.QPen(blackBrush, 2))
556         self.freqZoomer.setTrackerPen(Qt.QPen(blackBrush, 2))
557         self.freqZoomer.setRubberBandPen(Qt.QPen(blackBrush, 2))
558         self.psdcurve.setPen(Qt.QPen(blueBrush, 1))
559         self.rcurve.setPen(Qt.QPen(blueBrush, 2))
560         self.icurve.setPen(Qt.QPen(redBrush, 2))
561
562         self.gui.timePlot.replot()
563         self.gui.freqPlot.replot()
564
565     def color_white_on_black(self):
566         white = QtGui.qRgb(0xFF, 0xFF, 0xFF)
567         red = QtGui.qRgb(0xFF, 0x00, 0x00)
568
569         whiteBrush = Qt.QBrush(Qt.QColor("white"))
570         whiteBrush = Qt.QBrush(Qt.QColor(white))
571         redBrush = Qt.QBrush(Qt.QColor(red))
572         
573         self.gui.timePlot.setCanvasBackground(QtGui.QColor("black"))
574         self.gui.freqPlot.setCanvasBackground(QtGui.QColor("black"))
575         self.timeZoomer.setTrackerPen(Qt.QPen(whiteBrush, 2))
576         self.timeZoomer.setRubberBandPen(Qt.QPen(whiteBrush, 2))
577         self.freqZoomer.setTrackerPen(Qt.QPen(whiteBrush, 2))
578         self.freqZoomer.setRubberBandPen(Qt.QPen(whiteBrush, 2))
579         self.psdcurve.setPen(Qt.QPen(whiteBrush, 1))
580         self.rcurve.setPen(Qt.QPen(whiteBrush, 2))
581         self.icurve.setPen(Qt.QPen(redBrush, 2))
582
583         self.gui.timePlot.replot()
584         self.gui.freqPlot.replot()
585
586
587     def color_green_on_black(self):
588         green = QtGui.qRgb(0x00, 0xFF, 0x00)
589         red = QtGui.qRgb(0xFF, 0x00, 0x50)
590
591         whiteBrush = Qt.QBrush(Qt.QColor("white"))
592         greenBrush = Qt.QBrush(Qt.QColor(green))
593         redBrush = Qt.QBrush(Qt.QColor(red))
594         
595         self.gui.timePlot.setCanvasBackground(QtGui.QColor("black"))
596         self.gui.freqPlot.setCanvasBackground(QtGui.QColor("black"))
597         self.timeZoomer.setTrackerPen(Qt.QPen(whiteBrush, 2))
598         self.timeZoomer.setRubberBandPen(Qt.QPen(whiteBrush, 2))
599         self.freqZoomer.setTrackerPen(Qt.QPen(whiteBrush, 2))
600         self.freqZoomer.setRubberBandPen(Qt.QPen(whiteBrush, 2))
601         self.psdcurve.setPen(Qt.QPen(greenBrush, 1))
602         self.rcurve.setPen(Qt.QPen(greenBrush, 2))
603         self.icurve.setPen(Qt.QPen(redBrush, 2))
604
605         self.gui.timePlot.replot()
606         self.gui.freqPlot.replot()
607
608     def color_blue_on_black(self):
609         blue = QtGui.qRgb(0x00, 0x00, 0xFF)
610         red = QtGui.qRgb(0xFF, 0x00, 0x00)
611
612         whiteBrush = Qt.QBrush(Qt.QColor("white"))
613         blueBrush = Qt.QBrush(Qt.QColor(blue))
614         redBrush = Qt.QBrush(Qt.QColor(red))
615         
616         self.gui.timePlot.setCanvasBackground(QtGui.QColor("black"))
617         self.gui.freqPlot.setCanvasBackground(QtGui.QColor("black"))
618         self.timeZoomer.setTrackerPen(Qt.QPen(whiteBrush, 2))
619         self.timeZoomer.setRubberBandPen(Qt.QPen(whiteBrush, 2))
620         self.freqZoomer.setTrackerPen(Qt.QPen(whiteBrush, 2))
621         self.freqZoomer.setRubberBandPen(Qt.QPen(whiteBrush, 2))
622         self.psdcurve.setPen(Qt.QPen(blueBrush, 1))
623         self.rcurve.setPen(Qt.QPen(blueBrush, 2))
624         self.icurve.setPen(Qt.QPen(redBrush, 2))
625
626         self.gui.timePlot.replot()
627         self.gui.freqPlot.replot()
628
629 def setup_options():
630     usage="%prog: [options] (input_filename)"
631     description = ""
632
633     parser = OptionParser(conflict_handler="resolve", usage=usage, description=description)
634     parser.add_option("-B", "--block-length", type="int", default=8192,
635                       help="Specify the block size [default=%default]")
636     parser.add_option("-s", "--start", type="int", default=0,
637                       help="Specify where to start in the file [default=%default]")
638     parser.add_option("-R", "--sample-rate", type="float", default=1.0,
639                       help="Set the sampler rate of the data [default=%default]")
640     parser.add_option("", "--psd-size", type="int", default=2048,
641                       help="Set the size of the PSD FFT [default=%default]")
642     parser.add_option("", "--spec-size", type="int", default=2048,
643                       help="Set the size of the spectrogram FFT [default=%default]")
644
645     return parser
646
647 def main(args):
648     parser = setup_options()
649     (options, args) = parser.parse_args ()
650
651     if(len(args) == 1):
652         filename = args[0]
653     else:
654         filename = None
655
656     app = Qt.QApplication(args)
657     gplt = gr_plot_qt(app, filename, options)
658     app.exec_()
659
660 if __name__ == '__main__':
661     main(sys.argv)
662