Remove NamedInts: Convert HorizontalScroll to enum

Related #2273
This commit is contained in:
MattHag 2024-11-05 03:08:45 +01:00 committed by Peter F. Patel-Schneider
parent 96c9cc2aa4
commit b19c886426
2 changed files with 14 additions and 11 deletions

View File

@ -407,13 +407,13 @@ class ReprogrammableKeyV4(ReprogrammableKey):
msg=f'Tried to set mapping flag "{f}" on control "{self.key}" '
+ f'which does not support "{key_flag}" on device {self._device}.'
)
bfield |= int(f) if v else 0
bfield |= int(f) << 1 # The 'Xvalid' bit
bfield |= int(f.value) if v else 0
bfield |= int(f.value) << 1 # The 'Xvalid' bit
if self._mapping_flags: # update flags if already read
if v:
self._mapping_flags |= int(f)
self._mapping_flags |= int(f.value)
else:
self._mapping_flags &= ~int(f)
self._mapping_flags &= ~int(f.value)
if remap != 0 and remap not in self.remappable_to:
raise exceptions.FeatureNotSupported(
@ -633,7 +633,10 @@ class KeysArrayPersistent(KeysArray):
elif actionId == special_keys.ACTIONID.Mouse:
remapped = special_keys.MOUSE_BUTTONS[remapped]
elif actionId == special_keys.ACTIONID.Hscroll:
remapped = special_keys.HORIZONTAL_SCROLL[remapped]
try:
remapped = special_keys.HorizontalScroll(remapped)
except ValueError:
remapped = f"unknown horizontal scroll:{remapped:04X}"
elif actionId == special_keys.ACTIONID.Consumer:
remapped = special_keys.HID_CONSUMERCODES[remapped]
elif actionId == special_keys.ACTIONID.Empty: # purge data from empty value

View File

@ -1207,11 +1207,11 @@ MOUSE_BUTTONS = NamedInts(
)
MOUSE_BUTTONS._fallback = lambda x: f"unknown mouse button:{x:04X}"
HORIZONTAL_SCROLL = NamedInts(
Horizontal_Scroll_Left=0x4000,
Horizontal_Scroll_Right=0x8000,
)
HORIZONTAL_SCROLL._fallback = lambda x: f"unknown horizontal scroll:{x:04X}"
class HorizontalScroll(IntEnum):
Left = 0x4000
Right = 0x8000
# Construct universe for Persistent Remappable Keys setting (only for supported values)
KEYS = UnsortedNamedInts()
@ -1246,7 +1246,7 @@ for code in MOUSE_BUTTONS:
KEYS[(ACTIONID.Mouse << 24) + (int(code) << 8)] = str(code)
# Add Horizontal Scroll
for code in HORIZONTAL_SCROLL:
for code in HorizontalScroll:
KEYS[(ACTIONID.Hscroll << 24) + (int(code) << 8)] = str(code)