account for all GLib.id_add_watch variants

This commit is contained in:
Daniel Pavel 2013-06-08 21:07:24 +02:00
parent 5cf6777340
commit 2a6662472d
1 changed files with 12 additions and 11 deletions

View File

@ -136,25 +136,26 @@ def monitor_glib(callback, *device_filters):
event = monitor.receive_device() event = monitor.receive_device()
if event: if event:
action, device = event action, device = event
# print ("udev action:", action, device)
if action == 'add': if action == 'add':
for filter in filters: for filter in filters:
d_info = _match('add', device, *filter) d_info = _match(action, device, *filter)
if d_info: if d_info:
GLib.idle_add(cb, 'add', d_info) GLib.idle_add(cb, action, d_info)
break break
elif action == 'remove': elif action == 'remove':
for filter in filters: # the GLib notification does _not_ match!
d_info = _match('remove', device, *filter) pass
if d_info:
GLib.idle_add(cb, 'remove', d_info)
break
return True return True
try: try:
# io_add_watch_full appeared in a later version of glib # io_add_watch_full may not be available...
GLib.io_add_watch_full(m, GLib.PRIORITY_LOW, GLib.IO_IN, _process_udev_event, callback, device_filters) GLib.io_add_watch_full(m, GLib.PRIORITY_LOW, GLib.IO_IN, _process_udev_event, callback, device_filters)
except: except AttributeError:
GLib.io_add_watch(m, GLib.IO_IN, _process_udev_event, callback, device_filters) try:
# and the priority parameter appeared later in the API
GLib.io_add_watch(m, GLib.PRIORITY_LOW, GLib.IO_IN, _process_udev_event, callback, device_filters)
except:
GLib.io_add_watch(m, GLib.IO_IN, _process_udev_event, callback, device_filters)
m.start() m.start()