commit-gnuradio
[Top][All Lists]
Advanced

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

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


From: trondeau
Subject: [Commit-gnuradio] r10706 - gnuradio/branches/developers/trondeau/qtdevel2/gr-qtgui/src/python
Date: Sun, 29 Mar 2009 19:28:54 -0600 (MDT)

Author: trondeau
Date: 2009-03-29 19:28:54 -0600 (Sun, 29 Mar 2009)
New Revision: 10706

Added:
   
gnuradio/branches/developers/trondeau/qtdevel2/gr-qtgui/src/python/pyqt_example.py
Log:
wip: an example of mixing a PyQt dialog with the qtsink. I'm still working out 
how to pass this PyQt object as a parent to the qtsink for better structuring.

Added: 
gnuradio/branches/developers/trondeau/qtdevel2/gr-qtgui/src/python/pyqt_example.py
===================================================================
--- 
gnuradio/branches/developers/trondeau/qtdevel2/gr-qtgui/src/python/pyqt_example.py
                          (rev 0)
+++ 
gnuradio/branches/developers/trondeau/qtdevel2/gr-qtgui/src/python/pyqt_example.py
  2009-03-30 01:28:54 UTC (rev 10706)
@@ -0,0 +1,132 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio.qtgui import qtgui
+from PyQt4 import QtGui, QtCore
+import sys, sip
+
+class control_panel(QtGui.QWidget):
+    def __init__(self, parent=None):
+        QtGui.QWidget.__init__(self, parent)
+        self.setWindowTitle('Control Panel')
+
+        self.setToolTip('This Controls the Signals')
+        QtGui.QToolTip.setFont(QtGui.QFont('OldEnglish', 10))
+
+        self.grid = QtGui.QGridLayout()
+
+        # 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.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.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.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.connect(self.amp2Edit, QtCore.SIGNAL("editingFinished()"),
+                     self.amp2EditText)
+
+        self.quit = QtGui.QPushButton('Close', self)
+        self.grid.addWidget(self.quit, 4, 1)     
+
+        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()))
+        
self.amp1Edit.setText(QtCore.QString("%1").arg(self.signal1.amplitude()))
+
+    def attach_signal2(self, signal):
+        self.signal2 = signal
+        
self.freq2Edit.setText(QtCore.QString("%1").arg(self.signal2.frequency()))
+        
self.amp2Edit.setText(QtCore.QString("%1").arg(self.signal2.amplitude()))
+
+    def freq1EditText(self):
+        try:
+            newfreq = float(self.freq1Edit.text())
+            self.signal1.set_frequency(newfreq)
+        except ValueError:
+            print "Bad frequency value entered"
+
+    def amp1EditText(self):
+        try:
+            newamp = float(self.amp1Edit.text())
+            self.signal1.set_amplitude(newamp)
+        except ValueError:
+            print "Bad amplitude value entered"
+
+        
+    def freq2EditText(self):
+        try:
+            newfreq = float(self.freq2Edit.text())
+            self.signal2.set_frequency(newfreq)
+        except ValueError:
+            print "Bad frequency value entered"
+
+    def amp2EditText(self):
+        try:
+            newamp = float(self.amp2Edit.text())
+            self.signal2.set_amplitude(newamp)
+        except ValueError:
+            print "Bad amplitude value entered"
+
+
+class my_top_block(gr.top_block):
+    def __init__(self):
+        gr.top_block.__init__(self)
+
+        Rs = 8000
+        f1 = 1000
+        f2 = 2000
+
+        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()
+        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,
+                                 -Rs/2, Rs/2)
+
+        self.connect(src1, (src,0))
+        self.connect(src2, (src,1))
+        self.connect(src,  thr, self.snk1)
+
+        self.ctrl_win.attach_signal1(src1)
+        self.ctrl_win.attach_signal2(src2)
+        self.ctrl_win.show()
+       
+if __name__ == "__main__":
+    tb = my_top_block();
+    tb.start()
+    tb.qapp.exec_()
+    


Property changes on: 
gnuradio/branches/developers/trondeau/qtdevel2/gr-qtgui/src/python/pyqt_example.py
___________________________________________________________________
Added: svn:executable
   + *





reply via email to

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