From 2a6662472de2898d7f51f9c0925ac0ca88114f43 Mon Sep 17 00:00:00 2001 From: Daniel Pavel Date: Sat, 8 Jun 2013 21:07:24 +0200 Subject: [PATCH] account for all GLib.id_add_watch variants --- lib/hidapi/udev.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/hidapi/udev.py b/lib/hidapi/udev.py index 065103ab..b56ab0a3 100644 --- a/lib/hidapi/udev.py +++ b/lib/hidapi/udev.py @@ -136,25 +136,26 @@ def monitor_glib(callback, *device_filters): event = monitor.receive_device() if event: action, device = event - # print ("udev action:", action, device) if action == 'add': for filter in filters: - d_info = _match('add', device, *filter) + d_info = _match(action, device, *filter) if d_info: - GLib.idle_add(cb, 'add', d_info) + GLib.idle_add(cb, action, d_info) break elif action == 'remove': - for filter in filters: - d_info = _match('remove', device, *filter) - if d_info: - GLib.idle_add(cb, 'remove', d_info) - break + # the GLib notification does _not_ match! + pass return True + 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) - except: - GLib.io_add_watch(m, GLib.IO_IN, _process_udev_event, callback, device_filters) + except AttributeError: + 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()