C programming with gtk using glade and glade-2

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

C programming with gtk using glade and glade-2

#1 Post by technosaurus »

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)
Last edited by technosaurus on Fri 10 Feb 2012, 19:03, edited 2 times in total.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#2 Post by Lobster »

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 Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#3 Post by technosaurus »

i just patched the glade1 source (glade/source.c) with this:

Code: Select all

      fprintf (fp,
+	       "  add_pixmap_directory (\"/usr/share/pixmaps\");\n"
+	       "  add_pixmap_directory (\"/usr/share/mini-icons\");\n"
	       "  add_pixmap_directory (PACKAGE_DATA_DIR \"/pixmaps\");\n"
	       "  add_pixmap_directory (PACKAGE_SOURCE_DIR \"/%s\");\n",
	       relative_pixmaps_directory);
      g_free (relative_pixmaps_directory);
    }
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.
Attachments
glade-2.12.2-fix_includes_pixmap_paths.gz
(5.79 KiB) Downloaded 673 times
glade1-add_pixmap_path-rename_desktop.patch.gz
(19.58 KiB) Downloaded 597 times
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#4 Post by technosaurus »

here is a simple buttons app I wrote from what I learned playing with glade-0.6.x
gcc -Os -o gtkbuttons `gtk-config --cflags` main.c -lgtk -s
usage: ./gtkbuttons list of buttons

Code: Select all

#include <stdio.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>

void on_button_clicked(GtkButton *button, char *user_data){printf("%s\n",user_data);}

