Browse Source

Reformat python scripts

pull/2/head
Ali Hatami Tajik 2 years ago
parent
commit
f114fe248b
  1. 3
      src/scripts/python/changemouse.py
  2. 1
      src/scripts/python/setupmonitor.py
  3. 7
      src/scripts/python/udevhandle.py
  4. 7
      src/scripts/python/util/common.py
  5. 11
      src/scripts/python/util/egalax.py
  6. 19
      src/scripts/python/util/pointer.py
  7. 42
      src/scripts/python/util/randr.py
  8. 28
      src/scripts/python/util/x.py

3
src/scripts/python/changemouse.py

@ -36,10 +36,9 @@ if __name__ == "__main__":
pointers = xup.get_pointers() pointers = xup.get_pointers()
# TODO filter functionality inside utilities # TODO filter functionality inside utilities
core_master = list(filter(lambda x: "Virtual core" in x.name, pointers))[0] core_master = list(filter(lambda x: "Virtual core" in x.name, pointers))[0]
for pointer in filter(lambda x: x.slave, pointers): for pointer in filter(lambda x: x.slave, pointers):
if not "eGalax" in pointer.name: if not "eGalax" in pointer.name:
com.reattach(pointer.id, core_master.id) com.reattach(pointer.id, core_master.id)
else: else:
pass pass

1
src/scripts/python/setupmonitor.py

@ -1,4 +1,3 @@
"""Setup Monitor Script """Setup Monitor Script
Author: Ali Hatami Tajik [hatam](mailto:a.hatam008@gmail.com) Author: Ali Hatami Tajik [hatam](mailto:a.hatam008@gmail.com)

7
src/scripts/python/udevhandle.py

@ -57,9 +57,8 @@ class MouseHandler(Handler):
or we can invoke xinput binaries via python itself. a bash script or we can invoke xinput binaries via python itself. a bash script
solution would be benefitial since it can used as utility). solution would be benefitial since it can used as utility).
""" """
# TODO: use somthing that only captures # TODO: use somthing that only captures
super().__init__('usb') super().__init__("usb")
def callback(self, device): def callback(self, device):
print(device.action) print(device.action)

7
src/scripts/python/util/common.py

@ -1,10 +1,11 @@
"""Common Utilities""" """Common Utilities"""
def max_match(a: str, b: str) -> str: def max_match(a: str, b: str) -> str:
"""Maximum matching of intersection of pair of string """Maximum matching of intersection of pair of string
This function will return the intersection of two strings from the start. This function will return the intersection of two strings from the start.
Example: Example:
>>> a = "/sys/devices/folan/bahman" >>> a = "/sys/devices/folan/bahman"
>>> b = "/sys/devices/fol/bahman" >>> b = "/sys/devices/fol/bahman"
@ -19,10 +20,10 @@ def max_match(a: str, b: str) -> str:
str: intersection of two strings str: intersection of two strings
""" """
i = 0 i = 0
if len(b) < len(a): if len(b) < len(a):
a, b = b, a a, b = b, a
for c in a: for c in a:
if b[i] == c: if b[i] == c:
i += 1 i += 1

11
src/scripts/python/util/egalax.py

@ -9,22 +9,23 @@ from pathlib import Path
VENDOR_ID = "0EEF" VENDOR_ID = "0EEF"
DEVICE_ID = "C000" DEVICE_ID = "C000"
def get_egalax_path() -> Path: def get_egalax_path() -> Path:
"""Get device path """Get device path
This function will return the path of the HID device related to the pannel. 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. NOTE that it is not the path of the EDID but it can be extracted from it.
Returns: Returns:
Path: Path of the eGalax hid device OR None if device is not ceonnected Path: Path of the eGalax hid device OR None if device is not ceonnected
""" """
query = '*' + VENDOR_ID + ':' + DEVICE_ID + '*' query = "*" + VENDOR_ID + ":" + DEVICE_ID + "*"
devices = list(Path('/sys/devices').rglob(query)) devices = list(Path("/sys/devices").rglob(query))
if devices: if devices:
return devices[0] return devices[0]
else: else:
return None return None
def is_egalax_connected() -> bool: def is_egalax_connected() -> bool:
"""Checks if device is connected """Checks if device is connected
@ -36,4 +37,4 @@ def is_egalax_connected() -> bool:
bool: True if device is connected bool: True if device is connected
""" """
devpath = get_egalax_path() devpath = get_egalax_path()
return bool(devpath) return bool(devpath)

19
src/scripts/python/util/pointer.py

@ -17,7 +17,7 @@ class XInput:
Args: Args:
name (str): name of the input. No processing is done on the name name (str): name of the input. No processing is done on the name
id (int): id of the input 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.name = name
self.id = id self.id = id
@ -43,7 +43,7 @@ class Pointer(XInput):
def get_short_pointer(id) -> Pointer: def get_short_pointer(id) -> Pointer:
"""Generates Pointer object corresponding to id (short attrs) """Generates Pointer object corresponding to id (short attrs)
Args: Args:
id (int): pointer id id (int): pointer id
@ -56,15 +56,12 @@ def get_short_pointer(id) -> Pointer:
ValueError: if id is not a pointer id ValueError: if id is not a pointer id
""" """
desc = xutil.get_list_short(id) desc = xutil.get_list_short(id)
name, props = desc.rsplit('id=', 1) name, props = desc.rsplit("id=", 1)
if "pointer" in props: if "pointer" in props:
is_master = "master" in props is_master = "master" in props
return Pointer( return Pointer(name.strip(), props.split(maxsplit=1)[0], is_master)
name.strip(),
props.split(maxsplit=1)[0],
is_master)
else: 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): def get_pointers(is_short=True):
@ -99,8 +96,8 @@ def get_pointers(is_short=True):
def get_touch_master(pointers): def get_touch_master(pointers):
"""returns Pointer of the master touch pointer """returns Pointer of the master touch pointer
Args: Args:
pointers (List[Pointes]): list of pointers queried pointers (List[Pointes]): list of pointers queried
""" """
pass pass

