wxPython: My toolbar does't show buttons in Windows - python-2.7

I did a small application and it works nice in linux. But, I get some problems with the toolbar in Windows 7.
The toolbar has some buttons which Windows doesn't show (But, there are in Linux). I am using Python 2.7 and wxPython 2.8.
I don't know what I am missing.
Regards,
Cristian.
import wx
from wx.lib.pubsub import Publisher
from excel import excelmaker
from model import Model
from ObjectListView import ColumnDefn, ObjectListView
import utils
import threading
wildcard = "Excel (*.xlsx)|*.xlsx|" \
"All files (*.*)|*.*"
class ApplicationGui(wx.App):
def __init__(self, redirect=False, filename=None):
wx.App.__init__(self, redirect, filename)
def OnInit(self):
# create frame here
frame = MainFrame()
frame.Show()
return True
class MainPanel(wx.Panel):
def __init__(self,parent):
self.exportText=''
wx.Panel.__init__(self,parent=parent, id=wx.ID_ANY)
self.objectListView = ObjectListView(self, wx.ID_ANY,style=wx.LC_REPORT|wx.SUNKEN_BORDER)
self.objectListView.cellEditMode = ObjectListView.CELLEDIT_SINGLECLICK
self.objectListView.SetObjects([Model()])
mainSizer = wx.BoxSizer(wx.VERTICAL)
self.create_toolbar(mainSizer)
mainSizer.Add(self.progress, 0, wx.EXPAND)
mainSizer.Add(self.objectListView, 1, wx.ALL|wx.EXPAND, 5)
self.SetSizer(mainSizer)
def create_toolbar(self,sizer):
toolbar = wx.ToolBar(self)
loadBtn = toolbar.AddLabelTool(wx.ID_ANY, 'Cargar Excel', wx.Bitmap('resources/open.png'), shortHelp='Cargar Excel')
pasteBtn = toolbar.AddLabelTool(wx.ID_ANY, 'Pegar', wx.Bitmap('resources/paste.png'), shortHelp='Pegar Columnas')
cleanBtn = toolbar.AddLabelTool(wx.ID_ANY, 'Borrar', wx.Bitmap('resources/clean.png'), shortHelp='Borrar tabla')
toolbar.AddSeparator()
addBtn = toolbar.AddLabelTool(wx.ID_ANY, 'Agregar', wx.Bitmap('resources/add.png'), shortHelp='Agregar fila')
toolbar.AddSeparator()
self.exportText = wx.TextCtrl(toolbar, -1, size=(140,-1))
self.exportText.SetValue('output.xlsx')
toolbar.AddControl(self.exportText)
exportBtn = toolbar.AddLabelTool(wx.ID_ANY, 'Exportar', wx.Bitmap('resources/export.png'), shortHelp='Generar Excel')
toolbar.AddSeparator()
about = toolbar.AddLabelTool(wx.ID_ANY, 'Acerca', wx.Bitmap('resources/about.png'), shortHelp='Ayuda')
randomId = wx.NewId()
self.Bind(wx.EVT_MENU, self.onPaste, id=randomId)
accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('V'), randomId )])
self.SetAcceleratorTable(accel_tbl)
sizer.Add(toolbar, 0, wx.EXPAND)
self.Bind(wx.EVT_TOOL, self.onOpenFile, loadBtn)
self.Bind(wx.EVT_TOOL, self.onPaste, pasteBtn)
self.Bind(wx.EVT_TOOL, self.onClean, cleanBtn)
self.Bind(wx.EVT_TOOL, self.onExport, exportBtn)
self.Bind(wx.EVT_TOOL, self.onAddRow, addBtn)
self.Bind(wx.EVT_TOOL, self.onAbout, about)
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, parent=None, id=wx.ID_ANY,
title="Exceltronic", size=(800,600))
panel = MainPanel(self)

You are missing the call
toolbar.Realize()
http://wxpython.org/Phoenix/docs/html/ToolBar.html?highlight=toolbar#ToolBar.Realize

