wxBasicscript - script language for Xdialog

Stuff that has yet to be sorted into a category.
Message
Author
User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#41 Post by MU »

Lobster,

If you do not write an "if"-condition in 1 line, you must close it with "end if".

Ok:

Code: Select all

if result = 1 then print 1
Wrong:

Code: Select all

if result = 1 then 
  print 1
Ok:

Code: Select all

if result = 1 then 
  print 1
end if
This one works:

Code: Select all

#!/usr/bin/wxbasicscript
// a menue
include "/usr/lib/wxbasicscript/basefunctions.inc"


 //////////////////////////////////////////////////////////////////////
// Menu of available tutorials


dialog = "--title 'Tips' "&
"         --menu 'Double click for selected tip "&
" Choose a Section:' 0 0 10 "&
"        '1'  'Writing and running a first script' "&
"        '2'  'Calling sub programs or procedures' "&
"        '3'  'Other stuff'"

result , choice = xdialog ( dialog )

if result != 0 then
  dialog = "--title 'info' --msgbox 'dismissed' 0 0"
else

  if choice = "1" then dialog = "--title 'info' --msgbox 'Writing and running a first script' 0 0"
  if choice = "2" then dialog = "--title 'info' --msgbox 'Calling sub programs or procedures' 0 0"
  if choice = "3" then dialog = "--title 'info' --msgbox 'Other stuff' 0 0"

  result , choice = xdialog ( dialog )

end if


Also, you mixed up result and choice.
result just will have one of 3 values:
1=ok
2=cancel
255= Window was destroyed.

Your "1" "2" "3" -values will be returned in the choice-variable.

You can write the example a little bit shorter, using a list.

A list is a list of strings, you can index with a number, like mylist[1] mylist[2] mylist [3].

Look at this example:

Code: Select all

#!/usr/bin/wxbasicscript
// creating Menue with a list
include "/usr/lib/wxbasicscript/basefunctions.inc"


 //////////////////////////////////////////////////////////////////////
// Menu of available tutorials


//--- Putting the menue-points to a list 


MP = { "Writing and running a first script" , "Calling sub programs or procedures" , "Other stuff" }

dialog = "--title 'Tips' "&
"         --menu 'Double click for selected tip "&
" Choose a Section:' 0 0 10 "&
"        '1'  '" & MP[1] & "' "&
"        '2'  '" & MP[2] & "' "&
"        '3'  '" & MP[3] & "'"

result , choice = xdialog ( dialog )

if result != 0 then
  dialog = "--title 'info' --msgbox 'dismissed' 0 0"
else

 //--- to use the value of the string choice as an index-number, we must convert it to a number using "val()"
 result , choice = xdialog ( "--title 'info' --msgbox '" & MP[val(choice)] & "' 0 0" )

end if
Greets, Mark

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#42 Post by BarryK »

Beaver has color syntax highlighting compatible with UltraEdit.
So I got the highlighting file for Qbasic from www.ultraedit.com.

I have placed this into the file /root/.beaver/wordfile.txt
I only gave it one file extension, WXBS, but more can be added, separated
by spaces, for example
WXBS WX
and the extension has to be capitals.

I've attached the wordfile.txt because although wxBasic is based on Qbasic, it seems to be a somewhat tenuous relationship.
If anyone feels like it, they're welcome to fix it up to work better with
wxBasicScript.
Attachments
wordfile.txt.gz
(12.47 KiB) Downloaded 460 times

User avatar
JohnMurga
Site Admin
Posts: 555
Joined: Wed 04 May 2005, 04:26
Location: Far to the east
Contact:

#43 Post by JohnMurga »

Hey

Just a quick question ... How would you use a progress bar when using xdialog within wxBasic ?

I know how to do it in shell script, but I an not sure how it would work from here.

Cheers
JohnM

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#44 Post by MU »

I haven't looked at progressbars yet.

If you post the shellscriptexample, I might translate it to wxbs.

Mark

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#45 Post by MU »

Example: using a gauge (Progress-bar)

The gauge wants to get its values sent via Shellscript-echo-commands.

So I create those commands in wxbasicScript, and send them through a pipe(|) to the gauge.

You could add any commands, for example check the size of a large zip (50 MB) you create.

The example shows, that the gauge is really reacting to events.

First I define the commands.
Then I run xcalc in Background.
Now I launch the progressbar (gauge).

It is feeded from the shell-commands, that check with help of "ps", if xcalc still is running.
If not, the gauge is closed (exit).
If yes, the value in increased in 20%-steps, until 100% is reached.

If 100% is reached, xcalc is killed and the script ends.

So run it, and close xcalc, when the gauge reaches 40%, you will see the gauge stops.

Code: Select all

#!/usr/bin/wxbasicscript
include "/usr/lib/wxbasicscript/basefunctions.inc"


