0

I have a GUI which is created by PyQt. It works for copy any file chosen by Tkinter File Choose Dialog. I select the file to send but when I tried to send it, the shutil.copy() function starts to run. However, meanwhile, the GUI is freezing and is not react anyway.

class main(QMainWindow):

def __init__(self):
    super().__init__()
    self.MyUI()
    self.root = Tk()
    self.root.withdraw()

    self.isAlive = True
    self.lock= threading.Lock()

    self.angleDiffPitch = 0
    self.angleDiffRoll = 0
    self.angleDiffYaw = 0

    self.tempDataForPacketNumber = 0

    # gui.py
    self.gui = gui()
    self.gui.setupUi(self)
    self.msg = self.gui.msg

    self.m1 = mesh.Mesh.from_file('assets/uydu.stl')

    self.plottingThread = threading.Thread(
        target=self.pltAndSimFunc)
    self.plottingThread.daemon = True

    # start button
    self.gui.baslatButton.clicked.connect(self.startGcs)

    # stop button
    self.gui.durdurButton.clicked.connect(self.stopGcs)

    # video secme
    self.gui.secButton.clicked.connect(self.chooseFunc)

    # ayrilma
    self.gui.ayrilButton.clicked.connect(self.ayrilFunc)

    # video gönderme
    self.gui.gonderButton.clicked.connect(self.sendFileThread)

    # motor tahrik
    self.gui.tahrikButton.clicked.connect(self.tahrikFunc)

    # motor tahrik stop
    self.gui.tahrikButtonStop.clicked.connect(self.tahrikFuncStop)

def chooseFunc(self):
    fileName = askopenfile(mode='r')
    self.gui.lineEdit.setText(str(fileName.name))
    self.gui.gonderButton.setEnabled(True)

    self.DIRECTORY = self.gui.lineEdit.text()
    self.TARGET_DIRECTORY = r"Z:/"
    self.BASE_NAME = os.path.basename(self.DIRECTORY)

def sendFile(self):
    shutil.copy(self.DIRECTORY, self.TARGET_DIRECTORY+self.BASE_NAME)

    if(os.path.exists(self.TARGET_DIRECTORY+self.BASE_NAME)):
        self.msg.setWindowTitle('İşlem Tamamlandı')
        self.msg.setText('Dosya gönderimi başarıyla tamamlandı')
        self.msg.setIcon(QtWidgets.QMessageBox.Information)
        x = self.msg.exec_()
        dt.videoPaketGuncellemeKomut()

def sendFileThread(self):
    sendThread = threading.Thread(target=self.sendFile)
    sendThread.start()

I tried to use threads, but it does not work maybe I cannot write the structure of it. How can I solve this problem? Here is my code:

thanks for your help? :)

woz523
  • 39
  • 6

0 Answers0