|
| 1 | +# ProtoDecoder Python Desktop Application |
| 2 | + |
| 3 | +Complete migration of JavaScript ProtoDecoderWebUI to Python 3.10+ desktop application using Tkinter for GUI, maintaining 100% functional equivalence of `/traffic`, `/golbat`, and `/PolygonX/PostProtos` endpoints while eliminating all web-based dependencies. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Protocol Buffer Processing**: Process protobuf data using existing `protos/*` Python folder |
| 8 | +- **HTTP Endpoints**: Maintain identical functionality for `/traffic`, `/golbat`, and `/PolygonX/PostProtos` endpoints |
| 9 | +- **Desktop GUI**: Native Tkinter interface without web browser dependencies |
| 10 | +- **Alternating Row Colors**: Excel-style alternating row colors in data table (white/gray in light theme, dark/lighter-dark in dark theme) |
| 11 | +- **Configuration Management**: Desktop-based configuration with file persistence |
| 12 | +- **Theme Management**: Dark/light theme switching with persistence |
| 13 | +- **Geographic Processing**: Coordinate processing for location data (distance, area calculation) |
| 14 | +- **Error Recovery**: Graceful error handling with exponential backoff |
| 15 | +- **Performance Monitoring**: Real-time performance tracking against targets |
| 16 | +- **Code Documentation**: All comments and documentation translated to English for consistency |
| 17 | + |
| 18 | +## Requirements |
| 19 | + |
| 20 | +- Python 3.10+ |
| 21 | +- Tkinter (included with Python) |
| 22 | +- Existing `protos/*` Python folder |
| 23 | +- psutil (for performance monitoring) |
| 24 | + |
| 25 | +## Installation |
| 26 | + |
| 27 | +1. Clone this repository |
| 28 | +2. Install dependencies: |
| 29 | + ```bash |
| 30 | + pip install psutil |
| 31 | + ``` |
| 32 | +3. Ensure Python 3.10+ is installed |
| 33 | +4. Verify Tkinter is available: `python -m tkinter` |
| 34 | +5. Run the application: `python python/main.py` |
| 35 | + |
| 36 | +## Configuration |
| 37 | + |
| 38 | +Configuration is managed through: |
| 39 | +- Desktop GUI interface (recommended) |
| 40 | +- Configuration files in `config/` directory |
| 41 | +- Default config: `config/config.json` |
| 42 | +- Example config: `config/example.config.json` |
| 43 | + |
| 44 | +### Configuration Options |
| 45 | + |
| 46 | +- **Server Settings**: Port, traffic light identifier, protos path |
| 47 | +- **GUI Settings**: Window size, resizable, center on screen |
| 48 | +- **Theme Settings**: Dark/light themes, auto-switching, transition duration |
| 49 | +- **Logging Settings**: Log level, log file location |
| 50 | +- **Sample Saving**: Optional data sampling with path and format |
| 51 | + |
| 52 | +## Usage |
| 53 | + |
| 54 | +1. **Start Application**: Run `python python/main.py` |
| 55 | +2. **GUI Interface**: Use the desktop interface for configuration and monitoring |
| 56 | +3. **Server Control**: Start/stop HTTP server from GUI or menu |
| 57 | +4. **Theme Switching**: Use theme switcher in Configuration section |
| 58 | +5. **HTTP Endpoints**: Send protocol buffer data to: |
| 59 | + - `/traffic` - Traffic data processing |
| 60 | + - `/golbat` - Golbat data processing |
| 61 | + - `/PolygonX/PostProtos` - Polygon processing with geographic coordinates |
| 62 | + |
| 63 | +## GUI Features |
| 64 | + |
| 65 | +### Data Table |
| 66 | +- **Alternating Row Colors**: Excel-style row coloring for better readability |
| 67 | + - Light theme: White rows (#ffffff) and gray rows (#e8e8e8) |
| 68 | + - Dark theme: Dark rows (#1a1a1a) and lighter rows (#2d2d2d) |
| 69 | +- **Auto-Refresh**: Colors automatically refresh when data is added, deleted, or when themes change |
| 70 | +- **Double-Click**: View detailed JSON data in popup window |
| 71 | + |
| 72 | +### Theme Management |
| 73 | +- **Light Theme**: Clean, bright interface with high contrast |
| 74 | +- **Dark Theme**: Easy on the eyes for low-light environments |
| 75 | +- **Instant Switching**: Change themes without application restart |
| 76 | +- **Persistent Settings**: Theme preference saved across sessions |
| 77 | + |
| 78 | +### Data Filtering |
| 79 | +- **Instance Filtering**: Filter by specific instances |
| 80 | +- **Method Filtering**: Blacklist or whitelist specific method IDs |
| 81 | +- **Real-time Updates**: Filters apply immediately to new and existing data |
| 82 | + |
| 83 | +## API Endpoints |
| 84 | + |
| 85 | +### /traffic (POST) |
| 86 | +Process traffic protocol buffer data |
| 87 | +```json |
| 88 | +{ |
| 89 | + "protos": [ |
| 90 | + { |
| 91 | + "method": 101, |
| 92 | + "request": "base64_encoded_protobuf", |
| 93 | + "response": "base64_encoded_protobuf" |
| 94 | + } |
| 95 | + ] |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +### /golbat (POST) |
| 100 | +Process golbat protocol buffer data |
| 101 | +```json |
| 102 | +{ |
| 103 | + "data": "flexible_golbat_data_structure" |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +### /PolygonX/PostProtos (POST) |
| 108 | +Process polygon protocol buffer data with geographic calculations |
| 109 | +```json |
| 110 | +{ |
| 111 | + "polygon_data": { |
| 112 | + "coordinates": [ |
| 113 | + {"latitude": 37.7749, "longitude": -122.4194}, |
| 114 | + {"latitude": 37.7849, "longitude": -122.4094} |
| 115 | + ] |
| 116 | + } |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +## Project Structure |
| 121 | + |
| 122 | +``` |
| 123 | +python/ |
| 124 | +├── main.py # Application entry point |
| 125 | +├── config/ # Configuration management |
| 126 | +│ ├── manager.py # Configuration loading/saving |
| 127 | +│ └── validator.py # Configuration validation |
| 128 | +├── gui/ # Tkinter desktop interface |
| 129 | +│ ├── main_window.py # Main application window |
| 130 | +│ ├── config_dialog.py # Configuration settings dialog |
| 131 | +│ ├── theme_manager.py # Theme management |
| 132 | +│ ├── theme_config.py # Theme configuration |
| 133 | +│ ├── theme_switcher.py # Theme switcher widget |
| 134 | +│ └── error_dialogs.py # Error handling dialogs |
| 135 | +├── server/ # HTTP endpoint handling |
| 136 | +│ ├── http_handler.py # HTTP server setup and routing |
| 137 | +│ └── endpoints.py # /traffic, /golbat, and /PolygonX/PostProtos endpoint logic |
| 138 | +├── proto_processor/ # Protocol buffer processing |
| 139 | +│ ├── decoder.py # Protobuf decoding logic |
| 140 | +│ ├── traffic_handler.py # Traffic-specific processing |
| 141 | +│ ├── parser.py # Payload parsing functions |
| 142 | +│ └── polygon.py # Geographic coordinate processing |
| 143 | +├── utils/ # Shared utilities |
| 144 | +│ ├── logger.py # Logging configuration |
| 145 | +│ ├── error_recovery.py # Error recovery with exponential backoff |
| 146 | +│ ├── performance_monitor.py # Performance monitoring |
| 147 | +│ └── integration_test.py # Integration testing |
| 148 | +└── constants/ # Generated constants |
| 149 | +
|
| 150 | +config/ # Configuration files |
| 151 | +logs/ # Application logs |
| 152 | +scripts/ # Utility scripts |
| 153 | +protos/ # Existing protobuf definitions |
| 154 | +``` |
| 155 | + |
| 156 | +## Performance Targets |
| 157 | + |
| 158 | +- **Response Time**: <100ms average |
| 159 | +- **Memory Usage**: <50MB average |
| 160 | +- **CPU Utilization**: <10% average |
| 161 | + |
| 162 | +## Testing |
| 163 | + |
| 164 | +### Integration Testing |
| 165 | +Run integration tests to verify all components: |
| 166 | +```bash |
| 167 | +python python/utils/integration_test.py |
| 168 | +``` |
| 169 | + |
| 170 | +### Performance Testing |
| 171 | +Monitor performance through the GUI or programmatically: |
| 172 | +```python |
| 173 | +from python.utils.performance_monitor import PerformanceMonitor |
| 174 | + |
| 175 | +monitor = PerformanceMonitor() |
| 176 | +monitor.start_monitoring() |
| 177 | +# ... run application ... |
| 178 | +summary = monitor.get_performance_summary() |
| 179 | +``` |
| 180 | + |
| 181 | +## Error Recovery |
| 182 | + |
| 183 | +The application implements comprehensive error recovery: |
| 184 | +- **Exponential Backoff**: Automatic retry with increasing delays |
| 185 | +- **Graceful Degradation**: Continue operation with reduced functionality |
| 186 | +- **Error Categorization**: Different recovery strategies for different error types |
| 187 | +- **User Notifications**: Clear error messages and recovery status |
| 188 | + |
| 189 | +## Theme Management |
| 190 | + |
| 191 | +### Available Themes |
| 192 | +- **Light Theme**: Clean, bright interface |
| 193 | +- **Dark Theme**: Easy on the eyes for low-light environments |
| 194 | + |
| 195 | +### Theme Features |
| 196 | +- **Dynamic Switching**: Change themes without restart |
| 197 | +- **Auto-Switching**: Optional automatic theme based on system preference |
| 198 | +- **Persistence**: Theme preference saved across restarts |
| 199 | +- **Custom Colors**: Support for custom color schemes |
| 200 | + |
| 201 | +## Code Improvements |
| 202 | + |
| 203 | +### Comment Translation |
| 204 | +All code comments and documentation have been translated to English for consistency: |
| 205 | +- **French Comments**: Translated Portuguese/French comments to English |
| 206 | +- **Documentation**: Updated all docstrings and inline comments |
| 207 | +- **Consistency**: Unified language across all Python files |
| 208 | +- **Maintainability**: Improved code readability for international developers |
| 209 | + |
| 210 | +### Alternating Row Colors Implementation |
| 211 | +- **Dynamic Color Assignment**: Rows automatically get alternating colors based on position |
| 212 | +- **Theme-Aware**: Colors adapt to light/dark theme changes |
| 213 | +- **Persistent**: Colors maintained during table updates, deletions, and theme switches |
| 214 | +- **Excel-Style**: Classic alternating pattern (row 0: white, row 1: gray, row 2: white, etc.) |
| 215 | + |
| 216 | +### Performance Optimizations |
| 217 | +- **Efficient Color Refresh**: Only refresh colors when necessary (after data changes) |
| 218 | +- **Minimal Overhead**: Color assignment has negligible performance impact |
| 219 | +- **Scalable**: Works efficiently with large datasets (1000+ rows) |
| 220 | + |
| 221 | +## Migration Notes |
| 222 | + |
| 223 | +This application maintains 100% functional equivalence with the JavaScript version: |
| 224 | +- All HTTP endpoints preserve identical behavior |
| 225 | +- Configuration files remain compatible |
| 226 | +- Protocol buffer processing is unchanged |
| 227 | +- Visual layout and themes are preserved |
| 228 | +- Error handling follows the same patterns |
| 229 | + |
| 230 | +## Development |
| 231 | + |
| 232 | +This project uses only Python standard library modules plus psutil for system monitoring: |
| 233 | +- No web framework dependencies |
| 234 | +- Zero external dependencies except psutil |
| 235 | +- Clean separation from JavaScript code |
| 236 | +- Constants generation from JavaScript source |
| 237 | + |
| 238 | +## Troubleshooting |
| 239 | + |
| 240 | +### Common Issues |
| 241 | + |
| 242 | +1. **Server Won't Start** |
| 243 | + - Check if port is available |
| 244 | + - Verify protos directory exists |
| 245 | + - Check configuration file validity |
| 246 | + |
| 247 | +2. **Theme Not Applying** |
| 248 | + - Restart application after theme change |
| 249 | + - Check configuration file permissions |
| 250 | + - Verify theme configuration format |
| 251 | + |
| 252 | +3. **Performance Issues** |
| 253 | + - Monitor performance metrics in GUI |
| 254 | + - Check system resource usage |
| 255 | + - Reduce concurrent requests if needed |
| 256 | + |
| 257 | +### Logs |
| 258 | + |
| 259 | +Application logs are stored in `logs/app.log` by default. Check logs for detailed error information. |
| 260 | + |
| 261 | +## License |
| 262 | + |
| 263 | +[Add your license information here] |
0 commit comments