I wanted to write a small application that will display usb device\'s name in a small text browser, when it has been inserted. I am using pyudev to do that. Instead of using
You need to start the monitor before starting the event-loop. Also, avoid using the @pyqtSlot
decorator - it's rarely needed, and it's very easy to get the definition wrong if you don't know what you're doing (as you did in your example).
So your code should look like this:
class mainWindow(QWidget, Ui_Form):
def __init__(self):
...
context = Context()
monitor = Monitor.from_netlink(context)
monitor.filter_by(subsystem='tty')
self.observer = MonitorObserver(monitor)
self.observer.deviceEvent.connect(self.device_connected)
monitor.start()
def device_connected(self, device):
self.textBrowser.append(device.sys_name)
print("Test")
def main():
import sys
app = QApplication(sys.argv)
window = mainWindow()
window.show()
app.exec_()
PS: it might be a good idea to comment out the filter_by
line and plug in a usb device just to make sure everything is working okay.