Browse Source

Add UsbHandler

This handler runs callback on usb events.

When a usb is connected following events will capture:
 - add
 - change
 - add
 - bind
 - bind

and when usb mouse is removed following will captured:
- unbind
- remove
- unbind
- remove

these effects are tested with device logitech (R) B100 mouse.
pull/2/head
Ali Hatami Tajik 2 years ago
parent
commit
803e8f4de5
  1. 23
      src/scripts/python/udevhandle.py

23
src/scripts/python/udevhandle.py

@ -1,5 +1,5 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from pyudev import Context, Monitor, MonitorObserver from pyudev import Context, Monitor, MonitorObserver, Device
class Handler(ABC): class Handler(ABC):
@ -26,7 +26,7 @@ class Handler(ABC):
self.observer.start() self.observer.start()
@abstractmethod @abstractmethod
def callback(self, device): def callback(self, device: Device):
"""Callback """Callback
This method must be implemented by child calsses. This method is This method must be implemented by child calsses. This method is
@ -44,3 +44,22 @@ class Handler(ABC):
device (pyudev.Device): modified device passed by self.observer device (pyudev.Device): modified device passed by self.observer
""" """
self.callback(device) self.callback(device)
class MouseHandler(Handler):
def __init__(self) -> None:
"""Initiate UsbHanlder
Initialization contains two major steps. First it would do a
configuration for currently available devices and then it would wait for
USB udev events to reconfigure the settings. configurations would be
done by (This part is not decided yet. it could be done by BASH SCRIPTS
or we can invoke xinput binaries via python itself. a bash script
solution would be benefitial since it can used as utility).
"""
# TODO: use somthing that only captures
super().__init__('usb')
def callback(self, device):
print(device.action)
Loading…
Cancel
Save