Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 01 Aug 2014, 22:35
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Unsorted
GtkBasic 003e - small Basic interpreter/IDE - 3300 functions
Moderators: deshlab, Flash, GuestToo, Ian, JohnMurga, Lobster
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [28 Posts]   Goto page: 1, 2 Next
Author Message
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Wed 21 Nov 2007, 18:28    Post subject:  GtkBasic 003e - small Basic interpreter/IDE - 3300 functions
Subject description: august, 31, 2008
 

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/Programming/GtkBasic003/GtkBasic003e.pet
mirror:
http://puppyfiles.ca/dotpupsde/puppy3/dotpups/Programming/GtkBasic003/GtkBasic003e.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/Programming/GtkBasic003/Gtkbasic-0.0.3.jpg


Screenshot of the new translation tool of the IDE:



Full size:
http://dotpups.de/puppy3/dotpups/Programming/GtkBasic003/Gtkbasic-0.0.3-translatelocale.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-Cool.
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.php?p=160542#160542


Time to sleep Wink

Good night, Mark

Last edited by MU on Sun 31 Aug 2008, 01:59; edited 7 times in total
Back to top
View user's profile Send private message Visit poster's website 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Thu 22 Nov 2007, 02:05    Post subject:  

Quote:
Time to sleep


m m m . . . I thought they had good coffee in Germany? Very Happy
Many thanks Mark. Great News for Basic programmers (I am still baffled by the turtle in Logo - I tried to make him into a soup) . . .

_________________
Puppy WIKI
Back to top
View user's profile Send private message Visit poster's website 
BarryK
Puppy Master


Joined: 09 May 2005
Posts: 7047
Location: Perth, Western Australia

PostPosted: Thu 22 Nov 2007, 18:40    Post subject:  

Mark, does gtkbasic require puppybasic to be installed? In other words, is it a dependency?
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Thu 22 Nov 2007, 20:09    Post subject:  

not directly.

But several of my GtkBasic examples also use
/usr/lib/wxbasicscript/basefunctions.inc
So this file must be kept.
Less important is
/usr/lib/wxbasicscript/basefunctions2.inc

That uses a stricter syntax (uses strict mode, where every variable must be explicitly declared), but I think nobody has used it yet.

An important dependency beside the standard Gtk libraries is libglade, but this is in Puppy anyway.


I removed some days ago on my system
/usr/bin/wxbasicscript

Instead, I added a symlink:
cd /usr/bin
ln -s gtkbasic003 wxbasicscript

Until now I encountered no problems Smile

Even complex programs like PSI work as expected.
Mark
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Thu 22 Nov 2007, 21:37    Post subject:  

I added another example, XFE-to-dotpupwizard.

It is only a very short example of Drag'n'drop.

I use a list where I can drop folders on from XFileExplorer.
The first folder will be passed to a shellscript (the dotpupwizard).

This step is required, as I cannot drop files directly from XFE to a Rox-Icon, as XFE uses a different protocoll for DND.

So this simple example shows, how you can "convert" Drag'n'Drop protocols.

Mark
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Fri 23 Nov 2007, 14:53    Post subject:  

update:

in older versions of JWM there were problems with Buttons, so I had patched the Button events.
I now removed this patch, as it hindered checkboxes from working correct.

In JWM in Puppy3, it works ok now.

Older versions of JWM might/will have the erratic behaviour.

As checkbuttons are very important, and new versions of JWM work, I think it is acceptable to use the correct functions now, even if this means, that you cannot use Gtkbasic 003 in Puppy 2.

I also uploaded the current source to
http://noforum.de/files/wxbasic/gtkbasic/

It can be compiled with:
./___build_quick

Mark
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Sat 24 Nov 2007, 00:54    Post subject:  

this one is not finished yet, but I must sleep now.
At least I'm so far that it basically works.
I must do internal restructuring (save settings in $HOME/.screensaver) and also not all options work yet.

Screenshot:



If you want to try it, extract it in
/usr/local/Gtkbasic-003/Demos/
http://dotpups.de/diverse-tgz/Screensaver.tar.gz

Then start the GtkBasic demos again to see it.

It includes 2 older Xscreensavermodules that require OpenGL.
Antinspect (3DCC users know that), and the beautifull atlantis with whales and sharks.
They will open fullscreen on a second display.
The design is modular, so any program could be added in the modules folder.
Always 2 files are needed, a startscript and an executable file.

One thing I am not sure of how to solve, is how to deactivate the CTRL keys, so that you cannot switch the display or exit X when the password protection is activated (at moment password protection is always active).
I also must encrypt the password.

This screenshot shows atlantis, note that the password-login is mostly covered by Gimp, as that display has no windowmanager. So I cannot hide Gimp when I start the screenshot.



Mark

Last edited by MU on Sun 07 Dec 2008, 21:20; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Wed 05 Dec 2007, 00:37    Post subject:  

