QTextBrowser doesnt update with append, when calling this function from another class

90 Views Asked by At

Hello I have two function. One Class is a watchdog and the other class is a pyqt gui. I have three QTextBrowser. If I connect a button to the function in the QT Class and call the function my TextBrowser get updated normally. If I trigger an event in the watchdog and the watchdog class calls my QT class, my TextBrowser didnt update.

This is how I call the function from another class

class Handler(FileSystemEventHandler):

@staticmethod
def on_any_event(event):
    if event.is_directory:
        return None

    elif event.event_type == 'created':
        # Event is created, you can process it now
        print("Watchdog received created event - % s." % event.src_path)
        window = MyWindow()
        window.start_xl()

This is the function, which works when i call it with a button.

    def update(self):
    terminate('cmd.exe')
    terminate('EXCEL.exe')

    self.text_Browser = self.ui.textBrowser
    self.text_Browser_2 = self.ui.textBrowser_2
    self.text_Browser_3 = self.ui.textBrowser_3

    self.text_Browser.setTextColor(QtGui.QColor('white'))
    self.text_Browser_2.setTextColor(QtGui.QColor('white'))
    self.text_Browser_3.setTextColor(QtGui.QColor('white'))

    path = "C:/Program Files (x86)/STIHL/Faps/Temp"
    # Check if the folder is empty
    if os.listdir(path):
        # Get a list of all files in the directory
        files = os.listdir(path)
        # The first file in the directory
        first_file = files[0]
        self.text_Browser.append("FINISHED")
        self.text_Browser_2.append("goal_dir")
        self.text_Browser_3.append(first_file)

    else:
        self.ui.label.setText("Ordner ist Leer")
        pass

This is the function which is called by the class Handler. Everything is working besides the updating of the TextBrowser

def start_xl(self):

    terminate('cmd.exe')
    terminate('EXCEL.exe')

    self.text_Browser = self.ui.textBrowser
    self.text_Browser_2 = self.ui.textBrowser_2

    self.text_Browser.setTextColor(QtGui.QColor('white'))
    self.text_Browser_2.setTextColor(QtGui.QColor('white'))

    print(self.text_Browser)
    print(self.text_Browser_2)


        # QtCore.QMetaObject.invokeMethod(self.text_Browser, "append", QtCore.Qt.QueuedConnection,
        #                                 QtCore.Q_ARG(str, "FINISHED"))
        # QtCore.QMetaObject.invokeMethod(self.text_Browser_2, "append", QtCore.Qt.QueuedConnection,
        #                                 QtCore.Q_ARG(str, "goal_dir"))

        self.text_Browser.setPlainText("FINISHED")
        # self.text_Browser_2.append("goal_dir")

I tried it with invoke and append. The kill process get started, so the function is called. Is there something I should consider?

0

There are 0 best solutions below