Python Forum
[PyQt] Using Qt to emit a signal (or maybe with QTimer)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Using Qt to emit a signal (or maybe with QTimer)
#2
I took this answer for a related question.

https://stackoverflow.com/questions/6884...hdog-on-qt

And maybe modified it to work with your code. I do not have the watchdog module installed and I don't know anything about your image analyzer. Really untested code here:
# Many imports

class Bridge(QtCore.QObject):
    '''Serves as a bridge between watchdog thread and Qt thread'''
    created = QtCore.Signal(FileSystemEvent)


class Handler(FileSystemEventHandler):
    '''watchdog observer event handler'''
    def __init__(self):
        super().__init__()
        self.bridge = Bridge()

    def on_created(self, event):
        '''Emit signal when hdf5 file is created'''
        if event.src_path[-4:] == 'hdf5':
            self.bridge.created.emit(event)


class MyMainWindow(QtGui.QMainWindow, Ui_MainWindow):
    """My designer created window"""

    def __init__(self, path):
        super().__init__()

        ...

        # Create observer to signal my new_file method when an
        # hdf5 file is created in path.
        handler = Handler()
        handler.bridge.created.connect(self.new_file)
        observer = Observer()
        observer.schedule(handler, path, recursive=True)
        observer.start()

    def new_file(self, event):
        '''Method called when hdf5 file is created.  Passed a FileSystemEvent'''
        print(event.src_path)
        ...

def main():
    path = ...
    app = QtWidgets.QApplication()
    form = MyMainWindow(path)
    form.show()
    app.exec_()

if __name__ == '__main__':
    main()
Reply


Messages In This Thread
RE: Using Qt to emit a signal (or maybe with QTimer) - by deanhystad - Oct-07-2021, 01:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] About QTimer and QThread and some general question catlessness 1 2,695 Nov-02-2021, 07:20 PM
Last Post: deanhystad
  [PyQt] QTimer not activating function after timeout LavaCreeperKing 0 3,865 Apr-03-2017, 09:09 PM
Last Post: LavaCreeperKing

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020