Trying to make a program to monitor usb drive connections using pyudev. Here is the code:
def __init__(self):
self.window = gtk.Window()
self.window.set_default_size(300, 300)
self.vbox= gtk.VBox(False, 5)
label = gtk.Label("Please plug the device")
context = Context()
monitor = Monitor.from_netlink(context)
monitor.filter_by(subsystem='block',device_type='disk')
observer = GUDevMonitorObserver(monitor)
observer.connect("device-added",self.device_connected)
monitor.start()
self.vbox.pack_start(label)
self.window.add(self.vbox)
self.window.show_all()
def device_connected(self, device):
self.window.remove(self.vbox)
label = gtk.Label('{0!r} added'.format(device))
self.vbox.pack_end(label)
self.window.add(self.vbox)
The traceback :
vineet@vineet:~/Documents/Project$ python project.py
TypeError: device_connected() takes exactly 2 arguments (3 given)
TypeError: device_connected() takes exactly 2 arguments (3 given)
Please help me rectify this.
I am trying to use the piece of code given on the docs page. As you will notice , the device_connected
method has the arguments - device_connected(observer,device)
but the code doesn't work in that case either. It returns the throws the same error. But I was wondering how it would work in the first place. Shouldn't every method of a class have self
as an argument?