|
|
@@ -19,39 +19,6 @@ import sdcardio
|
|
19
|
19
|
import storage
|
|
20
|
20
|
import os
|
|
21
|
21
|
|
|
22
|
|
-def save_file():
|
|
23
|
|
- save_text = "save file"
|
|
24
|
|
- save_group = label.Label(terminalio.FONT, text=save_text)
|
|
25
|
|
- save_group.x = 10
|
|
26
|
|
- save_group.y = 10
|
|
27
|
|
- board.DISPLAY.root_group = save_group
|
|
28
|
|
-
|
|
29
|
|
-def open_file():
|
|
30
|
|
- open_text = "open file"
|
|
31
|
|
- open_group = label.Label(terminalio.FONT, text=open_text)
|
|
32
|
|
- open_group.x = 10
|
|
33
|
|
- open_group.y = 10
|
|
34
|
|
- board.DISPLAY.root_group = open_group
|
|
35
|
|
-
|
|
36
|
|
-def editor(text):
|
|
37
|
|
- if page == "editor":
|
|
38
|
|
- ## WRAPPING
|
|
39
|
|
- ## calculate wrapping when entering a character
|
|
40
|
|
- lines = text.split("\n")
|
|
41
|
|
- current_line = lines[len(lines)-1]
|
|
42
|
|
- if len(current_line) > 35:
|
|
43
|
|
- text=text+"\n" # <- start a new line here
|
|
44
|
|
- ##############################################
|
|
45
|
|
- text = text+key
|
|
46
|
|
- text_area.text = text
|
|
47
|
|
- return text
|
|
48
|
|
-
|
|
49
|
|
-def esc():
|
|
50
|
|
- if page == "editor":
|
|
51
|
|
- pass
|
|
52
|
|
- elif page == "save" or page == "open":
|
|
53
|
|
- board.DISPLAY.root_group = intro_text_area
|
|
54
|
|
-
|
|
55
|
22
|
## SD Card set up for saving text to SD card
|
|
56
|
23
|
spi = busio.SPI(board.SD_SCK, MOSI=board.SD_MOSI, MISO=board.SD_MISO)
|
|
57
|
24
|
cs = board.SD_CS
|
|
|
@@ -79,26 +46,82 @@ intro_text_area.y = 10
|
|
79
|
46
|
text = ""
|
|
80
|
47
|
text_area = label.Label(terminalio.FONT, text=text)
|
|
81
|
48
|
text_area.x = 0
|
|
82
|
|
-text_area.y = 40
|
|
|
49
|
+text_area.y = 30
|
|
83
|
50
|
|
|
84
|
51
|
board.DISPLAY.root_group = intro_text_area
|
|
85
|
52
|
intro_text_area.append(text_area)
|
|
86
|
53
|
|
|
|
54
|
+filename_text = ""
|
|
|
55
|
+save_text = "Save File - Enter Filename\nIf file exists, it will be overwritten"
|
|
|
56
|
+save_group = label.Label(terminalio.FONT, text=save_text, color="C3B")
|
|
|
57
|
+save_group.x = 10
|
|
|
58
|
+save_group.y = 10
|
|
|
59
|
+filename_group = label.Label(terminalio.FONT, text=filename_text)
|
|
|
60
|
+filename_group.x = 0
|
|
|
61
|
+filename_group.y = 60
|
|
|
62
|
+save_group.append(filename_group)
|
|
|
63
|
+
|
|
|
64
|
+open_text = "open file"
|
|
|
65
|
+open_group = label.Label(terminalio.FONT, text=open_text)
|
|
|
66
|
+open_group.x = 10
|
|
|
67
|
+open_group.y = 10
|
|
|
68
|
+
|
|
87
|
69
|
while True:
|
|
88
|
70
|
key = keyb.scan()
|
|
|
71
|
+
|
|
89
|
72
|
if key == "BACKSP":
|
|
90
|
|
- text = text[:-1]
|
|
|
73
|
+ if page == "editor":
|
|
|
74
|
+ text = text[:-1]
|
|
|
75
|
+ text_area.text = text
|
|
|
76
|
+ elif page == "save":
|
|
|
77
|
+ filename_text = filename_text[:-1]
|
|
|
78
|
+ filename_group.text = filename_text
|
|
|
79
|
+
|
|
91
|
80
|
elif key == "CTRLD":
|
|
92
|
|
- text = ""
|
|
|
81
|
+ if page == "editor":
|
|
|
82
|
+ text = ""
|
|
|
83
|
+ text_area.text = text
|
|
|
84
|
+ elif page == "save":
|
|
|
85
|
+ filename_text = ""
|
|
|
86
|
+ filename_group.text = filename_text
|
|
|
87
|
+
|
|
93
|
88
|
elif key == "CTRLS":
|
|
94
|
|
- save_file()
|
|
|
89
|
+ board.DISPLAY.root_group = save_group
|
|
95
|
90
|
page = "save"
|
|
|
91
|
+ filename_group.text=filename_text
|
|
|
92
|
+
|
|
96
|
93
|
elif key == "CTRLO":
|
|
97
|
|
- open_file()
|
|
|
94
|
+ board.DISPLAY.root_group = open_group
|
|
98
|
95
|
page="open"
|
|
|
96
|
+
|
|
99
|
97
|
elif key == "ESC":
|
|
100
|
|
- esc()
|
|
|
98
|
+ if page == "editor":
|
|
|
99
|
+ pass
|
|
|
100
|
+ elif page == "save" or page == "open":
|
|
|
101
|
+ board.DISPLAY.root_group = intro_text_area
|
|
101
|
102
|
page = "editor"
|
|
|
103
|
+
|
|
|
104
|
+
|
|
102
|
105
|
else:
|
|
103
|
|
- text = editor(text)
|
|
|
106
|
+ ## The actual editor
|
|
|
107
|
+ if page == "editor":
|
|
|
108
|
+ ## WRAPPING
|
|
|
109
|
+ ## calculate wrapping when entering a character
|
|
|
110
|
+ lines = text.split("\n")
|
|
|
111
|
+ current_line = lines[len(lines)-1]
|
|
|
112
|
+ if len(current_line) > 35:
|
|
|
113
|
+ text=text+"\n" # <- start a new line here
|
|
|
114
|
+ ##############################################
|
|
|
115
|
+ text = text+key
|
|
|
116
|
+ text_area.text = text
|
|
|
117
|
+
|
|
|
118
|
+ ## The save file menu - for typing the filename
|
|
|
119
|
+ elif page == "save":
|
|
|
120
|
+ if key == "\n":
|
|
|
121
|
+ pass # handle saving the file
|
|
|
122
|
+ elif not keyb.is_alphanumeric(key):
|
|
|
123
|
+ pass # dont allow special characters to be entered
|
|
|
124
|
+ else:
|
|
|
125
|
+ filename_text = filename_text+key
|
|
|
126
|
+ filename_group.text=filename_text
|
|
104
|
127
|
|