help on how to browse though folders and select files on gp2x

Previous topic - Next topic

lotus

on a windows based os you can pick a file with
Code (glbasic) Select
file$=FILEREQUEST$(TRUE, "Text|*.txt|All|*.*")
PRINT file$, 0, 100
SHOWSCREEN
MOUSEWAIT
and it opens a file browsing window but obviously not on gp2x, ive seen the example file with gl basic to view files and folders (example is in glbasic/samples/in_out/files_folders) but what can i add to this to make it so the usesr is able to select files or folders.

or is there an easy way to do this some other way on GP2X? Thanks in advance (I hope)

Kitty Hello

No. Please write a simple function for it, will you? :)

lotus

Err, well, thanks GernotFrisch, thats what i was hoping to do if someone gave me a few pointers, i`ve never really done anything like this before. I`m just trying to work out where to start. i`ll try n come up with something though cos its obviously not common knowledge or some of the good people on this forum would have posted by now. If i do come up with something ill be sure to post it.

lotus

To gernotFrisch, here is a  little file folder browser for GP2X, as promised. This one will browse for /play MP3 files.
EDIT: small bug fixed, browser works better and is no longer crashing at all.




Code (glbasic) Select
// --------------------------------- //
// Project: Files and folder browser (for GP2X or non windows based OS)
// By lotus guy
// Start: Monday, June 04, 2007
// IDE Version: 4.192

timer1 = 20
timer2 = 20
WHILE TRUE //start infinate loop
LIMITFPS 12 //limit FPS to 12 (so the munu is usable)
GOSUB fileviewer //activete sub directory (name)
WEND //end infinate loop


// ------------------------------------------------------------- //
// -=#  FILEVIEWER  #=-
// ------------------------------------------------------------- //
SUB fileviewer:
LOCAL files$[]

FILLRECT 0, 0, 320, 240, RGB(20,20,70) //Draw a rectangle for the background
dir$ = GETCURRENTDIR$() //dir$ = the current directory


get$ = GETFILELIST("*.*", files$[]) //get$ = list of files(all files.extentions


FOR i=0 TO BOUNDS(files$[], 0)-1 //BOUNDS(files$[], 0)-1 = num = num_dir+num_file
  PRINT files$[i], 15, m+100 +10*i //
l$= dir$ + files$[m*-0.1] //set l$ to the current dirctory + the number of
//the file in the list (using value "m"*-0.1)
NEXT


IF KEY(200) AND m < 0 THEN m= m+10
IF KEY(208) AND m > (i-1)*-10 THEN m= m-10

PRINT ">>", 0 , 100 //print >>> at 0, 100 to show line 100 is file being picked

 IF KEY(15)
SETCURRENTDIR(l$) //pick l$
//--------------------------------------------------------------------------
PLAYMUSIC l$ //THIS IS WHAT FUNCTION IS USED WITH THE CHOSEN FILE
//--------------------------------------------------------------------------
       m=0
  ENDIF

GOSUB scrollydirectory //activete sub directory (name)

SHOWSCREEN
ENDSUB // FILEVIEWER




// ------------------------------------------------------------- //
// -=#  SCROLLYDIRECTORY  #=-
// ------------------------------------------------------------- //
SUB scrollydirectory:

IF KEY(15) //if TAB key
 timer1 = 20 //reset timer1 to 20
  timer2 = 20 //reset timer2 to 20
   scroll = 0 //reset scroll to 0
ENDIF

FILLRECT 0, 0, 320, 10, RGB(20,20,120) //Draw blue rectangle at top
PRINT dir$, scroll, 1 //print the current directory address ,x ,y positions


length$=LEN(dir$)*8- 315 //Get the number of letters in the directory path * by 8 - almost the full screen width
//--------------timers to move and stop the directory scrolly---------------------
IF timer1 > 0 THEN timer1 = timer1 - 1
IF timer1 < 1 AND scroll > -length$ THEN  scroll = scroll-2
IF scroll < -length$ THEN timer2 = timer2 - 1
IF timer2 = 0 AND scroll < -length$
 scroll = 0
  timer1 = 20
   timer2 = 20
ENDIF
//--------------------------------------------------------------------------------


FILLRECT 0, 220, 320, 240, RGB(20,20,120) //Draw blue rectangle at the bottom
PRINT "Pick file/folder = SELECT(GP2X)/TAB(PC)", 0, 220 //print message over the rectangle
PRINT "Scroll list = STICK(GP2X)/ARROWS(PC)", 0, 230 //print message over the rectangle

ENDSUB // SCROLLYDIRECTORY

Kitty Hello


momosxp

sorry for writing in such an old thread but when i try to compile that i get this error:
Code (glbasic) Select
_______________________________________
*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.7.003 - 3D, NET
"test.gbas"(36) warning : probably unassigned variable : i
Wordcount:57 commands
compiling:
C:\Users\Mohammed\AppData\Local\Temp\glbasic\gpc_temp0.cpp: In function `DGInt __GLBASIC__::scrollydirectory()':
C:\Users\Mohammed\AppData\Local\Temp\glbasic\gpc_temp0.cpp:97: error: ambiguous overload for 'operator-' in '-__GLBASIC__::length_Str'
C:\Users\Mohammed\AppData\Local\Temp\glbasic\gpc_temp0.cpp:97: note: candidates are: operator-(DGNat) <built-in>
C:\Users\Mohammed\AppData\Local\Temp\glbasic\gpc_temp0.cpp:97: note:                 operator-(DGInt) <built-in>
C:\Users\Mohammed\AppData\Local\Temp\glbasic\gpc_temp0.cpp:99: error: ambiguous overload for 'operator-' in '-__GLBASIC__::length_Str'
C:\Users\Mohammed\AppData\Local\Temp\glbasic\gpc_temp0.cpp:99: note: candidates are: operator-(DGNat) <built-in>
C:\Users\Mohammed\AppData\Local\Temp\glbasic\gpc_temp0.cpp:99: note:                 operator-(DGInt) <built-in>
C:\Users\Mohammed\AppData\Local\Temp\glbasic\gpc_temp0.cpp:101: error: ambiguous overload for 'operator-' in '-__GLBASIC__::length_Str'
C:\Users\Mohammed\AppData\Local\Temp\glbasic\gpc_temp0.cpp:101: note: candidates are: operator-(DGNat) <built-in>
C:\Users\Mohammed\AppData\Local\Temp\glbasic\gpc_temp0.cpp:101: note:                 operator-(DGInt) <built-in>
*** FATAL ERROR - Bitte die Compiler-Ausgabe ins Forum kopieren
_______________________________________
*** Fertig ***
Dauer: 2.0 sek. Zeit: 04:11
Erstellen: 0 erfolgreich.
*** 1 FEHLGESCHLAGEN ***

