mobeus
Junior Member
Posts: 86
|
Post by mobeus on May 4, 2012 3:39:36 GMT 1
I am having trouble with a gtkbuilder example that Peter wrote in 2010. The code is here www.allbasic.info/mboard/index.php?topic=842.msg3076#msg3076 and the tut1.glade code is further up on the page. It compiles without error but the call to gtk_builder_add_from_file fails with a return code of zero. The glade file is in the same directory as the compiled program BTW. I am using BaCon version 1.0 build 23. Is this code valid for my version of BaCon?
|
|
|
Post by Pjot on May 4, 2012 6:32:15 GMT 1
Should work with build23 also, anyway, you have to make sure to export symbols dynamically. As you can see we're talking about the '-e' option which has been withdrawn, as compiler options should be given using the '-o' flag.
So for this program you have to compile as follows if you're using GCC:
Regards Peter
|
|
mobeus
Junior Member
Posts: 86
|
Post by mobeus on May 4, 2012 13:38:51 GMT 1
I have tried this on two different computers with different versions of Puppy Linux, both having the same BaCon build. It would be nice if I can get this to work.
# pwd /root/gtk-bacon/V1
# bacon -o -export-dynamic builder.bac Converting 'builder.bac'... done. Compiling 'builder.bac'... done. Program 'builder' ready. # ./builder
(<unknown>:14616): Gtk-CRITICAL **: gtk_widget_show: assertion `GTK_IS_WIDGET (widget)' failed ^C #
Is there a way to get the error message from the GError pointer in BaCon?
From gtkbuilder.h guint gtk_builder_add_from_file (GtkBuilder *builder, const gchar *filename, GError **error);
Best Regards, and thank you for your help with this.
EDIT: I have gtk+-2.0 v 2.20.0 and glade 3.6.7
|
|
|
Post by Pjot on May 4, 2012 13:43:23 GMT 1
You have to make sure the file 'tut1.glade' exists in the same directory as your binary. Note that Unix is case sensitive.
Regards Peter
|
|
mobeus
Junior Member
Posts: 86
|
Post by mobeus on May 4, 2012 13:48:40 GMT 1
Yes, same directory and correct file name. I even gave the files full permissions.
|
|
mobeus
Junior Member
Posts: 86
|
Post by mobeus on May 4, 2012 13:59:34 GMT 1
I modified the code a little to see the function returns SUB BacMain
gtk_init(0,0)
builder = gtk_builder_new() ret = gtk_builder_add_from_file (builder, "./tut1.glade", 0) window = gtk_builder_get_object (builder, "window") PRINT "builder ", builder PRINT "returned ", ret PRINT "window ", window gtk_builder_connect_signals (builder, 0) 'g_signal_connect_data(window, "delete-event", ADDRESS(on_window_destroy), 0, 0, 0) 'g_object_unref (builder) gtk_widget_show (window) gtk_main PRINT "OK"
END SUB
and this is what I see # bacon -o -export-dynamic builder.bac Converting 'builder.bac'... done. Compiling 'builder.bac'... done. Program 'builder' ready. # ./builder builder 134666952 returned 0 window 0
(<unknown>:984): Gtk-CRITICAL **: gtk_widget_show: assertion `GTK_IS_WIDGET (widget)' failed ^C
|
|
|
Post by Pjot on May 4, 2012 14:04:15 GMT 1
It seems in your case the builder does not return a WindowID.
How does your 'tut1.glade' file look like? Mine as follows:
<?xml version="1.0"?> <interface> <requires lib="gtk+" version="2.16"/> <!-- interface-naming-policy toplevel-contextual --> <object class="GtkWindow" id="window"> <signal name="destroy" handler="on_window_destroy"/> <child> <placeholder/> </child> </object> </interface>
Make sure no CR/LF exist in this file (as happens with Windows editors). The size of this file should be 272 bytes.
Which C compiler are you using? GCC or TCC? Which version?
Also what version of GTK are you using? On my Linux Mint 12 it works all fine.
Regards Peter
|
|
mobeus
Junior Member
Posts: 86
|
Post by mobeus on May 4, 2012 14:23:18 GMT 1
gtk+-2.0 v 2.20.0 and glade 3.6.7 Editor is Geany with LF (Unix) line endings on all docs. It would help if I knew how to get the error message from the GError pointer arg in gtk_builder_add_from_file.
# pwd /root/gtk-bacon/V1 # ls -l total 56 -rwxr-xr-x 1 root root 46712 2012-05-04 09:09 builder -rw-r--r-- 1 root root 1738 2012-05-04 09:06 builder.bac -rw-r--r-- 1 root root 272 2012-05-04 09:09 tut1.glade #
tut1.glade
<?xml version="1.0"?> <interface> <requires lib="gtk+" version="2.16"/> <!-- interface-naming-policy toplevel-contextual --> <object class="GtkWindow" id="window"> <signal name="destroy" handler="on_window_destroy"/> <child> <placeholder/> </child> </object> </interface>
builder.bac
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* 'tutorial.bac '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* TRAP LOCAL CATCH GOTO BadStuff
IMPORT "gtk_builder_add_from_file(long,char*,long)" FROM "libgtk-x11-2.0.so" TYPE int IMPORT "gtk_builder_connect_signals(long,long)" FROM "libgtk-x11-2.0.so" TYPE void IMPORT "gtk_builder_new" FROM "libgtk-x11-2.0.so" TYPE long IMPORT "gtk_builder_get_object(long,char*)" FROM "libgtk-x11-2.0.so" TYPE long
'IMPORT "g_object_unref(long)" FROM "libgobject-2.0.so.0" TYPE void 'IMPORT "g_signal_connect_data(long,char*,long,long,long,int)" FROM "libgobject-2.0.so" TYPE void
IMPORT "gtk_init(int*, char*)" FROM "libgtk-x11-2.0.so" TYPE void IMPORT "gtk_main_quit" FROM "libgtk-x11-2.0.so" TYPE void IMPORT "gtk_widget_show(long)" FROM "libgtk-x11-2.0.so" TYPE void IMPORT "gtk_main" FROM "libgtk-x11-2.0.so" TYPE void
'==============================================================================
SUB on_window_destroy(NUMBER user_data, NUMBER widget)
PRINT "Here before END" END
END SUB
'==============================================================================
SUB BacMain
gtk_init(0,0)
builder = gtk_builder_new() ret = gtk_builder_add_from_file (builder, "./tut1.glade", 0) window = gtk_builder_get_object (builder, "window") PRINT "builder ", builder PRINT "returned ", ret PRINT "window ", window gtk_builder_connect_signals (builder, 0) 'g_signal_connect_data(window, "delete-event", ADDRESS(on_window_destroy), 0, 0, 0) 'g_object_unref (builder) gtk_widget_show (window) gtk_main PRINT "OK"
END SUB
BacMain END
LABEL BadStuff PRINT ERR$(ERROR)
|
|
|
Post by Pjot on May 4, 2012 14:36:03 GMT 1
Weird, if I copy and paste your code of 'builder.bac' into a new file then my resulting filesize is 1681 bytes while yours seems to be 1738 bytes?
Are you using gcc or tcc?
To use the error return code, you can do the following:
SUB BacMain
DECLARE gerror
gtk_init(0,0)
builder = gtk_builder_new() ret = gtk_builder_add_from_file (builder, "./tut1.glade", ADDRESS(gerror)) PRINT gerror window = gtk_builder_get_object (builder, "window") PRINT "builder ", builder PRINT "returned ", ret PRINT "window ", window gtk_builder_connect_signals (builder, 0) 'g_signal_connect_data(window, "delete-event", ADDRESS(on_window_destroy), 0, 0, 0) 'g_object_unref (builder) gtk_widget_show (window) gtk_main PRINT "OK"
END SUB
For me it prints 0.
Regards Peter
|
|
mobeus
Junior Member
Posts: 86
|
Post by mobeus on May 4, 2012 15:18:11 GMT 1
Puppy has gcc. I used this code SUB BacMain DECLARE gerror gtk_init(0,0)
builder = gtk_builder_new() ret = gtk_builder_add_from_file (builder, "./tut1.glade", ADDRESS(gerror)) PRINT "GError ",gerror window = gtk_builder_get_object (builder, "window") PRINT "builder ", builder PRINT "returned ", ret PRINT "window ", window gtk_builder_connect_signals (builder, 0) 'g_signal_connect_data(window, "delete-event", ADDRESS(on_window_destroy), 0, 0, 0) 'g_object_unref (builder) gtk_widget_show (window) gtk_main PRINT "OK"
END SUB
and I get # bacon -c gcc -o -export-dynamic builder.bac Converting 'builder.bac'... done. Compiling 'builder.bac'... done. Program 'builder' ready. # ./builder GError 134662720 builder 134666952 returned 0 window 0
(<unknown>:12820): Gtk-CRITICAL **: gtk_widget_show: assertion `GTK_IS_WIDGET (widget)' failed ^C #
Is it possible to translate this struct to BaCon and retrieve the error *message? struct _GError { GQuark domain; gint code; gchar *message; };
I tried RECORD gerror LOCAL domain TYPE int LOCAL code TYPE int LOCAL message TYPE STRING END RECORD
and PRINT gerror.message. It didn't work, I know too little at this point.
|
|
mobeus
Junior Member
Posts: 86
|
Post by mobeus on May 4, 2012 16:48:53 GMT 1
I found a work around ;D Recompile with gcc! Does this mean it could be compiled with BaCon if a different set of options were specified? # bacon -p -c gcc -o -export-dynamic builder.bac Converting 'builder.bac'... done. WARNING: 'indent' not found on this system! Generated source code cannot be beautified. Compiling 'builder.bac'... done. Program 'builder' ready. # gcc -o builder builder.bac.c -export-dynamic `pkg-config --cflags --libs gtk+-2.0` # ./builder GError 0 builder 134633160 returned 1 window 134864896 Here before END #
I would still like to learn how to retrieve GError->message Thank you Peter for your patience and help. EDIT: Here is my working command for BaCon bacon -p -c gcc -o -export-dynamic -`pkg-config --cflags --libs gtk+-2.0` builder.bac It has been an education
|
|
|
Post by Pjot on May 4, 2012 17:06:45 GMT 1
That's weird, I do not need to do that. Your second compile in fact links the program with the GTK libraries.
If you run a "ldd builder" you'll see the binary dependencies to those libraries. With the BaCon compile the output of ldd will be different.
You probably also will succeed with the following line:
For GError, BaCon cannot query a struct. I created the same program in C below, to show how to read GError.
/* Compile as follows: gcc -export-dynamic `pkg-config --cflags --libs gtk+-2.0` builder.c -o builder -lgtk-x11-2.0 */
#include <stdio.h> #include <gtk/gtk.h> #include <gtk/gtk.h> #include <stdlib.h> #include <gtk/gtk.h>
void on_window_destroy(long user_data, long widget) { printf("Here before END\n"); exit(0); }
/*==============================================================================*/
void BacMain() { GtkBuilder *builder; GObject *window; GError *gerror = NULL; int ret;
gtk_init(0,0);
builder = gtk_builder_new(); ret = gtk_builder_add_from_file(builder, "./tut1.glade", &gerror);
if(gerror!=NULL) printf("%s\n", gerror->message);
window = gtk_builder_get_object(builder, "window"); gtk_builder_connect_signals(builder, 0); gtk_widget_show((GtkWidget*)window); gtk_main(); }
int main(int argc, char **argv) { BacMain(); return 0; }
Regards Peter
|
|
mobeus
Junior Member
Posts: 86
|
Post by mobeus on May 4, 2012 17:12:15 GMT 1
Thanks Peter, you replied while I was editing my last post with the working compile command for BaCon. The problem might be related to the setup of Puppy. No matter, my problem is solved and I can use BaCon for my project. Happy days!
Thanks again
|
|
|
Post by vovchik on May 5, 2012 9:31:21 GMT 1
Dear moebius and Peter,
Thanks for the example. I modded it a tiny bit (the first IMPORT) so that the xml file is contained in a string within the bacon source, which means there is no run time external dependency:
' bacon -o -export-dynamic -o `pkg-config --cflags --libs gtk+-2.0` builder1.bac
' *********************** ' ERROR HANDLER ' ***********************
TRAP LOCAL CATCH GOTO BadStuff
' *********************** ' END ERROR HANDLER ' ***********************
' *********************** ' IMPORTS ' ***********************
IMPORT "gtk_builder_add_from_string(long,char*,int,void*)" FROM "libgtk-x11-2.0.so" TYPE int IMPORT "gtk_builder_connect_signals(long,long)" FROM "libgtk-x11-2.0.so" TYPE void IMPORT "gtk_builder_new" FROM "libgtk-x11-2.0.so" TYPE long IMPORT "gtk_builder_get_object(long,char*)" FROM "libgtk-x11-2.0.so" TYPE long IMPORT "gtk_init(int*, char*)" FROM "libgtk-x11-2.0.so" TYPE void IMPORT "gtk_main_quit" FROM "libgtk-x11-2.0.so" TYPE void IMPORT "gtk_widget_show(long)" FROM "libgtk-x11-2.0.so" TYPE void IMPORT "gtk_main" FROM "libgtk-x11-2.0.so" TYPE void
' *********************** ' END IMPORTS ' ***********************
' *********************** ' SUBS & FUNCTIONS ' *********************** ' ------------------ SUB on_window_destroy(NUMBER user_data, NUMBER widget) ' ------------------ gtk_main_quit PRINT "Here before END" END END SUB
' ------------------ SUB BACMAIN ' ------------------ LOCAL xml$ = " \ <?xml version=\"1.0\"?> \ <interface> \ <requires lib=\"gtk+\" version=\"2.20\"/> \ <!-- interface-naming-policy toplevel-contextual --> \ <object class=\"GtkWindow\" id=\"window\"> \ <signal name=\"destroy\" handler=\"on_window_destroy\"/> \ <child> \ <placeholder/> \ </child> \ </object> \ </interface>" PRINT xml$ PRINT LEN(xml$) gtk_init(0, 0) builder = gtk_builder_new() ' ret = gtk_builder_add_from_file(builder, "tut1.glade", 0) ret = gtk_builder_add_from_string(builder,xml$,LEN(xml$), 0) window = gtk_builder_get_object(builder, "window") PRINT "builder ", builder PRINT "returned ", ret PRINT "window ", window gtk_builder_connect_signals (builder, 0) 'g_signal_connect_data(window, "delete-event", ADDRESS(on_window_destroy), 0, 0, 0) 'g_object_unref (builder) gtk_widget_show(window) gtk_main PRINT "OK" END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
BACMAIN END
' *********************** ' END MAIN ' ***********************
' *********************** ' ERROR HANDLER ' *********************** LABEL BadStuff PRINT ERR$(ERROR)
With kind regards, vovchik
|
|