yab | yet another Basic for HAIKU

Full Version: More spinner stuff.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I added a slinner to a Filebox.

FileboxDemo.yab ( minor changes)

Code:
#!yab

import spinner
import Filebox_spin



dir$ = "/boot/home/"

window open 100,100 to 500,500, "Demo",dir$
Window set "Demo","flags","Not-Zoomable Not-Resizable"
Filebox(10,20,350,385,"Filebox", 1, "Demo")
button 10,0,32,20, "DirUp", "..", "Demo"
FileboxDirectory("Filebox", dir$, true)


dim msg$(1)
inloop = true
while(inloop)
        n = split(message$, msg$(), "|")
    for i=1 to n
        print msg$(i)
        // Quit
        if(msg$(i) = "Demo:_QuitRequested") inloop = false

        // Button pressed and we are not in the root directory
        if(msg$(i) = "DirUp" and dir$"/") then
            t = len(dir$)-1
            while(mid$(dir$,t,1)"/")
                t = t - 1
            wend
            dir$ = left$(dir$,t)
            WINDOW SET "Demo", "Title", dir$
            FileboxDirectory("Filebox", dir$, false)
            
        endif

        // An item is invoked
        if(instr(msg$(i),"Filebox:_Invoke:")) then
            position = val(right$(msg$(i),len(msg$(i))-16))

            // if the item is a directory, then update the filebox else print the filename
            if(FileboxIsDirectory("Filebox", position,dir$)) then
                dir$ = dir$ + FileboxName$("Filebox", position) + "/"
                WINDOW SET "Demo", "Title", dir$
                FileboxDirectory("Filebox", dir$, true)
            else
                print dir$+FileboxName$("Filebox", position)
            endif
        endif
    next i
    
        sleep 0.01
wend

window close "Demo"


Filebox_spin.yab (modified Filebox.yab library file)

Code:
// Filebox is a library to have an easy access to a list of files.
// This is easier than poking around with columnboxes yourself.

// Open a new filebox from (x1,y1) to (x2,y2)
// with the id ID$, the type of scrollbar ScrollbarType on View$
export sub Filebox(x1,y1,x2,y2, ID$, ScrollbarType, View$)
    local myscrollbar
    columnbox x1,y1 to x2,y2, ID$, ScrollbarType, "resizable", View$
    columnbox column ID$, " ", 1, 20, 20, 20, "align-center"
    if(scrollbarType=1 or scrollbarType=3) myscrollbar = peek("scrollbarwidth")
    columnbox column ID$, "Name", 2, 1000, 21, x2-x1-24-myscrollbar, "align-left"
    columnbox color ID$, "Selection-Active", 220,220,250
        columnbox color ID$, "Row-Divider", 255,255,255
        new_spinner(x2-12,y2-12,12,12, ID$, View$)
        spinner_set(1,ID$)
        
    return
end sub

// Easy interface to a Filebox, simply name a directory
export sub FileboxDirectorySimple(ID$, dir$)
    FileboxDirectory(ID$,dir$,false)
    return
end sub

// return the name of the row position
export sub FileboxName$(ID$, position)
    return columnbox get$ ID$, 2, position
end sub

// return true, if the row position is a directory
export sub FileboxIsDirectory(ID$, position,dir$)
    local t$
    t$ = columnbox get$ ID$, 2, position
    print "t$ "+t$
    //if(t$ =  "__Path__="+path$+Name$"__Mime__=application/x-vnd.Be-directory") return true
    if(system("test -d \""+ dir$+t$+"\"") = 0) system("addattr -t mime BEOS:TYPE application/x-vnd.Be-directory \""+dir$+t$+"\"") : return true
    return false
end sub

