Browse Source

Reformat python scripts

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

1
src/scripts/python/changemouse.py

@ -41,5 +41,4 @@ if __name__ == "__main__":
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)

3
src/scripts/python/udevhandle.py

@ -58,8 +58,7 @@ class MouseHandler(Handler):
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)

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

@ -1,5 +1,6 @@
"""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

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

@ -9,6 +9,7 @@ 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
@ -18,8 +19,8 @@ def get_egalax_path() -> Path:
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:

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

@ -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):

32
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
@ -85,6 +88,7 @@ class 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] = []

24
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):
# TODO
pass pass
Loading…
Cancel
Save