Fixed version conflict.
This commit is contained in:
		| @@ -0,0 +1,90 @@ | ||||
| #!/usr/bin/env python3 | ||||
| # -*- coding: utf-8 -*- | ||||
|  | ||||
| # Fenrir TTY screen reader | ||||
| # By Chrys, Storm Dragon, and contributers. | ||||
|  | ||||
| from fenrirscreenreader.core import debug | ||||
| import os | ||||
|  | ||||
| class command(): | ||||
|     def __init__(self): | ||||
|         pass | ||||
|     def initialize(self, environment): | ||||
|         self.env = environment | ||||
|     def shutdown(self): | ||||
|         pass  | ||||
|     def getDescription(self): | ||||
|         return _('cycles between available keyboard layouts') | ||||
|      | ||||
|     def getAvailableLayouts(self): | ||||
|         """Get list of available keyboard layout files""" | ||||
|         layouts = [] | ||||
|          | ||||
|         # Check standard locations for keyboard layouts | ||||
|         settingsRoot = '/etc/fenrirscreenreader/' | ||||
|         if not os.path.exists(settingsRoot): | ||||
|             # Fallback to source directory | ||||
|             import fenrirscreenreader | ||||
|             fenrirPath = os.path.dirname(fenrirscreenreader.__file__) | ||||
|             settingsRoot = fenrirPath + '/../../config/' | ||||
|          | ||||
|         keyboardPath = settingsRoot + 'keyboard/' | ||||
|          | ||||
|         if os.path.exists(keyboardPath): | ||||
|             for file in os.listdir(keyboardPath): | ||||
|                 if file.endswith('.conf') and not file.startswith('__') and not file.lower().startswith('pty'): | ||||
|                     layout_name = file.replace('.conf', '') | ||||
|                     if layout_name not in layouts: | ||||
|                         layouts.append(layout_name) | ||||
|          | ||||
|         # Ensure we have at least basic layouts | ||||
|         if not layouts: | ||||
|             layouts = ['desktop', 'laptop'] | ||||
|         else: | ||||
|             layouts.sort() | ||||
|              | ||||
|         return layouts | ||||
|      | ||||
|     def run(self): | ||||
|         current_layout = self.env['runtime']['settingsManager'].getSetting('keyboard', 'keyboardLayout') | ||||
|          | ||||
|         # Extract layout name from full path if needed | ||||
|         if '/' in current_layout: | ||||
|             current_layout = os.path.basename(current_layout).replace('.conf', '') | ||||
|              | ||||
|         # Get available layouts | ||||
|         available_layouts = self.getAvailableLayouts() | ||||
|          | ||||
|         # Find next layout in cycle | ||||
|         try: | ||||
|             current_index = available_layouts.index(current_layout) | ||||
|             next_index = (current_index + 1) % len(available_layouts) | ||||
|         except ValueError: | ||||
|             # If current layout not found, start from beginning | ||||
|             next_index = 0 | ||||
|              | ||||
|         next_layout = available_layouts[next_index] | ||||
|          | ||||
|         # Update setting and reload shortcuts | ||||
|         self.env['runtime']['settingsManager'].setSetting('keyboard', 'keyboardLayout', next_layout) | ||||
|          | ||||
|         # Reload shortcuts with new layout | ||||
|         try: | ||||
|             self.env['runtime']['inputManager'].reloadShortcuts() | ||||
|             self.env['runtime']['outputManager'].presentText( | ||||
|                 _('Switched to {} keyboard layout').format(next_layout),  | ||||
|                 interrupt=True | ||||
|             ) | ||||
|         except Exception as e: | ||||
|             self.env['runtime']['debug'].writeDebugOut( | ||||
|                 "Error reloading shortcuts: " + str(e),  | ||||
|                 debug.debugLevel.ERROR | ||||
|             ) | ||||
|             self.env['runtime']['outputManager'].presentText( | ||||
|                 _('Error switching keyboard layout'),  | ||||
|                 interrupt=True | ||||
|             ) | ||||
|  | ||||
|     def setCallback(self, callback): | ||||
|         pass | ||||
| @@ -389,3 +389,35 @@ class inputManager(): | ||||
|         self.lastDetectedDevices =devices | ||||
|     def getLastDetectedDevices(self): | ||||
|         return self.lastDetectedDevices | ||||
|     def reloadShortcuts(self): | ||||
|         """Reload keyboard shortcuts from current layout setting""" | ||||
|         # Clear existing bindings | ||||
|         self.env['bindings'].clear() | ||||
|         self.env['rawBindings'].clear() | ||||
|          | ||||
|         # Get current layout path | ||||
|         layout_setting = self.env['runtime']['settingsManager'].getSetting('keyboard', 'keyboardLayout') | ||||
|          | ||||
|         # Resolve full path if needed | ||||
|         if not os.path.exists(layout_setting): | ||||
|             settingsRoot = '/etc/fenrirscreenreader/' | ||||
|             if not os.path.exists(settingsRoot): | ||||
|                 import fenrirscreenreader | ||||
|                 fenrirPath = os.path.dirname(fenrirscreenreader.__file__) | ||||
|                 settingsRoot = fenrirPath + '/../../config/' | ||||
|              | ||||
|             layout_path = settingsRoot + 'keyboard/' + layout_setting + '.conf' | ||||
|             if not os.path.exists(layout_path): | ||||
|                 # Fallback to default if layout not found | ||||
|                 layout_path = settingsRoot + 'keyboard/desktop.conf' | ||||
|         else: | ||||
|             layout_path = layout_setting | ||||
|          | ||||
|         # Reload shortcuts | ||||
|         self.loadShortcuts(layout_path) | ||||
|          | ||||
|         self.env['runtime']['debug'].writeDebugOut( | ||||
|             "Reloaded shortcuts from: " + layout_path,  | ||||
|             debug.debugLevel.INFO,  | ||||
|             onAnyLevel=True | ||||
|         ) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user