Most of the pep8 changes finished. Be careful, things may be horribly broken.

This commit is contained in:
Storm Dragon
2025-07-03 13:22:00 -04:00
parent 7408951152
commit 21bb9c6083
344 changed files with 6374 additions and 6083 deletions

View File

@ -6,7 +6,7 @@
import time
from fenrirscreenreader.core import debug
from fenrirscreenreader.core.inputDriver import inputDriver
from fenrirscreenreader.core.inputDriver import InputDriver as inputDriver
class driver(inputDriver):
@ -15,65 +15,65 @@ class driver(inputDriver):
def initialize(self, environment):
self.env = environment
self.env['runtime']['inputManager'].setShortcutType('KEY')
self.env['runtime']['InputManager'].set_shortcut_type('KEY')
self._initialized = True
print('Input Debug Driver: Initialized')
def shutdown(self):
if self._initialized:
self.removeAllDevices()
self.remove_all_devices()
self._initialized = False
print('Input Debug Driver: Shutdown')
def getInputEvent(self):
def get_input_event(self):
time.sleep(0.1)
if not self._initialized:
return None
print('Input Debug Driver: getInputEvent')
print('Input Debug Driver: get_input_event')
return None
def writeEventBuffer(self):
def write_event_buffer(self):
if not self._initialized:
return
print('Input Debug Driver: writeEventBuffer')
print('Input Debug Driver: write_event_buffer')
def clearEventBuffer(self):
def clear_event_buffer(self):
if not self._initialized:
return
del self.env['input']['eventBuffer'][:]
print('Input Debug Driver: clearEventBuffer')
print('Input Debug Driver: clear_event_buffer')
def updateInputDevices(self, newDevices=None, init=False):
def update_input_devices(self, new_devices=None, init=False):
if not self._initialized:
return
print('Input Debug Driver: updateInputDevices')
print('Input Debug Driver: update_input_devices')
def getLedState(self, led=0):
def get_led_state(self, led=0):
if not self._initialized:
return False
return False
def toggleLedState(self, led=0):
def toggle_led_state(self, led=0):
if not self._initialized:
return
print('Input Debug Driver: toggleLedState')
print('Input Debug Driver: toggle_led_state')
def grabAllDevices(self):
def grab_all_devices(self):
if not self._initialized:
return
print('Input Debug Driver: grabAllDevices')
print('Input Debug Driver: grab_all_devices')
def ungrabAllDevices(self):
def ungrab_all_devices(self):
if not self._initialized:
return
print('Input Debug Driver: ungrabAllDevices')
print('Input Debug Driver: ungrab_all_devices')
def removeAllDevices(self):
def remove_all_devices(self):
if not self._initialized:
return
print('Input Debug Driver: removeAllDevices')
print('Input Debug Driver: remove_all_devices')
def __del__(self):
if self._initialized:
self.removeAllDevices()
self.remove_all_devices()
print('Input Debug Driver: __del__')

View File

@ -6,7 +6,7 @@
import time
from fenrirscreenreader.core import debug
from fenrirscreenreader.core.inputDriver import inputDriver
from fenrirscreenreader.core.inputDriver import InputDriver as inputDriver
class driver(inputDriver):

View File

