This program can be used to view the list of files contained in an application.
For each file its size in bytes is specified. It is possible to view pictures and to delete selected files.
WARNING: there is no confirmation dialog for file deletion.
The program is written in Python. The following code needs to be saved as a PPL program.
Code:
#PYTHON filemanager
from hpprime import *
#The index in the list of files.
y=0
#A lock to prevent multiple keys being pressed.
q=0
#Whether image viewing mode is active.
d=0
#Whether the list of files is not empty.
n=1
#Loop is broken if escape key is pressed.
while 1:
#Whether down key on the dpad is pressed.
kd0=keyboard()>>12&1
#Whether up key on the dpad is pressed.
kd1=keyboard()>>2&1
#Whether enter key is pressed.
ken=keyboard()>>30&1
#Whether escape key is pressed.
kes=keyboard()>>4&1
#Whether delete key is pressed.
kde=keyboard()>>19&1
#If one of the keys is pressed an action is performed. The variable q is a lock and is set to 0 when a key is pressed to prevent triggering multiple actions when more than one of the specified keys are pressed. If none of the keys are pressed q is set to 1.
if kd0 or kd1 or ken or kes or kde:
#The index of the currently selected file in the list is increased as long as it does not exceed the list's length. The variable d is 0 when no image file is being displayed.
if kd0 and q and y<ln-1 and d<1:
y+=1
#The index of the currently selected file in the list is decreased as long as it is not less than 1.
if kd1 and q and y>0 and d<1:
y-=1
#The file at the specified index is deleted and the index is set to 0. WARNING: there is no confirmation dialog.
if kde and q and d<1:
eval("DelAFiles(AFiles("+str(y+1)+"))")
y=0
#Variable d is set to 1 when the enter key is pressed. The variable n is 0 when the list of files is empty.
if ken and q and n:
d=1
#The escape key either exits image viewing mode or it breaks the loop.
if kes and q:
if d<1:
break
d=0
q=0
else:
q=1
#G1 is set to a white background the size of the screen.
dimgrob(1,320,240,0xffffff)
#The variable l is set to the list of files contained in an application.
l=eval("AFiles()")
#The variable ln is set to l's length.
ln=len(l)
#In image viewing mode G1 is set to the currently selected file, regardless of it being displayable.
if d:
eval("G1:=AFiles(AFiles("+str(y+1)+"))")
#If the list of files is empty, a message is displayed.
elif ln<1:
n=0
textout(1,10,10,"No files present",0)
#The list of files is displayed. For each file its size in bytes is specified. The selected file is marked with character > placed in front.
else:
for i in range(ln):
b=eval("AFilesB(AFiles("+str(i+1)+"))")
textout(1,10,i*20+10,l[i]+" "+str(int(b))+" Bytes",0)
textout(1,2,y*20+10,">",0)
#G1 is copied to G0.
blit(0,0,0,1)
#end
EXPORT FILEMANAGER()
BEGIN
PYTHON(filemanager)
END;