| 1 |
#!/usr/bin/env python3 |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Fenrir TTY screen reader |
| 5 |
# By Chrys, Storm Dragon, and contributors. |
| 6 |
|
| 7 |
import inspect |
| 8 |
import os |
| 9 |
from argparse import Namespace |
| 10 |
from configparser import ConfigParser |
| 11 |
|
| 12 |
from fenrirscreenreader.core import applicationManager |
| 13 |
from fenrirscreenreader.core import attributeManager |
| 14 |
from fenrirscreenreader.core import barrierManager |
| 15 |
from fenrirscreenreader.core import backgroundTaskManager |
| 16 |
from fenrirscreenreader.core import clipboardSyncManager |
| 17 |
from fenrirscreenreader.core import commandManager |
| 18 |
from fenrirscreenreader.core import cursorManager |
| 19 |
from fenrirscreenreader.core import debug |
| 20 |
from fenrirscreenreader.core import debugManager |
| 21 |
from fenrirscreenreader.core import diffReviewManager |
| 22 |
from fenrirscreenreader.core import environment |
| 23 |
from fenrirscreenreader.core import eventManager |
| 24 |
from fenrirscreenreader.core import helpManager |
| 25 |
from fenrirscreenreader.core import inputManager |
| 26 |
from fenrirscreenreader.core import memoryManager |
| 27 |
from fenrirscreenreader.core import outputManager |
| 28 |
from fenrirscreenreader.core import processManager |
| 29 |
from fenrirscreenreader.core import punctuationManager |
| 30 |
from fenrirscreenreader.core import quickMenuManager |
| 31 |
from fenrirscreenreader.core import readAllManager |
| 32 |
from fenrirscreenreader.core import remoteManager |
| 33 |
from fenrirscreenreader.core import sayAllManager |
| 34 |
from fenrirscreenreader.core import screenManager |
| 35 |
from fenrirscreenreader.core import speechHistoryManager |
| 36 |
from fenrirscreenreader.core import speechDiscoveryManager |
| 37 |
from fenrirscreenreader.core import tableManager |
| 38 |
from fenrirscreenreader.core import textManager |
| 39 |
from fenrirscreenreader.core import vmenuManager |
| 40 |
from fenrirscreenreader.core.settingsData import settings_data |
| 41 |
from fenrirscreenreader.utils import module_utils |
| 42 |
|
| 43 |
currentdir = os.path.dirname( |
| 44 |
os.path.realpath(os.path.abspath(inspect.getfile(inspect.currentframe()))) |
| 45 |
) |
| 46 |
fenrir_path = os.path.dirname(currentdir) |
| 47 |
|
| 48 |
|
| 49 |
class SettingsManager: |
| 50 |
system_settings_root = "/etc/fenrirscreenreader/" |
| 51 |
system_settings_file = "/etc/fenrirscreenreader/settings/settings.conf" |
| 52 |
user_settings_file = ( |
| 53 |
"~/.local/share/stormux/fenrirscreenreader/settings/settings.conf" |
| 54 |
) |
| 55 |
user_resource_root = "~/.local/stormux/fenrir/" |
| 56 |
system_sound_roots = [ |
| 57 |
"/usr/share/sounds/fenrir/", |
| 58 |
"/usr/share/sounds/fenrirscreenreader/", |
| 59 |
] |
| 60 |
|
| 61 |
def __init__(self): |
| 62 |
self.settings = settings_data |
| 63 |
self.settingArgDict = {} |
| 64 |
self.bindingsBackup = None |
| 65 |
self.settings_file = "" |
| 66 |
self.save_settings_path = "" |
| 67 |
|
| 68 |
def initialize(self, environment): |
| 69 |
self.env = environment |
| 70 |
|
| 71 |
def shutdown(self): |
| 72 |
pass |
| 73 |
|
| 74 |
def format_cli_args(self, cliArgs): |
| 75 |
if cliArgs is None: |
| 76 |
return "{}" |
| 77 |
if isinstance(cliArgs, Namespace): |
| 78 |
args = vars(cliArgs) |
| 79 |
else: |
| 80 |
args = vars(cliArgs) if hasattr(cliArgs, "__dict__") else {} |
| 81 |
return str({key: args[key] for key in sorted(args)}) |
| 82 |
|
| 83 |
def get_binding_backup(self): |
| 84 |
return self.bindingsBackup.copy() |
| 85 |
|
| 86 |
def load_sound_icons(self, soundIconPath, environment=None): |
| 87 |
# Use passed environment or fall back to self.env |
| 88 |
env = environment if environment is not None else self.env |
| 89 |
try: |
| 90 |
with open(soundIconPath + "/soundicons.conf", "r") as siConfig: |
| 91 |
while True: |
| 92 |
line = siConfig.readline() |
| 93 |
if not line: |
| 94 |
break |
| 95 |
line = line.replace("\n", "") |
| 96 |
if line.replace(" ", "") == "": |
| 97 |
continue |
| 98 |
if line.replace(" ", "").startswith("#"): |
| 99 |
continue |
| 100 |
if line.count("=") != 1: |
| 101 |
continue |
| 102 |
values = line.split("=") |
| 103 |
sound_icon = values[0].upper() |
| 104 |
values[1] = values[1].replace("'", "") |
| 105 |
values[1] = values[1].replace('"', "") |
| 106 |
sound_icon_file = "" |
| 107 |
if os.path.exists(values[1]): |
| 108 |
sound_icon_file = values[1] |
| 109 |
else: |
| 110 |
if not soundIconPath.endswith("/"): |
| 111 |
soundIconPath += "/" |
| 112 |
if os.path.exists(soundIconPath + values[1]): |
| 113 |
sound_icon_file = soundIconPath + values[1] |
| 114 |
env["soundIcons"][sound_icon] = sound_icon_file |
| 115 |
env["runtime"]["DebugManager"].write_debug_out( |
| 116 |
"SoundIcon: " + sound_icon + "." + sound_icon_file, |
| 117 |
debug.DebugLevel.INFO, |
| 118 |
on_any_level=True, |
| 119 |
) |
| 120 |
except (IOError, OSError) as e: |
| 121 |
env["runtime"]["DebugManager"].write_debug_out( |
| 122 |
"load_sound_icons: failed to load sound icons from " |
| 123 |
+ soundIconPath |
| 124 |
+ ". Error: " |
| 125 |
+ str(e), |
| 126 |
debug.DebugLevel.ERROR, |
| 127 |
) |
| 128 |
|
| 129 |
def get_settings_file(self): |
| 130 |
return self.settings_file |
| 131 |
|
| 132 |
def set_settings_file(self, settings_file): |
| 133 |
if os.path.exists(settings_file) and not os.access( |
| 134 |
settings_file, os.R_OK |
| 135 |
): |
| 136 |
return |
| 137 |
self.settings_file = settings_file |
| 138 |
|
| 139 |
def get_user_settings_file(self): |
| 140 |
return os.path.expanduser(self.user_settings_file) |
| 141 |
|
| 142 |
def get_system_settings_file(self): |
| 143 |
return self.system_settings_file |
| 144 |
|
| 145 |
def is_user_settings_mode(self): |
| 146 |
return os.geteuid() != 0 |
| 147 |
|
| 148 |
def get_default_save_settings_file(self): |
| 149 |
if self.is_user_settings_mode(): |
| 150 |
return self.get_user_settings_file() |
| 151 |
return self.get_system_settings_file() |
| 152 |
|
| 153 |
def get_bundled_settings_root(self): |
| 154 |
return os.path.abspath(os.path.join(fenrir_path, "../../config/")) + "/" |
| 155 |
|
| 156 |
def get_user_resource_root(self): |
| 157 |
return os.path.expanduser(self.user_resource_root) |
| 158 |
|
| 159 |
def get_user_script_path(self): |
| 160 |
return self.get_user_resource_root() |
| 161 |
|
| 162 |
def get_user_sound_root(self): |
| 163 |
return os.path.join(self.get_user_resource_root(), "sounds/") |
| 164 |
|
| 165 |
def get_resource_settings_root(self): |
| 166 |
if os.path.exists(self.system_settings_root): |
| 167 |
return self.system_settings_root |
| 168 |
bundled_settings_root = self.get_bundled_settings_root() |
| 169 |
if os.path.exists(bundled_settings_root): |
| 170 |
return bundled_settings_root |
| 171 |
return "" |
| 172 |
|
| 173 |
def get_sound_theme_roots(self): |
| 174 |
candidate_roots = [ |
| 175 |
self.get_user_sound_root(), |
| 176 |
*self.system_sound_roots, |
| 177 |
os.path.join(self.get_bundled_settings_root(), "sound/"), |
| 178 |
] |
| 179 |
sound_roots = [] |
| 180 |
seen_roots = set() |
| 181 |
for root in candidate_roots: |
| 182 |
normalized_root = os.path.abspath(os.path.expanduser(root)) |
| 183 |
if normalized_root in seen_roots: |
| 184 |
continue |
| 185 |
sound_roots.append(normalized_root + "/") |
| 186 |
seen_roots.add(normalized_root) |
| 187 |
return sound_roots |
| 188 |
|
| 189 |
def resolve_sound_theme_path(self, theme): |
| 190 |
if not theme: |
| 191 |
return "" |
| 192 |
theme = os.path.expanduser(theme) |
| 193 |
if os.path.exists(os.path.join(theme, "soundicons.conf")): |
| 194 |
return theme |
| 195 |
for sound_root in self.get_sound_theme_roots(): |
| 196 |
theme_path = os.path.join(sound_root, theme) |
| 197 |
if os.path.exists(os.path.join(theme_path, "soundicons.conf")): |
| 198 |
return theme_path |
| 199 |
return "" |
| 200 |
|
| 201 |
def load_keyboard_layout(self, environment): |
| 202 |
settings_root = self.get_resource_settings_root() |
| 203 |
keyboard_layout = self.get_setting("keyboard", "keyboard_layout") |
| 204 |
if os.path.exists(keyboard_layout): |
| 205 |
environment["runtime"]["InputManager"].load_shortcuts( |
| 206 |
keyboard_layout |
| 207 |
) |
| 208 |
return |
| 209 |
|
| 210 |
layout_path = os.path.join(settings_root, "keyboard", keyboard_layout) |
| 211 |
if os.path.exists(layout_path): |
| 212 |
self.set_setting("keyboard", "keyboard_layout", layout_path) |
| 213 |
environment["runtime"]["InputManager"].load_shortcuts(layout_path) |
| 214 |
return |
| 215 |
|
| 216 |
layout_path = os.path.join( |
| 217 |
settings_root, "keyboard", keyboard_layout + ".conf" |
| 218 |
) |
| 219 |
if os.path.exists(layout_path): |
| 220 |
self.set_setting("keyboard", "keyboard_layout", layout_path) |
| 221 |
environment["runtime"]["InputManager"].load_shortcuts(layout_path) |
| 222 |
|
| 223 |
def resolve_settings_file(self, requested_settings_file=None): |
| 224 |
if requested_settings_file and os.path.exists(requested_settings_file): |
| 225 |
return requested_settings_file |
| 226 |
|
| 227 |
if self.is_user_settings_mode() and os.path.exists( |
| 228 |
self.get_user_settings_file() |
| 229 |
): |
| 230 |
return self.get_user_settings_file() |
| 231 |
|
| 232 |
if os.path.exists(self.get_system_settings_file()): |
| 233 |
return self.get_system_settings_file() |
| 234 |
|
| 235 |
bundled_settings_file = os.path.join( |
| 236 |
self.get_bundled_settings_root(), "settings/settings.conf" |
| 237 |
) |
| 238 |
if os.path.exists(bundled_settings_file): |
| 239 |
return bundled_settings_file |
| 240 |
|
| 241 |
return "" |
| 242 |
|
| 243 |
def load_settings(self, setting_config_path): |
| 244 |
if not os.path.exists(setting_config_path): |
| 245 |
return False |
| 246 |
if not os.access(setting_config_path, os.R_OK): |
| 247 |
return False |
| 248 |
self.env["settings"] = ConfigParser() |
| 249 |
try: |
| 250 |
self.env["settings"].read(setting_config_path) |
| 251 |
except Exception as e: |
| 252 |
self.env["runtime"]["DebugManager"].write_debug_out( |
| 253 |
"settings_manager load_settings: Error reading config file: " |
| 254 |
+ str(e), |
| 255 |
debug.DebugLevel.ERROR, |
| 256 |
) |
| 257 |
return False |
| 258 |
self.set_settings_file(setting_config_path) |
| 259 |
return True |
| 260 |
|
| 261 |
def save_settings(self, setting_config_path=None): |
| 262 |
if setting_config_path is None: |
| 263 |
if self.save_settings_path: |
| 264 |
setting_config_path = self.save_settings_path |
| 265 |
else: |
| 266 |
setting_config_path = self.get_default_save_settings_file() |
| 267 |
|
| 268 |
# Ensure directory exists for user-local settings |
| 269 |
if setting_config_path and setting_config_path.startswith( |
| 270 |
os.path.expanduser("~/.local/") |
| 271 |
): |
| 272 |
config_dir = os.path.dirname(setting_config_path) |
| 273 |
if not os.path.exists(config_dir): |
| 274 |
try: |
| 275 |
os.makedirs(config_dir, mode=0o755, exist_ok=True) |
| 276 |
except Exception as e: |
| 277 |
self.env["runtime"]["DebugManager"].write_debug_out( |
| 278 |
"save_settings: failed to create directory " |
| 279 |
+ config_dir |
| 280 |
+ ": " |
| 281 |
+ str(e), |
| 282 |
debug.DebugLevel.ERROR, |
| 283 |
) |
| 284 |
# set opt dict here |
| 285 |
# save file |
| 286 |
try: |
| 287 |
# print('file: ',setting_config_path) |
| 288 |
for section, settings in self.settingArgDict.items(): |
| 289 |
for setting, value in settings.items(): |
| 290 |
# print(section, setting, value) |
| 291 |
self.env["settings"].set(section, setting, value) |
| 292 |
# print('full',self.env['settings']) |
| 293 |
|
| 294 |
config_file = open(setting_config_path, "w") |
| 295 |
self.env["settings"].write(config_file) |
| 296 |
config_file.close() |
| 297 |
os.chmod(setting_config_path, 0o644) |
| 298 |
except Exception as e: |
| 299 |
self.env["runtime"]["DebugManager"].write_debug_out( |
| 300 |
"save_settings: save settingsfile:" |
| 301 |
+ setting_config_path |
| 302 |
+ "failed. Error:" |
| 303 |
+ str(e), |
| 304 |
debug.DebugLevel.ERROR, |
| 305 |
) |
| 306 |
|
| 307 |
def set_setting(self, section, setting, value): |
| 308 |
self.set_option_arg_dict(section, setting, value) |
| 309 |
# self.env['settings'].set(section, setting, value) |
| 310 |
|
| 311 |
def get_setting(self, section, setting): |
| 312 |
value = "" |
| 313 |
try: |
| 314 |
value = self.settingArgDict[section][setting] |
| 315 |
return value |
| 316 |
except Exception as e: |
| 317 |
pass |
| 318 |
try: |
| 319 |
value = self.env["settings"].get(section, setting) |
| 320 |
except Exception as e: |
| 321 |
value = str(self.settings[section][setting]) |
| 322 |
return value |
| 323 |
|
| 324 |
def get_setting_as_int(self, section, setting): |
| 325 |
value = 0 |
| 326 |
try: |
| 327 |
value = int(self.settingArgDict[section][setting]) |
| 328 |
return value |
| 329 |
except Exception as e: |
| 330 |
pass |
| 331 |
try: |
| 332 |
value = self.env["settings"].getint(section, setting) |
| 333 |
except Exception as e: |
| 334 |
value = self.settings[section][setting] |
| 335 |
return value |
| 336 |
|
| 337 |
def get_setting_as_float(self, section, setting): |
| 338 |
value = 0.0 |
| 339 |
try: |
| 340 |
value = float(self.settingArgDict[section][setting]) |
| 341 |
return value |
| 342 |
except Exception as e: |
| 343 |
pass |
| 344 |
try: |
| 345 |
value = self.env["settings"].getfloat(section, setting) |
| 346 |
except Exception as e: |
| 347 |
value = self.settings[section][setting] |
| 348 |
return value |
| 349 |
|
| 350 |
def get_setting_as_bool(self, section, setting): |
| 351 |
value = False |
| 352 |
try: |
| 353 |
value = self.settingArgDict[section][setting].upper() in [ |
| 354 |
"1", |
| 355 |
"YES", |
| 356 |
"JA", |
| 357 |
"TRUE", |
| 358 |
] |
| 359 |
return value |
| 360 |
except Exception as e: |
| 361 |
pass |
| 362 |
try: |
| 363 |
value = self.env["settings"].getboolean(section, setting) |
| 364 |
except Exception as e: |
| 365 |
value = self.settings[section][setting] |
| 366 |
return value |
| 367 |
|
| 368 |
def load_driver(self, driverName, driverType): |
| 369 |
# Map runtime keys to actual directory names |
| 370 |
driver_dir_map = { |
| 371 |
"InputDriver": "inputDriver", |
| 372 |
"ScreenDriver": "screenDriver", |
| 373 |
"SpeechDriver": "speechDriver", |
| 374 |
"SoundDriver": "soundDriver", |
| 375 |
"RemoteDriver": "remoteDriver", |
| 376 |
} |
| 377 |
driver_dir = driver_dir_map.get(driverType, driverType) |
| 378 |
|
| 379 |
try: |
| 380 |
if self.env["runtime"][driverType] is not None: |
| 381 |
self.env["runtime"][driverType].shutdown() |
| 382 |
except Exception as e: |
| 383 |
self.env["runtime"]["DebugManager"].write_debug_out( |
| 384 |
"settings_manager load_driver: Error shutting down driver: " |
| 385 |
+ str(e), |
| 386 |
debug.DebugLevel.ERROR, |
| 387 |
) |
| 388 |
try: |
| 389 |
driver_mod = module_utils.import_module( |
| 390 |
driverName, |
| 391 |
fenrir_path + "/" + driver_dir + "/" + driverName + ".py", |
| 392 |
) |
| 393 |
self.env["runtime"][driverType] = driver_mod.driver() |
| 394 |
self.env["runtime"][driverType].initialize(self.env) |
| 395 |
self.env["runtime"]["DebugManager"].write_debug_out( |
| 396 |
"Loading Driver " + driverType + " (" + driverName + ") OK", |
| 397 |
debug.DebugLevel.INFO, |
| 398 |
on_any_level=True, |
| 399 |
) |
| 400 |
except Exception as e: |
| 401 |
self.env["runtime"]["DebugManager"].write_debug_out( |
| 402 |
"Loading Driver " |
| 403 |
+ driverType |
| 404 |
+ " (" |
| 405 |
+ driverName |
| 406 |
+ ") FAILED:" |
| 407 |
+ str(e), |
| 408 |
debug.DebugLevel.ERROR, |
| 409 |
) |
| 410 |
try: |
| 411 |
driver_mod = module_utils.import_module( |
| 412 |
driverName, |
| 413 |
fenrir_path + "/" + driver_dir + "/dummyDriver.py", |
| 414 |
) |
| 415 |
self.env["runtime"][driverType] = driver_mod.driver() |
| 416 |
self.env["runtime"][driverType].initialize(self.env) |
| 417 |
except Exception as e: |
| 418 |
self.env["runtime"]["DebugManager"].write_debug_out( |
| 419 |
"(fallback) Loading Driver " |
| 420 |
+ driverType |
| 421 |
+ " (dummyDriver) FAILED:" |
| 422 |
+ str(e), |
| 423 |
debug.DebugLevel.ERROR, |
| 424 |
) |
| 425 |
|
| 426 |
def shutdown_driver(self, driverType): |
| 427 |
try: |
| 428 |
self.env["runtime"][driverType].shutdown() |
| 429 |
except Exception as e: |
| 430 |
pass |
| 431 |
del self.env["runtime"][driverType] |
| 432 |
|
| 433 |
def set_fenrir_keys(self, keys): |
| 434 |
keys = keys.upper() |
| 435 |
key_list = keys.split(",") |
| 436 |
for key in key_list: |
| 437 |
if key not in self.env["input"]["fenrir_key"]: |
| 438 |
self.env["input"]["fenrir_key"].append(key) |
| 439 |
|
| 440 |
def set_script_keys(self, keys): |
| 441 |
keys = keys.upper() |
| 442 |
key_list = keys.split(",") |
| 443 |
for key in key_list: |
| 444 |
if key not in self.env["input"]["script_key"]: |
| 445 |
self.env["input"]["script_key"].append(key) |
| 446 |
|
| 447 |
def reset_setting_arg_dict(self): |
| 448 |
self.settingArgDict = {} |
| 449 |
self.env["runtime"]["OutputManager"].reset_SpeechDriver() |
| 450 |
|
| 451 |
def set_option_arg_dict(self, section, setting, value): |
| 452 |
# section = section.lower() |
| 453 |
# setting = setting.lower() |
| 454 |
try: |
| 455 |
e = self.settingArgDict[section] |
| 456 |
except KeyError: |
| 457 |
self.settingArgDict[section] = {} |
| 458 |
try: |
| 459 |
t = self.settings[section][setting] |
| 460 |
except Exception as e: |
| 461 |
print(section, setting, "not found") |
| 462 |
return |
| 463 |
try: |
| 464 |
v = value # Initialize v with the original value |
| 465 |
if isinstance(self.settings[section][setting], str): |
| 466 |
v = str(value) |
| 467 |
elif isinstance(self.settings[section][setting], bool): |
| 468 |
if value not in ["True", "False"]: |
| 469 |
raise ValueError( |
| 470 |
"could not convert string to bool: " + value |
| 471 |
) |
| 472 |
v = value == "True" |
| 473 |
elif isinstance(self.settings[section][setting], int): |
| 474 |
v = int(value) |
| 475 |
elif isinstance(self.settings[section][setting], float): |
| 476 |
v = float(value) |
| 477 |
|
| 478 |
# Content validation for critical settings |
| 479 |
self._validate_setting_value(section, setting, v) |
| 480 |
|
| 481 |
self.settingArgDict[section][setting] = str(value) |
| 482 |
except Exception as e: |
| 483 |
print( |
| 484 |
"settings_manager:set_option_arg_dict:Datatype missmatch: " |
| 485 |
+ section |
| 486 |
+ "#" |
| 487 |
+ setting |
| 488 |
+ "=" |
| 489 |
+ str(value) |
| 490 |
+ " Error:" |
| 491 |
+ str(e) |
| 492 |
) |
| 493 |
# self.env['runtime']['DebugManager'].write_debug_out('settings_manager:set_option_arg_dict:Datatype |
| 494 |
# missmatch: '+ section + '#' + setting + '=' + value + ' Error:' |
| 495 |
# + str(e), debug.DebugLevel.ERROR) |
| 496 |
return |
| 497 |
|
| 498 |
def _validate_setting_value(self, section, setting, value): |
| 499 |
"""Validate setting values for critical screen reader functionality. |
| 500 |
Only validates settings that could cause crashes or accessibility issues. |
| 501 |
Invalid values raise ValueError which is caught by the calling method. |
| 502 |
""" |
| 503 |
|
| 504 |
# Speech settings validation - critical for accessibility |
| 505 |
if section == "speech": |
| 506 |
if setting == "rate": |
| 507 |
if not (0.0 <= value <= 3.0): |
| 508 |
raise ValueError( |
| 509 |
f"Speech rate must be between 0.0 and 3.0, got {value}" |
| 510 |
) |
| 511 |
elif setting == "pitch": |
| 512 |
if not (0.0 <= value <= 2.0): |
| 513 |
raise ValueError( |
| 514 |
f"Speech pitch must be between 0.0 and 2.0, got {value}" |
| 515 |
) |
| 516 |
elif setting == "volume": |
| 517 |
if not (0.0 <= value <= 1.5): |
| 518 |
raise ValueError( |
| 519 |
f"Speech volume must be between 0.0 and 1.5, got {value}" |
| 520 |
) |
| 521 |
elif setting == "driver": |
| 522 |
valid_drivers = [ |
| 523 |
"speechdDriver", |
| 524 |
"genericDriver", |
| 525 |
"dectalkDriver", |
| 526 |
"dectalkUsbDriver", |
| 527 |
"doubletalkDriver", |
| 528 |
"litetalkDriver", |
| 529 |
"tripletalkDriver", |
| 530 |
"dummyDriver", |
| 531 |
] |
| 532 |
if value not in valid_drivers: |
| 533 |
raise ValueError( |
| 534 |
f"Invalid speech driver: {value}. Valid options: {valid_drivers}" |
| 535 |
) |
| 536 |
|
| 537 |
# Sound settings validation |
| 538 |
elif section == "sound": |
| 539 |
if setting == "volume": |
| 540 |
if not (0.0 <= value <= 1.5): |
| 541 |
raise ValueError( |
| 542 |
f"Sound volume must be between 0.0 and 1.5, got {value}" |
| 543 |
) |
| 544 |
elif setting == "driver": |
| 545 |
valid_drivers = [ |
| 546 |
"genericDriver", |
| 547 |
"gstreamerDriver", |
| 548 |
"dummyDriver", |
| 549 |
] |
| 550 |
if value not in valid_drivers: |
| 551 |
raise ValueError( |
| 552 |
f"Invalid sound driver: {value}. Valid options: {valid_drivers}" |
| 553 |
) |
| 554 |
|
| 555 |
# Screen settings validation |
| 556 |
elif section == "screen": |
| 557 |
if setting == "driver": |
| 558 |
valid_drivers = ["vcsaDriver", "ptyDriver", "dummyDriver"] |
| 559 |
if value not in valid_drivers: |
| 560 |
raise ValueError( |
| 561 |
f"Invalid screen driver: {value}. Valid options: {valid_drivers}" |
| 562 |
) |
| 563 |
|
| 564 |
# Input settings validation |
| 565 |
elif section == "keyboard": |
| 566 |
if setting == "driver": |
| 567 |
valid_drivers = [ |
| 568 |
"evdevDriver", |
| 569 |
"x11Driver", |
| 570 |
"dummyDriver", |
| 571 |
] |
| 572 |
if value not in valid_drivers: |
| 573 |
raise ValueError( |
| 574 |
f"Invalid input driver: {value}. Valid options: {valid_drivers}" |
| 575 |
) |
| 576 |
|
| 577 |
# General settings validation |
| 578 |
elif section == "general": |
| 579 |
if setting == "debug_level": |
| 580 |
if not (0 <= value <= 3): |
| 581 |
raise ValueError( |
| 582 |
f"Debug level must be between 0 and 3, got {value}" |
| 583 |
) |
| 584 |
|
| 585 |
def parse_setting_args(self, settingArgs): |
| 586 |
if settingArgs is None: |
| 587 |
return |
| 588 |
for optionElem in settingArgs.split(";"): |
| 589 |
setting_val_list = [] |
| 590 |
section_option_list = [] |
| 591 |
section = "" |
| 592 |
option = "" |
| 593 |
value = "" |
| 594 |
setting_val_list = optionElem.split("=", 1) |
| 595 |
if len(setting_val_list) != 2: |
| 596 |
continue |
| 597 |
if "#" in setting_val_list[0]: |
| 598 |
section_option_list = setting_val_list[0].split("#", 1) |
| 599 |
elif "." in setting_val_list[0]: |
| 600 |
section_option_list = setting_val_list[0].split(".", 1) |
| 601 |
elif "," in setting_val_list[0]: |
| 602 |
section_option_list = setting_val_list[0].split(",", 1) |
| 603 |
elif "!" in setting_val_list[0]: |
| 604 |
section_option_list = setting_val_list[0].split("!", 1) |
| 605 |
else: |
| 606 |
continue |
| 607 |
if len(section_option_list) != 2: |
| 608 |
continue |
| 609 |
|
| 610 |
section = str(section_option_list[0]) |
| 611 |
option = str(section_option_list[1]) |
| 612 |
value = str(setting_val_list[1]) |
| 613 |
self.set_option_arg_dict(section, option, value) |
| 614 |
|
| 615 |
def init_fenrir_config( |
| 616 |
self, cliArgs, fenrir_manager=None, environment=environment.environment |
| 617 |
): |
| 618 |
self.cliArgs = cliArgs |
| 619 |
|
| 620 |
settings_root = self.get_resource_settings_root() |
| 621 |
if not settings_root: |
| 622 |
return None |
| 623 |
|
| 624 |
self.save_settings_path = self.get_default_save_settings_file() |
| 625 |
settings_file = self.resolve_settings_file(cliArgs.setting) |
| 626 |
if not settings_file: |
| 627 |
return None |
| 628 |
|
| 629 |
environment["runtime"]["SettingsManager"] = self |
| 630 |
environment["runtime"]["SettingsManager"].initialize(environment) |
| 631 |
|
| 632 |
valid_config = environment["runtime"]["SettingsManager"].load_settings( |
| 633 |
settings_file |
| 634 |
) |
| 635 |
if not valid_config: |
| 636 |
return None |
| 637 |
if cliArgs.options != "": |
| 638 |
self.parse_setting_args(cliArgs.options) |
| 639 |
if cliArgs.debug: |
| 640 |
self.set_setting("general", "debug_level", 3) |
| 641 |
if cliArgs.print: |
| 642 |
self.set_setting("general", "debug_level", 3) |
| 643 |
self.set_setting("general", "debug_mode", "PRINT") |
| 644 |
if cliArgs.x11: |
| 645 |
self.set_setting("screen", "driver", "ptyDriver") |
| 646 |
self.set_setting("keyboard", "driver", "x11Driver") |
| 647 |
if cliArgs.x11_window_id: |
| 648 |
self.set_setting( |
| 649 |
"keyboard", "x11_window_id", cliArgs.x11_window_id |
| 650 |
) |
| 651 |
|
| 652 |
self.set_fenrir_keys(self.get_setting("general", "fenrir_keys")) |
| 653 |
self.set_script_keys(self.get_setting("general", "script_keys")) |
| 654 |
|
| 655 |
environment["runtime"]["DebugManager"] = debugManager.DebugManager( |
| 656 |
self.env["runtime"]["SettingsManager"].get_setting( |
| 657 |
"general", "debug_file" |
| 658 |
) |
| 659 |
) |
| 660 |
environment["runtime"]["DebugManager"].initialize(environment) |
| 661 |
environment["runtime"]["DebugManager"].write_debug_out( |
| 662 |
"Fenrir startup CLI arguments: " + self.format_cli_args(cliArgs), |
| 663 |
debug.DebugLevel.INFO, |
| 664 |
on_any_level=True, |
| 665 |
) |
| 666 |
|
| 667 |
if cliArgs.force_all_screens: |
| 668 |
environment["runtime"]["force_all_screens"] = True |
| 669 |
|
| 670 |
if cliArgs.ignore_screen: |
| 671 |
current_ignore_screen = self.get_setting("screen", "ignore_screen") |
| 672 |
if current_ignore_screen: |
| 673 |
ignore_screens = ( |
| 674 |
current_ignore_screen.split(",") + cliArgs.ignore_screen |
| 675 |
) |
| 676 |
else: |
| 677 |
ignore_screens = cliArgs.ignore_screen |
| 678 |
self.set_setting( |
| 679 |
"screen", "ignore_screen", ",".join(ignore_screens) |
| 680 |
) |
| 681 |
|
| 682 |
sound_theme_path = self.resolve_sound_theme_path( |
| 683 |
self.get_setting("sound", "theme") |
| 684 |
) |
| 685 |
if sound_theme_path: |
| 686 |
self.set_setting("sound", "theme", sound_theme_path) |
| 687 |
environment["runtime"]["SettingsManager"].load_sound_icons( |
| 688 |
self.get_setting("sound", "theme"), environment |
| 689 |
) |
| 690 |
|
| 691 |
environment["runtime"][ |
| 692 |
"PunctuationManager" |
| 693 |
] = punctuationManager.PunctuationManager() |
| 694 |
environment["runtime"]["PunctuationManager"].initialize(environment) |
| 695 |
|
| 696 |
environment["runtime"]["TextManager"] = textManager.TextManager() |
| 697 |
environment["runtime"]["TextManager"].initialize(environment) |
| 698 |
|
| 699 |
if not os.path.exists( |
| 700 |
self.get_setting("general", "punctuation_profile") |
| 701 |
): |
| 702 |
if os.path.exists( |
| 703 |
settings_root |
| 704 |
+ "punctuation/" |
| 705 |
+ self.get_setting("general", "punctuation_profile") |
| 706 |
): |
| 707 |
self.set_setting( |
| 708 |
"general", |
| 709 |
"punctuation_profile", |
| 710 |
settings_root |
| 711 |
+ "punctuation/" |
| 712 |
+ self.get_setting("general", "punctuation_profile"), |
| 713 |
) |
| 714 |
environment["runtime"]["PunctuationManager"].load_dicts( |
| 715 |
self.get_setting("general", "punctuation_profile") |
| 716 |
) |
| 717 |
if os.path.exists( |
| 718 |
settings_root |
| 719 |
+ "punctuation/" |
| 720 |
+ self.get_setting("general", "punctuation_profile") |
| 721 |
+ ".conf" |
| 722 |
): |
| 723 |
self.set_setting( |
| 724 |
"general", |
| 725 |
"punctuation_profile", |
| 726 |
settings_root |
| 727 |
+ "punctuation/" |
| 728 |
+ self.get_setting("general", "punctuation_profile") |
| 729 |
+ ".conf", |
| 730 |
) |
| 731 |
environment["runtime"]["PunctuationManager"].load_dicts( |
| 732 |
self.get_setting("general", "punctuation_profile") |
| 733 |
) |
| 734 |
else: |
| 735 |
environment["runtime"]["PunctuationManager"].load_dicts( |
| 736 |
self.get_setting("general", "punctuation_profile") |
| 737 |
) |
| 738 |
|
| 739 |
if fenrir_manager: |
| 740 |
environment["runtime"]["FenrirManager"] = fenrir_manager |
| 741 |
|
| 742 |
environment["runtime"]["MemoryManager"] = memoryManager.MemoryManager() |
| 743 |
environment["runtime"]["MemoryManager"].initialize(environment) |
| 744 |
|
| 745 |
environment["runtime"][ |
| 746 |
"AttributeManager" |
| 747 |
] = attributeManager.AttributeManager() |
| 748 |
environment["runtime"]["AttributeManager"].initialize(environment) |
| 749 |
|
| 750 |
environment["runtime"]["EventManager"] = eventManager.EventManager() |
| 751 |
environment["runtime"]["EventManager"].initialize(environment) |
| 752 |
|
| 753 |
environment["runtime"][ |
| 754 |
"ProcessManager" |
| 755 |
] = processManager.ProcessManager() |
| 756 |
environment["runtime"]["ProcessManager"].initialize(environment) |
| 757 |
|
| 758 |
environment["runtime"][ |
| 759 |
"BackgroundTaskManager" |
| 760 |
] = backgroundTaskManager.BackgroundTaskManager() |
| 761 |
environment["runtime"]["BackgroundTaskManager"].initialize(environment) |
| 762 |
|
| 763 |
environment["runtime"]["OutputManager"] = outputManager.OutputManager() |
| 764 |
environment["runtime"]["OutputManager"].initialize(environment) |
| 765 |
|
| 766 |
environment["runtime"][ |
| 767 |
"SpeechHistoryManager" |
| 768 |
] = speechHistoryManager.SpeechHistoryManager() |
| 769 |
environment["runtime"]["SpeechHistoryManager"].initialize(environment) |
| 770 |
|
| 771 |
environment["runtime"]["InputManager"] = inputManager.InputManager() |
| 772 |
environment["runtime"]["InputManager"].initialize(environment) |
| 773 |
self.load_keyboard_layout(environment) |
| 774 |
|
| 775 |
environment["runtime"]["ScreenManager"] = screenManager.ScreenManager() |
| 776 |
environment["runtime"]["ScreenManager"].initialize(environment) |
| 777 |
|
| 778 |
environment["runtime"][ |
| 779 |
"CommandManager" |
| 780 |
] = commandManager.CommandManager() |
| 781 |
environment["runtime"]["CommandManager"].initialize(environment) |
| 782 |
|
| 783 |
environment["runtime"][ |
| 784 |
"ClipboardSyncManager" |
| 785 |
] = clipboardSyncManager.ClipboardSyncManager() |
| 786 |
environment["runtime"]["ClipboardSyncManager"].initialize( |
| 787 |
environment |
| 788 |
) |
| 789 |
|
| 790 |
environment["runtime"]["HelpManager"] = helpManager.HelpManager() |
| 791 |
environment["runtime"]["HelpManager"].initialize(environment) |
| 792 |
|
| 793 |
environment["runtime"]["RemoteManager"] = remoteManager.RemoteManager() |
| 794 |
environment["runtime"]["RemoteManager"].initialize(environment) |
| 795 |
|
| 796 |
environment["runtime"][ |
| 797 |
"DiffReviewManager" |
| 798 |
] = diffReviewManager.DiffReviewManager() |
| 799 |
environment["runtime"]["DiffReviewManager"].initialize(environment) |
| 800 |
|
| 801 |
environment["runtime"]["CursorManager"] = cursorManager.CursorManager() |
| 802 |
environment["runtime"]["CursorManager"].initialize(environment) |
| 803 |
environment["runtime"][ |
| 804 |
"ApplicationManager" |
| 805 |
] = applicationManager.ApplicationManager() |
| 806 |
environment["runtime"]["ApplicationManager"].initialize(environment) |
| 807 |
environment["runtime"]["TextManager"] = textManager.TextManager() |
| 808 |
environment["runtime"]["TextManager"].initialize(environment) |
| 809 |
environment["runtime"]["TableManager"] = tableManager.TableManager() |
| 810 |
environment["runtime"]["TableManager"].initialize(environment) |
| 811 |
environment["runtime"][ |
| 812 |
"BarrierManager" |
| 813 |
] = barrierManager.BarrierManager() |
| 814 |
environment["runtime"]["BarrierManager"].initialize(environment) |
| 815 |
environment["runtime"]["SayAllManager"] = sayAllManager.SayAllManager() |
| 816 |
environment["runtime"]["SayAllManager"].initialize(environment) |
| 817 |
environment["runtime"][ |
| 818 |
"SpeechDiscoveryManager" |
| 819 |
] = speechDiscoveryManager.SpeechDiscoveryManager() |
| 820 |
environment["runtime"]["SpeechDiscoveryManager"].initialize(environment) |
| 821 |
environment["runtime"]["VmenuManager"] = vmenuManager.VmenuManager() |
| 822 |
environment["runtime"]["VmenuManager"].initialize(environment) |
| 823 |
environment["runtime"][ |
| 824 |
"QuickMenuManager" |
| 825 |
] = quickMenuManager.QuickMenuManager() |
| 826 |
environment["runtime"]["QuickMenuManager"].initialize(environment) |
| 827 |
|
| 828 |
environment["runtime"][ |
| 829 |
"ReadAllManager" |
| 830 |
] = readAllManager.ReadAllManager() |
| 831 |
environment["runtime"]["ReadAllManager"].initialize(environment) |
| 832 |
|
| 833 |
# only possible after having input and screen managers with clean |
| 834 |
# buffer |
| 835 |
environment["runtime"]["InputManager"].write_event_buffer() |
| 836 |
environment["runtime"]["InputManager"].handle_device_grab(force=True) |
| 837 |
|
| 838 |
environment["runtime"]["DebugManager"].write_debug_out( |
| 839 |
r"/-------environment-------/", |
| 840 |
debug.DebugLevel.INFO, |
| 841 |
on_any_level=True, |
| 842 |
) |
| 843 |
environment["runtime"]["DebugManager"].write_debug_out( |
| 844 |
str(environment), debug.DebugLevel.INFO, on_any_level=True |
| 845 |
) |
| 846 |
environment["runtime"]["DebugManager"].write_debug_out( |
| 847 |
r"/-------settings.conf-------/", |
| 848 |
debug.DebugLevel.INFO, |
| 849 |
on_any_level=True, |
| 850 |
) |
| 851 |
environment["runtime"]["DebugManager"].write_debug_out( |
| 852 |
str(environment["settings"]._sections), |
| 853 |
debug.DebugLevel.INFO, |
| 854 |
on_any_level=True, |
| 855 |
) |
| 856 |
environment["runtime"]["DebugManager"].write_debug_out( |
| 857 |
r"/-------self.settingArgDict-------/", |
| 858 |
debug.DebugLevel.INFO, |
| 859 |
on_any_level=True, |
| 860 |
) |
| 861 |
environment["runtime"]["DebugManager"].write_debug_out( |
| 862 |
str(self.settingArgDict), debug.DebugLevel.INFO, on_any_level=True |
| 863 |
) |
| 864 |
self.bindingsBackup = environment["bindings"].copy() |
| 865 |
|
| 866 |
return environment |