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