int main(int argc, char *argv[]){
GtkWidget *window1, *vbox1, *button[0];
char *button_action[0];
int i=0;

gtk_set_locale ();
gtk_init (&argc, &argv);

window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_object_set_data (GTK_OBJECT (window1), "window1", window1);
gtk_window_set_title (GTK_WINDOW (window1), "window1");

vbox1 = gtk_vbox_new (FALSE, 0);
gtk_widget_ref (vbox1);
gtk_object_set_data_full (GTK_OBJECT (window1), "vbox1", vbox1,(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (vbox1);
gtk_container_add (GTK_CONTAINER (window1), vbox1);

while (i<argc-1){ /* loop through args to make buttons with actions */
	button[i] = gtk_button_new_with_label(argv[i+1]);
	gtk_widget_ref (button[i]);
	gtk_object_set_data_full (GTK_OBJECT (window1), argv[i+1], button[i],(GtkDestroyNotify) gtk_widget_unref);
	gtk_widget_show (button[i]);
	gtk_box_pack_start (GTK_BOX (vbox1), button[i], FALSE, FALSE, 0);
	button_action[i] = argv[i+1];
	gtk_signal_connect (GTK_OBJECT (button[i]), "clicked",GTK_SIGNAL_FUNC (on_button_clicked),button_action[i]);
	i++;
}

gtk_signal_connect (GTK_OBJECT (window1), "destroy",GTK_SIGNAL_FUNC (gtk_main_quit),NULL);
gtk_widget_show (window1);
gtk_main ();
return 0;
}
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#5 Post by technosaurus »

My little example has turned into this, just basically cutting and pasting from glade:

Code: Select all

#include <stdio.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>

/* TODO use these for switch case(s) in main loop */
#define FIVE_CHARS(x1,x2,x3,x4,x5)   (((((((((x5)<<8)|(x4))<<8)|(x3))<<8)|(x2))<<8)|(x1))
#define WINDOW FIVE_CHARS('-','w','i','n','d')
#define VBOX FIVE_CHARS('-','v','b','o','x')
#define HBOX FIVE_CHARS('-','h','b','o','x')
#define HSEPARATOR FIVE_CHARS('-','h','s','e','p')
#define VSEPARATOR FIVE_CHARS('-','v','s','e','p')
#define LABEL FIVE_CHARS('-','l','a','b','e')
#define BUTTON FIVE_CHARS('-','b','u','t','t')
#define CHECKBOX FIVE_CHARS('-','c','h','e','c')
#define TEXT FIVE_CHARS('-','t','e','x','t')
#define HSCALE FIVE_CHARS('-','h','s','c','a')
#define VSCALE FIVE_CHARS('-','v','s','c','a')

void on_button_clicked(GtkButton *button, char *user_data){printf("action=\"%s\"\n",user_data);}
void on_checkbutton_toggled(GtkToggleButton *togglebutton, char *user_data){
	if (GTK_TOGGLE_BUTTON(togglebutton)->active){
		printf("%s=\"on\"\n",user_data);
	}else{
		printf("%s=\"off\"\n",user_data);
	}
}

int main(int argc, char *argv[]){
GtkWidget *widgets[99],packers[9];
char *button_action[0];
int widget=0, packer=0 ,i=1,j;

gtk_set_locale ();
gtk_init (&argc, &argv);

while (i<argc){ /* loop through args to make widgets - buttons with actions */
j=FIVE_CHARS(argv[i][0],argv[i][1],argv[i][2],argv[i][3],argv[i][4]);
switch ( j ) {

case	WINDOW	:	
	i++;
	widgets[widget] = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_object_set_data(GTK_OBJECT(widgets[widget]), "window", widgets[widget]);
	gtk_window_set_title(GTK_WINDOW(widgets[widget]), argv[i]);
	gtk_widget_show(widgets[0]);
break;

case	VBOX	:
	widgets[widget] = gtk_vbox_new (FALSE, 0);
break;

case	HBOX	:
	widgets[widget] = gtk_hbox_new (FALSE, 0);
break;

case	HSEPARATOR	:
	widgets[widget] = gtk_hseparator_new ();
break;

case	VSEPARATOR	:
	widgets[widget] = gtk_vseparator_new ();
break;
	
case	LABEL	:	
	i++;
	widgets[widget] = gtk_label_new (argv[i]);
break;

case	BUTTON	:
	i++;
	widgets[widget] = gtk_button_new_with_label(argv[i]);
	i++;
	gtk_signal_connect(GTK_OBJECT (widgets[widget]), "clicked", GTK_SIGNAL_FUNC(on_button_clicked),argv[i]);
break;

case	CHECKBOX	:
	i++;
	widgets[widget] = gtk_check_button_new_with_label (argv[i]);
	i++;
	gtk_signal_connect (GTK_OBJECT (widgets[widget]), "toggled", GTK_SIGNAL_FUNC (on_checkbutton_toggled), argv[i]);
break;

case	TEXT	:
	widgets[widget] = gtk_text_new (NULL, NULL);
	i++;
	gtk_text_insert (GTK_TEXT (widgets[widget]), NULL, NULL, NULL, argv[i], -1);
	//gtk_signal_connect (GTK_OBJECT (widgets[widget]), "changed", GTK_SIGNAL_FUNC (on_text_changed), NULL);
break;

case	HSCALE	:
	widgets[widget] = gtk_hscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 100, 1, 0, 0)));
	//gtk_signal_connect (GTK_OBJECT (widgets[widget]), "drag_end", GTK_SIGNAL_FUNC (on_scale_drag_end), NULL);
break;

case	VSCALE	:
	widgets[widget] = gtk_vscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 100, 1, 0, 0)));
	//gtk_signal_connect (GTK_OBJECT (widgets[widget]), "drag_end", GTK_SIGNAL_FUNC (on_scale_drag_end), NULL);
break;

default   :
	printf(	"usage:\n%s -window title -{v,h}box [-button label action] [-checkbox label var]\n"
			"	Last argument processed was %s \n",argv[0],argv[i]);
	goto END;
break;
}

switch ( j ) {

case	WINDOW	:	break;
case	VBOX	:
case	HBOX	:
	gtk_widget_ref (widgets[widget]);
	gtk_object_set_data_full(GTK_OBJECT(widgets[0]), argv[i], widgets[widget], (GtkDestroyNotify) gtk_widget_unref);
	gtk_widget_show (widgets[widget]);
	gtk_container_add(GTK_CONTAINER (widgets[0]), widgets[widget]);
break;

default   :
	gtk_widget_ref (widgets[widget]);
	gtk_object_set_data_full (GTK_OBJECT (widgets[0]), argv[i], widgets[widget], (GtkDestroyNotify) gtk_widget_unref);
	gtk_widget_show (widgets[widget]);
	gtk_box_pack_start(GTK_BOX(widgets[1]), widgets[widget], TRUE, TRUE, 0);
break;
}
i++;widget++;
}

