|
1 | 1 | import math |
2 | 2 | import os |
3 | | -import re |
4 | 3 | import time |
5 | 4 |
|
6 | 5 | import pyglet |
|
20 | 19 | from .utils import ( |
21 | 20 | Rect, |
22 | 21 | compute_bounding_box, |
23 | | - simplify_model_name, |
24 | 22 | config, |
25 | 23 | find_matching_mode, |
26 | 24 | make_command, |
| 25 | + simplify_model_name, |
27 | 26 | sorted_frequencies, |
28 | 27 | sorted_resolutions, |
29 | 28 | trim_rects_flip_y, |
30 | 29 | ) |
31 | | -from .widgets import Button, Dropdown, HBox, Style, VBox, Widget, Spacer |
32 | | - |
| 30 | +from .widgets import Button, Dropdown, HBox, Spacer, Style, VBox, Widget |
33 | 31 |
|
34 | 32 | CONFIRM_DELAY = 20 |
35 | 33 |
|
| 34 | +KEY_RETURN = 65293 |
| 35 | +KEY_ESCAPE = 65307 |
| 36 | +KEY_BACKSPACE = 65288 |
| 37 | +KEY_TAB = 65289 |
| 38 | + |
36 | 39 |
|
37 | 40 | def get_closest_match(float_list, value): |
38 | 41 | return min(float_list, key=lambda x: abs(x - value)) |
@@ -383,24 +386,35 @@ def on_text(self, text): |
383 | 386 |
|
384 | 387 | def on_key_press(self, symbol, modifiers): |
385 | 388 | if self.text_input is None: |
386 | | - if symbol == 65293: # return |
| 389 | + if symbol == KEY_RETURN: |
387 | 390 | if self.confirmation_needed: |
388 | 391 | self.confirmation_needed = False |
389 | 392 | self.set_current_modes_as_ref() |
390 | 393 | else: |
391 | 394 | self.action_save_layout() |
392 | | - elif symbol == 65307 and self.confirmation_needed: # Escape |
| 395 | + elif symbol == KEY_ESCAPE and self.confirmation_needed: |
393 | 396 | os.system(self.original_cmd) |
394 | 397 | self.confirmation_needed = False |
395 | 398 | self.reset_sel() |
| 399 | + elif symbol == KEY_TAB: |
| 400 | + # cycle through profiles |
| 401 | + if not self.profile_list.options: |
| 402 | + return |
| 403 | + index = self.profile_list.selected_index |
| 404 | + index += 1 |
| 405 | + if index >= len(self.profile_list.options): |
| 406 | + index = 0 |
| 407 | + self.profile_list.selected_index = index |
| 408 | + # load the profile |
| 409 | + self.action_load_selected_profile() |
396 | 410 | else: |
397 | 411 | super().on_key_press(symbol, modifiers) |
398 | 412 | else: |
399 | | - if symbol == 65288: # backspace |
| 413 | + if symbol == KEY_BACKSPACE: |
400 | 414 | self.text_input = self.text_input[:-1] |
401 | | - elif symbol == 65293: # return |
| 415 | + elif symbol == KEY_RETURN: |
402 | 416 | self.validate_text_input() |
403 | | - elif symbol == 65307: # Escape |
| 417 | + elif symbol == KEY_ESCAPE: |
404 | 418 | self.text_input = None |
405 | 419 |
|
406 | 420 | def on_mouse_motion(self, x, y, dx, dy): |
|
0 commit comments