Skip to content

Commit

Permalink
Linter and typing
Browse files Browse the repository at this point in the history
Again, yes.
  • Loading branch information
C0rn3j committed Sep 17, 2024
1 parent 6eac649 commit 2d3e002
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 195 deletions.
2 changes: 1 addition & 1 deletion scc/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# Default delay after action, if used in macro. May be overriden using sleep() action.
DEFAULT_DELAY = 0.01
MOUSE_BUTTONS = ( Keys.BTN_LEFT, Keys.BTN_MIDDLE, Keys.BTN_RIGHT, Keys.BTN_SIDE, Keys.BTN_EXTRA )
TRIGGERS = ( Axes.ABS_Z, Axes.ABS_RZ )
TRIGGERS = ( Axes["ABS_Z"], Axes["ABS_RZ"] )


class Action(object):
Expand Down
11 changes: 4 additions & 7 deletions scc/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python3

# The MIT License (MIT)
#
# Copyright (c) 2015 Stany MARCEL <[email protected]>
Expand Down Expand Up @@ -109,17 +107,16 @@ class SCButtons(IntEnum):


class HapticPos(IntEnum):
"""Specify witch pad or trig is used"""
"""Specify witch pad or trig is used."""

RIGHT = 0
LEFT = 1
BOTH = 2 # emulated


class ControllerFlags(IntEnum):
"""
Used by mapper to workaround some physical differences between
Steam Controller and other pads.
"""
"""Used by mapper to workaround some physical differences between Steam Controller and other pads."""

NONE = 0 # No flags, default SC.
HAS_RSTICK = 1 << 0 # Controller has right stick instead of touchpad
SEPARATE_STICK = 1 << 1 # Left stick and left pad are using separate axes
Expand Down
7 changes: 3 additions & 4 deletions scc/lib/eudevmonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,15 @@ def next(self) -> str:


def __next__(self) -> str:
#def next(self):
if not self._enumeration_started:
self.__iter__() # Starts the enumeration
if self._next is None:
raise StopIteration
rv: ctypes.c_char_p | None = self._eudev._lib.udev_list_entry_get_name(self._next)
if rv is None:
udev_name_pointer: ctypes.c_char_p | None = self._eudev._lib.udev_list_entry_get_name(self._next)
if udev_name_pointer is None:
raise OSError("udev_list_entry_get_name failed, can't get syspath")
self._next = self._eudev._lib.udev_list_entry_get_next(self._next)
return str(rv, "utf-8")
return str(udev_name_pointer, "utf-8")

class DeviceEvent(NamedTuple):
action: str
Expand Down
46 changes: 30 additions & 16 deletions scc/mapper.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
#!/usr/bin/env python3
import logging
import os
import time
import traceback
from collections import deque
from scc.lib import xwrappers as X
from scc.uinput import UInput, Keyboard, Mouse, Dummy, Rels
from scc.constants import FE_STICK, FE_TRIGGER, FE_PAD, GYRO, STICK, RSTICK
from scc.constants import SCButtons, LEFT, RIGHT, CPAD, DPAD, HapticPos
from scc.constants import STICK_PAD_MAX, STICKTILT, ControllerFlags
from scc.aliases import ALL_AXES, ALL_BUTTONS

from scc.actions import ButtonAction, GyroAbsAction
from scc.controller import HapticData
from scc.aliases import ALL_AXES, ALL_BUTTONS
from scc.config import Config
from scc.constants import (
CPAD,
DPAD,
FE_PAD,
FE_STICK,
FE_TRIGGER,
GYRO,
LEFT,
RIGHT,
RSTICK,
STICK,
STICK_PAD_MAX,
STICKTILT,
ControllerFlags,
HapticPos,
SCButtons,
)
from scc.controller import HapticData
from scc.lib import xwrappers as X
from scc.profile import Profile
from scc.uinput import Dummy, Keyboard, Mouse, Rels, UInput


import traceback, logging, time, os
log = logging.getLogger("Mapper")

class Mapper(object):
Expand All @@ -21,11 +37,9 @@ class Mapper(object):
def __init__(self, profile, scheduler, keyboard=b"SCController Keyboard",
mouse=b"SCController Mouse",
gamepad=True, poller=None):
"""
If any of keyboard, mouse or gamepad is set to None, that device
will not be emulated.
Emulated gamepad will have rumble enabled only if poller is set to
instance and configuration allows it.
"""If any of keyboard, mouse or gamepad is set to None, that device will not be emulated.
Emulated gamepad will have rumble enabled only if poller is set to instance and configuration allows it.
"""
self.profile = profile
self.controller = None
Expand Down Expand Up @@ -249,7 +263,7 @@ def controller_flags(self):
return 0 if self.controller is None else self.controller.flags


def is_touched(self, what):
def is_touched(self, what) -> bool:
"""
Returns True if specified pad is being touched.
May randomly return False for aphephobic pads.
Expand Down
5 changes: 2 additions & 3 deletions scc/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import sys
import token as TokenType
from collections import namedtuple
from tokenize import TokenError, generate_tokens
from typing import NamedTuple

Expand Down Expand Up @@ -55,8 +54,8 @@ class ActionParser(object):
# do something with error
"""

class Token(NamedTuple):
type: str
class Token(NamedTuple):
type: int
value: str

CONSTS = build_action_constants()
Expand Down
Loading

0 comments on commit 2d3e002

Please sign in to comment.