GladeToBac (Glade to FreeBasic code sketcher)

User projects written in or related to FreeBASIC.
Post Reply
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

GladeToBac (Glade to FreeBasic code sketcher)

Post by TJF »

Image
Actually, the best way to generate cross-platform GUI applications with FreeBasic is to use the Gimp Tool Kit (GTK). This project 'GladeToBac' supports GTK usage by closing the gap between the graphical GUI designer (Glade3) and the FreeBasic compiler.

GladeToBac (= Glade To Basic) is a FreeBasic code sketcher. It generates FreeBasic source code from a GUI-XML-file, generated by Glade3. The generic source code afterwards gets extended by individual features before compiling with fbc. The FreeBasic source can be compiled for windows or LINUX OS.

GladeToBac reads a GUI-XML file, describing all GUI widgets. Then, GladeToBac generates a matching FreeBasic source code which contains all the needed bindings to the GUI (signal handlers and references). Individual features then gets added by the programmer.

In the actual Glade3 version (3.10) the GUI can be saved as .glade file (for libGlade) or as .ui file (for GtkBuilder). The later is the modern variant, supporting more features. GladeToBac generates code for both variants, depending on the suffix of the GUI-XML file.

The GtkBuilder features are not included in the GTK-bindings 'gtk/gtk.bi', which are shipped with original FreeBasic packages. Therefore the GladeToBac archive includes in the folder 'inc/TJF' a set of bindings for the current GTK-3 version. Multiple C-headers are translated into a few FreeBasic header files, one for each core library. The headers can easily be separated, if needed.

GladeToBac is the reviewed and enhanced follow-on project of GTK+tobac2.2.4. Itself it uses GtkBuilder in the source code. The source can be compiled against GTK-2 (>= 2.16) or GTK-3 (the image shows the new GtkAbout window). I18N is implemented by libintl.

GladeToBac has been inspired by Glade2Bas (haegartheroot) and by glade2fb (Galeon). But an alternative method is used to bind the signal handlers to the FreeBasic source, targeting a higher level of automation. GladeToBac supports the automatic generation of a first draft as well as further expansion of the GUI code. Therefore GladeToBac is recommended for big software projects.

Highlights:
  • multi lingual user interface (org. English / German translations included)
  • creates source code with I18N support
  • includes libintl.bi header 'TJF/libintl.bi'
  • automatically calls xgettext on all source code files
  • automatically generates matching signal handlers (GTK-2 / GTK-3)
  • generates source code for GtkBuilder (*.ui) or libglade (.glade)
  • generates references for objects (Widgets)
  • includes up to date GTK-3 bindings 'inc/TJF/gtk.bi'
  • includes GTK-2 bindings for older installations 'inc/gtk/GTK-2.22.0_TJF.bi'
  • can be used with older GTK versions as well
  • automated operation with command line parameters
  • separate folder for GUI files (tobac)
  • integrates GUI-XML-file into binary
  • generates ReadMe.txt and makefile
  • generates project files for different IDEs
Download:

http://www.freebasic-portal.de/download ... c-190.html

Feel free to translate into your native language and send your .po and .mo files. I'll add them into the next release.
Dinosaur
Posts: 1481
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Post by Dinosaur »

Hi all