gtk_signal_connect(GTK_OBJECT (widgets[0]), "destroy", GTK_SIGNAL_FUNC (gtk_main_quit),NULL);
gtk_main();
END:
return 0;
}
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
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#6 Post by technosaurus »

here are a couple of tricks for making smaller code:

#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
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

goingnuts
Posts: 932
Joined: Sun 07 Dec 2008, 13:33
Contact:

#7 Post by goingnuts »

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... :)

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#8 Post by technosaurus »

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.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#9 Post by technosaurus »

packing problem solved

Code: Select all

//#include <sys/timeb.h> //time metrics

#include <stdio.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#define GTK_NO_CHECK_CASTS
#define G_DISABLE_CAST_CHECKS
#define NDEBUG

#define FIVE_CHARS(x1,x2,x3,x4,x5)   (((((((((x5)<<8)|(x4))<<8)|(x3))<<8)|(x2))<<8)|(x1))
#define WINDOW FIVE_CHARS('-','w','i','n','d')
#define FRAME FIVE_CHARS('-','f','r','a','m')
#define VBOX FIVE_CHARS('-','v','b','o','x')
#define HBOX FIVE_CHARS('-','h','b','o','x')
#define CLOSE FIVE_CHARS('-','c','l','o','s')
#define HSEPARATOR FIVE_CHARS('-','h','s','e','p')
#define VSEPARATOR FIVE_CHARS('-','v','s','e','p')
#define LABEL FIVE_CHARS('-','l','a','b','e')
#define BUTTON FIVE_CHARS('-','b','u','t','t')
#define CHECKBOX FIVE_CHARS('-','c','h','e','c')
#define TEXT FIVE_CHARS('-','t','e','x','t')
#define HSCALE FIVE_CHARS('-','h','s','c','a')
#define VSCALE FIVE_CHARS('-','v','s','c','a')

void on_button_clicked(GtkButton *button, char *user_data){printf("action=\"%s\"\n",user_data);}
void on_checkbutton_toggled(GtkToggleButton *togglebutton, char *user_data){
	if (GTK_TOGGLE_BUTTON(togglebutton)->active){printf("%s=\"on\"\n",user_data);
	}else{printf("%s=\"off\"\n",user_data);}
}

int main(int argc, char *argv[]){
GtkWidget *widgets[99];
unsigned char widget=0, i=1, containers=0, packer=0, packers[9];
int j;

//struct timeb tmb; ftime(&tmb); printf("%ld.%d\n", tmb.time, tmb.millitm);//time metrics

gtk_set_locale ();
gtk_init (&argc, &argv);

while (i<argc){ /* loop through args to make widgets - buttons with actions */
j=FIVE_CHARS(argv[i][0],argv[i][1],argv[i][2],argv[i][3],argv[i][4]);

switch ( j ) { /* initialize widgets based on -tag */
case	WINDOW	:	
	i++;
	widgets[widget] = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_object_set_data(GTK_OBJECT(widgets[widget]), argv[i], widgets[widget]);
	gtk_window_set_title(GTK_WINDOW(widgets[widget]), argv[i]);
break;

case	CLOSE	:	break;

case	VBOX	:
	widgets[widget] = gtk_vbox_new (FALSE, 0);
break;

case	HBOX	:
	widgets[widget] = gtk_hbox_new (FALSE, 0);
break;

case	HSEPARATOR	:
	widgets[widget] = gtk_hseparator_new ();
break;

case	VSEPARATOR	:
	widgets[widget] = gtk_vseparator_new ();
break;
	
case	LABEL	:	
	i++;
	widgets[widget] = gtk_label_new (argv[i]);
break;

case	BUTTON	:
	i++;
	widgets[widget] = gtk_button_new_with_label(argv[i]);
	i++;
	gtk_signal_connect(GTK_OBJECT (widgets[widget]), "clicked", GTK_SIGNAL_FUNC(on_button_clicked),argv[i]);
break;

case	CHECKBOX	:
	i++;
	widgets[widget] = gtk_check_button_new_with_label (argv[i]);
	i++;
	gtk_signal_connect (GTK_OBJECT (widgets[widget]), "toggled", GTK_SIGNAL_FUNC (on_checkbutton_toggled), argv[i]);
break;

case	TEXT	:
	widgets[widget] = gtk_text_new (NULL, NULL);
	i++;
	gtk_text_insert (GTK_TEXT (widgets[widget]), NULL, NULL, NULL, argv[i], -1);
	//gtk_signal_connect (GTK_OBJECT (widgets[widget]), "changed", GTK_SIGNAL_FUNC (on_text_changed), NULL);
break;

case	HSCALE	:
	widgets[widget] = gtk_hscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 100, 1, 0, 0)));
	//gtk_signal_connect (GTK_OBJECT (widgets[widget]), "drag_end", GTK_SIGNAL_FUNC (on_scale_drag_end), NULL);
