only interacts with .txt files for simplicity

This commit is contained in:
cube
2025-03-07 18:44:05 +00:00
parent fc2757aa47
commit 9970fd3af3
2 changed files with 10 additions and 12 deletions

View File

@@ -7,7 +7,7 @@ When using a file in CircuitPython, it needs to be renamed to "code.py" as this
A mostly functional, but incredibly basic text editor.
### Features
- Cursor-less text editing (remember how Minecraft book writing used to feel like? Yeah. That.)
- Save file - You have to type in the filename and extension yourself. The good news is the "." key works on this screen.
- Save file - You only have to type the filename; the ".txt" extension will be automatically added.
- Open file - You can select from a list of files in the SD card. Still no line scrolling here, so only the first 7 files will be visible
- If you open a file, the save menu conveniently fills in the filename for you, so you don't have to write it again to re-save.
### Dependencies
@@ -15,5 +15,5 @@ A mostly functional, but incredibly basic text editor.
- adafruit_display_text from the bundle
### Issues
- No line scrolling. Once you exceed 7 lines, you're guessing, bud
- No folder support. Selecting folders in the SD card folder will break it.
- No folder support. It will only show text (.txt) files in the root /sd folder.
- There are no confirmation or warning messages. Use with caution and be sure that you aren't using a repeat filename, or it will overwrite the file without warning.

View File

@@ -30,6 +30,7 @@ def file_menu():
index = 0
for file in os.listdir("/sd"):
filename = str(file)
if ".txt" in filename:
if index == open_cursor:
filename = "> " + filename
files_text = files_text + filename+"\n"
@@ -151,11 +152,8 @@ while True:
## The save file menu - for typing the filename
elif page == "save":
if key == "DOWN":
filename_text = filename_text + "."
filename_group.text = filename_text
elif key == "\n":
with open("/sd/"+filename_text, "w") as f:
if key == "\n":
with open("/sd/"+filename_text+".txt", "w") as f:
f.write(text)
f.close()
board.DISPLAY.root_group = intro_text_area
@@ -188,7 +186,7 @@ while True:
for line in lines:
text = text + line
text_area.text = text
filename_text = fn
filename_text = fn.split(".txt")[0]
filename_group.text=filename_text
page = "editor"
board.DISPLAY.root_group = intro_text_area