|
19 | 19 | from lib.hydra.i18n import I18n |
20 | 20 |
|
21 | 21 |
|
22 | | -_MH_DISPLAY_HEIGHT = const(240) |
23 | | -_MH_DISPLAY_WIDTH = const(320) |
| 22 | +_MH_DISPLAY_HEIGHT = const(135) |
| 23 | +_MH_DISPLAY_WIDTH = const(240) |
24 | 24 |
|
25 | 25 |
|
26 | 26 | _TRANS = const("""[ |
|
44 | 44 |
|
45 | 45 | _ITEMS_PER_SCREEN = const(_MH_DISPLAY_HEIGHT // 32) |
46 | 46 | _ITEMS_PER_SCREEN_MINUS = const(_ITEMS_PER_SCREEN - 1) |
47 | | -_LEFT_PADDING = const(_MH_DISPLAY_WIDTH // 20) |
| 47 | +_LEFT_PADDING = const(_MH_DISPLAY_WIDTH // 24) |
48 | 48 |
|
49 | 49 | # calculate padding around items based on amount of unused space |
50 | 50 | _CHAR_PADDING = const((_MH_DISPLAY_HEIGHT - (_ITEMS_PER_SCREEN * 32)) // _ITEMS_PER_SCREEN) |
|
61 | 61 | # for horizontal text scroll animation: |
62 | 62 | _SCROLL_TIME = const(5000) # ms per one text scroll |
63 | 63 |
|
| 64 | +# Delimiter for multiple main.py paths |
64 | 65 | _PATH_JOIN = const("|//|") |
65 | 66 |
|
66 | | - |
67 | 67 | # hamburger menu icon: |
68 | 68 | _HAMBURGER_WIDTH = const(32) |
69 | 69 | _HAMBURGER_X = const(_DISPLAY_WIDTH_HALF - (_HAMBURGER_WIDTH // 2)) |
@@ -173,7 +173,7 @@ def draw(self): |
173 | 173 |
|
174 | 174 | # special stylilng on menu button |
175 | 175 | if mytext == "/.../": |
176 | | - self.draw_hamburger_menu(tft, idx * _LINE_HEIGHT, self.config.palette[clr_idx]) |
| 176 | + self.draw_hamburger_menu(tft, idx * _LINE_HEIGHT + _TOP_PADDING, self.config.palette[clr_idx]) |
177 | 177 | break # hamburger menu is always last |
178 | 178 |
|
179 | 179 | # special styling for directories |
@@ -258,6 +258,41 @@ def ping_pong_ease(value: int, modulo: int) -> float: |
258 | 258 | return (fac) |
259 | 259 |
|
260 | 260 |
|
| 261 | + |
| 262 | +def path_join(*args) -> str: |
| 263 | + """Join multiple paths together.""" |
| 264 | + path = "/".join(args) |
| 265 | + # Remove any repeated slashes |
| 266 | + while "//" in path: |
| 267 | + path = path.replace("//", "/") |
| 268 | + if path.endswith("/") and len(path) > 1: |
| 269 | + path = path[:-1] |
| 270 | + return path |
| 271 | + |
| 272 | + |
| 273 | +def path_split(path_str) -> tuple[str, str]: |
| 274 | + """Split last element off of path. (similar to os.path.split).""" |
| 275 | + # Early return on root dir |
| 276 | + if path_str == "/": |
| 277 | + return "/", "" |
| 278 | + |
| 279 | + *head, tail = path_str.split("/") |
| 280 | + head = path_join(*head) |
| 281 | + return head, tail |
| 282 | + |
| 283 | + |
| 284 | +def prev_dir(): |
| 285 | + """Move back to the previous directory (similar to "..").""" |
| 286 | + # this funciton is needed because ".." doesn't work as expected with SDCards |
| 287 | + # If you chdir("..") on "/sd" you will not move. |
| 288 | + # And, if you chdir("..") back to "/" from anywhere else, |
| 289 | + # "/sd" won't show up on os.listdir() |
| 290 | + head = path_split(os.getcwd())[0] |
| 291 | + if not head: |
| 292 | + head = "/" |
| 293 | + os.chdir(head) |
| 294 | + |
| 295 | + |
261 | 296 | def parse_files() -> tuple[list, dict]: |
262 | 297 | """Get a list of directories/files, and a dictionary of which is which. |
263 | 298 |
|
@@ -325,11 +360,11 @@ def ext_options(overlay): |
325 | 360 |
|
326 | 361 | source_path, file_name = clipboard |
327 | 362 |
|
328 | | - source = f"{source_path}/{file_name}".replace('//', '/') |
329 | | - dest = f"{cwd}/{file_name}".replace('//', '/') |
| 363 | + source = path_join(source_path, file_name) |
| 364 | + dest = path_join(cwd, file_name) |
330 | 365 |
|
331 | 366 | if source == dest: |
332 | | - dest = f"{cwd}/{file_name}.bak".replace('//', '/') |
| 367 | + dest += ".bak" |
333 | 368 |
|
334 | 369 | with open(source, "rb") as old_file, open(dest, "wb") as new_file: |
335 | 370 | while True: |
@@ -450,11 +485,7 @@ def handle_input(key, view, file_list, dir_dict) -> tuple[list, dict]: |
450 | 485 |
|
451 | 486 | elif key == "BSPC": |
452 | 487 | beep.play(("D3", "B3", "G3"), 30) |
453 | | - # previous directory |
454 | | - if os.getcwd() == "/sd": |
455 | | - os.chdir("/") |
456 | | - else: |
457 | | - os.chdir("..") |
| 488 | + prev_dir() |
458 | 489 | file_list, dir_dict = refresh_files(view) |
459 | 490 |
|
460 | 491 | elif key == kb.aux_action: |
|
0 commit comments