break;

case	VSCALE	:
	widgets[widget] = gtk_vscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 100, 1, 0, 0)));
	//gtk_signal_connect (GTK_OBJECT (widgets[widget]), "drag_end", GTK_SIGNAL_FUNC (on_scale_drag_end), NULL);
break;

default   :
	printf(	"usage:\n%s -window title -{v,h}box [-button label action] [-checkbox label var]\n"
			"	Last argument processed was %s \n",argv[0],argv[i]);
	goto END;
break;
} /* end initializing widgets from -tag */

/* begin stuff that all widgets need to do */
gtk_widget_show (widgets[widget]);
gtk_widget_ref (widgets[widget]);
gtk_object_set_data_full (GTK_OBJECT (widgets[0]), argv[i], widgets[widget], (GtkDestroyNotify) gtk_widget_unref);
/* end stuff that all widgets need to do */

switch ( j ) { /* begin packing */
case	CLOSE	:
case	WINDOW	:	break;

default   :
	if (containers > 0){
		gtk_container_add(GTK_CONTAINER (widgets[0]), widgets[widget]);
		containers--;
	}else{
		gtk_box_pack_start(GTK_BOX(widgets[packers[packer]]), widgets[widget], TRUE, TRUE, 0);
	}
break;
} /* end packing */

switch	( j )	{ /* PUSH/POP packers */
case	CLOSE	:	packer--; break;
case	FRAME	:	
case	WINDOW	:	containers++;
case	VBOX	:	
case	HBOX	:	packer++;
					packers[packer] = widget;
					break;
} /* PUSH/POP packers */

i++;widget++;  /* for argv[] and widgets[] */
} /* end arg loop */

gtk_signal_connect(GTK_OBJECT (widgets[0]), "destroy", GTK_SIGNAL_FUNC (gtk_main_quit),NULL);

//ftime(&tmb); printf("%ld.%d\n", tmb.time, tmb.millitm);//time metrics --currently about 45 msec

gtk_main();
END:
return 0;
}
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#10 Post by disciple »

potential for a new small gtkdialog
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.
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

goingnuts
Posts: 932
Joined: Sun 07 Dec 2008, 13:33
Contact:

#11 Post by goingnuts »

Great with the packer working :D. For the visual oriented attached 2 examples running the present sdialog:

./sdialog -window "Test Widgets" -vbox -button Help helpme -hbox -button OK ok -vbox -checkbox Check1 TEST1 -checkbox Check2 TEST2 -close -button "New Button" exit -text "Some text in text widget" -close -hseparator -label "And a horizontal slider..." -hseparator -hscale -close

and a simple yes/no-dialog:
./sdialog -window "Test of sdialog 110212" -vbox -vbox -label "Is This Cool?" -close -hbox -button Yes yep -button No nono -close -close
Attachments
snap0003.png
(8.71 KiB) Downloaded 1806 times
snap0002.png
(5.07 KiB) Downloaded 1681 times

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#12 Post by technosaurus »

oops the -close tag didn't work -fixed
moved the window show to the end to prevent a flicker that the human eye could barely see (due to window drawing and later resizing)
Attachments
sdialog-test.tar.gz
here it is with a prebuilt binary, build script and sources
(5.24 KiB) Downloaded 564 times
sdialog.png
(4.35 KiB) Downloaded 1697 times
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#13 Post by technosaurus »

