Reputation: 356
I'm working on Pyside2, python 3.8, windows 10
I have an app that parses a file and show data in QtableView. What I'm trying to implement is a Dialog Window with only one button, the only purpose of this dialog window is to give a minimalistic and simple view to the user, where he can first select the file to be parsed and have a Loading progress barwhile the LoadData() function is runned. The Home Dialog should only be hidden/closed when the parsing is done.
Here's what I've tried so far:
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self, file_name,parent=None):
"""
..
__init__ code lines
"""
self.change_val = QtCore.Signal(int)
self.change_val[int].connect(self.set_progress_val)
self.progress = QtWidgets.QProgressDialog('loading...', 'cancel', 0, 100, self)
self.progress.show()
self.LoadData(d.path)
@QtCore.Slot(int)
def set_progress_val(self, val):
self.progress.setValue(val)
def LoadData(self, file_path):
"""
Parsing lines of code
..
self.change_val.emit(30)
..
..
self.change_val.emit(60)
..
..
"""
self.progress.hide()
#Parsing finished -> show the mainWindow
self.show()
class HomeDialog(QtWidgets.QDialog, home_dialog.Ui_Dialog):
def __init__(self, parent=None):
super(HomeDialog, self).__init__(parent)
self.setupUi(self)
self.openB6.clicked.connect(self.get_file_name)
def get_file_name(self):
file_name = QtWidgets.QFileDialog.getOpenFileName(self, 'Open config file',
dir=path.join("/"),
filter="B6 (*.b6)")
if not file_name[0]:
return None
else:
self.path = file_name
self.accept()
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
app.setStyle(ProxyStyle())
d = HomeDialog()
if d.exec_():
mainWin = MainWindow(file_name=d.path)
mainWin.show()
sys.exit(app.exec_())
I'm getting the follwoing error on self.change_val[int].connect(self.set_progress_val)
line :
'str' object has no attribute 'connect'
Upvotes: 0
Views: 567
Reputation: 244202
The signals are not declared in the class constructor or in the methods but in the static part:
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
change_val = QtCore.Signal(int)
def __init__(self, file_name,parent=None):
"""
..
__init__ code lines
"""
self.change_val[int].connect(self.set_progress_val)
self.progress = QtWidgets.QProgressDialog('loading...', 'cancel', 0, 100, self)
self.progress.show()
self.LoadData(d.path)
Upvotes: 1