|
2 | 2 | import locale
|
3 | 3 | import logging
|
4 | 4 | import curses
|
| 5 | +from datetime import datetime |
5 | 6 | from copy import deepcopy
|
6 | 7 | from textwrap import wrap
|
7 | 8 | import glob
|
8 | 9 | import csv
|
9 |
| -from os import path, sep |
| 10 | +from os import path, sep, rename |
10 | 11 | from sys import platform, version_info
|
11 | 12 |
|
12 | 13 | from .common import *
|
@@ -3366,4 +3367,69 @@ def show(self):
|
3366 | 3367 | def keypress(self, char):
|
3367 | 3368 | pass
|
3368 | 3369 |
|
| 3370 | + |
| 3371 | +class PyRadioKeyboardConfig(): |
| 3372 | + |
| 3373 | + _focus = 0 |
| 3374 | + |
| 3375 | + def __init__(self): |
| 3376 | + pass |
| 3377 | + |
| 3378 | + def _rename_keyboard_json_file(file_path): |
| 3379 | + # Check if the file path ends with "keyboard.json" |
| 3380 | + if not file_path.endswith("keyboard.json"): |
| 3381 | + raise ValueError("The file path must end with 'keyboard.json'") |
| 3382 | + |
| 3383 | + # Get the current date and time |
| 3384 | + now = datetime.now() |
| 3385 | + formatted_time = now.strftime("%Y-%m-%d_%H-%M-%S") |
| 3386 | + |
| 3387 | + # Create the new file name |
| 3388 | + new_file_name = f"{formatted_time}-keyboard.json" |
| 3389 | + |
| 3390 | + # Get the directory of the original file |
| 3391 | + directory = path.dirname(file_path) |
| 3392 | + |
| 3393 | + # Create the full new file path |
| 3394 | + new_file_path = path.join(directory, new_file_name) |
| 3395 | + |
| 3396 | + # Rename the file |
| 3397 | + rename(file_path, new_file_path) |
| 3398 | + |
| 3399 | + return new_file_name |
| 3400 | + |
| 3401 | + def _focus_nect(self): |
| 3402 | + pass |
| 3403 | + |
| 3404 | + def _focus_previous(self): |
| 3405 | + pass |
| 3406 | + |
| 3407 | + def show(self): |
| 3408 | + pass |
| 3409 | + |
| 3410 | + def keypress(self, char): |
| 3411 | + ''' PyRadioKeyboardConfig keypress |
| 3412 | + Returns: |
| 3413 | + -1: Cancel |
| 3414 | + 0: Done |
| 3415 | + 1: Continue |
| 3416 | + 2: Display help |
| 3417 | + 3: Display line editor help |
| 3418 | + ''' |
| 3419 | + if char == kbkey['?'] and self._focus > 0: |
| 3420 | + return 3 |
| 3421 | + elif char == kbkey['?']: |
| 3422 | + return 2 |
| 3423 | + elif char in (curses.KEY_EXIT, 27, kbkey['q']) and \ |
| 3424 | + self._focus > 0: |
| 3425 | + self.edit_string = '' |
| 3426 | + return -1 |
| 3427 | + elif char in (ord('\t'), 9, curses.KEY_DOWN, kbkey['tab']): |
| 3428 | + self._focus_next() |
| 3429 | + elif char in (curses.KEY_BTAB, curses.KEY_UP, kbkey['stab']): |
| 3430 | + self._focus_previous() |
| 3431 | + elif char in (curses.KEY_ENTER, ord('\n'), ord('\r')): |
| 3432 | + pass |
| 3433 | + return 1 |
| 3434 | + |
3369 | 3435 | # pymode:lint_ignore=W901
|
0 commit comments