Related

How can i disable the selection highlighted green in table widget using pyqt4

Here is my sample code.I need to remove green highlighted selection in my table widget for that i wrote QtGui.QAbstractItemView.NoSelection but using this line i am not able to move my cursor up,down ,left and right in table widget.Can any one please tell me how to disable the green selection and i want to move my cursor using with arrow keys in keyboard..Please help me..Thank you in advance..
Given below is my code:
import sys
from PyQt4 import QtCore,QtGui
global data_arraylist,count,pushBtnList,lineeditList
class Table_Program(QtGui.QMainWindow ):
def __init__(self,config=None, parent=None):
super(Table_Program, self).__init__(parent)
global data_arraylist,count,pushBtnList,lineeditList
self.scrollArea_left = QtGui.QScrollArea(widgetResizable=True)
self.mainw2 = QtGui.QWidget()
self.mainw2.showFullScreen()
self.scrollArea_left.setWidget(self.mainw2)
self.newvbox = QtGui.QGridLayout(self.mainw2)
self.table = QtGui.QTableWidget()
self.table_item = QtGui.QTableWidgetItem()
self.table.setRowCount(1)
self.table.verticalHeader().hide()
self.table.setColumnCount(4)
self.table.setHorizontalHeaderLabels(("S.no, Item Description,Qty,Rate(Rs:),"",").split(','))
self.newvbox.addWidget(self.table,0,0)
self.table.setColumnWidth(2,170)
self.table.setColumnWidth(3,200)
self.btn1 = QtGui.QPushButton(icon=QtGui.QIcon("./plus1.png"))
self.btn1.setIconSize(QtCore.QSize(30,20))
self.table.setCellWidget(0,0,self.btn1)
self.btn1.clicked.connect(self.insert_rows)
self.table.setItem(0,4,QtGui.QTableWidgetItem(str(" ")))
self.setCentralWidget(self.scrollArea_left)
# QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Up), self, self.moveup)
def insert_rows(self,typ=None):
layout_item = QtGui.QHBoxLayout()
cellWidget = QtGui.QWidget()
self.itemlineedit = QtGui.QLineEdit()
self.itemlineedit.setFrame(False)
self.search_btn = QtGui.QPushButton(icon=QtGui.QIcon('search.png'))
self.search_btn.setIconSize(QtCore.QSize(20,20))
layout_item.addWidget(self.itemlineedit)
layout_item.addStretch()
layout_item.addWidget(self.search_btn)
cellWidget.setLayout(layout_item)
global pushBtnList
ct = self.table.rowCount()
self.table.insertRow(ct-1)
self.btn = QtGui.QPushButton()
self.btn.setIcon(QtGui.QIcon("./delete.png"))
self.btn.setIconSize(QtCore.QSize(30,60))
self.table.setItem(ct-1,0,QtGui.QTableWidgetItem(str(ct)))
self.table.setCellWidget(ct -1,5,self.btn)
index = QtCore.QPersistentModelIndex(self.table.model().index(ct -1, 5))
self.quantybutton = QtGui.QLineEdit()
self.itemlineedit.textChanged.connect(partial(self.product_rate,ct))
completer = QtGui.QCompleter()
self.itemlineedit.setCompleter(completer)
self.model = QtGui.QStringListModel()
self.itemlineedit.resize(100,50)
completer.setModel(self.model)
self.item_rate = QtGui.QLabel()
self.table.setCellWidget(ct-1, 3,self.item_rate)
self.table.setCellWidget(ct-1, 2, self.quantybutton)
self.table.setCellWidget(ct -1, 1, cellWidget)
self.table.setRowHeight(ct-1,50)
self.table.setColumnWidth(1,170)
def get_data(self,model):
model.setStringList(["item1","item2","item3"])
def product_rate(self,text,index):
self.quantybutton.setText("1")
self.item_rate.setText(str("20"))
self.get_data(self.model)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
tb = Table_Program()
tb.show()
tb.resize(600,300)
sys.exit(app.exec_())
A simple solution is to implement a custom QStyle that disables the highlight option in the QTableWidget:
from PyQt4 import QtCore, QtGui
class CustomStyle(QtGui.QCommonStyle):
def drawPrimitive(self, element, option, painter, widget):
if element == QtGui.QStyle.PE_PanelItemViewItem:
option.state &= ~QtGui.QStyle.State_Selected
super(CustomStyle, self).drawPrimitive(element, option, painter, widget)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
w = QtGui.QTableWidget(5, 4)
w.setStyle(CustomStyle()) # <--- set style
w.show()
sys.exit(app.exec_())