Neurox

the error is type of variable :
length not length$
numeric not text ;)

Bye,
Neurox
Paolo Borzini | paolo@borzini.it
The WhiteFly Software | www.thewhitefly.it
Service on line for screen printers | www.4pellicole.it

momosxp

thx, works now. There was another fault, too:

this will work:

Code (glbasic) Select
// --------------------------------- //
// Project: Files and folder browser (for GP2X or non windows based OS)
// By lotus guy
// Start: Monday, June 04, 2007
// IDE Version: 4.192

timer1 = 20
timer2 = 20
m=-10
WHILE TRUE //start infinate loop
LIMITFPS 12 //limit FPS to 12 (so the munu is usable)
GOSUB fileviewer //activete sub directory (name)
PRINT m ,400,0
PRINT (i-1)*-10,400,12
WEND //end infinate loop


// ------------------------------------------------------------- //
// -=#  FILEVIEWER  #=-
// ------------------------------------------------------------- //
SUB fileviewer:
LOCAL files$[]

DRAWRECT 0, 0, 320, 240, RGB(20,20,70) //Draw a rectangle for the background
dir$ = GETCURRENTDIR$() //dir$ = the current directory


get$ = GETFILELIST("*.*", files$[]) //get$ = list of files(all files.extentions


FOR i=0 TO BOUNDS(files$[], 0)-1 //BOUNDS(files$[], 0)-1 = num = num_dir+num_file
  PRINT files$[i], 15, m+100 +10*i //
l$= dir$ + files$[m*-0.1] //set l$ to the current dirctory + the number of
//the file in the list (using value "m"*-0.1)
NEXT
IF KEY(200) AND m < 0 THEN m= m+10
IF KEY(208) AND m > (BOUNDS(files$[], 0)-1)*-10 THEN m=m-10


PRINT ">>", 0 , 100 //print >>> at 0, 100 to show line 100 is file being picked

IF KEY(15)
SETCURRENTDIR(l$) //pick l$
//--------------------------------------------------------------------------
PLAYMUSIC l$,0 //THIS IS WHAT FUNCTION IS USED WITH THE CHOSEN FILE
//--------------------------------------------------------------------------
       m=0
  ENDIF

GOSUB scrollydirectory //activete sub directory (name)

SHOWSCREEN
ENDSUB // FILEVIEWER




// ------------------------------------------------------------- //
// -=#  SCROLLYDIRECTORY  #=-
// ------------------------------------------------------------- //
SUB scrollydirectory:

IF KEY(15) //if TAB key
timer1 = 20 //reset timer1 to 20
  timer2 = 20 //reset timer2 to 20
   scroll = 0 //reset scroll to 0
ENDIF

DRAWRECT 0, 0, 320, 10, RGB(20,20,120) //Draw blue rectangle at top
PRINT dir$, scroll, 1 //print the current directory address ,x ,y positions


length=LEN(dir$)*8- 315 //Get the number of letters in the directory path * by 8 - almost the full screen width
//--------------timers to move and stop the directory scrolly---------------------
IF timer1 > 0 THEN timer1 = timer1 - 1
IF timer1 < 1 AND scroll > -length THEN  scroll = scroll-2
IF scroll < -length THEN timer2 = timer2 - 1
IF timer2 = 0 AND scroll < -length
scroll = 0
  timer1 = 20
   timer2 = 20
ENDIF
//--------------------------------------------------------------------------------


DRAWRECT 0, 220, 320, 240, RGB(20,20,120) //Draw blue rectangle at the bottom
PRINT "Pick file/folder = SELECT(GP2X)/TAB(PC)", 0, 220 //print message over the rectangle
PRINT "Scroll list = STICK(GP2X)/ARROWS(PC)", 0, 230 //print message over the rectangle

ENDSUB // SCROLLYDIRECTORY



MrTAToad

Why not use this to display the results in DDGui ?

Kitty Hello


momosxp

IIRC???
Something that works on wiz , too?

edit: found it:

Code (glbasic) Select
DDgui_pushdialog(0,0,320,240)
WHILE TRUE
SETFONT 1
DDgui_FileDialog$(TRUE,"*.*")
DDgui_show(TRUE);
SHOWSCREEN
WEND


DDgui is really nice tool. Goodjob Gernot :good:
There is a fault in the pdf file for ddgui on page 9 (about filedialog)

Code (glbasic) Select
DDgui_list("id_text", "test.bmp", _
"Graphics|*.bmp;*.png|All files|*.*", 0,0)

has to be:
Code (glbasic) Select
DDgui_file("id_text", "test.bmp", _
"Graphics|*.bmp;*.png|All files|*.*", 0,0)

Kitty Hello

No need for DDgui_pushdialog. DDgui_filedialog is a new dialog itself.