File: development.txt

package info (click to toggle)
fenrir 2025.0.7.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,112 kB
  • sloc: python: 19,660; sh: 302; makefile: 12
file content (389 lines) | stat: -rw-r--r-- 9,296 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# Fenrir Development Guide

This document provides information for developers who want to contribute to Fenrir or understand its architecture.

## Project Structure

Fenrir follows a modular, driver-based architecture:

```
src/fenrirscreenreader/
├── core/                    # Core system modules
│   ├── fenrirManager.py    # Main application manager
│   ├── screenManager.py   # Screen handling
│   ├── inputManager.py    # Input handling
│   ├── outputManager.py   # Speech/sound output
│   ├── commandManager.py  # Command system
│   └── settingsManager.py # Configuration management
├── commands/               # Command implementations
│   ├── commands/          # User-invoked commands
│   ├── onCursorChange/   # Cursor movement hooks
│   ├── onScreenUpdate/   # Screen update hooks
│   ├── onKeyInput/       # Key input hooks
│   └── help/             # Tutorial system
├── drivers/              # Driver implementations
│   ├── inputDriver/     # Input drivers (evdev, pty, atspi)
│   ├── screenDriver/    # Screen drivers (vcsa, pty)
│   ├── speechDriver/    # Speech drivers (speechd, generic)
│   └── soundDriver/     # Sound drivers (generic, gstreamer)
└── utils/               # Utility modules
```

## Core Architecture

### Driver System
Fenrir uses a pluggable driver architecture:

1. **Input Drivers**: Capture keyboard input
   - evdevDriver: Linux evdev (recommended)
   - ptyDriver: Terminal emulation
   - atspiDriver: AT-SPI for desktop

2. **Screen Drivers**: Read screen content
   - vcsaDriver: Linux VCSA devices
   - ptyDriver: Terminal emulation

3. **Speech Drivers**: Text-to-speech output
   - speechdDriver: Speech-dispatcher
   - genericDriver: Command-line TTS

4. **Sound Drivers**: Audio output
   - genericDriver: Sox-based
   - gstreamerDriver: GStreamer

5. **Remote Drivers**: Remote control interfaces
   - unixDriver: Unix socket control
   - tcpDriver: TCP socket control

### Command System
Commands are Python modules that implement specific functionality:

```python
class command():
    def __init__(self):
        pass
    
    def initialize(self, environment):
        self.env = environment
    
    def shutdown(self):
        pass
    
    def getDescription(self):
        return _('Command description')
    
    def run(self):
        # Command implementation
        pass
```

### Event Hooks
Fenrir supports various event hooks:

- **onCursorChange**: Triggered when cursor moves
- **onScreenUpdate**: Triggered on screen content changes
- **onKeyInput**: Triggered on key presses
- **onByteInput**: Triggered on byte-level input
- **onScreenChanged**: Triggered when switching screens

## Development Setup

### Requirements
- Python 3.6+
- python3-evdev
- python3-pyudev
- speech-dispatcher
- sox

### Getting Started
```bash
# Clone repository
git clone https://git.stormux.org/storm/fenrir.git
cd fenrir

# Install dependencies
sudo pip3 install -r requirements.txt

# Run from source
cd src/
sudo ./fenrir -f -d
```

### Testing
```bash
# Run in debug mode
sudo ./fenrir -f -d -p

# Debug output goes to:
# - Console (with -p flag)
# - /var/log/fenrir.log
```

## Creating Commands

### Basic Command
Create a file in `src/fenrirscreenreader/commands/commands/`:

```python
from fenrirscreenreader.core import debug

class command():
    def __init__(self):
        pass
        
    def initialize(self, environment):
        self.env = environment
        
    def shutdown(self):
        pass
        
    def getDescription(self):
        return _('My custom command')
        
    def run(self):
        # Get current text
        text = self.env['screen']['newContentText']
        
        # Speak something
        self.env['runtime']['outputManager'].presentText('Hello World')
        
        # Play sound
        self.env['runtime']['outputManager'].playSoundIcon('Accept')
```

### Key Bindings
Add key bindings in keyboard layout files:
`config/keyboard/desktop.conf` or `config/keyboard/laptop.conf`

```ini
[KEY_CTRL]#[KEY_ALT]#[KEY_H]=my_command
```

### Event Hooks
Create event handlers in appropriate directories:

```python
# onCursorChange/my_hook.py
class command():
    def __init__(self):
        pass
        
    def initialize(self, environment):
        self.env = environment
        
    def shutdown(self):
        pass
        
    def getDescription(self):
        return _('My cursor change handler')
        
    def run(self):
        if self.env['runtime']['cursorManager'].isCursorHorizontalMove():
            # Handle horizontal cursor movement
            pass
```