disciple wrote:
potential for a new small gtkdialog
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]
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#14 Post by disciple »

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.
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...
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#15 Post by disciple »

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...
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#16 Post by disciple »

People might also be interested in this vala based project, too: http://code.google.com/p/gladev/
I don't know how usable it is - it didn't last long.
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#17 Post by technosaurus »

This whole little experiment got me thinking what if??? (you know something is wrong when technosaurus starts thinking - even worse when he refers to himself in the 3rd person)
what if we ported gtk2 to use gtk1 as its base (vs cairo, pango, atk,...) and then maybe gtk3?
here is what I mean take most of (and only) the new widgets/functions etc that are in gtk2 where practical
and build them on top of gtk1 widgets/functions into a separate library that has the new widgets and links in gtk1
such that when you link with -lgtk-x11-2.0 it links in the library with the new widgets and its -lgtk dependency (this will allow gtk1 and gtk2 programs to share overhead)
... same for glib1/2
once that is working, the same thing could be done with many gtk3 widgets/functions
sure there would be some functionality loss in what atk, pango and cairo do, but IMHO those usually aren't essential to an applications functionality ... more importantly it would reduce the resource consumption by ~500% and allow more applications to be used on the much lighter gtk1 base
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#18 Post by amigo »

It's an idea, but I think you've got it backwards. What would be nice is to have gtk with *some* forward-compatibility for gtk-compatible programs. Particularly the text and tree widgets -we've been talking about them lately, huh.