// Give a directory and the following options:
// showDot: set this to true to show hidden (dot) files
export sub FileboxDirectory(ID$, dir$, showDot)
display_spinner(ID$)
spin(ID$)
    local t$
    local i
    local n
    local arraysizeDir
    local arraysizeFiles

    dim directories$(1)
    dim files$(1)

    arraysizeDir = 0
    arraysizeFiles = 0

    columnbox clear ID$
    if(showDot) then
        t$ = system$("ls --format=single-column --color=none -aF \""+dir$+"\" |sort -f")
    else
        t$ = system$("ls --format=single-column --color=none -F \""+dir$+"\" |sort -f")
    endif

    dim splitdir$(1)
    spin=1
    n = split(t$, splitdir$(), "\n")
    for i=1 to n-1
    if n=spin spin(ID$):spin=spin+10
                
                //print dir$+splitdir$(i)
                
                
                //print dir$+splitdir$(i)
                if  (right$(splitdir$(i),1)="/") then
    
               //if(system("test -d \""+ dir$+splitdir$(i)+"\"") = 0) then
                        // comment the if clause out if you want to have the direcotries "." and ".." listed
                        if(splitdir$(i)<>"./" and splitdir$(i)<>"../") then
                            arraysizeDir = arraysizeDir + 1
                            dim directories$(arraysizeDir)
                            splitdir$(i) = left$(splitdir$(i),len( splitdir$(i))-1)
                            directories$(arraysizeDir-1) = splitdir$(i)
                       endif
                // handle files
              
                else
                
                
                        arraysizeFiles = arraysizeFiles + 1
                        dim files$(arraysizeFiles)
                        if right$(splitdir$(i),1)="*" then
                            files$(arraysizeFiles-1) = left$(splitdir$(i), len(splitdir$(i)) -1)
                        elseif right$(splitdir$(i),1)="@" then
                            files$(arraysizeFiles-1) = left$(splitdir$(i), len(splitdir$(i)) -1)
                        else    
                            files$(arraysizeFiles-1) = splitdir$(i)
                        endif
                endif
    next i
    
    for i=0 to arraysizeDir-1
        FileboxAdd(ID$, directories$(i), true,dir$)
        spin(ID$)
    next i
    for i=0 to arraysizeFiles-1
        FileboxAdd(ID$, files$(i), false,dir$)
        spin(ID$)
    next i
    hide_spinner(ID$)
    return
end sub

sub FileboxAdd(ID$, Name$, IsFolder, path$)
    local maxpos

    maxpos = (columnbox count ID$) + 1
    a$=""
        
    if(IsFolder) then
        columnbox add ID$, 1, maxpos, 18, "__SmIC__="+path$+Name$
    else
        columnbox add ID$, 1, maxpos, 18, "__SmIC__="+path$+Name$
    
    //else    
        //columnbox add ID$, 1, maxpos, 18, "__Mime__=application/octet-stream"
    endif
    columnbox add ID$, 2, maxpos, 20, Name$
    columnbox select ID$, 1
    columnbox select ID$, 0
    return
end sub

[Image: Filebox-spinner.png]

Note the spinner in the lower right. It only shows as the file listing is being filled.
---Error in Filebox_spin.yab, line 37: syntax error at ""+ dir$+t$+""

Sorry, don't have time to trace that fault right now.
I cannot duplicate your issue. I get no errors. Any help would be appreciated.
Let me copy that code from my Mac and try again.Will let you know.
Nope. Still doing it.
I just copied and pasted from the forum, and the program runs fine. What version of Haiku and yab are you running?
I've copied this text from three browsers now on two OS's and it keeps giving me errors. Probably embedded binary codes, although I don't see anything stange in DiskProbe.

I've copied the two libraries into the demo and removed the export statements

---Error in fileboxdemo.yab, line 86: syntax error at "") = 0) then0x0a"
---Error: Program not executed
~/Desktop/fileboxdemo> yab fileboxdemo.yab
---Error in fileboxdemo.yab, line 87: syntax error at "")0x0a"
---Error: Program not executed
~/Desktop/fileboxdemo> yab fileboxdemo.yab
---Error in fileboxdemo.yab, line 87: syntax error at "")0x0a"
---Error: Program not executed
~/Desktop/fileboxdemo> yab fileboxdemo.yab
---Error in fileboxdemo.yab, line 112: syntax error at ""+dir$+""
---Error: Program not executed
~/Desktop/fileboxdemo> yab fileboxdemo.yab
---Error in fileboxdemo.yab, line 110: syntax error at ""+dir$+""

As you can see the error just keeps moving up as I try to edit. "0x0a" is computerese for linefeed, so that must be the issue here.

Do you think you can zip up the two files and give a link? Perhaps that would be a good policy for all of us. Paste the code here so people can read it, but also give a download link.
(05-18-2016, 12:56 PM)clasqm Wrote: [ -> ]Do you think you can zip up the two files and give a link? Perhaps that would be a good policy for all of us. Paste the code here so people can read it, but also give a download link.


OK, here is a link to the zipped files. http://coquillemartialarts.com/jim/FBDemo.zip
Ah I found the issue. I was not seeing it because my library was in ~/config/settings/yab. There seems to have been a problem with the escape characters not being copied. I corected the post and updated the zip with the proper file. Arg!
Works perfectly now.
Free Web Hosting