Foreword:
I like to compile small statically compiled apps written in C, but the new versions of glade have removed the ability to output the C code. For a while this was bad because you had to include libglade, but then there was gtkbuilder (since gtk-2.12). The problem is that when you highly optimize your compiles, the code that is reference in the gtkbuilder UI file can get removed. There are plenty of other reasons for wanting all the code compiled in, but I don't need any more than that, so I have started learning how to use the older versions of glade (0.6.4 for gtk1 and 2.12.2 for gtk2) and thought I would share it here.

The 2 biggest things you need to know are:

1. You need to add a signal handler to the window to "destroy" signals with gtk_main_quit

2. If you want to insert code for a button press, etc... you need to add a signal for that event ... ex. button1 clicked - by default will give you an empty callback function in callbacks.c for on_button1_clicked (add your code there)

tutorial to follow (it is taking 10x longer to write the tutorial than it did to figure it out)_________________Web Programming - Pet Packaging 100 & 101Last edited by technosaurus on Fri 10 Feb 2012, 15:03; edited 2 times in total

technosaurus just want to thank you for this.
I may not use it for some time but glade is something I had difficulty with using.
Be interested in how others get on with the tutorial? _________________Puppy WIKI

This would allow us to use the regular /usr/share/pixmaps and /usr/share/mini-icons directories for the pixmaps, so that they can be shared with other apps - I haven't posted the pet yet, because I am not sure if they should be first or last in the search order??? (I was initially going to remove the others all together)... I seem to recall wrong icons causing a problem before (but that was gtk2)

I also patched the sources of glade2 so it would compile, but then I decided to remove all gtk/gtk*.h references (the offenders) and replace them with a single <gtk/gtk.h> in config.h

I'm not trying to "fork" them but sometimes you have to sharpen even borrowed tools.

The process is pretty simple. add a widget that you like from glade write the code and paste into one of the templates.
Now if I could only get the packers (windows, v/hboxes, frames, notebooks...) figured out, it could be a fast alternative to other *dialog programs_________________Web Programming - Pet Packaging 100 & 101

#define DTOS(x) #x
// allows you to write number types as strings using puts or write
//the stdio functions like *printf add ~10kb of overhead in static builds
//this is especially important for daemon processes that need to be fast ...
//... it helps them stay in cache

in my previous example I used a switch-case on a 5 character string
normally this is not possible since the case values need to evaluate to a constant int
to get around this requirement we perform bit operation on the string
this is done inside a macro (#define ...) in order to simplify type
... and so that the c preprocessor can evaluate the value prior to run time
the only code added then is a static constant
if you need to do this many times, you can decrease the compiled size with
-fmerge-all-constants
(this may make break some code... usually C++, so it is not enabled by default)
anyhow, with all that said even if you don't use extra compiler flags,
the switch case is much smaller and faster than a series of string comparisons_________________Web Programming - Pet Packaging 100 & 101

This is really cool! Compiled your gtk-thing to 7K so although rudimentary at the moment it could have potential for a new small gtkdialog with a more clean approach to parsing scripts...Do you plan to take it further?
The define and macro technique might be optimal - but not easy to read...

if it is hard to read I am open to suggestion, but I always use tabs vs spaces and don't habitually wrap at 80 chars unless it reads better that way (my font screen combo is limited to 150, but there is always a convenient break well before that)... but yes I do want to take it further. The all caps thing is common practice for macros, but not absolutely necessary if its bothersome (sidebar: some people even replace entire sets of typedefs with macros to cut overhead in embedded systems to save having to do silly stuff like converting gint to int to tell gcc to shut the Hell up, but then the programmer isn't protected from himself and things may go boom ... or so they say - basically glib is reimplementing some functionality and protections of the C++ stl with its typedefs)

before I take it too much further, I need to solve the packing problem. I have it solved in my head, but getting it coded will test my fledgling coding ability to its max. basically I need to track packers in a stack so they can be "popped" when a -close tag is hit, but some widgets can only have one thing packed inside (window, frame, notebook...) so just pack 1 widget in those with a container_add and POP it, while others can have multiple widgets (hbox, vbox, and even buttons) so keep packing widgets in there until a new packer tag is reached (which will get pushed) or a -close tag is reached then POP it.

I am going through the gtk1.2 tutorial to get an understanding of the shared properties between widgets, so that it can be generalized properly from the start ... its much easier to fix 100 lines of code than 1000.

The whole idea is to use the arg parameters to do all of the widget drawing and have everything else controlled by input/output streams (fifos and pipes from shell, tcl, perl, compiled programs, etc...) the Unix philosophy basically, do 1 thing and do it well. gtk has idle functions that can be used to process the stream... but I am not sure if I should use sockets or just open arson for monitoring i/o... put that on the todo list as well, whichever is the simplest that barely gets the job done wins... it just needs to be able to get data so it can go through a switch-case for the action, do an exact match on the widget by name or class and process an event or call a handler function to do it. I'm leaning towards stdin + stdout since nearly every language I know of can handle it._________________Web Programming - Pet Packaging 100 & 101

And here I was thinking everybody wanted gtkdialog without a glade dependency...
I suppose it's a bit different if glade is only used for generating C code, and is not a runtime dependency._________________Classic Puppy quotes
-
root: n. the superuser or administrator account that has complete control over everything in the machine. Running as root is a taonga of Puppy Linux users.

And here I was thinking everybody wanted gtkdialog without a glade dependency...
I suppose it's a bit different if glade is only used for generating C code, and is not a runtime dependency.

that would be _libglade because with gtk2.12, they introduced gtkbuilder which does essentially the same thing... glade otoh continues to be an excellent development tool, but for whatever reason, instead of dropping support for libglade xml files when it was deprecated, they dropped support for c output instead ... I guess they figured that everyone preferred xml to having to compile... they do work pretty well and now that I understand the callback functions, it may be more useful.[/b]_________________Web Programming - Pet Packaging 100 & 101

There's a lot of discussion on old mailing lists about why glade doesn't generate code anymore. It mostly seems to come down to an accepted wisdom that generated code is "bad" and that it would make both glade and the applications produced more complicated and difficult to maintain.
Also, Glade-3 is supposed to be:

Wikipedia wrote:

a complete rewrite, in order to take advantage of the new features of GTK+ 2 and the GObject system (Glade-3 was started when Glade-1 hadn't yet been ported to GTK+ 2)

I don't know how much a "complete rewrite" is the same as "starting from scratch", but maybe it was less a case of removing support for code generation, and more a case of not spending the time to reimplement it.

Quote:

I guess they figured that everyone preferred xml to having to compile

I'm not sure there's much of an advantage here - libglade or gtkbuilder files are both typically used by compiled programs anyway..._________________Classic Puppy quotes
-
root: n. the superuser or administrator account that has complete control over everything in the machine. Running as root is a taonga of Puppy Linux users.

BTW, thanks for the packages. I always wanted to have a play around with glade-2, but I think at one stage it was hard to find for some reason.

I'm curious as to why more people are downloading the GTK1 version..._________________Classic Puppy quotes
-
root: n. the superuser or administrator account that has complete control over everything in the machine. Running as root is a taonga of Puppy Linux users.

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