Browse Source

only interacts with .txt files for simplicity

cube 9 months ago
parent
commit
9970fd3af3

+ 2
- 2
CARDPUTER CircuitPython/projects/README.md View File

@@ -7,7 +7,7 @@ When using a file in CircuitPython, it needs to be renamed to "code.py" as this
7 7
 A mostly functional, but incredibly basic text editor.
8 8
 ### Features
9 9
 - Cursor-less text editing (remember how Minecraft book writing used to feel like? Yeah. That.)
10
-- Save file - You have to type in the filename and extension yourself. The good news is the "." key works on this screen.
10
+- Save file - You only have to type the filename; the ".txt" extension will be automatically added.
11 11
 - 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
12 12
 - 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.
13 13
 ### Dependencies
@@ -15,5 +15,5 @@ A mostly functional, but incredibly basic text editor.
15 15
 - adafruit_display_text from the bundle
16 16
 ### Issues
17 17
 - No line scrolling. Once you exceed 7 lines, you're guessing, bud
18
-- No folder support. Selecting folders in the SD card folder will break it.
18
+- No folder support. It will only show text (.txt) files in the root /sd folder.
19 19
 - 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. 

+ 8
- 10
CARDPUTER CircuitPython/projects/text_editor.py View File

@@ -30,10 +30,11 @@ def file_menu():
30 30
     index = 0
31 31
     for file in os.listdir("/sd"):
32 32
         filename = str(file)
33
-        if index == open_cursor:
34
-            filename = "> " + filename
35
-        files_text = files_text + filename+"\n"
36
-        index += 1
33
+        if ".txt" in filename:
34
+            if index == open_cursor:
35
+                filename = "> " + filename
36
+            files_text = files_text + filename+"\n"
37
+            index += 1
37 38
     files_group.text = files_text
38 39
 
39 40
 ## SD Card set up for saving text to SD card
@@ -151,11 +152,8 @@ while True:
151 152
 
152 153
         ## The save file menu - for typing the filename
153 154
         elif page == "save":
154
-            if key == "DOWN":
155
-                filename_text = filename_text + "."
156
-                filename_group.text = filename_text
157
-            elif key == "\n":
158
-                with open("/sd/"+filename_text, "w") as f:
155
+            if key == "\n":
156
+                with open("/sd/"+filename_text+".txt", "w") as f:
159 157
                     f.write(text)
160 158
                     f.close()
161 159
                 board.DISPLAY.root_group = intro_text_area
@@ -188,7 +186,7 @@ while True:
188 186
                 for line in lines:
189 187
                     text = text + line
190 188
                 text_area.text = text
191
-                filename_text = fn
189
+                filename_text = fn.split(".txt")[0]
192 190
                 filename_group.text=filename_text
193 191
                 page = "editor"
194 192
                 board.DISPLAY.root_group = intro_text_area