Having a preliminary look at GTK+ and cannot find a step by step intro for FB.
From my initial downloads and reading, it looks like I have to
1. Download Glade and compile it. (Didn't find any binaries)
2. Learn how to use Glade to develop the gui.
3. Download GladeToBac and go through the process of converting the Glade files to .bas files.
4. Modify the .bas files and add proprietery code to it.
5. ?

TJF, your earlier posts from around 2009 showed some procedural steps. Is there an update to that, and do I have the above completely wrong ?

Regards
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Post by TJF »

Dinosaur wrote:Hi all

Having a preliminary look at GTK+ and cannot find a step by step intro for FB.
From my initial downloads and reading, it looks like I have to
1. Download Glade and compile it. (Didn't find any binaries)
2. Learn how to use Glade to develop the gui.
3. Download GladeToBac and go through the process of converting the Glade files to .bas files.
4. Modify the .bas files and add proprietery code to it.
5. ?

TJF, your earlier posts from around 2009 showed some procedural steps. Is there an update to that, and do I have the above completely wrong ?

Regards
  • 5. Compile and run your cross-platform GUI app.
You're completely right. And the procedural steps are still valid. I just renamed GTK+tobac to GladeToBac because it's not GTK translated in to a set of .bas files, it's a Glade XML file. So I hope this new name is more precise.

I guess you're on windows.

Of course, you'll need a GTK installation on your system. So you may add to your list
  • 0. install GTK+ (ATM I recommend to use version 2.22 on windows and to mind the notes for GTK version 3)
Find more info in the ReadMe.txt file in the archiv (if you have a GTK installation and you can run GladeToBac just press Crtl-H or choose menu Help -> Help to read the file).

Since Glade3 is under heavy development for GTK version 3 it's best to compile from source (for windows). But you also can find binaries here.

GTK binaries are shiped with FB (old version 2.8). Never versions are avialable here. Use a version > 2.16 for GtkBuilder support. For compiling with FB you'll need the dev and the runtime package. At the customers side only the runtime is needed. (AMIBCT made an windows NSIS installer for GTK runtime here).

A simple FB example can be found here (all GladeToBac files are packed in to one file for the upload). Or have a look at the GladeToBac source (it's self-hosting).

I fixed some small bugs in GladeToBac regarding the use with GTK versions < 3 and I'll upload the new version soon (watch this thread).
AGS
Posts: 1284
Joined: Sep 25, 2007 0:26
Location: the Netherlands

Post by AGS »

GTK 3 support for windows is lacking. I don't think GTK3 can be considered cross platform yet. This has nothing to do with glade2bac but everything with gtk3.

The latest version of glade uses gtk3. Some gtk3 features used by glade have not been implemented on the win32 platform yet. Which renders the latest version of glade (the one that uses gtk3) useless on the win32 platform.

I think adding gtk3 support (on windows) to glade2bac is something that might be nice to have in the future but not right now. Without a working gtk3 -based-version of glade there is little point in having a win32 version of glade2bac that support gtk3.

Aside:
The stable branch of some distros (including Debian Linux) do not include gtk3 yet (the 'testing' branch of Debian Linux does contain gtk3).
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Post by TJF »

AGS wrote:GTK 3 support for windows is lacking. I don't think GTK3 can be considered cross platform yet. This has nothing to do with glade2bac but everything with gtk3.
Agreed! That's why I recommended GTK 2.22.
AGS wrote:The latest version of glade uses gtk3. Some gtk3 features used by glade have not been implemented on the win32 platform yet. Which renders the latest version of glade (the one that uses gtk3) useless on the win32 platform.
Interesting! I never tested newer versions of Glade3 on windows yet.
AGS wrote:I think adding gtk3 support (on windows) to glade2bac is something that might be nice to have in the future but not right now. Without a working gtk3 -based-version of glade there is little point in having a win32 version of glade2bac that support gtk3.
GladeToBac is single source. The same code can be compiled on windows or LINUX. I wont make special versions for different OSs. Also this one code can be compiled against GTK2 or GTK3 for the next few month.
AGS wrote:Aside:
The stable branch of some distros (including Debian Linux) do not include gtk3 yet (the 'testing' branch of Debian Linux does contain gtk3).
It isn't that bad on LINUX. Most of the apps are not ported to GTK3 so GTK2 is still needed.

Meanwhile I ported some of my apps to GTK3. I test under Ubuntu 11.04 (Natty) where I installed both GTK2 and GTK3.

On windows there are no installers for GTK3 yet. When I test the versions provided by Galeon I get some problems with images in toolbars or menus. But the functions I tested ran well -- it's just a look and feel problem.

Since the version numbers change pretty fast from 3.0 to 3.1.x I guess the problems will be solved soon.
Dinosaur
Posts: 1481
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Post by Dinosaur »

Hi all

The more I look around for an alternative gui, the harder it gets.
I am spoilt by the simplicity of CGUI, and can't understand why there isn't a suitable FB alternative. With the aid of 2 libraries (cgui & Allegro) and one include file(cgui.bi ) I can create apps that will run on Dos, Windows and Linux, in fact any system Allegro will run on. (which includes iPhone now).For those who think there is, I have listed below some features of cgui, and an example of the ease with which to create a window with a button that has text or a bmp on it.See this link as an example:http://www.compu-weigh.com.au/batch/Screens.html
This is not intended as criticism of any one, but as a guide to what I need a simple intuative gui to do. I am equally guilty of over complicating things, and forgetting the KISS principle, but don't want to make a hammer before I can drive a nail.

Create a window with one statement.
MkDialogue( X,Y, "-MAIN-", 0)
or make an adaptive floating window that sizes itself to the largest item on it
MkDialogue( Cgui_Adaptive, FileName, CGUI_W_Floating)
Add a button which calls your sub with a data Ptr
AddButton( CGUI_DOWNLEFT, "#Logo", @ShowStatus, MC)
Set the color of any of the Tab's /Buttons Text etc
CguiSetColor(CGUI_COLOR_SELECTED_TAB,R,G,B)
Load a special font
load_font(*PathPtr->Font + "12x24.pcx",Null, NULL)
The downside of all this is, that the only FB code I use is the background logic of the app, and the only other .bi file is vbcompat.bi.

There, now I got that off my chest.

Regards
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Post by TJF »

@Dinosaur

Two years ago I was in the same situation, searching for a GUI toolkit for bussiness applications on LINUX and windows. I choosed GTK and I'm still satisfied.
Dinosaur wrote:... but don't want to make a hammer before I can drive a nail.
That's why I use a toolkit and don't code the GUI myself. To use a hammer you have to know how it works -- where to hold it and what to do with it. Some hammers are only for driving a nail. Others have additional feature, ie for pull out a nail. The more features the more you have to learn.

Of course at the beginning GTK isn't as easy as a simple CGUI. But it has much more features. Have a look at your examples:
Dinosaur wrote:Create a window with one statement.
MkDialogue( X,Y, "-MAIN-", 0)
Using Glade3, GladeToBac and GTK you need no code to create a window. It's just one click in Glade3 to make a new window. You'll need some more clicks for individual features. But you need not look up parameters in any documentation. The Glade UI shows everything available.
Dinosaur wrote:or make an adaptive floating window that sizes itself to the largest item on it
MkDialogue( Cgui_Adaptive, FileName, CGUI_W_Floating)
All GTK windows are adaptive floating windows (if you don't block this feature).
Dinosaur wrote:Add a button which calls your sub with a data Ptr
AddButton( CGUI_DOWNLEFT, "#Logo", @ShowStatus, MC)
Just add in Glade3 a button to your GUI and connect the signal On_Button_clicked with your FB handler (no code in FB -- just the handler itself and GladeToBac cares about the right parameter list for your handler).
Dinosaur wrote:Set the color of any of the Tab's /Buttons Text etc
CguiSetColor(CGUI_COLOR_SELECTED_TAB,R,G,B)
In GTK usually the user is resposible for setting the color. Ie if the user is colorblind he might want to use special colors. So the user chooses a theme for all GUIs on his system to adjust the look and feel to his needs.
Dinosaur wrote:Load a special font
load_font(*PathPtr->Font + "12x24.pcx",Null, NULL)
What about vector fonts? How do you know which fonts are installed on the system? In Glade3 you create a GtkFontButton in your GUI and let the user choose one of his installed fonts. The FB code just calls gtk_font_button_get_use_font and gtk_font_button_get_use_size to set the right font.


Of course, at the beginning you have to learn how to use Glade3, what to do in Glade3 and what to do in the FB source. But after a short learning curve you'll see that it is much easier to rearange your GUI using a grafical designer. The quality of your GUI and your development speed will increase.
Dinosaur
Posts: 1481
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Post by Dinosaur »

Hi all

TJf, many thanks for your detailed answer.
One point I need to make.
My machines operate in factories where the operator may not understand computers at all. They get taught which buttons to press, at what time, and a lot of features are protected from their wondering mouse clicks. For that reason I have designed the gui with as little as possible instructions or written messages. All major buttons have pictures on them. Looking through the examples I cannot see any buttons with photo's. Is that avaiable ?

Regards
EDIT:Installing the Glade Binaries and trying to run it, creates an error relating to FreeType6.dll. There is a LibFreeType-6.dll in the GTK package, and renaming that or finding the library on the Net doesn't help. Any ideas ?
Tried using the combined package and installing induvidually. In both caeses the Gtkdemo works, but Glade has an error with FreeType6. As I am using W7 64 bit, I have only installed the 32 bit versions, and also tried looking for FreeType6.dll in XP (Mode). Downloading the dll creates a diffrent error when Glade tries to start.(something about a start address not found)

EDIT2: Managed to get a system up after missing libraries etc.
To avoid a Path nightmare, what is the directory structure most suited for the four apps, GTK, Glade,FB, Glade2Bac ?
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Post by TJF »

Dinosaur wrote:My machines operate in factories where the operator may not understand computers at all. They get taught which buttons to press, at what time, and a lot of features are protected from their wondering mouse clicks.
This problem is well known to me. GTK offers everything you need to block some features in different user levels and to show the user which operations can be choosen. You can arange blocked features visible (in a gray style) or unvisible (hided).
Dinosaur wrote:All major buttons have pictures on them. Looking through the examples I cannot see any buttons with photo's. Is that avaiable ?
In GTK a button can be
  • empty or
    a label (= text with or without markups) or
    an image and a label or
    an image (ie a photo) or
    a drawing area (gdk, cairo or OpenGl)
As an example you may have a look at this source where I use a GTK button with a drawing area to show an OpenGl animation. The execution of the underlaying 3D simulation can be stopped and restarted by pressing this button.

GTK is very flexible. That's one reason why it isn't easy to start with.


Regarding your installation problem on win7:

I'm sorry, I never used win7 nor did any installation. All my windows testing has been done on XP SP2.

My directory structure
  • C:\opt\gtk for GTK (runtime and dev, system wide installation, PATH set to C:\opt\gtk\bin)
    C:\programs\glade3 for Glade (no GTK here)
    C:\programs\GladeToBac for GladeToBac (no GTK here, use #LIBPATH "C:\opt\gkt\lib" to compile)
    C:\programs\freebasic for FB (system wide)
BTW:
Sooner or later you'll need UTF-8 character encoding. Make sure that your IDE supports that. (I use Geany -- available for win and LINUX.)
Dinosaur
Posts: 1481
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Post by Dinosaur »

Hi all

TJF, I have now managed to install all apps into a common tree, and no dll warnings. However, when I run Glade and try to follow a tutorial, I notice that the icons are missing from all the slelection buttons. For example the button to create a horizontal box has a X in it and looks like all the others.
Where are these stored, and is is part of Glade or another library.?
I used Glade3-3.6.4-installer.exe

Your help is much appreciated. Once I can get to using the tutorial, I can then test a simple app through the whole process of Glade / GTK / Glade2Bac / FB

There are folders like \Glade\Share\Icons\hicolor & 16x16 ...48x48 ..scalable
and each of these has a glade-3.png in a apps subdirectory.

Regards
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Post by TJF »

See this page as an example how the Glade3 GUI should look like.

Your installation seems to be uncomplete/broken. All buttons should have small icons instead of the X. Start Glade3 from a console window to see error messages at startup.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

New on GitHub: GladeToBac (Glade to FreeBasic code sketcher)

Post by TJF »

The source code is now hosted at GitHub. Current version is 3.2.2:
  • ready for 64 systems
  • requires Gtk-3.10 minimum
[Edit]Typo fixed in link.[/Edit]
Post Reply