GtkBasic 003e - small Basic interpreter/IDE - 3300 functions
Posted: Wed 21 Nov 2007, 22:28
Download (560 kb, august 31, 2008, for Puppy 2, 3 and 4)
(can be installed in addition to, or without version 002):
http://dotpups.de/puppy3/dotpups/Progra ... ic003e.pet
mirror:
http://puppyfiles.ca/dotpupsde/puppy3/d ... ic003e.pet
You also need Puppybasic 2.6, as it includes an important function-library:
http://murga-linux.com/puppy/viewtopic.php?t=11090
I do not bundle both, as Puppybasic uses less memory, so it should be used for small scripts instead of Gtkbasic.
Screenshot of IDE and examples:
Full size:
http://dotpups.de/puppy3/dotpups/Progra ... -0.0.3.jpg
Screenshot of the new translation tool of the IDE:
Full size:
http://dotpups.de/puppy3/dotpups/Progra ... locale.jpg
Release notes:
------------------------------------------------
Overview
------------------------------------------------
Gtkbasic is based on Puppybasic, a very small Basic-Interpreter, that is shipped as system-utility with Puppylinux.
It allows to handle Windows created with the mouse using simple Basic-code.
It is pretty small, less than 500 kb uncompressed, 95 kb compressed.
Due to its original purpose, it has functions that give extended access to a Linux-based System, so you can for example remotely move any window on your desktop using the internal functions to access Xlib.
Or use resultlist = xwin_system( "cat thefile | sed -e 's/word/replacement/' | some_weired_shell_options" ) to access Unix-tools that cover more advanced functions like regular expressions.
As Puppybasic was a pure comandline-interpreter, it also included a function-library for simplified access to external grafical tools like Xdialog or Gtkdialog.
But those dialog-tools had several limitations, that finally lead to the direct integration of libglade and the Gtk+ Api.
The first testversion was called "ginsbasic", as it only had wrappers to a utility originally written for shell-scripts.
The gins-library allows to load a XML-file generated with the grafical designer "Glade" using libglade.
So you do not code windows by hand, but instead use the grafical designer Glade.
Like this you can create very custom programs, e.g. combine lists with as many buttons as you like.
Gins has a few set of commands to read or modify those elements at runtime, but you quickly reached limits.
So I started writing wrappers to directly execute Gtk+ functions.
They allow to set far more options, or to create objects not supported by gins.
Meanwhile more than 700 Gtk+ functions are "automatically" wrapped, hence I now call it "Gtkbasic".
Not every function might work though, as the wrappers are created by a script, and it might not have detected all required conversions.
The Gtk+ C-API supports some objects not available in Basic, and those cannot be accessed directly like in C.
So I added some custom functions, that internally convert objects, or add them to an internal reference-table.
One example are Clists, that now are much easier to use than using standard-calls.
They include support for drag'n'drop and pictures.
Who ever tried to write a program using Clists in C, knows how difficult they are to handle.
But with the Gtkbasic functions, it becomes pretty easy.
------------------------------------------------
Changes from 002 to 003:
------------------------------------------------
The API changed slightly in 2 concerns.
1.) Objectnames
To adapt old programs:
remove the ":" from your objects.
- Old code:
gtk_create_object("mylist1")
gtk_do_something("window1", ":mylist1" , ...)
- New code:
gtk_create_object("mylist1")
gtk_do_something("window1", "mylist1" , ...)
The partially required ":" were confusing and slowed down execution, and were just used because it helped me to understand some mechanisms.
2.) Use the standard wrappers
The "handcoded" function "gtk_create_object" now only supports objects, that cannot be created with standard Gtk-functions in Gtkbasic.
For example because they depend on "Enums" not yet implemented.
Like Windows and Fileselectors.
I removed buttons and boxes from this function, as they can be built with the standard-functions.
So use standard-calls now, to keep your code easily portable.
- Old code:
gtk_create_object("label1" , "test" , 0 , 0)
- New code:
gtk("gtk_create_label_with_text" , "test" , 0 ,0 , 0 , 0 , 0 )
gtk_setobjectname("label1")
Whenever you create a new Gtk-object, you afterwards must assign the name for it, as Basic can not receive the objects directly.
In C, it would look like this:
GtkWidget *label1 = gtk_create_label_with_text( "test" );
Note, that the automatically generated Gtk-funtions gtk("gtk_whatever" ... ) always expect 6 argument after the functionname.
Unused arguments must be set to 0.
------------------------------------------------
Concerning object-creation, I however added a special feature to V003:
Objects created by reference calls now can get the names directly.
But that is extremely seldom, e.g. used to generate Gdk pixmaps and masks.
Such a function looks like this in C:
Widget *firstnewwidget;
firstnewwidget = new_widgettype(options);
Widget *secondnewwidget;
secondnewwidget = new_widgettype(options);
gtk_create_gdk_stuff(Widget *source , Widget &firstnewwidget , Widget &secondnewwidget)
In Gtkbasic003, this simply looks so:
gtk("gtk_create_gdk_stuff" , "sourcewidget" , "firstnewwidget" , "secondnewwidget" ,0 , 0 , 0)
Gtkbasic knows by the functionname, what type of new object is needed, and uses internally already reseved objects.
So you create them by simply assigning a new name.
------------------------------------------------
Pictures:
New since 003.
Gtk supports several different objects like images, pixmaps, bitmaps.
Very confusing, especially as there are in addition those types of the underlying "Gdk" library.
So I created a handwritten function to load Gtk-pixmaps, and convert them to gdk-objects.
Those are required by some older functions, that do not accept the new, easy to use "Gtk-image".
Look at the Demos to see, how you can display and clone pictures, or how to add them to other widgets.
------------------------------------------------
Project structure:
The easiest way to start, is to run the IDE from the demos.
Create a new project in it.
Version 002 created a file "start-project".
Version 003 now creates "project", a shellscript.
And "project.gtb" , the Basic-program.
In the shellscript, you could add any stuff you want to run before the Basic-program.
It already includes a simple mechanism for localization, and example locale-files for english and german.
------------------------------------------------
IDE:
If you execute a project, it now is run from a yellow rxvt, so you can see everything the program prints.
Needed to see events or analyze crashes.
------------------------------------------------
Lists:
They can use pictures now.
They use a different selection-method now.
Drag'n'drop was only partially supported in 002.
Now it has a "sensefull" fixed defined behaviour, and you can analyze the "drops" in detail from Basic.
See the example in the demos.
------------------------------------------------
Other fixes:
Fixed bug with missing ":" in Textviews, so now they are really usable.
If you load text from files, they should be saved as Unicode (UTF-8).
If you want to display files in different encodings, use first before attaching it to a textbuffer or widget:
thetext = g_locale_to_utf8( thetext )
Fixed severe memory-leaks (required memory was contiously increasing at runtime)
Radiobuttons no longer crash Glade in Puppy 3.
So I now added a demo how to use them.
Note: how to use sqlite with GtkBasic:
http://murga-linux.com/puppy/viewtopic. ... 542#160542
Time to sleep
Good night, Mark
(can be installed in addition to, or without version 002):
http://dotpups.de/puppy3/dotpups/Progra ... ic003e.pet
mirror:
http://puppyfiles.ca/dotpupsde/puppy3/d ... ic003e.pet
You also need Puppybasic 2.6, as it includes an important function-library:
http://murga-linux.com/puppy/viewtopic.php?t=11090
I do not bundle both, as Puppybasic uses less memory, so it should be used for small scripts instead of Gtkbasic.
Screenshot of IDE and examples:
Full size:
http://dotpups.de/puppy3/dotpups/Progra ... -0.0.3.jpg
Screenshot of the new translation tool of the IDE:
Full size:
http://dotpups.de/puppy3/dotpups/Progra ... locale.jpg
Release notes:
------------------------------------------------
Overview
------------------------------------------------
Gtkbasic is based on Puppybasic, a very small Basic-Interpreter, that is shipped as system-utility with Puppylinux.
It allows to handle Windows created with the mouse using simple Basic-code.
It is pretty small, less than 500 kb uncompressed, 95 kb compressed.
Due to its original purpose, it has functions that give extended access to a Linux-based System, so you can for example remotely move any window on your desktop using the internal functions to access Xlib.
Or use resultlist = xwin_system( "cat thefile | sed -e 's/word/replacement/' | some_weired_shell_options" ) to access Unix-tools that cover more advanced functions like regular expressions.
As Puppybasic was a pure comandline-interpreter, it also included a function-library for simplified access to external grafical tools like Xdialog or Gtkdialog.
But those dialog-tools had several limitations, that finally lead to the direct integration of libglade and the Gtk+ Api.
The first testversion was called "ginsbasic", as it only had wrappers to a utility originally written for shell-scripts.
The gins-library allows to load a XML-file generated with the grafical designer "Glade" using libglade.
So you do not code windows by hand, but instead use the grafical designer Glade.
Like this you can create very custom programs, e.g. combine lists with as many buttons as you like.
Gins has a few set of commands to read or modify those elements at runtime, but you quickly reached limits.
So I started writing wrappers to directly execute Gtk+ functions.
They allow to set far more options, or to create objects not supported by gins.
Meanwhile more than 700 Gtk+ functions are "automatically" wrapped, hence I now call it "Gtkbasic".
Not every function might work though, as the wrappers are created by a script, and it might not have detected all required conversions.
The Gtk+ C-API supports some objects not available in Basic, and those cannot be accessed directly like in C.
So I added some custom functions, that internally convert objects, or add them to an internal reference-table.
One example are Clists, that now are much easier to use than using standard-calls.
They include support for drag'n'drop and pictures.
Who ever tried to write a program using Clists in C, knows how difficult they are to handle.
But with the Gtkbasic functions, it becomes pretty easy.
------------------------------------------------
Changes from 002 to 003:
------------------------------------------------
The API changed slightly in 2 concerns.
1.) Objectnames
To adapt old programs:
remove the ":" from your objects.
- Old code:
gtk_create_object("mylist1")
gtk_do_something("window1", ":mylist1" , ...)
- New code:
gtk_create_object("mylist1")
gtk_do_something("window1", "mylist1" , ...)
The partially required ":" were confusing and slowed down execution, and were just used because it helped me to understand some mechanisms.
2.) Use the standard wrappers
The "handcoded" function "gtk_create_object" now only supports objects, that cannot be created with standard Gtk-functions in Gtkbasic.
For example because they depend on "Enums" not yet implemented.
Like Windows and Fileselectors.
I removed buttons and boxes from this function, as they can be built with the standard-functions.
So use standard-calls now, to keep your code easily portable.
- Old code:
gtk_create_object("label1" , "test" , 0 , 0)
- New code:
gtk("gtk_create_label_with_text" , "test" , 0 ,0 , 0 , 0 , 0 )
gtk_setobjectname("label1")
Whenever you create a new Gtk-object, you afterwards must assign the name for it, as Basic can not receive the objects directly.
In C, it would look like this:
GtkWidget *label1 = gtk_create_label_with_text( "test" );
Note, that the automatically generated Gtk-funtions gtk("gtk_whatever" ... ) always expect 6 argument after the functionname.
Unused arguments must be set to 0.
------------------------------------------------
Concerning object-creation, I however added a special feature to V003:
Objects created by reference calls now can get the names directly.
But that is extremely seldom, e.g. used to generate Gdk pixmaps and masks.
Such a function looks like this in C:
Widget *firstnewwidget;
firstnewwidget = new_widgettype(options);
Widget *secondnewwidget;
secondnewwidget = new_widgettype(options);
gtk_create_gdk_stuff(Widget *source , Widget &firstnewwidget , Widget &secondnewwidget)
In Gtkbasic003, this simply looks so:
gtk("gtk_create_gdk_stuff" , "sourcewidget" , "firstnewwidget" , "secondnewwidget" ,0 , 0 , 0)
Gtkbasic knows by the functionname, what type of new object is needed, and uses internally already reseved objects.
So you create them by simply assigning a new name.
------------------------------------------------
Pictures:
New since 003.
Gtk supports several different objects like images, pixmaps, bitmaps.
Very confusing, especially as there are in addition those types of the underlying "Gdk" library.
So I created a handwritten function to load Gtk-pixmaps, and convert them to gdk-objects.
Those are required by some older functions, that do not accept the new, easy to use "Gtk-image".
Look at the Demos to see, how you can display and clone pictures, or how to add them to other widgets.
------------------------------------------------
Project structure:
The easiest way to start, is to run the IDE from the demos.
Create a new project in it.
Version 002 created a file "start-project".
Version 003 now creates "project", a shellscript.
And "project.gtb" , the Basic-program.
In the shellscript, you could add any stuff you want to run before the Basic-program.
It already includes a simple mechanism for localization, and example locale-files for english and german.
------------------------------------------------
IDE:
If you execute a project, it now is run from a yellow rxvt, so you can see everything the program prints.
Needed to see events or analyze crashes.
------------------------------------------------
Lists:
They can use pictures now.
They use a different selection-method now.
Drag'n'drop was only partially supported in 002.
Now it has a "sensefull" fixed defined behaviour, and you can analyze the "drops" in detail from Basic.
See the example in the demos.
------------------------------------------------
Other fixes:
Fixed bug with missing ":" in Textviews, so now they are really usable.
If you load text from files, they should be saved as Unicode (UTF-8).
If you want to display files in different encodings, use first before attaching it to a textbuffer or widget:
thetext = g_locale_to_utf8( thetext )
Fixed severe memory-leaks (required memory was contiously increasing at runtime)
Radiobuttons no longer crash Glade in Puppy 3.
So I now added a demo how to use them.
Note: how to use sqlite with GtkBasic:
http://murga-linux.com/puppy/viewtopic. ... 542#160542
Time to sleep
Good night, Mark