QThread and pyqtgraph no performance improvement

I am trying to do a multigraph window for plotting different data using pyqtgraph. I have a working version with no threads using timers for getting the data. I also tried a threaded version but it seems to have no performance boost when use htop for visually inspecting the CPU Usage.
I am new to GUIs and Threads so I followed this code that I saw in a youtube tutorial. It uses a QThread to get the CPU usage using psutil.cpu_percent in intervals of 0.1 seconds and then updates a progress bar.
import sys
from PyQt4 import QtCore
from PyQt4 import QtGui
import progress
import sysinfo
class MainUIClass(QtGui.QMainWindow, progress.Ui_MainWindow):
def __init__(self, parent = None):
super(MainUIClass, self).__init__(parent)
self.setupUi(self)
self.threadClass = ThreadClass()
self.threadClass.start()
self.connect(self.threadClass, QtCore.SIGNAL('CPU_VALUE'),
self.updateProgressBar)
def updateProgressBar(self, val):
self.progressBar.setValue(val)
class ThreadClass(QtCore.QThread):
def __init__(self, parent = None):
super(ThreadClass, self).__init__(parent)
def run(self):
while 1:
val = sysinfo.getCPU()
self.emit(QtCore.SIGNAL('CPU_VALUE'), val)
if __name__ == '__main__':
a = QtGui.QApplication(sys.argv)
app = MainUIClass()
app.show()
a.exec_()
I tried using cProfile for comparing performance but it throws lot of stuff that couldn't read, so I use the example of the progress bar to average the cpu usage after 10 seconds. Sorry if my measure performance method is so poor.
My two codes for benchmarking are
Threaded Version with a very consistent average CPU Usage of 64%:
import sys
from pyqtgraph.Qt import QtCore
from pyqtgraph.Qt import QtGui
import pyqtgraph as pg
import numpy as np
import time
class GraphWindow_Thread(pg.GraphicsWindow):
def __init__(self, rows, cols, titles):
super(GraphWindow_Thread, self).__init__()
# Code to draw the GUI
self.rows = rows
self.cols = cols
self.titles = titles
self.plots = [] # List of PlotItems
self.curves = [] # List of PlotDataItems in each PlotItem
for i in range(self.rows):
for j in range(self.cols):
p = self.addPlot()
self.plots.append(p)
if titles != [] or len(titles) == 1:
p.setLabel('left', self.titles[i+j+1])
p.setDownsampling(mode='peak')
p.setClipToView(True)
pp = p.plot(pen=(155, 255, 50))
pp1 = p.plot(pen=(55, 130, 255))
self.curves.append((pp, pp1))
self.nextRow()
# Thread to get the data and redraw plots
self.thread_graph = DataThread()
self.thread_graph.start()
self.connect(self.thread_graph, QtCore.SIGNAL('DATA_VALUE'),
self.update_plots)
def set_titles(self, titles):
for i, p in enumerate(self.plots):
p.setLabel('left', titles[i])
def update_plots(self, data, dataD):
for curve in self.curves:
curve[0].setData(data)
curve[1].setData(dataD)
class DataThread(QtCore.QThread):
def __init__(self, parent = None):
super(DataThread, self).__init__(parent)
def run(self):
while 1:
data = np.random.random((30,))
dataD = np.random.random((30,))
self.emit(QtCore.SIGNAL('DATA_VALUE'), data, dataD)
time.sleep(.1)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
gui = GraphWindow_Thread(2,3,[])
gui.show()
app.exec_()
No Thread Version with a very consistent average CPU Usage of 65%:
import sys
from pyqtgraph.Qt import QtCore
from pyqtgraph.Qt import QtGui
import pyqtgraph as pg
import numpy as np
import time
class GraphWindow(pg.GraphicsWindow):
def __init__(self, rows, cols, titles):
super(GraphWindow, self).__init__()
# Code to draw the GUI
self.rows = rows
self.cols = cols
self.titles = titles
self.plots = [] # List of PlotItems
self.curves = [] # List of PlotDataItems in each PlotItem
for i in range(self.rows):
for j in range(self.cols):
p = self.addPlot()
self.plots.append(p)
if titles != [] or len(titles) == 1:
p.setLabel('left', self.titles[i+j+1])
p.setDownsampling(mode='peak')
p.setClipToView(True)
pp = p.plot(pen=(155, 255, 50))
pp1 = p.plot(pen=(55, 130, 255))
self.curves.append((pp, pp1))
self.nextRow()
# Timer to redraw plots
timer = QtCore.QTimer(self)
self.connect(timer, QtCore.SIGNAL('timeout()'),self.update_plots)
timer.start(100)
def set_titles(self, titles):
for i, p in enumerate(self.plots):
p.setLabel('left', titles[i])
def update_plots(self):
np.random.seed()
data = np.random.random((30,))
dataD = np.random.random((30,))
for curve in self.curves:
curve[0].setData(data)
curve[1].setData(dataD)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
gui = GraphWindow(2,3,[])
gui.show()
app.exec_()
The full app is meant to be a window with multiple tabs, each one with a GraphWindow in which each graph uses a Thread for plotting different data.
What am I missing? Why my threaded version does not represent a performance improvement?

