6
6
# Display file icons on screen
7
7
8
8
import os
9
- import board
10
9
import time
10
+ import board
11
11
import displayio
12
12
import adafruit_imageload
13
13
import terminalio
20
20
# means the filename is a directory, else false.
21
21
def get_files (base ):
22
22
files = os .listdir (base )
23
- filenames = []
24
- for i , file in enumerate (files ):
23
+ file_names = []
24
+ for file in enumerate (files ):
25
25
if not file .startswith ("." ):
26
- if ( file != " boot_out.txt" ) and ( file != " System Volume Information" ):
26
+ if file not in ( ' boot_out.txt' , ' System Volume Information' ):
27
27
stats = os .stat (base + file )
28
28
isdir = stats [0 ] & 0x4000
29
29
if isdir :
30
- filenames .append ((file , True ))
30
+ file_names .append ((file , True ))
31
31
else :
32
- filenames .append ((file , False ))
33
- print ("Files found = " , len (filenames ))
32
+ file_names .append ((file , False ))
34
33
return filenames
35
34
36
- def get_touch (ts ):
35
+ def get_touch (screen ):
37
36
p = None
38
37
while p is None :
39
38
time .sleep (0.05 )
40
- p = ts .touch_point
39
+ p = screen .touch_point
41
40
return p [0 ]
42
41
43
42
# Icon Positions
@@ -112,37 +111,36 @@ def get_touch(ts):
112
111
xpos = LEFTSPACE
113
112
ypos = TOPSPACE
114
113
115
- base = "/" # Get file names in base directory
116
- filenames = get_files (base )
114
+ displaybase = "/" # Get file names in base directory
115
+ filenames = get_files (displaybase )
117
116
118
117
currentfile = 0 # Which file is being processed in all files
119
118
spot = 0 # Which spot on the screen is getting a file icon
120
119
PAGE = 1 # Which page of icons is displayed on screen, 1 is first
121
120
122
121
while True :
123
122
if currentfile < len (filenames ) and spot < PAGEMAXFILES :
124
- filename , dir = filenames [currentfile ]
125
- if dir :
126
- type = DIR
123
+ filename , dirfile = filenames [currentfile ]
124
+ if dirfile :
125
+ filetype = DIR
127
126
elif filename .endswith (".bmp" ):
128
- type = BMP
127
+ filetype = BMP
129
128
elif filename .endswith (".wav" ):
130
- type = WAV
129
+ filetype = WAV
131
130
elif filename .endswith (".py" ):
132
- type = PY
131
+ filetype = PY
133
132
else :
134
- type = FILE
133
+ filetype = FILE
135
134
# Set icon location information and icon type
136
135
sprites [spot ].x = xpos
137
136
sprites [spot ].y = ypos
138
- sprites [spot ][0 ] = type
137
+ sprites [spot ][0 ] = filetype
139
138
#
140
139
# Set filename
141
140
labels [spot ].x = xpos
142
141
labels [spot ].y = ypos + ICONSIZE + TEXTSPACE
143
142
# The next line gets the filename without the extension, first 11 chars
144
143
labels [spot ].text = filename .rsplit ('.' , 1 )[0 ][0 :10 ]
145
- # labels[spot].anchor_point = (0.5, 1.0)
146
144
147
145
currentpage = PAGE
148
146
@@ -169,18 +167,14 @@ def get_touch(ts):
169
167
if spot == (PAGEMAXFILES - 1 ): # Page full
170
168
if currentfile < (len (filenames )): # and more files
171
169
PAGE = PAGE + 1 # Increment page
172
- print ("> Touched! " )
173
170
if touch_x <= ICONSIZE : # < Touched
174
171
if PAGE > 1 :
175
172
PAGE = PAGE - 1 # Decrement page
176
- print ("< Touched! " )
177
173
else :
178
174
lesssprite [0 ] = BLANK # Not show < for first page
179
175
print ("Page " , PAGE )
180
- # print("currentfile after page =", currentfile)
181
176
# Icon Positioning
182
- # print("currentpage = ", currentpage)
183
- # print("PAGE = ", PAGE)
177
+
184
178
if PAGE != currentpage : # We have a page change
185
179
# Reset icon locations to upper left
186
180
xpos = LEFTSPACE
@@ -206,13 +200,7 @@ def get_touch(ts):
206
200
# End If Changed Page
207
201
# Blank out rest if needed
208
202
if currentfile == len (filenames ):
209
- print ("blanking" )
210
203
for i in range (spot , PAGEMAXFILES ):
211
- print ("blanking spot " , i )
212
204
sprites [i ][0 ] = BLANK
213
205
labels [i ].text = " "
214
206
# End while
215
-
216
- print ("At end of program" )
217
- while True :
218
- pass
0 commit comments