Adding ability to change line width and style (only a handful of current styles enabled).
authorTom Rondeau <trondeau@molly.home>
Wed, 2 Sep 2009 02:46:16 +0000 (22:46 -0400)
committerTom Rondeau <trondeau@molly.home>
Wed, 2 Sep 2009 02:46:16 +0000 (22:46 -0400)
gr-utils/src/python/gr_plot_qt.py
gr-utils/src/python/pyqt_plot.py
gr-utils/src/python/pyqt_plot.ui

index 906bb2d3358df67784eaf9a4901a3a9069fd01e6..3d77787d4570f821e023c31906f38bf91430b54a 100755 (executable)
@@ -84,6 +84,7 @@ class gr_plot_qt(QtGui.QMainWindow):
         self.winfunc = scipy.blackman
         self.sizeof_data = 8
         self.datatype = scipy.complex64
+        self.pen_width = 1
         self.iq = list()
         self.time = list()
 
@@ -125,6 +126,18 @@ class gr_plot_qt(QtGui.QMainWindow):
                      self.colorComboBoxEdit)
         
         
+        # Set up line style combo box
+        self.line_styles = {"None" : Qwt.QwtSymbol.NoSymbol,
+                            "Circle" : Qwt.QwtSymbol.Ellipse,
+                            "Diamond"  : Qwt.QwtSymbol.Rect,
+                            "Triangle" : Qwt.QwtSymbol.Triangle}
+        self.gui.lineStyleComboBox.addItems(self.line_styles.keys())
+        pos = self.gui.lineStyleComboBox.findText("None")
+        self.gui.lineStyleComboBox.setCurrentIndex(pos)
+        self.connect(self.gui.lineStyleComboBox,
+                     Qt.SIGNAL("activated (const QString&)"),
+                     self.lineStyleComboBoxEdit)
+
         # Create zoom functionality for the plots
         self.timeZoomer = Qwt.QwtPlotZoomer(self.gui.timePlot.xBottom,
                                             self.gui.timePlot.yLeft,
@@ -195,8 +208,20 @@ class gr_plot_qt(QtGui.QMainWindow):
                      Qt.SIGNAL("editingFinished()"),
                      self.file_time_length_changed)
 
+        stylestr = str(self.gui.lineStyleComboBox.currentText().toAscii())
+        style = self.line_styles[stylestr]
+
         self.rcurve = Qwt.QwtPlotCurve("Real")
         self.icurve = Qwt.QwtPlotCurve("Imaginary")
+        self.rsym = Qwt.QwtSymbol()
+        self.rsym.setStyle(style)
+        self.rsym.setSize(10)
+        self.isym = Qwt.QwtSymbol()
+        self.isym.setStyle(style)
+        self.isym.setSize(10)
+        self.rcurve.setSymbol(self.rsym)
+        self.icurve.setSymbol(self.isym)
+
 
         self.icurve.attach(self.gui.timePlot)
         self.rcurve.attach(self.gui.timePlot)
@@ -204,7 +229,6 @@ class gr_plot_qt(QtGui.QMainWindow):
         self.psdcurve = Qwt.QwtPlotCurve("PSD")
         self.psdcurve.attach(self.gui.freqPlot)
 
-
         # Set up specTab plot as a spectrogram
         self.specdata = SpectrogramData(range(0, 10), range(0, 10))
 
@@ -229,6 +253,13 @@ class gr_plot_qt(QtGui.QMainWindow):
         # Set up initial color scheme
         self.color_modes["Blue on Black"]()
 
