Bug in FORM(map) example [nope, my bad]

Started by lettersquash, April 06, 2020, 01:20:27

Previous topic - Next topic

lettersquash

I tried running the example of the FORM(map) function at https://smallbasic.github.io/reference/525.html and it reports the error Failed to load image: 'name field empty' on the line
f = form(f)

Can anyone debug it? It looks like a very useful function.

f.handleKeys = 0
' create some buttons
button1.y = 120
button1.label = "Button1"
button1.value = "valudofButton1"
button1.backgroundcolor = rgb(255,0,0)
button1.onclick = HelloWorld 'this prints on load
button2.x = -1
button2.y = 120
button2.label = "Button2"
button2.value = "valueofButton2"
button3.type = "image"
button3.value = "cats"
button3.x = -1
button3.y = 120
button3.background = 223344
b4.type = "choice"
b4.value = "cats|dogs|Fish|cats|dogs|Fish|cats|dogs|Fish|cats|dogs|Fish"
b4.selectedIndex = 2
b4.x = -1
b4.y = 120
b5.type = "list"
b5.value = "cats|dogs|Fish|cats|dogs|Fish|cats|dogs|Fish|cats|dogs|Fish|end|lol"
b5.x = -1
b5.y = 120
b5.height = 120
b6.type = "text"
b6.value = "cats"
b6.length=30
b6.x = -1
b6.y = 120
b6.width = 50
b6.noFocus = 0
' add buttons to the form
f.inputs << button1
f.inputs << button2
f.inputs << button3
f.inputs << b4
f.inputs << b5
f.inputs << b6
f.backgroundcolor = "green"
' at this stage 'f' is just a plain user defined structure (map)
' after calling FORM, 'f' becomes a system form object with three special functions
' doEvents, close and refresh (see sokoban.bas for refresh)
f = form(f)
' the string version of the form is JSON  (see https://en.wikipedia.org/wiki/JSON)
TSAVE "f.frm", f
while 1
  ' pump the system event queue
  f.doEvents()
  ' process the event
  in$ = inkey
  at 0,0
  if len(in$)>1 then
    flag= asc(left(in$,1))
    keychar =right(in$,1)
  n= asc(keychar)
    if (flag == 1)
      ? "Ctrl    : ";keychar ; "   "
    else if (flag == 2)
      ? "Alt    : "; keychar
    else if (flag == 3)
      ? "Ctrl+Alt: "; keychar ; "   "
    else
      ? "Arrow: "; n ; "   "
    end if
  else
    vkey = asc(in$)
    if (vkey == 8) then
      ? "backspace!"
    else if (vkey == 127) then
      ? "delete !"
    else
      ? " key=           "; in$; " "; vkey
    endif
endif
if b6.value <> "cats" then ? b6.value
  if (len(f.value) > 0) then
    print f.value; "                  "
  end if
wend
f.close()
func HelloWorld
? "hello world"
end
I'll have you know, I'm coding all the right commands, just not necessarily in the right order.

chrisws

hmmm, that error message isn't the best  :-[

You could either call

button3.name  ="c:/image.png"

or just comment out

f.inputs << button3



lettersquash

Oh I see, just needed the file, thanks Chris. Is there a way to set the CWD to be the same as the script folder? I see you can read the constant, CWD, but it's not settable. I tried putting an image file in the same folder as the script first off, and then realised it wasn't finding that. It'll take the "C:/image.png" fine presumably because that's an absolute path, but "image.png" doesn't work unless I find out what the current working directory is.

That's neat, but I'm slightly disappointed - I thought this might use the default (in my current case, Windows) dialogue forms/windows. Is that outside of smallBASIC's remit, or just complicated?
I'll have you know, I'm coding all the right commands, just not necessarily in the right order.

chrisws

#3
You can change the working directory with the CHDIR command.

Making 'name' a relative path to the location of your .bas file *should* work. Some of the included examples rely on this to read from the resources folder.

There's a whole other world of possibilities for extending SmallBASIC with 'plugins'.

see: https://github.com/smallbasic/smallbasic.plugins

The idea was to create a bunch of DLL's that could extend the command line version and then wrap libraries such as these:

TinyFD
https://sourceforge.net/projects/tinyfiledialogs/

NFD
https://github.com/mlabbe/nativefiledialog

Open-source Embedded GUI Library
https://littlevgl.com/   

I had the 'nuklear' library more or less working, but only in linux. I'm not sure whether there is some show stopper for making this all work in windows.

lettersquash

#4
Quote from: chrisws on April 06, 2020, 20:55:49
You can change the working directory with the CHDIR command.
D'oh.  :))

Quote
Making 'name' a relative path to the location of your .bas file *should* work. Some of the included examples rely on this to read from the resources folder.
Yeah that should be fine.

Quote
There's a whole other world of possibilities for extending SmallBASIC with 'plugins'.

see: https://github.com/smallbasic/smallbasic.plugins

The idea was to create a bunch of DLL's that could extend the command line version and then wrap libraries such as these:

TinyFD
https://sourceforge.net/projects/tinyfiledialogs/

NFD
https://github.com/mlabbe/nativefiledialog

Open-source Embedded GUI Library
https://littlevgl.com/   

I had the 'nuklear' library more or less working, but only in linux. I'm not sure whether there is some show stopper for making this all work in windows.
Thanks, that's interesting, but I'm lacking a lot of background knowledge and wouldn't know where to begin - not that it's important for my purposes; I'm just a hobby programmer. I haven't a clue about C, C++, etc., and wouldn't know how to compile or write a DLL.

This makes me curious, though. These projects all seem to be software delivering bespoke GUI dialogs and controls (i.e. ones the developer has designed and coded). I'm wondering why this is the route taken, rather than writing/including code that accesses the native ones. Maybe it's just easier, as the other way the interpreter would need to parse commands for several platforms?

I'm thinking how another three languages I use do this, BBC BASIC for Windows, RFO BASIC! and AutoHotkey, but each is dedicated to one platform, or has forks that are gradually adding support for others (like BBCSDL, which is supposed to work on Linux and Android, but had all manner of bugs on those the last time I looked, or ran very slowly).

I guess smallBASIC already fits itself into the Linux, Windows and Android environments with its own console and output windows (and does it very well from my testing on the latter two - I've not tried it on Linux), but without the native dialogs.

Anyhoo, it's nice developing code to create good looking buttons and other controls within sB. Lots of possibilities there, including drawing each one directly, or loading an image and checking mouse click positions....and, of course, FORM(map).
I'll have you know, I'm coding all the right commands, just not necessarily in the right order.

Aurel [banned]

QuoteI'm not sure whether there is some show stopper for making this all work in windows.
That is a main problem with sb,there is no native support for windows api in windows version.
(Y)