Quellcode durchsuchen

only interacts with .txt files for simplicity

cube vor 9 Monaten
Ursprung
Commit
9970fd3af3

+ 2
- 2
CARDPUTER CircuitPython/projects/README.md Datei anzeigen

7
 A mostly functional, but incredibly basic text editor.
7
 A mostly functional, but incredibly basic text editor.
8
 ### Features
8
 ### Features
9
 - Cursor-less text editing (remember how Minecraft book writing used to feel like? Yeah. That.)
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
 - 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
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
 - 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.
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
 ### Dependencies
13
 ### Dependencies
15
 - adafruit_display_text from the bundle
15
 - adafruit_display_text from the bundle
16
 ### Issues
16
 ### Issues
17
 - No line scrolling. Once you exceed 7 lines, you're guessing, bud
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
 - 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. 
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 Datei anzeigen

30
     index = 0
30
     index = 0
31
     for file in os.listdir("/sd"):
31
     for file in os.listdir("/sd"):
32
         filename = str(file)
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
     files_group.text = files_text
38
     files_group.text = files_text
38
 
39
 
39
 ## SD Card set up for saving text to SD card
40
 ## SD Card set up for saving text to SD card
151
 
152
 
152
         ## The save file menu - for typing the filename
153
         ## The save file menu - for typing the filename
153
         elif page == "save":
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
                     f.write(text)
157
                     f.write(text)
160
                     f.close()
158
                     f.close()
161
                 board.DISPLAY.root_group = intro_text_area
159
                 board.DISPLAY.root_group = intro_text_area
188
                 for line in lines:
186
                 for line in lines:
189
                     text = text + line
187
                     text = text + line
190
                 text_area.text = text
188
                 text_area.text = text
191
-                filename_text = fn
189
+                filename_text = fn.split(".txt")[0]
192
                 filename_group.text=filename_text
190
                 filename_group.text=filename_text
193
                 page = "editor"
191
                 page = "editor"
194
                 board.DISPLAY.root_group = intro_text_area
192
                 board.DISPLAY.root_group = intro_text_area