Python: Script doesn't run without print

I have written a small executable script. This program only works when I use a print-statement (at the end of the on_start()-method of the QDialog()class). Please, take a look in the on_start()-method of the QDialog-class.
As you can see I create an a task_thread- and work_object-instance. But, when I execute this script without print-statement nothing happens - no Traceback or other error messages.
Where is the bug? I guess the problem is that I create the instances at the local level - I am not sure. How can I fix it?
import sys
from time import sleep
from PyQt4.QtCore import QThread, pyqtSignal, Qt, QStringList, QObject, QTimer
from PyQt4.QtGui import QVBoxLayout, QPushButton, QDialog, QProgressBar, QApplication, \
QMessageBox, QTreeWidget, QTreeWidgetItem, QLabel
def create_items(total):
for elem in range(total):
yield elem
class WorkObject(QObject):
notify_progress = pyqtSignal(object)
fire_label = pyqtSignal(object)
finished = pyqtSignal()
def __init__(self, parent=None):
QObject.__init__(self, parent)
def add_items(self):
total = 190000
x = (total/100*1)
a = x
counter = 0
for element in create_items(10000):
counter += 1
self.notify_progress.emit((element))
self.fire_label.emit((counter))
if counter == x:
x += a
sleep(1)
if not self.keep_running:
self.keep_running = True
break
def run(self):
self.keep_running = True
self.add_items()
def stop(self):
self.keep_running = False
class MyCustomDialog(QDialog):
finish = pyqtSignal()
def __init__(self, parent=None):
QDialog.__init__(self, parent)
layout = QVBoxLayout(self)
self.tree = QTreeWidget(self)
self.label = QLabel(self)
self.pushButton_start = QPushButton("Start", self)
self.pushButton_stopp = QPushButton("Stopp", self)
self.pushButton_close = QPushButton("Close", self)
layout.addWidget(self.label)
layout.addWidget(self.tree)
layout.addWidget(self.pushButton_start)
layout.addWidget(self.pushButton_stopp)
layout.addWidget(self.pushButton_close)
self.pushButton_start.clicked.connect(self.on_start)
self.pushButton_stopp.clicked.connect(self.on_finish)
self.pushButton_close.clicked.connect(self.close)
def fill_tree_widget(self, i):
parent = QTreeWidgetItem(self.tree)
self.tree.addTopLevelItem(parent)
parent.setText(0, unicode(i))
parent.setCheckState(0, Qt.Unchecked)
parent.setFlags(parent.flags() | Qt.ItemIsTristate | Qt.ItemIsUserCheckable)
def on_label(self, i):
self.label.setText("Result: {}".format(i))
def on_start(self):
self.tree.clear()
self.label.clear()
task_thread = QThread(self)
work_object = WorkObject()
work_object.fire_label.connect(self.on_label)
work_object.notify_progress.connect(self.fill_tree_widget)
work_object.finished.connect(task_thread.quit)
self.finish.connect(work_object.stop)
work_object.moveToThread(task_thread)
task_thread.started.connect(work_object.run)
task_thread.finished.connect(task_thread.deleteLater)
timer = QTimer()
# I set the single shot timer on False,
# because I don't want the timer to fires only once,
# it should fires every interval milliseconds
timer.setSingleShot(False)
timer.timeout.connect(work_object.stop)
timer.start(0)
task_thread.start()
print
def on_finish(self):
self.finish.emit()
def main():
app = QApplication(sys.argv)
window = MyCustomDialog()
window.resize(600, 400)
window.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
You are right, work_object is created as a local instance.
Here is a simple solution:
work_object = WorkObject()
self.work_object = work_object # Add this line