## Creating Drivers

### Driver Template
```python
class driver():
    def __init__(self):
        pass
        
    def initialize(self, environment):
        self.env = environment
        
    def shutdown(self):
        pass
        
    # Driver-specific methods...
```

### Input Driver
Implement these methods:
- `getInputEvent()`: Return input events
- `writeEventBuffer()`: Handle output events
- `grabDevices()`: Take exclusive control
- `releaseDevices()`: Release control

### Screen Driver
Implement these methods:
- `getCurrScreen()`: Get current screen content
- `getSessionInformation()`: Get session info

### Speech Driver
Implement these methods:
- `speak()`: Speak text
- `cancel()`: Stop speech
- `setCallback()`: Set callback functions

### Remote Driver
Implement these methods:
- `initialize()`: Setup socket/connection
- `watchDog()`: Listen for incoming commands
- `shutdown()`: Clean up connections

#### Remote Driver Example
```python
class driver(remoteDriver):
    def initialize(self, environment):
        self.env = environment
        # Start watchdog thread
        self.env['runtime']['processManager'].addCustomEventThread(
            self.watchDog, multiprocess=True
        )
    
    def watchDog(self, active, eventQueue):
        # Listen for connections and process commands
        while active.value:
            # Accept connections
            # Parse incoming data
            # Send to event queue
            eventQueue.put({
                "Type": fenrirEventType.RemoteIncomming,
                "Data": command_text
            })
```

## Configuration

### Settings System
Settings are hierarchical:
1. Command-line options (`-o`)
2. Configuration file
3. Hard-coded defaults

### Adding Settings
1. Add default value to `core/settingsData.py`
2. Access via `self.env['runtime']['settingsManager'].getSetting(section, key)`

## Debugging

### Debug Levels
- 0: DEACTIVE
- 1: ERROR
- 2: WARNING  
- 3: INFO

### Debug Output
```python
self.env['runtime']['debug'].writeDebugOut(
    'Debug message', 
    debug.debugLevel.INFO
)
```

### Testing Commands
```bash
# Test specific functionality
sudo fenrir -f -d -o "general#debugLevel=3"

# Test with custom config
sudo fenrir -f -s /path/to/test.conf
```

## Contributing

### Code Style
- Follow PEP 8
- Use descriptive variable names
- Add docstrings for complex functions
- Handle exceptions gracefully

### Testing
- Test with different drivers
- Test keyboard layouts
- Test on different terminals
- Verify accessibility features

### Submitting Changes
1. Fork the repository
2. Create feature branch
3. Make changes with clear commit messages
4. Test thoroughly
5. Submit pull request

## API Reference

### Environment Structure
The `environment` dict contains all runtime data:

```python
environment = {
    'runtime': {
        'settingsManager': settingsManager,
        'commandManager': commandManager,
        'screenManager': screenManager,
        'inputManager': inputManager,
        'outputManager': outputManager,
        'debug': debugManager,
        # ... other managers
    },
    'screen': {
        'newContentText': '',
        'oldContentText': '',
        'newCursor': {'x': 0, 'y': 0},
        'oldCursor': {'x': 0, 'y': 0},
        # ... screen data
    },
    'general': {
        'prevCommand': '',
        'currCommand': '',
        # ... general data
    }
}
```

### Common Operations

#### Speaking Text
```python
self.env['runtime']['outputManager'].presentText('Hello')
```

#### Playing Sounds
```python
self.env['runtime']['outputManager'].playSoundIcon('Accept')
```

#### Getting Settings
```python
rate = self.env['runtime']['settingsManager'].getSetting('speech', 'rate')
```

#### Cursor Information
```python
x = self.env['screen']['newCursor']['x']
y = self.env['screen']['newCursor']['y']
```

#### Screen Content
```python
text = self.env['screen']['newContentText']
lines = text.split('\n')
current_line = lines[self.env['screen']['newCursor']['y']]
```

## Maintenance

### Release Process
1. Update version in `fenrirVersion.py`
2. Update changelog
3. Test on multiple systems
4. Tag release
5. Update documentation

### Compatibility
- Maintain Python 3.6+ compatibility
- Test on multiple Linux distributions
- Ensure driver compatibility
- Check dependencies

## Resources

- **Repository**: https://git.stormux.org/storm/fenrir
- **Wiki**: https://git.stormux.org/storm/fenrir/wiki
- **Issues**: Use repository issue tracker
- **Community**: IRC irc.stormux.org #stormux
- **Email**: stormux+subscribe@groups.io