Debian Codegraph @

docs/development.txt

raw
1 # Fenrir Development Guide
2
3 This document provides information for developers who want to contribute to Fenrir or understand its architecture.
4
5 ## Project Structure
6
7 Fenrir follows a modular, driver-based architecture:
8
9 ```
10 src/fenrirscreenreader/
11 ├── core/ # Core system modules
12 │ ├── fenrirManager.py # Main application manager
13 │ ├── screenManager.py # Screen handling
14 │ ├── inputManager.py # Input handling
15 │ ├── outputManager.py # Speech/sound output
16 │ ├── commandManager.py # Command system
17 │ └── settingsManager.py # Configuration management
18 ├── commands/ # Command implementations
19 │ ├── commands/ # User-invoked commands
20 │ ├── onCursorChange/ # Cursor movement hooks
21 │ ├── onScreenUpdate/ # Screen update hooks
22 │ ├── onKeyInput/ # Key input hooks
23 │ └── help/ # Tutorial system
24 ├── drivers/ # Driver implementations
25 │ ├── inputDriver/ # Input drivers (evdev, x11)
26 │ ├── screenDriver/ # Screen drivers (vcsa, pty)
27 │ ├── speechDriver/ # Speech drivers (speechd, generic)
28 │ └── soundDriver/ # Sound drivers (generic, gstreamer)
29 └── utils/ # Utility modules
30 ```
31
32 ## Core Architecture
33
34 ### Driver System
35 Fenrir uses a pluggable driver architecture:
36
37 1. **Input Drivers**: Capture keyboard input
38 - evdevDriver: Linux evdev (recommended)
39 - x11Driver: X11 terminal-scoped input
40
41 2. **Screen Drivers**: Read screen content
42 - vcsaDriver: Linux VCSA devices
43 - ptyDriver: Terminal emulation
44
45 3. **Speech Drivers**: Text-to-speech output
46 - speechdDriver: Speech-dispatcher
47 - genericDriver: Command-line TTS
48
49 4. **Sound Drivers**: Audio output
50 - genericDriver: Sox-based
51 - gstreamerDriver: GStreamer
52
53 5. **Remote Drivers**: Remote control interfaces
54 - unixDriver: Unix socket control
55 - tcpDriver: TCP socket control
56
57 ### Command System
58 Commands are Python modules that implement specific functionality:
59
60 ```python
61 class command():
62 def __init__(self):
63 pass
64
65 def initialize(self, environment):
66 self.env = environment
67
68 def shutdown(self):
69 pass
70
71 def getDescription(self):
72 return _('Command description')
73
74 def run(self):
75 # Command implementation
76 pass
77 ```
78
79 ### Event Hooks
80 Fenrir supports various event hooks:
81
82 - **onCursorChange**: Triggered when cursor moves
83 - **onScreenUpdate**: Triggered on screen content changes
84 - **onKeyInput**: Triggered on key presses
85 - **onScreenChanged**: Triggered when switching screens
86
87 ## Development Setup
88
89 ### Requirements
90 - Python 3.6+
91 - python3-evdev
92 - python3-pyudev
93 - speech-dispatcher
94 - sox
95
96 ### Getting Started
97 ```bash
98 # Clone repository
99 git clone https://git.stormux.org/storm/fenrir.git
100 cd fenrir
101
102 # Install dependencies
103 sudo pip3 install -r requirements.txt
104
105 # Run from source
106 cd src/
107 sudo ./fenrir -f -d
108 ```
109
110 ### Testing
111 ```bash
112 # Run in debug mode
113 sudo ./fenrir -f -d -p
114
115 # Debug output goes to:
116 # - Console (with -p flag)
117 # - /tmp/fenrir.log
118 ```
119
120 ## Creating Commands
121
122 ### Basic Command
123 Create a file in `src/fenrirscreenreader/commands/commands/`:
124
125 ```python
126 from fenrirscreenreader.core import debug
127
128 class command():
129 def __init__(self):
130 pass
131
132 def initialize(self, environment):
133 self.env = environment
134
135 def shutdown(self):
136 pass
137
138 def getDescription(self):
139 return _('My custom command')
140
141 def run(self):
142 # Get current text
143 text = self.env['screen']['newContentText']
144
145 # Speak something
146 self.env['runtime']['outputManager'].presentText('Hello World')
147
148 # Play sound
149 self.env['runtime']['outputManager'].playSoundIcon('Accept')
150 ```
151
152 ### Key Bindings
153 Add key bindings in keyboard layout files:
154 `config/keyboard/desktop.conf` or `config/keyboard/laptop.conf`
155
156 ```ini
157 [KEY_CTRL]#[KEY_ALT]#[KEY_H]=my_command
158 ```
159
160 ### Event Hooks
161 Create event handlers in appropriate directories:
162
163 ```python
164 # onCursorChange/my_hook.py
165 class command():
166 def __init__(self):
167 pass
168
169 def initialize(self, environment):
170 self.env = environment
171
172 def shutdown(self):
173 pass
174
175 def getDescription(self):
176 return _('My cursor change handler')
177
178 def run(self):
179 if self.env['runtime']['cursorManager'].isCursorHorizontalMove():
180 # Handle horizontal cursor movement
181 pass
182 ```
183
184 ## Creating Drivers
185
186 ### Driver Template
187 ```python
188 class driver():
189 def __init__(self):
190 pass
191
192 def initialize(self, environment):
193 self.env = environment
194
195 def shutdown(self):
196 pass
197
198 # Driver-specific methods...
199 ```
200
201 ### Input Driver
202 Implement these methods:
203 - `getInputEvent()`: Return input events
204 - `writeEventBuffer()`: Handle output events
205 - `grabDevices()`: Take exclusive control
206 - `releaseDevices()`: Release control
207
208 ### Screen Driver
209 Implement these methods:
210 - `getCurrScreen()`: Get current screen content
211 - `getSessionInformation()`: Get session info
212
213 ### Speech Driver
214 Implement these methods:
215 - `speak()`: Speak text
216 - `cancel()`: Stop speech
217 - `setCallback()`: Set callback functions
218
219 ### Remote Driver
220 Implement these methods:
221 - `initialize()`: Setup socket/connection
222 - `watchDog()`: Listen for incoming commands
223 - `shutdown()`: Clean up connections
224
225 #### Remote Driver Example
226 ```python
227 class driver(remoteDriver):
228 def initialize(self, environment):
229 self.env = environment
230 # Start watchdog thread
231 self.env['runtime']['processManager'].addCustomEventThread(
232 self.watchDog, multiprocess=True
233 )
234
235 def watchDog(self, active, eventQueue):
236 # Listen for connections and process commands
237 while active.value:
238 # Accept connections
239 # Parse incoming data
240 # Send to event queue
241 eventQueue.put({
242 "Type": fenrirEventType.RemoteIncomming,
243 "Data": command_text
244 })
245 ```
246
247 ## Configuration
248
249 ### Settings System
250 Settings are hierarchical:
251 1. Command-line options (`-o`)
252 2. Configuration file
253 3. Hard-coded defaults
254
255 ### Adding Settings
256 1. Add default value to `core/settingsData.py`
257 2. Access via `self.env['runtime']['settingsManager'].getSetting(section, key)`
258
259 ## Debugging
260
261 ### Debug Levels
262 - 0: DEACTIVE
263 - 1: ERROR
264 - 2: WARNING
265 - 3: INFO
266
267 ### Debug Output
268 ```python
269 self.env['runtime']['debug'].writeDebugOut(
270 'Debug message',
271 debug.debugLevel.INFO
272 )
273 ```
274
275 ### Testing Commands
276 ```bash
277 # Test specific functionality
278 sudo fenrir -f -d -o "general#debugLevel=3"
279
280 # Test with custom config
281 sudo fenrir -f -s /path/to/test.conf
282 ```
283
284 ## Contributing
285
286 ### Code Style
287 - Follow PEP 8
288 - Use descriptive variable names
289 - Add docstrings for complex functions
290 - Handle exceptions gracefully
291
292 ### Testing
293 - Test with different drivers
294 - Test keyboard layouts
295 - Test on different terminals
296 - Verify accessibility features
297
298 ### Submitting Changes
299 1. Fork the repository
300 2. Create feature branch
301 3. Make changes with clear commit messages
302 4. Test thoroughly
303 5. Submit pull request
304
305 ## API Reference
306
307 ### Environment Structure
308 The `environment` dict contains all runtime data:
309
310 ```python
311 environment = {
312 'runtime': {
313 'settingsManager': settingsManager,
314 'commandManager': commandManager,
315 'screenManager': screenManager,
316 'inputManager': inputManager,
317 'outputManager': outputManager,
318 'debug': debugManager,
319 # ... other managers
320 },
321 'screen': {
322 'newContentText': '',
323 'oldContentText': '',
324 'newCursor': {'x': 0, 'y': 0},
325 'oldCursor': {'x': 0, 'y': 0},
326 # ... screen data
327 },
328 'general': {
329 'prevCommand': '',
330 'currCommand': '',
331 # ... general data
332 }
333 }
334 ```
335
336 ### Common Operations
337
338 #### Speaking Text
339 ```python
340 self.env['runtime']['outputManager'].presentText('Hello')
341 ```
342
343 #### Playing Sounds
344 ```python
345 self.env['runtime']['outputManager'].playSoundIcon('Accept')
346 ```
347
348 #### Getting Settings
349 ```python
350 rate = self.env['runtime']['settingsManager'].getSetting('speech', 'rate')
351 ```
352
353 #### Cursor Information
354 ```python
355 x = self.env['screen']['newCursor']['x']
356 y = self.env['screen']['newCursor']['y']
357 ```
358
359 #### Screen Content
360 ```python
361 text = self.env['screen']['newContentText']
362 lines = text.split('\n')
363 current_line = lines[self.env['screen']['newCursor']['y']]
364 ```
365
366 ## Maintenance
367
368 ### Release Process
369 1. Update version in `fenrirVersion.py`
370 2. Update changelog
371 3. Test on multiple systems
372 4. Tag release
373 5. Update documentation
374
375 ### Compatibility
376 - Maintain Python 3.6+ compatibility
377 - Test on multiple Linux distributions
378 - Ensure driver compatibility
379 - Check dependencies
380
381 ## Resources
382
383 - **Repository**: https://git.stormux.org/storm/fenrir
384 - **Wiki**: https://git.stormux.org/storm/fenrir/wiki
385 - **Issues**: Use repository issue tracker
386 - **Community**: IRC irc.stormux.org #stormux
387 - **Email**: [email protected]