+        # When line width spin box changes, update the pen size
+        self.connect(self.gui.lineWidthSpinBox,
+                     Qt.SIGNAL("valueChanged(int)"),
+                     self.change_pen_width)
+        self.gui.lineWidthSpinBox.setRange(1, 10)
+
+
         # Connect a signal for when the sample rate changes
         self.set_sample_rate(self.sample_rate)
         self.connect(self.gui.sampleRateLineEdit,
@@ -346,6 +377,14 @@ class gr_plot_qt(QtGui.QMainWindow):
         color_func = self.color_modes[colorstr]
         color_func()
 
+    def lineStyleComboBoxEdit(self, styleSelection):
+        stylestr = str(styleSelection.toAscii())
+        self.rsym.setStyle(self.line_styles[stylestr])
+        self.isym.setStyle(self.line_styles[stylestr])
+        self.rcurve.setSymbol(self.rsym)
+        self.icurve.setSymbol(self.isym)
+        self.gui.timePlot.replot()
+
     def sliderMoved(self, value):
         pos_start = value
         pos_end = value + self.gui.plotHBar.pageStep()
@@ -540,24 +579,33 @@ class gr_plot_qt(QtGui.QMainWindow):
     def tabChanged(self, index):
         self.gui.timePlot.replot()
         self.gui.freqPlot.replot()
+        self.gui.specPlot.replot()
+
+    def change_pen_width(self, width):
+        self.pen_width = width
+        colormode = str(self.gui.colorComboBox.currentText().toAscii())
+        color_func = self.color_modes[colormode]()
 
     def color_black_on_white(self):
         blue = QtGui.qRgb(0x00, 0x00, 0xFF)
         red = QtGui.qRgb(0xFF, 0x00, 0x00)
 
-        blackBrush = Qt.QBrush(Qt.QColor("black"))
-        blueBrush = Qt.QBrush(Qt.QColor(blue))
-        redBrush = Qt.QBrush(Qt.QColor(red))
+        blackPen = Qt.QPen(Qt.QBrush(Qt.QColor("black")), self.pen_width)
+        bluePen = Qt.QPen(Qt.QBrush(Qt.QColor(blue)), self.pen_width)
+        redPen = Qt.QPen(Qt.QBrush(Qt.QColor(red)), self.pen_width)
 
         self.gui.timePlot.setCanvasBackground(Qt.QColor("white"))
         self.gui.freqPlot.setCanvasBackground(Qt.QColor("white"))
-        self.timeZoomer.setTrackerPen(Qt.QPen(blackBrush, 2))
-        self.timeZoomer.setRubberBandPen(Qt.QPen(blackBrush, 2))
-        self.freqZoomer.setTrackerPen(Qt.QPen(blackBrush, 2))
-        self.freqZoomer.setRubberBandPen(Qt.QPen(blackBrush, 2))
-        self.psdcurve.setPen(Qt.QPen(blueBrush, 1))
-        self.rcurve.setPen(Qt.QPen(blueBrush, 2))
-        self.icurve.setPen(Qt.QPen(redBrush, 2))
+        self.timeZoomer.setTrackerPen(blackPen)
+        self.timeZoomer.setRubberBandPen(blackPen)
+        self.freqZoomer.setTrackerPen(blackPen)
+        self.freqZoomer.setRubberBandPen(blackPen)
+        self.psdcurve.setPen(bluePen)
+        self.rcurve.setPen(bluePen)
+        self.icurve.setPen(redPen)
+
+        self.rsym.setPen(bluePen)
+        self.isym.setPen(redPen)
 
         self.gui.timePlot.replot()
         self.gui.freqPlot.replot()
@@ -572,13 +620,13 @@ class gr_plot_qt(QtGui.QMainWindow):
         
         self.gui.timePlot.setCanvasBackground(QtGui.QColor("black"))
         self.gui.freqPlot.setCanvasBackground(QtGui.QColor("black"))
-        self.timeZoomer.setTrackerPen(Qt.QPen(whiteBrush, 2))
-        self.timeZoomer.setRubberBandPen(Qt.QPen(whiteBrush, 2))
-        self.freqZoomer.setTrackerPen(Qt.QPen(whiteBrush, 2))
-        self.freqZoomer.setRubberBandPen(Qt.QPen(whiteBrush, 2))
-        self.psdcurve.setPen(Qt.QPen(whiteBrush, 1))
-        self.rcurve.setPen(Qt.QPen(whiteBrush, 2))
-        self.icurve.setPen(Qt.QPen(redBrush, 2))
+        self.timeZoomer.setTrackerPen(Qt.QPen(whiteBrush, self.pen_width))
+        self.timeZoomer.setRubberBandPen(Qt.QPen(whiteBrush, self.pen_width))
+        self.freqZoomer.setTrackerPen(Qt.QPen(whiteBrush, self.pen_width))
+        self.freqZoomer.setRubberBandPen(Qt.QPen(whiteBrush, self.pen_width))
+        self.psdcurve.setPen(Qt.QPen(whiteBrush, self.pen_width))
+        self.rcurve.setPen(Qt.QPen(whiteBrush, self.pen_width))
+        self.icurve.setPen(Qt.QPen(redBrush, self.pen_width))
 
         self.gui.timePlot.replot()
         self.gui.freqPlot.replot()
@@ -594,13 +642,13 @@ class gr_plot_qt(QtGui.QMainWindow):
         
         self.gui.timePlot.setCanvasBackground(QtGui.QColor("black"))
         self.gui.freqPlot.setCanvasBackground(QtGui.QColor("black"))
-        self.timeZoomer.setTrackerPen(Qt.QPen(whiteBrush, 2))
-        self.timeZoomer.setRubberBandPen(Qt.QPen(whiteBrush, 2))
-        self.freqZoomer.setTrackerPen(Qt.QPen(whiteBrush, 2))
-        self.freqZoomer.setRubberBandPen(Qt.QPen(whiteBrush, 2))
-        self.psdcurve.setPen(Qt.QPen(greenBrush, 1))
-        self.rcurve.setPen(Qt.QPen(greenBrush, 2))
-        self.icurve.setPen(Qt.QPen(redBrush, 2))
+        self.timeZoomer.setTrackerPen(Qt.QPen(whiteBrush, self.pen_width))
+        self.timeZoomer.setRubberBandPen(Qt.QPen(whiteBrush, self.pen_width))
+        self.freqZoomer.setTrackerPen(Qt.QPen(whiteBrush, self.pen_width))
+        self.freqZoomer.setRubberBandPen(Qt.QPen(whiteBrush, self.pen_width))
+        self.psdcurve.setPen(Qt.QPen(greenBrush, self.pen_width))
+        self.rcurve.setPen(Qt.QPen(greenBrush, self.pen_width))
+        self.icurve.setPen(Qt.QPen(redBrush, self.pen_width))
 
         self.gui.timePlot.replot()
         self.gui.freqPlot.replot()
@@ -615,13 +663,13 @@ class gr_plot_qt(QtGui.QMainWindow):
         
         self.gui.timePlot.setCanvasBackground(QtGui.QColor("black"))
         self.gui.freqPlot.setCanvasBackground(QtGui.QColor("black"))
-        self.timeZoomer.setTrackerPen(Qt.QPen(whiteBrush, 2))
-        self.timeZoomer.setRubberBandPen(Qt.QPen(whiteBrush, 2))
-        self.freqZoomer.setTrackerPen(Qt.QPen(whiteBrush, 2))
-        self.freqZoomer.setRubberBandPen(Qt.QPen(whiteBrush, 2))
-        self.psdcurve.setPen(Qt.QPen(blueBrush, 1))
-        self.rcurve.setPen(Qt.QPen(blueBrush, 2))
-        self.icurve.setPen(Qt.QPen(redBrush, 2))
+        self.timeZoomer.setTrackerPen(Qt.QPen(whiteBrush, self.pen_width))
+        self.timeZoomer.setRubberBandPen(Qt.QPen(whiteBrush, self.pen_width))
+        self.freqZoomer.setTrackerPen(Qt.QPen(whiteBrush, self.pen_width))
+        self.freqZoomer.setRubberBandPen(Qt.QPen(whiteBrush, self.pen_width))
+        self.psdcurve.setPen(Qt.QPen(blueBrush, self.pen_width))
+        self.rcurve.setPen(Qt.QPen(blueBrush, self.pen_width))
+        self.icurve.setPen(Qt.QPen(redBrush, self.pen_width))
 
         self.gui.timePlot.replot()
         self.gui.freqPlot.replot()
index 22492b0d0cc2d2218f725eaf72458e4517d143de..c6e7fd5a2c2882c39586328b81eca2247df23129 100644 (file)
@@ -2,7 +2,7 @@
 
 # Form implementation generated from reading ui file 'pyqt_plot.ui'
 #
-# Created: Tue Sep  1 21:40:08 2009
+# Created: Tue Sep  1 22:46:04 2009
 #      by: PyQt4 UI code generator 4.4.3
 #
 # WARNING! All changes made in this file will be lost!
@@ -12,7 +12,7 @@ from PyQt4 import QtCore, QtGui
 class Ui_MainWindow(object):
     def setupUi(self, MainWindow):
         MainWindow.setObjectName("MainWindow")
-        MainWindow.resize(927, 696)
+        MainWindow.resize(927, 693)
         self.centralwidget = QtGui.QWidget(MainWindow)
         self.centralwidget.setObjectName("centralwidget")
         self.gridLayout = QtGui.QGridLayout(self.centralwidget)
@@ -142,19 +142,26 @@ class Ui_MainWindow(object):
         self.sampleRateLineEdit.setObjectName("sampleRateLineEdit")
         self.formLayout_2.setWidget(0, QtGui.QFormLayout.FieldRole, self.sampleRateLineEdit)
         self.displayGroupBox = QtGui.QGroupBox(self.filePosBox)
-        self.displayGroupBox.setGeometry(QtCore.QRect(730, 0, 170, 120))
+        self.displayGroupBox.setGeometry(QtCore.QRect(730, 0, 170, 142))
         self.displayGroupBox.setMinimumSize(QtCore.QSize(170, 0))
         self.displayGroupBox.setObjectName("displayGroupBox")
-        self.verticalLayoutWidget = QtGui.QWidget(self.displayGroupBox)
-        self.verticalLayoutWidget.setGeometry(QtCore.QRect(0, 20, 160, 91))
-        self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
-        self.verticalLayout = QtGui.QVBoxLayout(self.verticalLayoutWidget)
-        self.verticalLayout.setObjectName("verticalLayout")
-        self.colorComboBox = QtGui.QComboBox(self.verticalLayoutWidget)
+        self.gridLayout_2 = QtGui.QGridLayout(self.displayGroupBox)
+        self.gridLayout_2.setObjectName("gridLayout_2")
+        self.colorComboBox = QtGui.QComboBox(self.displayGroupBox)
         self.colorComboBox.setObjectName("colorComboBox")
-        self.verticalLayout.addWidget(self.colorComboBox)
-        spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
-        self.verticalLayout.addItem(spacerItem)
+        self.gridLayout_2.addWidget(self.colorComboBox, 0, 0, 1, 2)
+        self.lineWidthSpinBox = QtGui.QSpinBox(self.displayGroupBox)
+        self.lineWidthSpinBox.setObjectName("lineWidthSpinBox")
+        self.gridLayout_2.addWidget(self.lineWidthSpinBox, 1, 1, 1, 1)
+        self.lineWidthLabel = QtGui.QLabel(self.displayGroupBox)
+        self.lineWidthLabel.setObjectName("lineWidthLabel")
+        self.gridLayout_2.addWidget(self.lineWidthLabel, 1, 0, 1, 1)
+        self.label = QtGui.QLabel(self.displayGroupBox)
+        self.label.setObjectName("label")
+        self.gridLayout_2.addWidget(self.label, 2, 0, 1, 1)
+        self.lineStyleComboBox = QtGui.QComboBox(self.displayGroupBox)
+        self.lineStyleComboBox.setObjectName("lineStyleComboBox")
+        self.gridLayout_2.addWidget(self.lineStyleComboBox, 2, 1, 1, 1)
         self.gridLayout.addWidget(self.filePosBox, 3, 0, 1, 1)
         MainWindow.setCentralWidget(self.centralwidget)
         self.menubar = QtGui.QMenuBar(MainWindow)
@@ -201,6 +208,8 @@ class Ui_MainWindow(object):
         self.sysGroupBox.setTitle(QtGui.QApplication.translate("MainWindow", "System Properties", None, QtGui.QApplication.UnicodeUTF8))
         self.sampleRateLabel.setText(QtGui.QApplication.translate("MainWindow", "Sample Rate", None, QtGui.QApplication.UnicodeUTF8))
         self.displayGroupBox.setTitle(QtGui.QApplication.translate("MainWindow", "Display Properties", None, QtGui.QApplication.UnicodeUTF8))
+        self.lineWidthLabel.setText(QtGui.QApplication.translate("MainWindow", "Line Width", None, QtGui.QApplication.UnicodeUTF8))
+        self.label.setText(QtGui.QApplication.translate("MainWindow", "Line Style", None, QtGui.QApplication.UnicodeUTF8))
         self.menu_File.setTitle(QtGui.QApplication.translate("MainWindow", "&File", None, QtGui.QApplication.UnicodeUTF8))
         self.action_open.setText(QtGui.QApplication.translate("MainWindow", "&Open", None, QtGui.QApplication.UnicodeUTF8))
         self.action_open.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+O", None, QtGui.QApplication.UnicodeUTF8))
index 023010f8ca7ff426c87d968976e06ee0f4c3fafc..df3d6119766a1842c1fddab8eb842a72d53e5ca4 100644 (file)
@@ -6,7 +6,7 @@
     <x>0</x>
     <y>0</y>
     <width>927</width>
-    <height>696</height>
+    <height>693</height>
    </rect>
   </property>
   <property name="windowTitle" >
          <x>730</x>
          <y>0</y>
          <width>170</width>
-         <height>120</height>
+         <height>142</height>
         </rect>
        </property>
        <property name="minimumSize" >
        <property name="title" >
         <string>Display Properties</string>
        </property>
-       <widget class="QWidget" name="verticalLayoutWidget" >
-        <property name="geometry" >
-         <rect>
-          <x>0</x>
-          <y>20</y>
-          <width>160</width>
-          <height>91</height>
-         </rect>
-        </property>
-        <layout class="QVBoxLayout" name="verticalLayout" >
-         <item>
-          <widget class="QComboBox" name="colorComboBox" />
-         </item>
-         <item>
-          <spacer name="verticalSpacer" >
-           <property name="orientation" >
-            <enum>Qt::Vertical</enum>
-           </property>
-           <property name="sizeHint" stdset="0" >
-            <size>
-             <width>20</width>
-             <height>40</height>
-            </size>
-           </property>
-          </spacer>
-         </item>
-        </layout>
-       </widget>
+       <layout class="QGridLayout" name="gridLayout_2" >
+        <item row="0" column="0" colspan="2" >
+         <widget class="QComboBox" name="colorComboBox" />
+        </item>
+        <item row="1" column="1" >
+         <widget class="QSpinBox" name="lineWidthSpinBox" />
+        </item>
+        <item row="1" column="0" >
+         <widget class="QLabel" name="lineWidthLabel" >
+          <property name="text" >
+           <string>Line Width</string>
+          </property>
+         </widget>
+        </item>
+        <item row="2" column="0" >
+         <widget class="QLabel" name="label" >
+          <property name="text" >
+           <string>Line Style</string>
+          </property>
+         </widget>
+        </item>
+        <item row="2" column="1" >
+         <widget class="QComboBox" name="lineStyleComboBox" />
+        </item>
+       </layout>
       </widget>
      </widget>
     </item>