Using yoshi in yab
#1
WHAT!? why would you want to do that when you can make all your windows and gadgets in yab itself?

1. For the same reason you don't laboriously make your own ALERT and FILEPANEL widgets. You could, you know. But someone already did all the heavy lifting here in terms of layout, so why bother?
2. Because using yoshi lets you tweak the dialogue OUTSIDE yab.

I can think of a number of ways to do this. The easiest is to construct the yoshi dialogue in a separate file and just call it. But I have a fondness for shipping apps with as few files as possible (It goes back to my BeOS days) and constructing secondary files on the fly, so that's what I will do here.

Code:
#!/bin/env yab

restore yoshi
open "cmds.yoshi" for writing as #1
    while(line$ <> "end_of_data")
        read line$
        print #1 line$
    wend
close #1
result$ = system$("yoshi cmds.yoshi")
if instr(result$, "chk=OFF") <> 0 then
    alert "You turned off the checkbox. Thank you for following instructions", "OK", "none"
else
    alert "You did not turn off the checkbox. Try again", "OK", "none"
endif
system("rm -f cmds.yoshi")
end

label yoshi
data "*.title = Example window title"
data "*.bgcolor = 255-,232,181"
data "txt.type = text"
data "txt.default = yoshi in yab demo"
data "txt.lines = 2"
data "txt.align = centered"
data "txt.scrollbar = 1"
data "txt.bg = white"
data "chk.type = checkbox"
data "chk.default = 1"
data "chk.label = Turn off this checkbox, click OK and see what happens"
data "end_of_data"

The INSTR command in yab makes it a lot easier to retrieve yoshi's output than it is in bash. Here, all I wanted to know was whether a specific action had been taken. For more complex yoshi scripts, you will have to use all of yab's string-splitting tricks to parse the output (e.g TOKEN, SPLIT, LEFT$ and RIGHT$).
Reply


Messages In This Thread
Using yoshi in yab - by clasqm - 05-02-2016, 04:43 AM
RE: Using yoshi in yab - by clasqm - 05-02-2016, 07:05 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)
Free Web Hosting