I uploaded a new source-archive.
It includes a new binary gtkbasic003.
This is intended for tests, not to replace the dotpups.
I will make a new dotpup in some days.

http://noforum.de/files/wxbasic/gtkbasic/Gtkbasic-0.0.3-source-2007-12-05.tar.gz
mirror:
http://puppyfiles.org/stuff/wxbasic/Gtkbasic-0.0.3-source-2007-12-05.tar.gz

The interpreter is 260 kb compressed, or 1.3 MB uncompressed.
It now wraps all Gdk and Gtk functions (except several older, depreciated, and Cairo) - 3300 functioncalls.

So the size represents the "final size", it will not become much huger in future.

I did not test them, maybe several simply will crash your application.
It will take some days playing around, until I see what my completely rewritten build-script still does not manage.

I'm very impressed however, how easy it finally was to let it generate all the wrappers.
I had to add almost no more manual entries in the code to correct the automatic conversion.
That was very different before Smile

----------------------------------------
In one of the last versions I added the ability to use functions, that have pointers to other widgets.
You also can access pointers to floating point numbers now.
Example:

Code:
gtk("gtk_button_set_alignment" , "button1" ,"1","1",0,0,0)
gtk("gtk_button_get_alignment" , "button1" ,0,0,0,0,0)
a = gtk_returnpointervalue("1")
print "alignment:" & a
a = gtk_returnpointervalue("2")
print "alignment:" & a


The corresponding C-function:
Code:
void gtk_button_get_alignment  (GtkButton *button,  gfloat *xalign, gfloat *yalign);


What currently not works, is to use integers or char that are pointers.
Such functions might simply crash. But those are not used very often.
It should not be so difficult to add this, too, so I will do it this year.

--------------------------------------------------

Here is an example to use enums:
Code:
gtk("gtk_window_new" , "1",0,0,0,0,0)
gtk_setobjectname("mywin")
gtk("gtk_widget_show" , "mywin" , 0 ,0,0,0,0)


C-function:
Code:
GtkWidget*  gtk_window_new (GtkWindowType type);


In the C-documentation you find:
Code:
typedef enum
{
  GTK_WINDOW_TOPLEVEL,
  GTK_WINDOW_POPUP
} GtkWindowType;


So GtkWindowType can have the value 0 or 1.
If I remember well, those values progress, if you have more:
Code:
typedef enum
{
  value1,
  value2,
  value3,
  value4,
  value5
} WHATEVER;


To use an enum, you would pass the corresponding number:
0
1
2
4
8

If you combine these values, you could activate 2 values, if the function supports it.
so gtk("gtk_teststuff_set_shadow_on_some_borders" , "testobject" , "3",0,0,0,0) could set a shadow on the top and left border of a testobject.
Just a fictive example, that does not work of course.

Mark
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Wed 05 Dec 2007, 20:54    Post subject:  

the dotpup will of course contain new demos.
Until then some code-snippets to play with.
In the IDE, create a new project.
Copy a test.png to the subfolder /resource of your project with your filemanager.

Then add some lines after where the window is positioned after clicking on "edit" in the IDE.

Code:
//-- manipulate a widget, e.g. move the window
gins_set("window1" , "10" , "10" , "<uposition>")


//-- load a picture and display it
gtk_createobject("PixmapwidFromFile" , "pixmap1", "test.png" , 0)
gtk("gtk_pixmap_get" , "pixmap1" , "gdkpixmap1" ,"gdkmask1",0,0,0)
gtk_destroyobject("pixmap1") // free memory
gtk("gtk_image_new_from_pixmap" ,  "gdkpixmap1" , "gdkmask1" ,0, 0 , 0 , 0)
gtk_setobjectname("image1")


//-- attach the image to the window
gtk("gtk_widget_show" , "image1" , 0 ,0,0,0,0)
gtk("gtk_box_pack_start" , "vbox1" , "image1" , "0","0","0",0)

//-- create a GDK grafics context
gtk("gdk_gc_new" , "gdkpixmap1"  , 0 ,0,0,0,0)
gtk_setobjectname("gc1")

//-- draw a black line
gtk("gdk_draw_line" , "gdkpixmap1"  , "gc1" , "0" , "0" , "40" , "40")

//-- load a font and draw a text
gtk("gdk_font_load" , "-*-helvetica-bold-r-normal--*-180-*-*-*-*-iso8859-1"  , 0 ,0,0,0,0)
gtk_setobjectname("font1")
gtk("gdk_draw_string" , "gdkpixmap1"  ,"font1" , "gc1" , "20" , "20" , "test" )


Like this you could plot diagrams for example.

Unfortunately, some drawing-functions like rectangulars, need more than 6 arguments.
So you cannot use them.
I must add a new gtk_long() , that gives access to functions with up to 10 arguments.

Mark
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Thu 06 Dec 2007, 13:01    Post subject:  

