66# Display file icons on screen
77
88import os
9- import board
109import time
10+ import board
1111import displayio
1212import adafruit_imageload
1313import terminalio
2020# means the filename is a directory, else false.
2121def get_files (base ):
2222 files = os .listdir (base )
23- filenames = []
24- for i , file in enumerate (files ):
23+ file_names = []
24+ for file in enumerate (files ):
2525 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' ):
2727 stats = os .stat (base + file )
2828 isdir = stats [0 ] & 0x4000
2929 if isdir :
30- filenames .append ((file , True ))
30+ file_names .append ((file , True ))
3131 else :
32- filenames .append ((file , False ))
33- print ("Files found = " , len (filenames ))
32+ file_names .append ((file , False ))
3433 return filenames
3534
36- def get_touch (ts ):
35+ def get_touch (screen ):
3736 p = None
3837 while p is None :
3938 time .sleep (0.05 )
40- p = ts .touch_point
39+ p = screen .touch_point
4140 return p [0 ]
4241
4342# Icon Positions
@@ -112,37 +111,36 @@ def get_touch(ts):
112111xpos = LEFTSPACE
113112ypos = TOPSPACE
114113
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 )
117116
118117currentfile = 0 # Which file is being processed in all files
119118spot = 0 # Which spot on the screen is getting a file icon
120119PAGE = 1 # Which page of icons is displayed on screen, 1 is first
121120
122121while True :
123122 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
127126 elif filename .endswith (".bmp" ):
128- type = BMP
127+ filetype = BMP
129128 elif filename .endswith (".wav" ):
130- type = WAV
129+ filetype = WAV
131130 elif filename .endswith (".py" ):
132- type = PY
131+ filetype = PY
133132 else :
134- type = FILE
133+ filetype = FILE
135134 # Set icon location information and icon type
136135 sprites [spot ].x = xpos
137136 sprites [spot ].y = ypos
138- sprites [spot ][0 ] = type
137+ sprites [spot ][0 ] = filetype
139138 #
140139 # Set filename
141140 labels [spot ].x = xpos
142141 labels [spot ].y = ypos + ICONSIZE + TEXTSPACE
143142 # The next line gets the filename without the extension, first 11 chars
144143 labels [spot ].text = filename .rsplit ('.' , 1 )[0 ][0 :10 ]
145- # labels[spot].anchor_point = (0.5, 1.0)
146144
147145 currentpage = PAGE
148146
@@ -169,18 +167,14 @@ def get_touch(ts):
169167 if spot == (PAGEMAXFILES - 1 ): # Page full
170168 if currentfile < (len (filenames )): # and more files
171169 PAGE = PAGE + 1 # Increment page
172- print ("> Touched! " )
173170 if touch_x <= ICONSIZE : # < Touched
174171 if PAGE > 1 :
175172 PAGE = PAGE - 1 # Decrement page
176- print ("< Touched! " )
177173 else :
178174 lesssprite [0 ] = BLANK # Not show < for first page
179175 print ("Page " , PAGE )
180- # print("currentfile after page =", currentfile)
181176 # Icon Positioning
182- # print("currentpage = ", currentpage)
183- # print("PAGE = ", PAGE)
177+
184178 if PAGE != currentpage : # We have a page change
185179 # Reset icon locations to upper left
186180 xpos = LEFTSPACE
@@ -206,13 +200,7 @@ def get_touch(ts):
206200 # End If Changed Page
207201 # Blank out rest if needed
208202 if currentfile == len (filenames ):
209- print ("blanking" )
210203 for i in range (spot , PAGEMAXFILES ):
211- print ("blanking spot " , i )
212204 sprites [i ][0 ] = BLANK
213205 labels [i ].text = " "
214206# End while
215-
216- print ("At end of program" )
217- while True :
218- pass
0 commit comments