In order to convince you think about this: Why is gtk2 so undesirable?
1. lots of overhead (size). Needs atk, cairo and pango (now gdk-pixbuf2 which has been (again) split out from gtk.
2. Long startup latency. Much of this is due to the extra time needed to link the external libs mentioned above. part is due to the larger size of the libs, so simply including everything in a smaller number of libs won't help there. The other thing that makes gtk2 slow is themeable icons. A nice feature, but costly vis-a-vis latency. I could see this pretty dramatically with the gtk1 version of sylpheed mail. When I started using/hacking the gtk1 sylpheed-*claws* version, the raw startup time went from less than a half-second to a couple of seconds.

I used to dream of back-porting some gtk2 code to gtk1, but just didn't have the code fu to make it happen. One might take some of the earliest gtk2 code and start from there -actually I mean from gtk-1.3 which used pango -no cairo IIRC and I'm not sure about atk. The thing that pango makes possible is bi-directional text.

Over the years I've found some hacks and tweaks which improve some of the old-fashionedness of gtk1. Patched to make the colors look more pleasing, tweaks for using utf8-encoded fonts, using xft for anti-aliased fonts.

Since I was always looking for enough tools to make a real desktop, I was dissapointed when I'd find small gtk2 apps which used the text or tree widgets, beacuse of the difficulty of porting them, so it seemd like the 'low-fruit' might be to incorporate those widgets into gtk1.

I want to repeat how excited I am that you and goingnuts are *really* interested in gtk1 -because you both are more capable than I am of getting something done there. I do run a highly-patched version of gkt1 which includes *all* the known bug-fixes from every distro out there, plus some attractive added features from selected distros.

There were so many apps written for gtk1 that it still seems viable to use, right? But for modern systems where multi-language support is expected, it starts to fall short. And there were a few drawbacks to it. But I've often thought how great it would be if someone updated it *slightly*. It's one of truly-lightest-weight TK's ever written. Of course now they've even abandoned gtk2 for gtk3. Actually the worst thing about gtk2 is that the API was broken so many times during its' lifetime. I'm sure they'll do the same with gtk3...

Another change to gtk1 that might be nice, would be to incorporate a more user-friendly file-selector -like that used by mtpaint. Pretty low-hanging for someone like you... The version I use does have an improved file-selector, but something more like mt-style might be better.

Hope I gave you something to think about, but please resist the urge to do *full retail plus shipping* changes to the original sources -think about it as if someone else might want to use it. Whatever you decide to do, it would be really beneficial to start off by using my patchset which includes *lots* of patches. Most of them are pretty small, but I spent a lot of time to re-factor them so they all work together -good starting point anyway.

I think trying do things the other way and get gtk2 apps to link back to gtk1 would only bring misery -there are just too many changes. But giving gtk1 forward-capable widgets would make it much easier to back-port simple gtk2 apps. Oh, another thing you'd want to look at would be gtk-extra -some extra widgets that do some of what you allude to. They were mostly widgets which somewhat mimicked some of the gnome1 widgets -for data-plotting, etc. At the least, it provides a framework or example of how you could add extra widgets. There is also the gdkxft library which I am using -it could use a little love for some apps and fonts, but the substitue code could also be folded into the main gdk code for anti-aliased support. As it is, it 'shadows' some gdk font functions using LD_PRELOAD. Using it *really* makes things look a lot better and modern -unless you hate anti-aliasing, so having it as an option via LD_PRELOAD is nice, too.

Another thing, there wass something called 'easygtk' which was a small library which wrapped gtk1 functions for easier widget creation. It could easily do 'wizard'-style widgets and other things. i have it around here but it is not on my site, I think.

Looking at my site I also found this, which I had forgot:
http://distro.ibiblio.org/amigolinux/do ... vas-0.1.1/
Backport of gnome-canvas for gtk1! Maybe we don't need cairo after all.

Let me explain a bit what I said about 'full retail plus shipping' changes. Another of my favorite pices of software is WindowMaker. Of course the original devs gave up on it nearyl 10 years ago. It sat there un-maintained until about 4-5 years ago, when a fellow named Carlos Mafra created a new branch and began working on it. He's gotten *lots* of help and interest from others and they have done huge amounts of work on it. But, along the way, I got disssillusioned with his branch because he kept *removing* things that were working perfectly well. Then once, he decided that the code indentation-style didn't suit him, so he re-indented the whole thing -the diff for just that change was over *500,000* lines long. Having done that, it made it very hard work to incorporate any of the stray patches that were around for the original version. And there were lots of good strays out there which never made it into the upstream. Those strays comprise a large part of the changes that I have applied to my wmaker branch. One of the handiest things I've learned when creating and modifying patches, is to keep the changes extremely well separated -coding-style and whitespace changes should be kept separate from diffs which include real meat. And each bug-fix or feature-addition should be in a separate patch. Just makes it easier to manage the changes. Also, very important to keep autoconf or whatever working correctly so that you can be more versatile and upgrade easier.

Kudos!

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#19 Post by technosaurus »

you hit on most of what I was thinking except that my reason for having just a compatibility layer on top of gtk1 was so that we would still have backwards compatibility with gtk1 apps with no additional overhead, but still be compatible with gtk2 VIA the compatibility layer (much like x11-xcb) then we could have a gtk3 layer on top of that. (it would be doable to do this by minor version adding widgets as they were originally, and let the linker do the work)
ex
ldd gtk-2.0
would be just libgtk and its deps
ldd gtk-2.2
would give libgtk-2.0, libgtk...
and so on for up to 2.16 ...
then the same for gtk3 where the minor versions could be shared/static, but preferring a shared lib for the 2.16 layer and latest 3 series (the linker will do most of the work here)
Attachments
sdialog-0.1-a2.tar.gz
(6.37 KiB) Downloaded 478 times
sdialog.png
(7.11 KiB) Downloaded 864 times
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#20 Post by amigo »

Sounds pretty complicated to get and keep working... -even though gtk1 and gtk2 are no longer 'moving targets', gtk3 is and will be for its' whole life. I think that anyone who insists on running an app should be willing to have the libs for it installed as well -nothing is for free. for instance, I use only gtk1 apps for everything on the basic desktop. But, if I want seamonkey to work then I have to pay the 'gtk2 price' for it -it needs still other stuff anyway.

The challenge for me was to find enough of the right gtk1 apps to have something complete enough for daily use, or as a starter system. You can even get several small browsers within that. You can use anyone of those to install a real browser of the users' choice.

I am also working out a similar list of gtk2 apps to comprise a nice starter desktop. Window Managers are handled similarly, so that any combination of WM, graphics toolkit and starter apps all work together using a common underlying system.

I hope you don't spread yourself too thin with all the different ideas...

Post Reply