Unexpected Output In Python While Using MoviePy

Hi i added a simple GUI in this script
A python script to automatically summarize soccer videos based on the crowd's reactions
The GUI script is the following
from Tkinter import *
from tkFileDialog import askopenfilename
from soccer_reacts import video_edit
class MyFrame(Frame):
def __init__(self):
master = Tk()
Label(master, text="Please Insert Video Path With Browse", width=30).grid(row=0)
Frame.__init__(self)
self.master.title("Video Editor")
self.master.geometry('{}x{}'.format(300, 200))
self.master.rowconfigure(5, weight=1)
self.master.columnconfigure(5, weight=1)
self.grid(sticky=W+E+N+S)
self.button = Button(self, text="Browse", command=self.load_file, width=15)
self.button.grid(row=1, column=0, sticky=W)
self.button2 = Button(self, text="Start", command=self.vid_reactions, width=15)
self.button2.grid(row=2, column=0, sticky=W)
def load_file(self):
fname = askopenfilename(filetypes=(("MP4 files", "*.mp4"),("All files", "*.*") ))
if fname:
self.fname = fname
def vid_reactions(self):
print("[*]Starting operation")
print("[*]File : "+self.fname)
video_edit(self.fname)
print("[*]Operation Finished")
if __name__ == "__main__":
MyFrame().mainloop()
End this is the new code of soccer cuts
import numpy as np # for numerical operations
from moviepy.editor import VideoFileClip, concatenate
def video_edit(file_name):
clip = VideoFileClip(file_name)
cut = lambda i: clip.audio.subclip(i,i+1).to_soundarray(fps=22000)
volume = lambda array: np.sqrt(((1.0*array)**2).mean())
volumes = [volume(cut(i)) for i in range(0,int(clip.audio.duration-2))]
averaged_volumes = np.array([sum(volumes[i:i+10])/10
for i in range(len(volumes)-10)])
increases = np.diff(averaged_volumes)[:-1]>=0
decreases = np.diff(averaged_volumes)[1:]<=0
peaks_times = (increases * decreases).nonzero()[0]
peaks_vols = averaged_volumes[peaks_times]
peaks_times = peaks_times[peaks_vols>np.percentile(peaks_vols,90)]
final_times=[peaks_times[0]]
for t in peaks_times:
if (t - final_times[-1]) < 60:
if averaged_volumes[t] > averaged_volumes[final_times[-1]]:
final_times[-1] = t
else:
final_times.append(t)
final = concatenate([clip.subclip(max(t-5,0),min(t+5, clip.duration))
for t in final_times])
final.to_videofile(file_name) # low quality is the default
When i run the new code, the output is a mp4 file, with the sound of the match
but with no video. I ve checked all the changes i made and i cannot find something wrong. Can anyone help?
I do not why but changing last line from
final.to_videofile(file_name)
to final.write_videofile('The result.mp4')
was a solution