update:
http://noforum.de/files/wxbasic/gtkbasic/

now has gtk_long(), it supports functions with up to 13 arguments.
Integers that are pointers now can be used like the pointer-floats mentioned above.
GdkColor now is referenced, they had the same syntax as for other objects, so my script did not recognize that.
Added a manual entry for GdkColor now.

I include an example using all this, in the subfolder testprojects.

It shows an icon with transparent, shadowed text beneath it.
Almost like in Rox, just the text is not centered.
It can be dragged around, a click on it starts leafpad. Right-click exits.
So far the theorie.
In practice, I encountered timing problems.
I wanted to make it like in Rox, with the left button you can click or drag around.
This behaves sluggish at moment.
Strange though that it works perfect, if I declare the window as "popup" in Gade.
Popups are not managed by the windowmanager, so there should be a way to achive the same behaviour with toplevel windows.
The disadvantage of the popup is, that it is always on top of all other windows.
I must try again after I got some sleep.

Mark

Last edited by MU on Sun 09 Dec 2007, 16:45; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Sun 09 Dec 2007, 16:04    Post subject:  

uploaded new source, and updated also the dotpup.

Changes:
- now includes gdk-pixbuf.
- Removed memory-leaks.
- Reduced size from 1.4 MB to to 929 kb (200 kb compressed) by Code-optimization.
- The interpreter now can load includefiles "dynamically", by defining an environment-variable before running it (this is set by the IDE automatically in new projects to load the locale-files without copying them to /tmp/ first as before)
Details about that:
http://wxbasic.sourceforge.net/phpBB2/viewtopic.php?t=1066

- Added an analogclock to show how to use the GDK library.
- added a prototype of an Icewm configurationtool. This will be completely rewritten by a more generic approach soon.

Mark
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Thu 13 Dec 2007, 16:50    Post subject:  

here is a snapshot of what I'm working on.
It is not of any use yet, as it cannot save any values yet.
I'm just happy that I could get the subcategories working, if you click on a categorie, the subcategories under it open.
If you click on another one, they close, and the subcategories of the new one open.

Darn, that was difficult, also to get transparent icons displayed for the subcategories.
Unfortunately transparency has no nice borders with rounded icons.

It will take some more days until it becomes usable.

**edit** snapshot removed, prototype now is included as demo in GtkBasic.

Mark
GtkBasic-ConfigCenter.jpg
 Description   
 Filesize   27.98 KB
 Viewed   3919 Time(s)

GtkBasic-ConfigCenter.jpg


Last edited by MU on Sun 16 Dec 2007, 17:12; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Thu 13 Dec 2007, 18:21    Post subject:  

I updated the dotpup.

Fixed a bug with GdkColor.
Added support for Trayicons including a demo.

http://dotpups.de/puppy3/dotpups/Programming/GtkBasic003/Gtkbasic-003.pup

Mark
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Sun 16 Dec 2007, 14:16    Post subject:  

updated the dotpup.

Changes:
the "translate locale" utility of the IDE now can use variables, that are elements in a list/table (comparable to Perls "Hashes").
I discussed this issue with David Cuny, core developer of wxBasic, that is used as the base for GtkBasic:
http://wxbasic.sourceforge.net/phpBB2/viewtopic.php?t=1068

So you now can add variables like:
l["welcome"]

Attention: if you do that, you MUST define a table, before the .mo files are included, like this:
Code:

l={}
includeenv "MOEN"
includeenv "MO"


The line "l={}" is new.

I need this feature for the Config-Center.
It reads in a configfile, and if it finds words that begin with a "_", it will look up in a table containing the translations.

This configcenter now is part of the demos, though it is not "finished" yet.
But it already can save the values.
There are however some enhancements required, until it can be used as a standalone-program to configure icewm or so.

Mark
Back to top
View user's profile Send private message Visit poster's website 
mcewanw

Joined: 16 Aug 2007
Posts: 2253
Location: New Zealand

PostPosted: Fri 04 Jan 2008, 23:46    Post subject: Re: GtkBasic 003 - small Basic interpreter/IDE - 3300 functi  

MU wrote:

Gtkbasic is based on Puppybasic, a very small Basic-Interpreter, that is shipped as system-utility with Puppylinux.


This looks interesting, I'll give it a spin sometime when I have a freer moment.

It would be good if Gtkbasic or similar came preinstalled in Puppy Linux. Something like this, permanently in there, would improve utility/apps development immensely for little cost in terms of size it seems. I've been using gtkdialog for some frontend GUIs; it is nice and simple for some things, but limiting.

Does Gtkbasic support drag and drop? And, though I realise Gtkbasic is an interpreter, I wonder how it compares in size to gcc (and any required libraries etc)?
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 2 [28 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Unsorted
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1325s ][ Queries: 13 (0.0113s) ][ GZIP on ]