diff --git a/src/scripts/python/changemouse.py b/src/scripts/python/changemouse.py index db5494d..f10447d 100644 --- a/src/scripts/python/changemouse.py +++ b/src/scripts/python/changemouse.py @@ -36,10 +36,9 @@ if __name__ == "__main__": pointers = xup.get_pointers() # TODO filter functionality inside utilities core_master = list(filter(lambda x: "Virtual core" in x.name, pointers))[0] - + for pointer in filter(lambda x: x.slave, pointers): if not "eGalax" in pointer.name: com.reattach(pointer.id, core_master.id) else: - pass diff --git a/src/scripts/python/setupmonitor.py b/src/scripts/python/setupmonitor.py index ba3e849..aa43d9e 100644 --- a/src/scripts/python/setupmonitor.py +++ b/src/scripts/python/setupmonitor.py @@ -1,4 +1,3 @@ - """Setup Monitor Script Author: Ali Hatami Tajik [hatam](mailto:a.hatam008@gmail.com) diff --git a/src/scripts/python/udevhandle.py b/src/scripts/python/udevhandle.py index 5891dac..1e79eb3 100644 --- a/src/scripts/python/udevhandle.py +++ b/src/scripts/python/udevhandle.py @@ -57,9 +57,8 @@ class MouseHandler(Handler): 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') - + # TODO: use somthing that only captures + super().__init__("usb") def callback(self, device): - print(device.action) \ No newline at end of file + print(device.action) diff --git a/src/scripts/python/util/common.py b/src/scripts/python/util/common.py index a66bb6f..6d40ee7 100644 --- a/src/scripts/python/util/common.py +++ b/src/scripts/python/util/common.py @@ -1,10 +1,11 @@ """Common Utilities""" + def max_match(a: str, b: str) -> str: """Maximum matching of intersection of pair of string This function will return the intersection of two strings from the start. - + Example: >>> a = "/sys/devices/folan/bahman" >>> b = "/sys/devices/fol/bahman" @@ -19,10 +20,10 @@ def max_match(a: str, b: str) -> str: str: intersection of two strings """ i = 0 - + if len(b) < len(a): a, b = b, a - + for c in a: if b[i] == c: i += 1 diff --git a/src/scripts/python/util/egalax.py b/src/scripts/python/util/egalax.py index 2a29c0b..074735a 100644 --- a/src/scripts/python/util/egalax.py +++ b/src/scripts/python/util/egalax.py @@ -9,22 +9,23 @@ from pathlib import Path VENDOR_ID = "0EEF" DEVICE_ID = "C000" + def get_egalax_path() -> Path: """Get device path - + This function will return the path of the HID device related to the pannel. NOTE that it is not the path of the EDID but it can be extracted from it. Returns: Path: Path of the eGalax hid device OR None if device is not ceonnected """ - query = '*' + VENDOR_ID + ':' + DEVICE_ID + '*' - devices = list(Path('/sys/devices').rglob(query)) + query = "*" + VENDOR_ID + ":" + DEVICE_ID + "*" + devices = list(Path("/sys/devices").rglob(query)) if devices: return devices[0] else: return None - + def is_egalax_connected() -> bool: """Checks if device is connected @@ -36,4 +37,4 @@ def is_egalax_connected() -> bool: bool: True if device is connected """ devpath = get_egalax_path() - return bool(devpath) \ No newline at end of file + return bool(devpath) diff --git a/src/scripts/python/util/pointer.py b/src/scripts/python/util/pointer.py index 364e515..d645a4b 100644 --- a/src/scripts/python/util/pointer.py +++ b/src/scripts/python/util/pointer.py @@ -17,7 +17,7 @@ class XInput: Args: name (str): name of the input. No processing is done on the name id (int): id of the input - is_master (bool): master status of the input device + is_master (bool): master status of the input device """ self.name = name self.id = id @@ -43,7 +43,7 @@ class Pointer(XInput): def get_short_pointer(id) -> Pointer: - """Generates Pointer object corresponding to id (short attrs) + """Generates Pointer object corresponding to id (short attrs) Args: id (int): pointer id @@ -56,15 +56,12 @@ def get_short_pointer(id) -> Pointer: ValueError: if id is not a pointer id """ desc = xutil.get_list_short(id) - name, props = desc.rsplit('id=', 1) + name, props = desc.rsplit("id=", 1) if "pointer" in props: is_master = "master" in props - return Pointer( - name.strip(), - props.split(maxsplit=1)[0], - is_master) + return Pointer(name.strip(), props.split(maxsplit=1)[0], is_master) else: - raise TypeError(f'id[{id}] is not a pointer id') + raise TypeError(f"id[{id}] is not a pointer id") def get_pointers(is_short=True): @@ -99,8 +96,8 @@ def get_pointers(is_short=True): def get_touch_master(pointers): """returns Pointer of the master touch pointer - + Args: - pointers (List[Pointes]): list of pointers queried + pointers (List[Pointes]): list of pointers queried """ - pass + pass diff --git a/src/scripts/python/util/randr.py b/src/scripts/python/util/randr.py index 82f6fae..37fe1da 100644 --- a/src/scripts/python/util/randr.py +++ b/src/scripts/python/util/randr.py @@ -1,4 +1,3 @@ - """RandR Author: Ali Hatami Tajik [hatam](mailto:a.hatam008@gmail.com) @@ -35,10 +34,11 @@ class Pos(Enum): Position the output relative to the position of another output. """ - LEFT_OF = 0, - RIGHT_OF = 1, - ABOVE = 2, - BELOW = 3, + + LEFT_OF = (0,) + RIGHT_OF = (1,) + ABOVE = (2,) + BELOW = (3,) SAME_AS = 4 @@ -47,9 +47,10 @@ class RotationDir(Enum): This causes the output contents to be rotated in the specified direction. """ - NORMAL = 0, - LEFT = 1, - RIGHT = 2, + + NORMAL = (0,) + LEFT = (1,) + RIGHT = (2,) INVERTED = 3 @@ -58,9 +59,10 @@ class ReflectDir(Enum): This causes the output contents to be reflected across the specified axes. """ - NORMAL = 0, - X = 1, - Y = 2, + + NORMAL = (0,) + X = (1,) + Y = (2,) XY = 3 @@ -71,9 +73,10 @@ class Setting: This data struct will be used as the config of each screen. Note that default screen cannot be use """ - resolution = None, - is_primary = False, - is_enabeled = True, + + resolution = (None,) + is_primary = (False,) + is_enabeled = (True,) rotation = None position = None reflection = None @@ -82,9 +85,10 @@ class Setting: @dataclass class Mode: """Mode - + Mode of the screen including width, height, refresh rate(s) """ + height: int = 0 width: int = 0 frequency: List[int] = [] @@ -94,14 +98,14 @@ class Screen: """Screen class This class will hold screen properties and methods related to the screens. - + At the time it will use xrandr (and not the verbose mode) to list the screens and modes. """ - + class Monitor: """Monitor Class - + List Monitor Outputs and their states - """ \ No newline at end of file + """ diff --git a/src/scripts/python/util/x.py b/src/scripts/python/util/x.py index dee5673..a9cdba7 100644 --- a/src/scripts/python/util/x.py +++ b/src/scripts/python/util/x.py @@ -1,8 +1,9 @@ import subprocess from typing import List from multipledispatch import dispatch +from pathlib import Path -ENCODING = 'utf-8' +ENCODING = "utf-8" @dispatch() @@ -10,7 +11,8 @@ def get_list_short(): """Returns string output of the `xinput --list --short` command encoded as UTF-8""" completed = subprocess.run( - ['xinput', '--list', '--short'], capture_output=True) + ["xinput", "--list", "--short"], capture_output=True + ) return completed.stdout.decode(ENCODING) @@ -25,12 +27,13 @@ def get_list_short(id): ValueError: in case of id not found in devices """ completed = subprocess.run( - ['xinput', '--list', '--short', str(id)], capture_output=True) + ["xinput", "--list", "--short", str(id)], capture_output=True + ) if completed.returncode == 0: return completed.stdout.decode(ENCODING) else: - ValueError(f'id[{id}] is not registered') + ValueError(f"id[{id}] is not registered") def reattach(id, master): @@ -44,7 +47,8 @@ def reattach(id, master): id is not valid, xinput will not do anything and nothing bad will happen :) """ completed = subprocess.run( - ['xinput', '--reattach', str(id), str(master)], capture_output=True) + ["xinput", "--reattach", str(id), str(master)], capture_output=True + ) return completed.returncode @@ -52,22 +56,22 @@ def reattach(id, master): def get_ids() -> List[int]: """returns list of ids registered in xinput""" completed = subprocess.run( - ['xinput', '--list', '--id-only'], capture_output=True) + ["xinput", "--list", "--id-only"], capture_output=True + ) return list(map(int, completed.stdout.decode(ENCODING).split())) -def create_master(name: str = 'touch'): +def create_master(name: str = "touch"): """Creates master with specified name Args: name (str, optional): name of the master. Defaults to 'touch'. """ - completed = subprocess.run( - ['xinput create-master', name] - ) - + completed = subprocess.run(["xinput create-master", name]) + return completed.returncode def map_to_output(output, device_id): - pass \ No newline at end of file + # TODO + pass