Skip to content

Commit

Permalink
Merge pull request #405 from tadeubas/code-refactor
Browse files Browse the repository at this point in the history
Show sorted directories first in SD filemanager
  • Loading branch information
odudex committed Jun 20, 2024
2 parents cc5fe0d + a29f42b commit f4de9ec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,12 @@ Use [MaixPy IDE](https://dl.sipeed.com/shareURL/MAIX/MaixPy/ide/v0.2.5) to debug
## WDT watchdog
Krux makes use of MaixPy's [WDT watchdog module](https://wiki.sipeed.com/soft/maixpy/en/api_reference/machine/wdt.html), you can see it [here](src/krux/wdt.py). This will reset the device if not fed for some time. To stop the watchdog, when connected through the terminal, run the following:
```python
# This will read the board config file, add the config to disable watchdog, save the new config file and reset the device (in order to make krux read the new file!)
# Run this everytime you want to stop the watchdog

from krux.wdt import wdt
wdt.stop()

# OR create this config to disable the watchdog, save the settings file and reset the device (in order to make krux read the new file!)

import json, machine

Expand Down
19 changes: 17 additions & 2 deletions src/krux/pages/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,23 @@ def select_file(
items.append("..")
menu_items.append(("..", lambda: MENU_EXIT))

dir_files = os.listdir(path)
for filename in sorted(dir_files):
# sorts by name ignorecase
dir_files = sorted(os.listdir(path), key=str.lower)

# separate directories from files
directories = []
files = []

for filename in dir_files:
if SDHandler.file_exists(path + "/" + filename):
files.append(filename)
else:
directories.append(filename)

del dir_files

# show sorted folders first than sorted files
for filename in directories + files:
extension_match = False
if isinstance(file_extension, str):
# No extension filter or matches
Expand Down

0 comments on commit f4de9ec

Please sign in to comment.