diff --git a/CARDPUTER CircuitPython/projects/README.md b/CARDPUTER CircuitPython/projects/README.md index 7225a55..e1a0dbe 100644 --- a/CARDPUTER CircuitPython/projects/README.md +++ b/CARDPUTER CircuitPython/projects/README.md @@ -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. \ No newline at end of file diff --git a/CARDPUTER CircuitPython/projects/text_editor.py b/CARDPUTER CircuitPython/projects/text_editor.py index 181ccf1..c045bfd 100644 --- a/CARDPUTER CircuitPython/projects/text_editor.py +++ b/CARDPUTER CircuitPython/projects/text_editor.py @@ -30,10 +30,11 @@ def file_menu(): index = 0 for file in os.listdir("/sd"): filename = str(file) - if index == open_cursor: - filename = "> " + filename - files_text = files_text + filename+"\n" - index += 1 + if ".txt" in filename: + if index == open_cursor: + filename = "> " + filename + files_text = files_text + filename+"\n" + index += 1 files_group.text = files_text ## SD Card set up for saving text to SD card @@ -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