Browse Source
Fn. get_list_short(id) is added because it outputs simpler syntax and per-case output.pull/2/head
1 changed files with 29 additions and 0 deletions
@ -1,10 +1,39 @@ |
|||||
import subprocess |
import subprocess |
||||
|
from typing import List |
||||
|
from multipledispatch import dispatch |
||||
|
|
||||
ENCODING = 'utf-8' |
ENCODING = 'utf-8' |
||||
|
|
||||
|
@dispatch() |
||||
def get_list_short(): |
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) |
||||
|
|
||||
|
|
||||
|
@dispatch(int) |
||||
|
def get_list_short(id): |
||||
|
"""Short List of the id |
||||
|
|
||||
|
Args: |
||||
|
id (int): id registered in xinput |
||||
|
|
||||
|
Rises: |
||||
|
ValueError: in case of id not found in devices |
||||
|
""" |
||||
|
completed = subprocess.run( |
||||
|
['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') |
||||
|
|
||||
|
|
||||
|
def get_ids() -> List[int]: |
||||
|
"""returns list of ids registered in xinput""" |
||||
|
completed = subprocess.run( |
||||
|
['xinput', '--list', '--id-only'], capture_output=True) |
||||
|
return list(map(int), completed.decode(ENCODING)) |
Loading…
Reference in new issue