ich brauch mal eure Hilfe, ich bin in der GUI-Welt recht neu und deshalb wäre es schön wenn ihr so manches verzeiht
Jetzt zu meinem Projekt, ich hab vor eine GUI zu schreiben wenn ich einen Button klicke soll sich ein zweites Fenster öffnen mit dem Hinweis, das sich das Fenster automatisch schließt.
Im Hintergrund soll, sobald das zweite Fenster offen ist ein Background prozess gestartet werden.
Anbei habe ich mal ein stück Code das die Funktion relativ gut macht, jedoch schließt er das Sub-Fenster und öffnet das selbe wieder, normal soll er wieder das Main Fenster zeigen.
Code: Alles auswählen
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QThread, pyqtSignal
import sys
import time
from pyqt_ui import Ui_Form_Sub, Ui_Form_Main
class Main_Window(QtWidgets.QMainWindow, Ui_Form_Main):
switch_window = QtCore.pyqtSignal()
def __init__(self, parent=None):
super(QtWidgets.QWidget, self).__init__(parent)
self.setupUi(self)
self.pushButton.setText("Git clone with Thread")
# Here we are telling to call git_clone method when
# someone clicks on the pushButton.
self.pushButton.clicked.connect(self.git_clone)
self.git_thread = CloneThread() # This is the thread object
# Connect the signal from the thread to the finished method
self.git_thread.signal.connect(self.finished)
def git_clone(self):
self.switch_window.emit()
self.pushButton.setEnabled(False) # Disables the pushButton
self.textEdit.setText("Started git clone operation.") # Updates the UI
self.git_thread.start() # Finally starts the thread
def finished(self, run):
#self.textEdit.setText("Close Popup".format(result)) # Show the output to the user
self.pushButton.setEnabled(True) # Enable the pushButton
########
########
#######
#falscher switch
self.switch_window.emit()
class CloneThread(QThread):
signal = pyqtSignal('PyQt_PyObject')
switch_window = QtCore.pyqtSignal()
def __init__(self):
QThread.__init__(self)
#evtl. umbasteln zu treeview
self.git_url = ""
# run method gets called when we start the thread
def run(self):
#hier wird rfid bearbeitet und wartet auf das ok
time.sleep(1)
#reader.write(text)
# git clone done, now inform the main thread with the output
self.signal.emit(self)
class RFID_popup(QtWidgets.QWidget, Ui_Form_Sub):
switch_window = QtCore.pyqtSignal()
def __init__(self):
QtWidgets.QWidget.__init__(self)
self.setupUi(self)
def pushbutton_handler(self):
print("123")
self.switch_window.emit()
class Controller:
def __init__(self):
pass
def show_main_win(self):
self.login = Main_Window()
self.login.switch_window.connect(self.show_rfid_popup)
self.login.show()
def show_rfid_popup(self):
self.window = RFID_popup()
self.window.switch_window.connect(self.show_main_win)
self.login.close()
self.window.show()
def main():
app = QtWidgets.QApplication(sys.argv)
controller = Controller()
controller.show_main_win()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
Aber vielleicht ist es auch ein ganz was anders.
Hoffe ihr könnt mich, mein Problem verstehen und mir hoffentlich auf meinen Fehler aufmerksam machen.
mfg Schechner