Attribute error while executing a python code

I am a student and working on GNU Radio.
I have a python code which i want to run in GNU radio companion but i am unable to search for the right block to execute that code...can anyone help me with that??When I execute the same python code(not in GNU), I get the following error:
AttributeError: 'top_block_sptr' object has no attribute 'wxgui_'
the code is as shown:
#!/usr/bin/env python
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio import uhd
#from gnuradio import window
from gnuradio.eng_option import eng_option
#from gnuradio.gr import firdes
from gnuradio.wxgui import forms
from gnuradio.wxgui import waterfallsink2
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import wx
class top_block(grc_wxgui.top_block_gui):
def __init__(self):
grc_wxgui.top_block_gui.__init__(self, title="Top Block")
_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))
##################################################
# Variables
###
###############################################
self.variable_slider_1 = variable_slider_1 = 32
self.variable_slider_0 = variable_slider_0 = 0
self.samp_rate = samp_rate = 21e6
self.gain = gain = variable_slider_1
self.delay_length = delay_length= variable_slider_0
##################################################
# Blocks
##################################################
self.wxgui_waterfallsink2_0_0 = waterfallsink2.waterfall_sink_c(
self.GetWin(),
baseband_freq=0,
dynamic_range=100,
ref_level=0,
ref_scale=2.0,
sample_rate=samp_rate,
fft_size=512,
fft_rate=15,
average=False,
avg_alpha=None,
title="Output Waterfall Plot",
)
self.GridAdd(self.wxgui_waterfallsink2_0_0.win, 0, 10, 10, 10)
self.wxgui_
waterfallsink2_0 = waterfallsink2.waterfall_sink_c(
self.GetWin(),
baseband_freq=0,
dynamic_range=100,
ref_level=0,
ref_scale=2.0,
sample_rate=samp_rate,
fft_size=512,
fft_rate=15,
average=False,
avg_alpha=None,
title="Input Waterfall Plot",
)
self.GridAdd(self.wxgui_waterfallsink2_0.win, 0, 0, 10, 10)
_variable_slider_1_sizer = wx.BoxSizer(wx.VERTICAL)
self._variable_slider_1_text_box = forms.text_box(
parent=self.GetWin(),
sizer=_variable_slider_1_sizer,
value=self.variable_slider_1,
callback=self.set_variable_slider_1,
label="Output Gain",
converter=forms.float_converter(),
proportion=0,
)
self._variable_slider_1_slider = forms.slider(
parent=self.GetWin(),
sizer=_variable_slider_1_sizer,
value=self.variable_slider_1,
callback=self.set_variable_slider_1,
minimum=0,
maximum=32,
num_steps=31,
style=wx.SL_HORIZONTAL,
cast=float,
proportion=1,
)
self.GridAdd(_variable_slider_1_sizer, 12, 10, 1, 9)
_variable_sl
ider_0_sizer = wx.BoxSizer(wx.VERTICAL)
self._variable_slider_0_text_box = forms.text_box(
parent=self.GetWin(),
sizer=_variable_slider_0_sizer,
value=self.variable_slider_0,
callback=self.set_variable_slider_0,
label="Delay Length",
converter=forms.int_converter(),
proportion=0,
)
self._variable_slider_0_slider = forms.slider(
parent=self.GetWin(),
sizer=_variable_slider_0_sizer,
value=self.variable_slider_0,
callback=self.set_variable_slider_0,
minimum=0,
maximum=710000,
num_steps=1000,
style=wx.SL_HORIZONTAL,
cast=int,
proportion=1,
)
self.GridAdd(_variable_slider_0_sizer, 10, 10, 1, 9)
self.uhd_usrp_source_0 = uhd.usrp_source(
device_addr="",
stream_args=uhd.stream_args(
cpu_format="fc32",
channels=range(1),
),
)
self.uhd_usrp_source_0.set_samp_rate(samp_rate)
self.uhd_usrp_source_0.set_center_freq(2.28e9, 0)
self.uhd_usrp_source_0.set_gain(0, 0)
self.uhd_usrp_sink_0 = uhd.usrp_sink(
device_addr="",
stream_args
=uhd.stream_args(
cpu_format="fc32",
channels=range(1),
),
)
self.uhd_usrp_sink_0.set_samp_rate(samp_rate)
self.uhd_usrp_sink_0.set_center_freq(2.28e9, 0)
self.uhd_usrp_sink_0.set_gain(gain, 0)
self.gr_file_source_0_0 = gr.file_source(
gr.sizeof_gr_complex*1,
"/home/ubuntu/radar-rx3.capture", True)
self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1,
"/home/ubuntu/radar-rx3.capture", True)
self.gr_delay_0_0 = gr.delay(gr.sizeof_gr_complex*1, delay_length)
self.blocks_mult
iply_xx_0 = blocks.multiply_vcc(1)
##################################################
# Connections
##################################################
self.connect((self.uhd_usrp_source_0, 0), (self.wxgui_waterfallsink2_0, 0))
self.connect((self.gr_file_source_0_0, 0), (self.gr_delay_0_0, 0))
self.connect((self.gr_file_source_0, 0), (self.blocks_multiply_xx_0, 0))
self.connect((self.gr_delay_0_0, 0), (self.blocks_multiply_xx_0, 1))
self.connect((self.blocks_multiply_xx_0, 0), (self.uhd_usrp_sink_0, 0))
self.connect((self.blocks_multiply_xx_0, 0), (self.wxgui_waterfallsink2_0_0, 0))
def get_variable_slider_1(self):
return self.variable_slider_1
def set_variable_slider_1(self, variable_slider_1):
self.variable_slider_1 = variable_slider_1
self.set_gain(self.variable_slider_1)
self._variable_slider_1_slider.set_value(self.variable_slider_1)
self._variable_slider_1_text_box.set_value(self.variable_slider_1)
def get_variable_slider_0(self):
return self.variable_slider_0
def set_variable_slider_0(self, variable_slider_0):
self.variable_slider_0 = variable_slider_0
self.set_delay_length(self.variable_slider_0)
self._variable_slider_0_slider.set_value(self.variable_slider_0)
self._variable_slider_0_text_box.set_value(self.variable_slider_0)
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
self.wxgui_waterfallsink2_0.set_sample_rate(self.samp_rate)
self.wxgui_waterfallsink2_0_0.set_sample_rate(self.samp_rate)
self.uhd_usrp_sink_0.set_samp_rate(self.samp_rate)
self.uhd_usrp_source_0.set_samp_rate(self.samp_rate)
def get_gain(self):
return self.gain
def set_gain(self, gain):
self.gain = gain
self.uhd_usrp_sink_0.set_gain(self.gain, 0)
def get_delay_length(self):
return self.delay_length
def set_delay_length(self, delay_length):
self.delay_length = delay_length
self.gr_delay_0_0.set_delay(self.delay_length)
if __name__ == '__main__':
parser = OptionParser(option_class=eng_option,usage="%prog: [options]")
(options, args) = parser.parse_args()
tb = top_block()
tb.Run(True)
There's an erroneous line break in
self.wxgui_
waterfallsink2_0 = waterfallsink2.waterfall_sink_c(...
remove the wrong line breaks, and it should work. If in doubt, re-generate the python file using the GNU Radio Companion. Make sure your editor doesn't add line breaks where he should not.