42
src/scripts/python/util/randr.py

@ -1,4 +1,3 @@
"""RandR """RandR
Author: Ali Hatami Tajik [hatam](mailto:a.hatam008@gmail.com) 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. Position the output relative to the position of another output.
""" """
LEFT_OF = 0,
RIGHT_OF = 1, LEFT_OF = (0,)
ABOVE = 2, RIGHT_OF = (1,)
BELOW = 3, ABOVE = (2,)
BELOW = (3,)
SAME_AS = 4 SAME_AS = 4
@ -47,9 +47,10 @@ class RotationDir(Enum):
This causes the output contents to be rotated in the specified direction. This causes the output contents to be rotated in the specified direction.
""" """
NORMAL = 0,
LEFT = 1, NORMAL = (0,)
RIGHT = 2, LEFT = (1,)
RIGHT = (2,)
INVERTED = 3 INVERTED = 3
@ -58,9 +59,10 @@ class ReflectDir(Enum):
This causes the output contents to be reflected across the specified axes. This causes the output contents to be reflected across the specified axes.
""" """
NORMAL = 0,
X = 1, NORMAL = (0,)
Y = 2, X = (1,)
Y = (2,)
XY = 3 XY = 3
@ -71,9 +73,10 @@ class Setting:
This data struct will be used as the config of each screen. Note that This data struct will be used as the config of each screen. Note that
default screen cannot be use default screen cannot be use
""" """
resolution = None,
is_primary = False, resolution = (None,)
is_enabeled = True, is_primary = (False,)
is_enabeled = (True,)
rotation = None rotation = None
position = None position = None
reflection = None reflection = None
@ -82,9 +85,10 @@ class Setting:
@dataclass @dataclass
class Mode: class Mode:
"""Mode """Mode
Mode of the screen including width, height, refresh rate(s) Mode of the screen including width, height, refresh rate(s)
""" """
height: int = 0 height: int = 0
width: int = 0 width: int = 0
frequency: List[int] = [] frequency: List[int] = []
@ -94,14 +98,14 @@ class Screen:
"""Screen class """Screen class
This class will hold screen properties and methods related to the screens. 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 At the time it will use xrandr (and not the verbose mode) to list the
screens and modes. screens and modes.
""" """
class Monitor: class Monitor:
"""Monitor Class """Monitor Class
List Monitor Outputs and their states List Monitor Outputs and their states
""" """

28
src/scripts/python/util/x.py

@ -1,8 +1,9 @@
import subprocess import subprocess
from typing import List from typing import List
from multipledispatch import dispatch from multipledispatch import dispatch
from pathlib import Path
ENCODING = 'utf-8' ENCODING = "utf-8"
@dispatch() @dispatch()
@ -10,7 +11,8 @@ def get_list_short():
"""Returns string output of the `xinput --list --short` command encoded as """Returns string output of the `xinput --list --short` command encoded as
UTF-8""" UTF-8"""
completed = subprocess.run( completed = subprocess.run(
['xinput', '--list', '--short'], capture_output=True) ["xinput", "--list", "--short"], capture_output=True
)
return completed.stdout.decode(ENCODING) return completed.stdout.decode(ENCODING)
@ -25,12 +27,13 @@ def get_list_short(id):
ValueError: in case of id not found in devices ValueError: in case of id not found in devices
""" """
completed = subprocess.run( completed = subprocess.run(
['xinput', '--list', '--short', str(id)], capture_output=True) ["xinput", "--list", "--short", str(id)], capture_output=True
)
if completed.returncode == 0: if completed.returncode == 0:
return completed.stdout.decode(ENCODING) return completed.stdout.decode(ENCODING)
else: else:
ValueError(f'id[{id}] is not registered') ValueError(f"id[{id}] is not registered")
def reattach(id, master): 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 :) id is not valid, xinput will not do anything and nothing bad will happen :)
""" """
completed = subprocess.run( completed = subprocess.run(
['xinput', '--reattach', str(id), str(master)], capture_output=True) ["xinput", "--reattach", str(id), str(master)], capture_output=True
)
return completed.returncode return completed.returncode
@ -52,22 +56,22 @@ def reattach(id, master):
def get_ids() -> List[int]: def get_ids() -> List[int]:
"""returns list of ids registered in xinput""" """returns list of ids registered in xinput"""
completed = subprocess.run( 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())) 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 """Creates master with specified name
Args: Args:
name (str, optional): name of the master. Defaults to 'touch'. name (str, optional): name of the master. Defaults to 'touch'.
""" """
completed = subprocess.run( completed = subprocess.run(["xinput create-master", name])
['xinput create-master', name]
)
return completed.returncode return completed.returncode
def map_to_output(output, device_id): def map_to_output(output, device_id):
pass # TODO
pass

Loading…
Cancel
Save