commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r10795 - gnuradio/branches/developers/trondeau/qtdevel


From: trondeau
Subject: [Commit-gnuradio] r10795 - gnuradio/branches/developers/trondeau/qtdevel2/gr-qtgui/src/python
Date: Wed, 8 Apr 2009 19:33:32 -0600 (MDT)

Author: trondeau
Date: 2009-04-08 19:33:32 -0600 (Wed, 08 Apr 2009)
New Revision: 10795

Modified:
   
gnuradio/branches/developers/trondeau/qtdevel2/gr-qtgui/src/python/pyqt_example.py
Log:
Working example of how to mix PyQt and the qtsink widget.

Modified: 
gnuradio/branches/developers/trondeau/qtdevel2/gr-qtgui/src/python/pyqt_example.py
===================================================================
--- 
gnuradio/branches/developers/trondeau/qtdevel2/gr-qtgui/src/python/pyqt_example.py
  2009-04-09 01:00:28 UTC (rev 10794)
+++ 
gnuradio/branches/developers/trondeau/qtdevel2/gr-qtgui/src/python/pyqt_example.py
  2009-04-09 01:33:32 UTC (rev 10795)
@@ -1,61 +1,61 @@
 #!/usr/bin/env python
 
-from gnuradio import gr
+from gnuradio import gr, blks2
 from gnuradio.qtgui import qtgui
 from PyQt4 import QtGui, QtCore
 import sys, sip
 
-class control_panel(QtGui.QWidget):
+class dialog_box(QtGui.QWidget):
+    def __init__(self, display, control):
+        QtGui.QWidget.__init__(self, None)
+        self.setWindowTitle('PyQt Test GUI')
+
+        self.boxlayout = QtGui.QBoxLayout(QtGui.QBoxLayout.LeftToRight, self)
+        self.boxlayout.addWidget(display, 1)
+        self.boxlayout.addWidget(control)
+
+        self.resize(800, 500)
+
+class control_box(QtGui.QWidget):
     def __init__(self, parent=None):
         QtGui.QWidget.__init__(self, parent)
         self.setWindowTitle('Control Panel')
 
-        self.setToolTip('This Controls the Signals')
+        self.setToolTip('Control the signals')
         QtGui.QToolTip.setFont(QtGui.QFont('OldEnglish', 10))
 
-        self.grid = QtGui.QGridLayout()
+        self.layout = QtGui.QFormLayout(self)
 
         # Control the first signal
-        self.freq1Label = QtGui.QLabel("Signal 1 Frequency", self)
         self.freq1Edit = QtGui.QLineEdit(self)
-        self.grid.addWidget(self.freq1Label, 0, 0)
-        self.grid.addWidget(self.freq1Edit, 0, 1)
+        self.layout.addRow("Signal 1 Frequency:", self.freq1Edit)
         self.connect(self.freq1Edit, QtCore.SIGNAL("editingFinished()"),
                      self.freq1EditText)
 
-        self.amp1Label = QtGui.QLabel("Signal 1 Amplitude", self)
         self.amp1Edit = QtGui.QLineEdit(self)
-        self.grid.addWidget(self.amp1Label, 1, 0)
-        self.grid.addWidget(self.amp1Edit, 1, 1)
+        self.layout.addRow("Signal 1 Amplitude:", self.amp1Edit)
         self.connect(self.amp1Edit, QtCore.SIGNAL("editingFinished()"),
                      self.amp1EditText)
 
 
         # Control the second signal
-        self.freq2Label = QtGui.QLabel("Signal 2 Frequency", self)
         self.freq2Edit = QtGui.QLineEdit(self)
-        self.grid.addWidget(self.freq2Label, 2, 0)
-        self.grid.addWidget(self.freq2Edit, 2, 1)
+        self.layout.addRow("Signal 2 Frequency:", self.freq2Edit)
         self.connect(self.freq2Edit, QtCore.SIGNAL("editingFinished()"),
                      self.freq2EditText)
 
-        self.amp2Label = QtGui.QLabel("Signal 2 Amplitude", self)
+
         self.amp2Edit = QtGui.QLineEdit(self)
-        self.grid.addWidget(self.amp2Label, 3, 0)
-        self.grid.addWidget(self.amp2Edit, 3, 1)
+        self.layout.addRow("Signal 2 Amplitude:", self.amp2Edit)
         self.connect(self.amp2Edit, QtCore.SIGNAL("editingFinished()"),
                      self.amp2EditText)
 
         self.quit = QtGui.QPushButton('Close', self)
-        self.grid.addWidget(self.quit, 4, 1)     
+        self.layout.addWidget(self.quit)
 
         self.connect(self.quit, QtCore.SIGNAL('clicked()'),
                      QtGui.qApp, QtCore.SLOT('quit()'))
 
-
-        self.setLayout(self.grid)
-
-
     def attach_signal1(self, signal):
         self.signal1 = signal
         
self.freq1Edit.setText(QtCore.QString("%1").arg(self.signal1.frequency()))
@@ -107,24 +107,34 @@
         fftsize = 2048
 
         self.qapp = QtGui.QApplication(sys.argv)
-        self.ctrl_win = control_panel()
         
         src1 = gr.sig_source_c(Rs, gr.GR_SIN_WAVE, f1, 0.1, 0)
         src2 = gr.sig_source_c(Rs, gr.GR_SIN_WAVE, f2, 0.1, 0)
         src  = gr.add_cc()
+        channel = blks2.channel_model(0.001)
         thr = gr.throttle(gr.sizeof_gr_complex, 100*fftsize)
-        self.snk1 = qtgui.sink_c(None, #sip.unwrapinstance(ctrl_win),
-                                 fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
+        self.snk1 = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
                                  -Rs/2, Rs/2)
 
         self.connect(src1, (src,0))
         self.connect(src2, (src,1))
-        self.connect(src,  thr, self.snk1)
+        self.connect(src,  channel, thr, self.snk1)
 
+        self.ctrl_win = control_box()
         self.ctrl_win.attach_signal1(src1)
         self.ctrl_win.attach_signal2(src2)
-        self.ctrl_win.show()
-       
+
+        # Get the reference pointer to the SpectrumDisplayForm QWidget
+        pyQt  = self.snk1.pyqwidget()
+
+        # Wrap the pointer as a PyQt SIP object
+        # This can now be manipulated as a PyQt4.QtGui.QWidget
+        pyWin = sip.wrapinstance(pyQt, QtGui.QWidget)
+
+        self.main_box = dialog_box(pyWin, self.ctrl_win)
+
+        self.main_box.show()
+        
 if __name__ == "__main__":
     tb = my_top_block();
     tb.start()





reply via email to

[Prev in Thread] Current Thread [Next in Thread]