Export current configuration to a file
(self)
| 343 | del input_win |
| 344 | |
| 345 | def _export_config(self): |
| 346 | """Export current configuration to a file""" |
| 347 | height, width = self.stdscr.getmaxyx() |
| 348 | |
| 349 | # Create input window |
| 350 | input_win = curses.newwin(5, width - 20, height // 2 - 2, 10) |
| 351 | input_win.box() |
| 352 | input_win.attron(curses.color_pair(2)) |
| 353 | input_win.addstr(0, 2, " Export Configuration ") |
| 354 | input_win.attroff(curses.color_pair(2)) |
| 355 | input_win.addstr(2, 2, "File:") |
| 356 | input_win.refresh() |
| 357 | |
| 358 | # Get input |
| 359 | curses.echo() |
| 360 | curses.curs_set(1) |
| 361 | |
| 362 | try: |
| 363 | filename = input_win.getstr(2, 8, width - 32).decode('utf-8').strip() |
| 364 | |
| 365 | if filename: |
| 366 | # Collect all field values |
| 367 | config = {} |
| 368 | for tab in self.tabs: |
| 369 | for option in tab['options']: |
| 370 | dest = option['dest'] |
| 371 | value = option['value'] if option['value'] is not None else option.get('default') |
| 372 | |
| 373 | if option['type'] == 'bool': |
| 374 | config[dest] = bool(value) |
| 375 | elif option['type'] == 'int': |
| 376 | config[dest] = int(value) if value else None |
| 377 | elif option['type'] == 'float': |
| 378 | config[dest] = float(value) if value else None |
| 379 | else: |
| 380 | config[dest] = value |
| 381 | |
| 382 | # Set defaults for unset options |
| 383 | for option in self.parser.option_list: |
| 384 | if option.dest not in config or config[option.dest] is None: |
| 385 | config[option.dest] = defaults.get(option.dest, None) |
| 386 | |
| 387 | # Save config |
| 388 | try: |
| 389 | saveConfig(config, filename) |
| 390 | |
| 391 | # Show success message |
| 392 | input_win.clear() |
| 393 | input_win.box() |
| 394 | input_win.attron(curses.color_pair(5)) |
| 395 | input_win.addstr(0, 2, " Export Successful ") |
| 396 | input_win.attroff(curses.color_pair(5)) |
| 397 | input_win.addstr(2, 2, "Configuration exported to:") |
| 398 | input_win.addstr(3, 2, filename[:width - 26]) |
| 399 | input_win.refresh() |
| 400 | curses.napms(2000) |
| 401 | except Exception as ex: |
| 402 | # Show error message |
no test coverage detected