Skip to content

Commit d262553

Browse files
authored
Update code.py
Slight changes to make Mu happy, cut out some debug code.
1 parent a094e80 commit d262553

File tree

1 file changed

+89
-6
lines changed
  • PyPortal_Floppy_with_Display

1 file changed

+89
-6
lines changed

PyPortal_Floppy_with_Display/code.py

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@
2121
def get_files(base):
2222
files = os.listdir(base)
2323
file_names = []
24-
for file in enumerate(files):
25-
if not file.startswith("."):
26-
if file not in ('boot_out.txt', 'System Volume Information'):
27-
stats = os.stat(base + file)
24+
for j, filetext in enumerate(files):
25+
if not filetext.startswith("."):
26+
if filetext not in ('boot_out.txt', 'System Volume Information'):
27+
stats = os.stat(base + filetext)
2828
isdir = stats[0] & 0x4000
2929
if isdir:
30-
file_names.append((file, True))
30+
file_names.append((filetext, True))
3131
else:
32-
file_names.append((file, False))
32+
file_names.append((filetext, False))
3333
return filenames
3434

35+
# Get a touch from the touchscreen (blocking function)
3536
def get_touch(screen):
3637
p = None
3738
while p is None:
@@ -144,6 +145,88 @@ def get_touch(screen):
144145

145146
currentpage = PAGE
146147

148+
# Pagination Handling
149+
if spot >= PAGEMAXFILES - 1:
150+
if currentfile < (len(filenames) + 1):
151+
# Need to display the greater than touch sprite
152+
moresprite[0] = RIGHT
153+
else:
154+
# Blank out more and extra icon spaces
155+
moresprite[0] = BLANK
156+
if PAGE > 1: # Need to display the less than touch sprite
157+
lesssprite[0] = LEFT
158+
else:
159+
lesssprite[0] = BLANK
160+
161+
# Time to check for user touch of screen (BLOCKING)
162+
touch_x = get_touch(ts)
163+
print("Touch Registered ")
164+
# Check if touch_x is around the LEFT or RIGHT arrow
165+
currentpage = PAGE
166+
if touch_x >= int(WIDTH - ICONSIZE): # > Touched
167+
if moresprite[0] != BLANK: # Ensure there are more
168+
if spot == (PAGEMAXFILES - 1): # Page full
169+
if currentfile < (len(filenames)): # and more files
170+
PAGE = PAGE + 1 # Increment page
171+
if touch_x <= ICONSIZE: # < Touched
172+
if PAGE > 1:
173+
PAGE = PAGE - 1 # Decrement page
174+
else:
175+
lesssprite[0] = BLANK # Not show < for first page
176+
print("Page ", PAGE)
177+
# Icon Positioning
178+
179+
if PAGE != currentpage: # We have a page change
180+
# Reset icon locations to upper left
181+
xpos = LEFTSPACE
182+
ypos = TOPSPACE
183+
spot = 0
184+
if currentpage > PAGE:
185+
# Decrement files by a page (current page & previous page)
186+
currentfile = currentfile - (PAGEMAXFILES * 2) + 1
187+
else:
188+
# Forward go to the next file
189+
currentfile = currentfile + 1
190+
else:
191+
currentfile += 1 # Increment file counter
192+
spot += 1 # Increment icon space counter
193+
if spot == PAGEMAXFILES: # Last page ended with
194+
print("hit")
195+
# calculate next icon location
196+
if spot % ICONSACROSS: # not at end of icon row
197+
xpos += SPACING + ICONSIZE
198+
else: # start new icon row
199+
ypos += ICONSIZE + SPACING + TEXTSPACE
200+
xpos = LEFTSPACE
201+
# End If Changed Page
202+
# Blank out rest if needed
203+
if currentfile == len(filenames):
204+
for i in range(spot, PAGEMAXFILES):
205+
sprites[i][0] = BLANK
206+
labels[i].text = " "
207+
# End while
208+
209+
210+
filetype = BMP
211+
elif filename.endswith(".wav"):
212+
filetype = WAV
213+
elif filename.endswith(".py"):
214+
filetype = PY
215+
else:
216+
filetype = FILE
217+
# Set icon location information and icon type
218+
sprites[spot].x = xpos
219+
sprites[spot].y = ypos
220+
sprites[spot][0] = filetype
221+
#
222+
# Set filename
223+
labels[spot].x = xpos
224+
labels[spot].y = ypos + ICONSIZE + TEXTSPACE
225+
# The next line gets the filename without the extension, first 11 chars
226+
labels[spot].text = filename.rsplit('.', 1)[0][0:10]
227+
228+
currentpage = PAGE
229+
147230
# Pagination Handling
148231
if spot >= PAGEMAXFILES - 1:
149232
if currentfile < (len(filenames) + 1):

0 commit comments

Comments
 (0)