@ -1,10 +1,10 @@
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from fenrirscreenreader.core.inputDriver import inputDriver
from fenrirscreenreader.core.inputDriver import InputDriver as inputDriver
from fenrirscreenreader.core import debug
from fenrirscreenreader.core import inputData
from fenrirscreenreader.core.eventData import fenrirEventType
from fenrirscreenreader.core.eventData import FenrirEventType
import threading
from ctypes import c_bool
from multiprocessing.sharedctypes import Value
@ -39,44 +39,44 @@ class driver(inputDriver):
self.uDevices = {}
self.gDevices = {}
self.iDeviceNo = 0
self.watchDog = Value(c_bool, True)
self.watch_dog = Value(c_bool, True)
self.UInputinject = UInput()
self._deviceLock = threading.Lock()
def initialize(self, environment):
self.env = environment
self.env['runtime']['inputManager'].setShortcutType('KEY')
self.env['runtime']['InputManager'].set_shortcut_type('KEY')
global _evdevAvailable
global _udevAvailable
global _evdevAvailableError
global _udevAvailableError
if not _udevAvailable:
self.env['runtime']['debug'].writeDebugOut(
'InputDriver:' + _udevAvailableError, debug.debugLevel.ERROR)
self.env['runtime']['DebugManager'].write_debug_out(
'InputDriver:' + _udevAvailableError, debug.DebugLevel.ERROR)
if not _evdevAvailable:
self.env['runtime']['debug'].writeDebugOut(
'InputDriver:' + _evdevAvailableError, debug.debugLevel.ERROR)
self.env['runtime']['DebugManager'].write_debug_out(
'InputDriver:' + _evdevAvailableError, debug.DebugLevel.ERROR)
return
if _udevAvailable:
self.env['runtime']['processManager'].addCustomEventThread(
self.plugInputDeviceWatchdogUdev)
self.env['runtime']['processManager'].addCustomEventThread(
self.inputWatchdog)
self.env['runtime']['ProcessManager'].add_custom_event_thread(
self.plug_input_device_watchdog_udev)
self.env['runtime']['ProcessManager'].add_custom_event_thread(
self.input_watchdog)
self._initialized = True
def plugInputDeviceWatchdogUdev(self, active, eventQueue):
def plug_input_device_watchdog_udev(self, active, event_queue):
context = pyudev.Context()
monitor = pyudev.Monitor.from_netlink(context)
monitor.filter_by(subsystem='input')
monitor.start()
ignorePlug = False
ignore_plug = False
while active.value:
validDevices = []
valid_devices = []
device = monitor.poll(1)
while device:
self.env['runtime']['debug'].writeDebugOut(
'plugInputDeviceWatchdogUdev:' + str(device), debug.debugLevel.INFO)
self.env['runtime']['DebugManager'].write_debug_out(
'plug_input_device_watchdog_udev:' + str(device), debug.DebugLevel.INFO)
try:
try:
# FIX: Check if attributes exist before accessing them
@ -86,42 +86,42 @@ class driver(inputDriver):
'',
'SPEAKUP',
'FENRIR-UINPUT']:
ignorePlug = True
ignore_plug = True
if hasattr(
device,
'phys') and device.phys and device.phys.upper() in [
'',
'SPEAKUP',
'FENRIR-UINPUT']:
ignorePlug = True
ignore_plug = True
if hasattr(
device,
'name') and device.name and 'BRLTTY' in device.name.upper():
ignorePlug = True
ignore_plug = True
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
"plugInputDeviceWatchdogUdev CHECK NAME CRASH: " + str(e), debug.debugLevel.ERROR)
self.env['runtime']['DebugManager'].write_debug_out(
"plug_input_device_watchdog_udev CHECK NAME CRASH: " + str(e), debug.DebugLevel.ERROR)
if not ignorePlug:
if not ignore_plug:
virtual = '/sys/devices/virtual/input/' in device.sys_path
if device.device_node:
validDevices.append(
valid_devices.append(
{'device': device.device_node, 'virtual': virtual})
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
"plugInputDeviceWatchdogUdev APPEND CRASH: " + str(e), debug.debugLevel.ERROR)
self.env['runtime']['DebugManager'].write_debug_out(
"plug_input_device_watchdog_udev APPEND CRASH: " + str(e), debug.DebugLevel.ERROR)
try:
pollTimeout = 1
device = monitor.poll(pollTimeout)
poll_timeout = 1
device = monitor.poll(poll_timeout)
except Exception:
device = None
ignorePlug = False
if validDevices:
eventQueue.put(
{"Type": fenrirEventType.PlugInputDevice, "Data": validDevices})
ignore_plug = False
if valid_devices:
event_queue.put(
{"Type": FenrirEventType.plug_input_device, "data": valid_devices})
return time.time()
def inputWatchdog(self, active, eventQueue):
def input_watchdog(self, active, event_queue):
try:
while active.value:
# Get a snapshot of devices for select() to avoid lock
@ -135,9 +135,9 @@ class driver(inputDriver):
r, w, x = select(devices_snapshot, [], [], 0.8)
event = None
foundKeyInSequence = False
found_key_in_sequence = False
foreward = False
eventFired = False
event_fired = False
for fd in r:
# Check if device still exists before accessing
with self._deviceLock:
@ -149,193 +149,193 @@ class driver(inputDriver):
try:
event = device.read_one()
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
'evdevDriver handleInputEvent: Error reading event: ' + str(e),
debug.debugLevel.ERROR)
self.removeDevice(fd)
self.env['runtime']['DebugManager'].write_debug_out(
'evdevDriver handle_input_event: Error reading event: ' + str(e),
debug.DebugLevel.ERROR)
self.remove_device(fd)
continue
while (event):
self.env['runtime']['debug'].writeDebugOut(
'inputWatchdog: EVENT:' + str(event), debug.debugLevel.INFO)
self.env['runtime']['DebugManager'].write_debug_out(
'input_watchdog: EVENT:' + str(event), debug.DebugLevel.INFO)
self.env['input']['eventBuffer'].append(
[device, udevice, event])
if event.type == evdev.events.EV_KEY:
if not foundKeyInSequence:
foundKeyInSequence = True
if not found_key_in_sequence:
found_key_in_sequence = True
if event.code != 0:
currMapEvent = self.mapEvent(event)
if not currMapEvent:
curr_map_event = self.map_event(event)
if not curr_map_event:
event = device.read_one()
continue
if not isinstance(
currMapEvent['EventName'], str):
curr_map_event['EventName'], str):
event = device.read_one()
continue
if currMapEvent['EventState'] in [0, 1, 2]:
eventQueue.put(
{"Type": fenrirEventType.KeyboardInput, "Data": currMapEvent.copy()})
eventFired = True
if curr_map_event['EventState'] in [0, 1, 2]:
event_queue.put(
{"Type": FenrirEventType.keyboard_input, "data": curr_map_event.copy()})
event_fired = True
else:
if event.type in [2, 3]:
foreward = True
event = device.read_one()
if not foundKeyInSequence:
if foreward and not eventFired:
self.writeEventBuffer()
self.clearEventBuffer()
if not found_key_in_sequence:
if foreward and not event_fired:
self.write_event_buffer()
self.clear_event_buffer()
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
"INPUT WATCHDOG CRASH: " + str(e), debug.debugLevel.ERROR)
self.env['runtime']['DebugManager'].write_debug_out(
"INPUT WATCHDOG CRASH: " + str(e), debug.DebugLevel.ERROR)
def writeEventBuffer(self):
def write_event_buffer(self):
if not self._initialized:
return
for iDevice, uDevice, event in self.env['input']['eventBuffer']:
try:
if uDevice:
if self.gDevices[iDevice.fd]:
self.writeUInput(uDevice, event)
self.write_u_input(uDevice, event)
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
'evdevDriver writeEventBuffer: Error writing event: ' + str(e),
debug.debugLevel.ERROR)
self.env['runtime']['DebugManager'].write_debug_out(
'evdevDriver write_event_buffer: Error writing event: ' + str(e),
debug.DebugLevel.ERROR)
def writeUInput(self, uDevice, event):
def write_u_input(self, uDevice, event):
if not self._initialized:
return
uDevice.write_event(event)
time.sleep(0.0000002)
uDevice.syn()
def updateInputDevices(self, newDevices=None, init=False):
def update_input_devices(self, new_devices=None, init=False):
if init:
self.removeAllDevices()
self.remove_all_devices()
deviceFileList = None
device_file_list = None
if newDevices and not init:
if not isinstance(newDevices, list):
newDevices = [newDevices]
deviceFileList = newDevices
if new_devices and not init:
if not isinstance(new_devices, list):
new_devices = [new_devices]
device_file_list = new_devices
else:
deviceFileList = evdev.list_devices()
if len(deviceFileList) == self.iDeviceNo:
device_file_list = evdev.list_devices()
if len(device_file_list) == self.iDeviceNo:
return
if not deviceFileList:
if not device_file_list:
return
mode = self.env['runtime']['settingsManager'].getSetting(
mode = self.env['runtime']['SettingsManager'].get_setting(
'keyboard', 'device').upper()
iDevicesFiles = []
i_devices_files = []
for device in self.iDevices:
iDevicesFiles.append(self.iDevices[device].fn)
i_devices_files.append(self.iDevices[device].fn)
eventType = evdev.events
for deviceFile in deviceFileList:
event_type = evdev.events
for deviceFile in device_file_list:
try:
if not deviceFile:
continue
if deviceFile == '':
continue
if deviceFile in iDevicesFiles:
if deviceFile in i_devices_files:
continue
try:
with open(deviceFile) as f:
pass
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
'evdevDriver updateInputDevices: Error opening device file: ' + str(e),
debug.debugLevel.ERROR)
self.env['runtime']['DebugManager'].write_debug_out(
'evdevDriver update_input_devices: Error opening device file: ' + str(e),
debug.DebugLevel.ERROR)
continue
# 3 pos absolute
# 2 pos relative
# 1 Keys
try:
currDevice = evdev.InputDevice(deviceFile)
curr_device = evdev.InputDevice(deviceFile)
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
self.env['runtime']['DebugManager'].write_debug_out(
'evdevDriver createDeviceType: Error creating device: ' + str(e),
debug.debugLevel.ERROR)
debug.DebugLevel.ERROR)
continue
try:
# FIX: Check if attributes exist before accessing them
if hasattr(
currDevice,
'name') and currDevice.name and currDevice.name.upper() in [
curr_device,
'name') and curr_device.name and curr_device.name.upper() in [
'',
'SPEAKUP',
'FENRIR-UINPUT']:
continue
if hasattr(
currDevice,
'phys') and currDevice.phys and currDevice.phys.upper() in [
curr_device,
'phys') and curr_device.phys and curr_device.phys.upper() in [
'',
'SPEAKUP',
'FENRIR-UINPUT']:
continue
if hasattr(
currDevice,
'name') and currDevice.name and 'BRLTTY' in currDevice.name.upper():
curr_device,
'name') and curr_device.name and 'BRLTTY' in curr_device.name.upper():
continue
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
self.env['runtime']['DebugManager'].write_debug_out(
'evdevDriver: Error checking device capabilities: ' + str(e),
debug.debugLevel.ERROR)
cap = currDevice.capabilities()
debug.DebugLevel.ERROR)
cap = curr_device.capabilities()
if mode in ['ALL', 'NOMICE']:
if eventType.EV_KEY in cap:
if 116 in cap[eventType.EV_KEY] and len(
cap[eventType.EV_KEY]) < 10:
self.env['runtime']['debug'].writeDebugOut(
'Device Skipped (has 116):' + currDevice.name, debug.debugLevel.INFO)
if event_type.EV_KEY in cap:
if 116 in cap[event_type.EV_KEY] and len(
cap[event_type.EV_KEY]) < 10:
self.env['runtime']['DebugManager'].write_debug_out(
'Device Skipped (has 116):' + curr_device.name, debug.DebugLevel.INFO)
continue
if len(cap[eventType.EV_KEY]) < 60:
self.env['runtime']['debug'].writeDebugOut(
'Device Skipped (< 60 keys):' + currDevice.name, debug.debugLevel.INFO)
if len(cap[event_type.EV_KEY]) < 60:
self.env['runtime']['DebugManager'].write_debug_out(
'Device Skipped (< 60 keys):' + curr_device.name, debug.DebugLevel.INFO)
continue
if mode == 'ALL':
self.addDevice(currDevice)
self.env['runtime']['debug'].writeDebugOut(
'Device added (ALL):' + self.iDevices[currDevice.fd].name, debug.debugLevel.INFO)
self.add_device(curr_device)
self.env['runtime']['DebugManager'].write_debug_out(
'Device added (ALL):' + self.iDevices[curr_device.fd].name, debug.DebugLevel.INFO)
elif mode == 'NOMICE':
if not (
(eventType.EV_REL in cap) or (
eventType.EV_ABS in cap)):
self.addDevice(currDevice)
self.env['runtime']['debug'].writeDebugOut(
'Device added (NOMICE):' + self.iDevices[currDevice.fd].name, debug.debugLevel.INFO)
(event_type.EV_REL in cap) or (
event_type.EV_ABS in cap)):
self.add_device(curr_device)
self.env['runtime']['DebugManager'].write_debug_out(
'Device added (NOMICE):' + self.iDevices[curr_device.fd].name, debug.DebugLevel.INFO)
else:
self.env['runtime']['debug'].writeDebugOut(
'Device Skipped (NOMICE):' + currDevice.name, debug.debugLevel.INFO)
self.env['runtime']['DebugManager'].write_debug_out(
'Device Skipped (NOMICE):' + curr_device.name, debug.DebugLevel.INFO)
else:
self.env['runtime']['debug'].writeDebugOut(
'Device Skipped (no EV_KEY):' + currDevice.name, debug.debugLevel.INFO)
elif currDevice.name.upper() in mode.split(','):
self.addDevice(currDevice)
self.env['runtime']['debug'].writeDebugOut(
'Device added (Name):' + self.iDevices[currDevice.fd].name, debug.debugLevel.INFO)
self.env['runtime']['DebugManager'].write_debug_out(
'Device Skipped (no EV_KEY):' + curr_device.name, debug.DebugLevel.INFO)
elif curr_device.name.upper() in mode.split(','):
self.add_device(curr_device)
self.env['runtime']['DebugManager'].write_debug_out(
'Device added (Name):' + self.iDevices[curr_device.fd].name, debug.DebugLevel.INFO)
except Exception as e:
try:
device_name = currDevice.name if hasattr(
currDevice, 'name') else "unknown"
self.env['runtime']['debug'].writeDebugOut(
device_name = curr_device.name if hasattr(
curr_device, 'name') else "unknown"
self.env['runtime']['DebugManager'].write_debug_out(
"Device Skipped (Exception): " +
deviceFile +
' ' +
device_name +
' ' +
str(e),
debug.debugLevel.INFO)
debug.DebugLevel.INFO)
except Exception as ex:
self.env['runtime']['debug'].writeDebugOut(
self.env['runtime']['DebugManager'].write_debug_out(
"Device Skipped (Exception): " + deviceFile + ' ' + str(ex),
debug.debugLevel.INFO)
debug.DebugLevel.INFO)
self.iDeviceNo = len(evdev.list_devices())
self.updateMPiDevicesFD()
self.update_m_pi_devices_fd()
def updateMPiDevicesFD(self):
def update_m_pi_devices_fd(self):
try:
for fd in self.iDevices:
if fd not in self.iDevicesFD:
@ -344,37 +344,37 @@ class driver(inputDriver):
if fd not in self.iDevices:
self.iDevicesFD.remove(fd)
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
'evdevDriver updateMPiDevicesFD: Error updating device file descriptors: ' +
self.env['runtime']['DebugManager'].write_debug_out(
'evdevDriver update_m_pi_devices_fd: Error updating device file descriptors: ' +
str(e),
debug.debugLevel.ERROR)
debug.DebugLevel.ERROR)
def mapEvent(self, event):
def map_event(self, event):
if not self._initialized:
return None
if not event:
return None
mEvent = inputData.inputEvent
m_event = inputData.input_event
try:
# mute is a list = ['KEY_MIN_INTERESTING', 'KEY_MUTE']
mEvent['EventName'] = evdev.ecodes.keys[event.code]
if isinstance(mEvent['EventName'], list):
if len(mEvent['EventName']) > 0:
mEvent['EventName'] = mEvent['EventName'][0]
if isinstance(mEvent['EventName'], list):
if len(mEvent['EventName']) > 0:
mEvent['EventName'] = mEvent['EventName'][0]
mEvent['EventValue'] = event.code
mEvent['EventSec'] = event.sec
mEvent['EventUsec'] = event.usec
mEvent['EventState'] = event.value
mEvent['EventType'] = event.type
return mEvent
m_event['EventName'] = evdev.ecodes.keys[event.code]
if isinstance(m_event['EventName'], list):
if len(m_event['EventName']) > 0:
m_event['EventName'] = m_event['EventName'][0]
if isinstance(m_event['EventName'], list):
if len(m_event['EventName']) > 0:
m_event['EventName'] = m_event['EventName'][0]
m_event['EventValue'] = event.code
m_event['EventSec'] = event.sec
m_event['EventUsec'] = event.usec
m_event['EventState'] = event.value
m_event['EventType'] = event.type
return m_event
except Exception as e:
return None
def getLedState(self, led=0):
if not self.hasIDevices():
def get_led_state(self, led=0):
if not self.has_i_devices():
return False
# 0 = Numlock
# 1 = Capslock
@ -384,39 +384,39 @@ class driver(inputDriver):
return True
return False
def toggleLedState(self, led=0):
if not self.hasIDevices():
def toggle_led_state(self, led=0):
if not self.has_i_devices():
return False
ledState = self.getLedState(led)
led_state = self.get_led_state(led)
for i in self.iDevices:
if self.gDevices[i]:
# 17 LEDs
if 17 in self.iDevices[i].capabilities():
if ledState == 1:
if led_state == 1:
self.iDevices[i].set_led(led, 0)
else:
self.iDevices[i].set_led(led, 1)
def grabAllDevices(self):
def grab_all_devices(self):
if not self._initialized:
return True
ok = True
for fd in self.iDevices:
if not self.gDevices[fd]:
ok = ok and self.grabDevice(fd)
ok = ok and self.grab_device(fd)
return ok
def ungrabAllDevices(self):
def ungrab_all_devices(self):
if not self._initialized:
return True
ok = True
for fd in self.iDevices:
if self.gDevices[fd]:
ok = ok and self.ungrabDevice(fd)
ok = ok and self.ungrab_device(fd)
return ok
def createUInputDev(self, fd):
if not self.env['runtime']['settingsManager'].getSettingAsBool(
def create_u_input_dev(self, fd):
if not self.env['runtime']['SettingsManager'].get_setting_as_bool(
'keyboard', 'grabDevices'):
self.uDevices[fd] = None
return
@ -432,8 +432,8 @@ class driver(inputDriver):
self.iDevices[fd], name='fenrir-uinput', phys='fenrir-uinput')
except Exception as e:
try:
self.env['runtime']['debug'].writeDebugOut(
'InputDriver evdev: compat fallback: ' + str(e), debug.debugLevel.WARNING)
self.env['runtime']['DebugManager'].write_debug_out(
'InputDriver evdev: compat fallback: ' + str(e), debug.DebugLevel.WARNING)
dev = self.iDevices[fd]
cap = dev.capabilities()
del cap[0]
@ -443,46 +443,46 @@ class driver(inputDriver):
phys='fenrir-uinput'
)
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
self.env['runtime']['DebugManager'].write_debug_out(
'InputDriver evdev: init Uinput not possible: ' + str(e),
debug.debugLevel.ERROR)
debug.DebugLevel.ERROR)
return
def addDevice(self, newDevice):
self.env['runtime']['debug'].writeDebugOut(
def add_device(self, newDevice):
self.env['runtime']['DebugManager'].write_debug_out(
'InputDriver evdev: device added: ' + str(
newDevice.fd) + ' ' + str(newDevice),
debug.debugLevel.INFO)
debug.DebugLevel.INFO)
with self._deviceLock:
try:
self.iDevices[newDevice.fd] = newDevice
self.createUInputDev(newDevice.fd)
self.create_u_input_dev(newDevice.fd)
self.gDevices[newDevice.fd] = False
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
'InputDriver evdev: error adding device: ' + str(e), debug.debugLevel.ERROR)
self.env['runtime']['DebugManager'].write_debug_out(
'InputDriver evdev: error adding device: ' + str(e), debug.DebugLevel.ERROR)
# if it doesnt work clean up
try:
del (self.iDevices[newDevice.fd])
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
'evdevDriver removeDevice: Error removing iDevice: ' + str(e),
debug.debugLevel.ERROR)
self.env['runtime']['DebugManager'].write_debug_out(
'evdevDriver remove_device: Error removing iDevice: ' + str(e),
debug.DebugLevel.ERROR)
try:
del (self.uDevices[newDevice.fd])
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
'evdevDriver removeDevice: Error removing uDevice: ' + str(e),
debug.debugLevel.ERROR)
self.env['runtime']['DebugManager'].write_debug_out(
'evdevDriver remove_device: Error removing uDevice: ' + str(e),
debug.DebugLevel.ERROR)
try:
del (self.gDevices[newDevice.fd])
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
'evdevDriver addDevice: Error cleaning up gDevice: ' + str(e),
debug.debugLevel.ERROR)
self.env['runtime']['DebugManager'].write_debug_out(
'evdevDriver add_device: Error cleaning up gDevice: ' + str(e),
debug.DebugLevel.ERROR)
def grabDevice(self, fd):
if not self.env['runtime']['settingsManager'].getSettingAsBool(
def grab_device(self, fd):
if not self.env['runtime']['SettingsManager'].get_setting_as_bool(
'keyboard', 'grabDevices'):
return True
@ -491,24 +491,24 @@ class driver(inputDriver):
try:
self.iDevices[fd].grab()
self.gDevices[fd] = True
self.env['runtime']['debug'].writeDebugOut(
'InputDriver evdev: grab device (' + str(self.iDevices[fd].name) + ')', debug.debugLevel.INFO)
self.env['runtime']['DebugManager'].write_debug_out(
'InputDriver evdev: grab device (' + str(self.iDevices[fd].name) + ')', debug.DebugLevel.INFO)
# Reset modifier keys on successful grab
if self.uDevices[fd]:
modifierKeys = [
modifier_keys = [
e.KEY_LEFTCTRL,
e.KEY_RIGHTCTRL,
e.KEY_LEFTALT,
e.KEY_RIGHTALT,
e.KEY_LEFTSHIFT,
e.KEY_RIGHTSHIFT]
for key in modifierKeys:
for key in modifier_keys:
try:
self.uDevices[fd].write(e.EV_KEY, key, 0) # 0 = key up
self.uDevices[fd].syn()
except Exception as mod_error:
self.env['runtime']['debug'].writeDebugOut(
'Failed to reset modifier key: ' + str(mod_error), debug.debugLevel.WARNING)
self.env['runtime']['DebugManager'].write_debug_out(
'Failed to reset modifier key: ' + str(mod_error), debug.DebugLevel.WARNING)
except IOError:
if not self.gDevices[fd]:
return False
@ -516,16 +516,16 @@ class driver(inputDriver):
grab_error = ex
if grab_error:
self.env['runtime']['debug'].writeDebugOut(
self.env['runtime']['DebugManager'].write_debug_out(
'InputDriver evdev: grabing not possible: ' +
str(grab_error),
debug.debugLevel.ERROR)
debug.DebugLevel.ERROR)
return False
return True
def ungrabDevice(self, fd):
if not self.env['runtime']['settingsManager'].getSettingAsBool(
def ungrab_device(self, fd):
if not self.env['runtime']['SettingsManager'].get_setting_as_bool(
'keyboard', 'grabDevices'):
return True
@ -534,8 +534,8 @@ class driver(inputDriver):
try:
self.iDevices[fd].ungrab()
self.gDevices[fd] = False
self.env['runtime']['debug'].writeDebugOut(
'InputDriver evdev: ungrab device (' + str(self.iDevices[fd].name) + ')', debug.debugLevel.INFO)
self.env['runtime']['DebugManager'].write_debug_out(
'InputDriver evdev: ungrab device (' + str(self.iDevices[fd].name) + ')', debug.DebugLevel.INFO)
except IOError:
if self.gDevices[fd]:
return False
@ -543,67 +543,67 @@ class driver(inputDriver):
ungrab_error = ex
if ungrab_error:
self.env['runtime']['debug'].writeDebugOut(
self.env['runtime']['DebugManager'].write_debug_out(
'InputDriver evdev: ungrabing not possible: ' +
str(ungrab_error),
debug.debugLevel.ERROR)
debug.DebugLevel.ERROR)
return False
return True
def removeDevice(self, fd):
def remove_device(self, fd):
with self._deviceLock:
try:
self.env['runtime']['debug'].writeDebugOut(
self.env['runtime']['DebugManager'].write_debug_out(
'InputDriver evdev: device removed: ' + str(fd) + ' ' + str(
self.iDevices[fd]), debug.debugLevel.INFO)
self.iDevices[fd]), debug.DebugLevel.INFO)
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
self.env['runtime']['DebugManager'].write_debug_out(
'InputDriver evdev: device removed: ' +
str(fd) +
' Error: ' +
str(e),
debug.debugLevel.INFO)
self.clearEventBuffer()
debug.DebugLevel.INFO)
self.clear_event_buffer()
try:
self.ungrabDevice(fd)
self.ungrab_device(fd)
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
'evdevDriver removeDevice: Error ungrabbing device ' + str(fd) + ': ' + str(e),
debug.debugLevel.ERROR)
self.env['runtime']['DebugManager'].write_debug_out(
'evdevDriver remove_device: Error ungrabbing device ' + str(fd) + ': ' + str(e),
debug.DebugLevel.ERROR)
try:
self.iDevices[fd].close()
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
'evdevDriver removeDevice: Error closing iDevice ' + str(fd) + ': ' + str(e),
debug.debugLevel.ERROR)
self.env['runtime']['DebugManager'].write_debug_out(
'evdevDriver remove_device: Error closing iDevice ' + str(fd) + ': ' + str(e),
debug.DebugLevel.ERROR)
try:
self.uDevices[fd].close()
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
'evdevDriver removeDevice: Error closing uDevice ' + str(fd) + ': ' + str(e),
debug.debugLevel.ERROR)
self.env['runtime']['DebugManager'].write_debug_out(
'evdevDriver remove_device: Error closing uDevice ' + str(fd) + ': ' + str(e),
debug.DebugLevel.ERROR)
try:
del (self.iDevices[fd])
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
'evdevDriver removeDevice: Error deleting iDevice ' + str(fd) + ': ' + str(e),
debug.debugLevel.ERROR)
self.env['runtime']['DebugManager'].write_debug_out(
'evdevDriver remove_device: Error deleting iDevice ' + str(fd) + ': ' + str(e),
debug.DebugLevel.ERROR)
try:
del (self.uDevices[fd])
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
'evdevDriver removeDevice: Error deleting uDevice ' + str(fd) + ': ' + str(e),
debug.debugLevel.ERROR)
self.env['runtime']['DebugManager'].write_debug_out(
'evdevDriver remove_device: Error deleting uDevice ' + str(fd) + ': ' + str(e),
debug.DebugLevel.ERROR)
try:
del (self.gDevices[fd])
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
'evdevDriver removeDevice: Error deleting gDevice ' + str(fd) + ': ' + str(e),
debug.debugLevel.ERROR)
self.updateMPiDevicesFD()
self.env['runtime']['DebugManager'].write_debug_out(
'evdevDriver remove_device: Error deleting gDevice ' + str(fd) + ': ' + str(e),
debug.DebugLevel.ERROR)
self.update_m_pi_devices_fd()
def hasIDevices(self):
def has_i_devices(self):
if not self._initialized:
return False
if not self.iDevices:
@ -612,23 +612,23 @@ class driver(inputDriver):
return False
return True
def sendKey(self, key, state):
def send_key(self, key, state):
if not self._initialized:
return
try:
self.UInputinject.write(e.EV_KEY, e.ecodes[key], state)
self.UInputinject.syn()
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(
'evdevDriver sendKey: Error sending key ' + str(key) + ': ' + str(e),
debug.debugLevel.ERROR)
self.env['runtime']['DebugManager'].write_debug_out(
'evdevDriver send_key: Error sending key ' + str(key) + ': ' + str(e),
debug.DebugLevel.ERROR)
def removeAllDevices(self):
if not self.hasIDevices():
def remove_all_devices(self):
if not self.has_i_devices():
return
devices = self.iDevices.copy()
for fd in devices:
self.removeDevice(fd)
self.remove_device(fd)
self.iDevices.clear()
self.uDevices.clear()
self.gDevices.clear()

View File

@ -6,15 +6,15 @@
import time
from fenrirscreenreader.core import debug
from fenrirscreenreader.core.inputDriver import inputDriver
from fenrirscreenreader.core.inputDriver import InputDriver as inputDriver
class driver(inputDriver):
def __init__(self):
self._isInitialized = False
self._is_initialized = False
inputDriver.__init__(self)
def initialize(self, environment):
self.env = environment
self.env['runtime']['inputManager'].setShortcutType('BYTE')
self._isInitialized = True
self.env['runtime']['InputManager'].set_shortcut_type('BYTE')
self._is_initialized = True