GAUGE = "("&
"echo \"20\" ; sleep 5;"&
" if [ ! \"`ps |grep xcalc`\" ];then exit;fi;  echo \"40\" ; sleep 5;"&
" if [ ! \"`ps |grep xcalc`\" ];then exit;fi;  echo \"60\" ; sleep 5;"&
" if [ ! \"`ps |grep xcalc`\" ];then exit;fi;  echo \"80\" ; sleep 5;"&
" if [ ! \"`ps |grep xcalc`\" ];then exit;fi;  echo \"100\" ; sleep 5;"&
")"

shell ("xcalc&")
xwin_exec( GAUGE & "|Xdialog --title \"Gauge\" --gauge \"test\" 8 30" )
shell ("killall xcalc")

User avatar
JohnMurga
Site Admin
Posts: 555
Joined: Wed 04 May 2005, 04:26
Location: Far to the east
Contact:

#46 Post by JohnMurga »

In that example you seem to be calling xdialog as a command as I would from a shell script ...

What if the wxBasic program is doing what you want to report progress on, how do you do this without having to run the function as another process piped to xdialog ?

Also, on the GtkDialog homepage there is a REALLY cool example of doing event driven BASH ... Would it be possible to do even driven wxBasic ?

Cheers
JohnM

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#47 Post by MU »

JohnMurga wrote: What if the wxBasic program is doing what you want to report progress on, how do you do this without having to run the function as another process piped to xdialog ?
I think this will not work, you would have to do this with the "big" wxBasic.
It allows you to run subs or functions parrallel, with help of wxTimer().
An example can be found here:
http://wxbasic.sourceforge.net/phpBB2/v ... .php?t=769

The Backup-program displayes the procentual size of a tempfile in a wxGauge, while a file is zipped.

The only way to do it with wxbs would be something like this (this does not work,dont't know how to use while in shellscripts, just as an idea):

Code: Select all

GAUGE="("&
"while [ ! "`cat gauge.tmp`" = "20" ];do;done; echo "20";"& 
"while [ ! "`cat gauge.tmp`" = "40" ];do;done; echo "40";"& 
")"

xin_exec( GAUGE & "|Xdialog ...  &" )
mysub1()
mysub2()
end

sub1()
  dosomething()
  writestringtofile("gauge.tmp" , "20")
endsub

sub2()
  dosomethingelse()
  writestringtofile("gauge.tmp" , "40")
endsub
JohnMurga wrote: Also, on the GtkDialog homepage there is a REALLY cool example of doing event driven BASH ... Would it be possible to do even driven wxBasic ?
Do you mean updating the RPM-lists?
The Dotpup-downloader uses Gtkdialog embedded in wxBasicscript, I will write an introduction to use Gtkdialog to create such programs this weekend.
Meanwhile you might to have a look at the source, added some comments, but it is not well documentated yet.

http://www.murga.org/%7Epuppy/viewtopic.php?t=2144

Mark

User avatar
JohnMurga
Site Admin
Posts: 555
Joined: Wed 04 May 2005, 04:26
Location: Far to the east
Contact:

#48 Post by JohnMurga »

MU wrote:Do you mean updating the RPM-lists?
The Dotpup-downloader uses Gtkdialog embedded in wxBasicscript, I will write an introduction to use Gtkdialog to create such programs this weekend.
Meanwhile you might to have a look at the source, added some comments, but it is not well documentated yet.

http://www.murga.org/%7Epuppy/viewtopic.php?t=2144

Mark
Yeah, in the RPM-lists program it calls functions inside a bash script.

Thanks, I did look at the source. It looked like it invoked the sub-routines as scripts in themselves, which is cool ... But I was wondering if it would be possible to call functions in the same way as with the Bash example.

Cheers
JohnM

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#49 Post by MU »

No, I think this is not possible.

In fact wxbs/Xdialog is not a perfect combination.

wxbs is just a "wrapper", that "hides" shell-commands by putting them in functions in basefunctions.inc.

basefunctions.inc itself creates shell-commands to run Xdialog/Gtkdialog.

But wxbs is missing the functionality of opening a process connected via a pipe to other programs.
I wish I had such functions, but I am not fit enough in C to add them to the interpreter yet.
Maybe in half a year or so.

I'm sorry :?

Greets, Mark

User avatar
JohnMurga
Site Admin
Posts: 555
Joined: Wed 04 May 2005, 04:26
Location: Far to the east
Contact:

#50 Post by JohnMurga »

MU wrote:But wxbs is missing the functionality of opening a process connected via a pipe to other programs.
I wish I had such functions, but I am not fit enough in C to add them to the interpreter yet.
Maybe in half a year or so.

I'm sorry :?
No problem !

I was trying to discover the limits of what can be done currently ... What you are are doing is still really cool ;-)

Cheers
JohnM

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#51 Post by MU »

Yes, it is not really a problem.
wxBasicscript is intented to be mainly for Beginners.
(Although the string-functions are nice for advanced, too).

If you are experienced and want to use some advanced techniques, you might try the "big" wxBasic, or write the applications completely using shellscripts :)

Mark

Post Reply