|
Post by bigbass on Oct 11, 2017 16:59:24 GMT 1
Hey Guy Doing this HUG styled with IMPORTS for gtk3 this time The idea is add to gtk2 when we can and add new stuff from gtk3 I wrote a bash script to convert the code to baconized syntax and after testing more widgets and adding the new IMPORTS step by step I will post that code later still in alpha since this was the first gtk3 with IMPORTS (I did all the demos with proto before so it can be done with import also) '--- a working generic template made from linkbutton.c '--- Ported from the gtk3 gnome offical demo to BaCon IMPORTS in (gtk3) by bigbass
'--- auto generated a short IMPORTS list of gtk function with args HUG styled IMPORT "gtk_container_add(long,long)" FROM "libgtk-3.so.0" TYPE void IMPORT "gtk_link_button_new(char*)" FROM "libgtk-3.so.0" TYPE long IMPORT "gtk_link_button_set_uri(long,char*)" FROM "libgtk-3.so.0" TYPE void IMPORT "gtk_widget_show_all(long)" FROM "libgtk-3.so.0" TYPE void IMPORT "gtk_window_set_default_size(long,int,int)" FROM "libgtk-3.so.0" TYPE void IMPORT "gtk_window_set_title(long,char*)" FROM "libgtk-3.so.0" TYPE void
'--- auto generated a short IMPORTS list of gtk/ gdk functions with args HUG styled '--- we need these always IMPORT "gtk_init(int*,void*)" FROM "libgtk-3.so.0" TYPE void IMPORT "gtk_main" FROM "libgtk-3.so.0" TYPE void IMPORT "gtk_main_quit(int)" FROM "libgtk-3.so.0" TYPE void IMPORT "gtk_window_new(int)" FROM "libgtk-3.so.0" TYPE long
'--- for the callbacks IMPORT "g_signal_connect_data(long,char*,long,long,long,int)" FROM "libgobject-2.0.so.0" TYPE void
'===================== SUB exit_prog '===================== gtk_main_quit(0) END SUB
gtk_init(0, 0) window =gtk_window_new(0)
gtk_window_set_title (window, "BaCon LinkButton") gtk_window_set_default_size (window, 250, 50)
linkbutton = gtk_link_button_new ("Link to The BaCon Website!") gtk_link_button_set_uri (linkbutton, "http://www.basic-converter.org/") gtk_container_add (window, linkbutton)
'--- Connecting the delete-event signal to the callback g_signal_connect_data(window, "delete-event", ADDRESS(exit_prog), 0, 0, 0) gtk_widget_show_all (window) gtk_main
here is the c code as a reference only #include <gtk/gtk.h>
static void activate (GtkApplication *app, gpointer user_data) { GtkWidget *window; GtkWidget *linkbutton;
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "GNOME LinkButton"); gtk_window_set_default_size (GTK_WINDOW (window), 250, 50);
linkbutton = gtk_link_button_new ("Link to GNOME live!"); gtk_link_button_set_uri (GTK_LINK_BUTTON (linkbutton), "http://live.gnome.org");
gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (linkbutton));
gtk_widget_show_all (window); }
int main (int argc, char **argv) { GtkApplication *app; int status;
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE); g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); status = g_application_run (G_APPLICATION (app), argc, argv); g_object_unref (app);
return status; }
|
|
|
Post by bigbass on Oct 12, 2017 18:52:25 GMT 1
Hey Guys These were all done with PROTOI was disappointed that all the PROTO code wouldn't compile on a 64bit box (I did them all on a 32 bit box) so I went back and fixed them all 29 widgets no html page just code examples and images of what to expect a mix of gtk2 and gtk3 widgets good news they all work again Joe PROTO-GTK.tar.gz (495.49 KB)
|
|
|
Post by bigbass on Oct 15, 2017 2:51:37 GMT 1
Hey Guys
This was done with gtk3 and IMPORTS had to manually add some imports because gtk2 doesn't have them and g_timeout from glib getting the idea of this way also but this one was a pain to do but it now compiles cleanly
'--- a working generic template only made from progress.c
'--- auto generated a short IMPORTS list of gtk function with args HUG styled IMPORT "gtk_button_new_with_label(char*)" FROM "libgtk-3.so.0" TYPE long IMPORT "gtk_container_add(long,long)" FROM "libgtk-3.so.0" TYPE void IMPORT "gtk_init(int*,void*)" FROM "libgtk-3.so.0" TYPE void IMPORT "gtk_main" FROM "libgtk-3.so.0" TYPE void IMPORT "gtk_main_quit" FROM "libgtk-3.so.0" TYPE void IMPORT "gtk_progress_bar_new" FROM "libgtk-3.so.0" TYPE long IMPORT "gtk_progress_bar_pulse(long)" FROM "libgtk-3.so.0" TYPE void IMPORT "gtk_progress_bar_set_fraction(long,double)" FROM "libgtk-3.so.0" TYPE void IMPORT "gtk_widget_show_all(long)" FROM "libgtk-3.so.0" TYPE void IMPORT "gtk_window_new(int)" FROM "libgtk-3.so.0" TYPE long IMPORT "gtk_window_set_default_size(long,int,int)" FROM "libgtk-3.so.0" TYPE void IMPORT "gtk_window_set_title(long,char*)" FROM "libgtk-3.so.0" TYPE void
'--- manually added new for gtk3 IMPORTS IMPORT "gtk_grid_attach (long,long,int,int,int,int)" FROM "libgtk-3.so.0" TYPE void IMPORT "gtk_grid_attach_next_to(long,long,long,int,int,int)" FROM "libgtk-3.so.0" TYPE void IMPORT "gtk_grid_new (void)" FROM "libgtk-3.so.0" TYPE long
'--- for the callbacks IMPORT "g_signal_connect_data(long,char*,long,long,long,int)" FROM "libgobject-2.0.so.0" TYPE void
'--- manually added new for gtk3 IMPORTS IMPORT "g_timeout_add(int,long,int) " FROM "libgobject-2.0.so.0" TYPE void
gtk_init(0, 0)
GTK_POS_BOTTOM = 3
fraction = 0.1
'---How to use a time out to update a progress bar
'============================= FUNCTION timeout_callback '=============================
gtk_progress_bar_pulse(progress_bar)
'---Increase the bar by 10% each time this function is called
'---Fill in the bar with the new fraction gtk_progress_bar_set_fraction (progress_bar, fraction)
fraction = fraction + 0.1 IF fraction >= 1 THEN fraction = 0 END IF
RETURN TRUE
END FUNCTION
'============== SUB EXIT_PROG '============== gtk_main_quit(0) END SUB
gtk_init(0, 0)
'---Create the window and set a title window = gtk_window_new(0) gtk_window_set_title(window, "Progress Example") gtk_window_set_default_size (window, 270, 70) g_signal_connect_data(window, "destroy", (long)EXIT_PROG, 0, 0, 0)
'---Create a button with a label button = gtk_button_new_with_label ("QUIT")
'---Create the progress bar progress_bar = gtk_progress_bar_new(0)
'---Create a grid and attach the button and progress bar accordingly grid = gtk_grid_new() gtk_grid_attach (grid, button, 1, 1, 1, 1) gtk_grid_attach_next_to (grid, \ progress_bar, \ button, \ GTK_POS_BOTTOM, 1, 1)
'---Connecting the clicked signal to the callback function g_signal_connect_data (button, "clicked",(long) EXIT_PROG,0,0,0)
'---got that g_timeout working g_timeout_add(500,(long) timeout_callback, 0) gtk_container_add(window, grid) gtk_widget_show_all(window) gtk_main(0)
|
|
|
Post by bigbass on Oct 15, 2017 3:12:43 GMT 1
gtk IMPORTS is great when they are listed but what happens when we move to gtk3 and there are missing IMPORTS ? there is no easy answer to explain this quickly and completely but I made a script to convert some of them and its a work in progress but if you look at the generated output compared to the functions.txt you can figure out what gets changed its a tool to "decode" the gtk to BaCon experience Joe import-tool.tar.gz (1.86 KB) and the template tool for gtk3 this took some time and still is a work in progress template-gtk3.tar.gz (37.69 KB)
|
|
|
Post by bigbass on Oct 19, 2017 17:04:52 GMT 1
Just a note sometimes when we compile we can get a warning we know that we caused for example when you use PROTO gcc now complains about -Wimplicit-function-declaration and we can turn off this warning for a clean compile with adding -Wno-implicitto our options if you feel better about a clean compile second note when you use IMPORTS you avoid this error because you manually redefine the function reference link gcc.gnu.org/onlinedocs/gcc-4.0.3/gcc/Warning-Options.htmlPRAGMA OPTIONS `pkg-config --cflags gtk+-3.0` PRAGMA LDFLAGS `pkg-config --libs gtk+-3.0` PRAGMA COMPILER gcc PRAGMA OPTIONS -Wno-implicit
|
|
|
Post by bigbass on Oct 26, 2017 6:58:39 GMT 1
Hey Guys Decoding gtk for bacon use is no easy matter and you wont find anything explaining it in detail step by step but we have IMPORTS for gtk2 this is a way to pass the functions there is a decoding process that is not in any way simple to do this manually so I wanted to try perl but didn't have a real reason to try and do it in perl except to see what were the differences using sed and perl is very powerful much more then just a stream editor like sed this is a middle step decoding gtk functions to bacon to understand all the renaming a little better I hope glib renames everything then gtk throws around pointers everywhere later I will make it auto generate some of the missing IMPORTS when we move to gtk3 decodegtk.tar.gz (2.21 KB)[/code] here is just a snippet of five to view from the list this is what you see when you use the official gtk docs later this gets modified for bacon GtkWidget * gtk_entry_new (void);
GtkWidget * gtk_entry_new_with_buffer (GtkEntryBuffer *buffer);
GtkEntryBuffer * gtk_entry_get_buffer (GtkEntry *entry);
void gtk_entry_set_buffer (GtkEntry *entry, GtkEntryBuffer *buffer);
void gtk_entry_set_text (GtkEntry *entry, const gchar *text);
then they get converted using the attached script if you look at the official gtk then how we read it in bacon remember this is a middle step so you can understand what is happening a little better TYPE long gtk_entry_new (void);
TYPE long gtk_entry_new_with_buffer (long);
TYPE long gtk_entry_get_buffer (long);
TYPE void gtk_entry_set_buffer (long, long);
TYPE void gtk_entry_set_text (long, char* );
|
|
|
Post by bigbass on Oct 30, 2017 18:24:29 GMT 1
Hey Guys Finally got a working gtk3 syntax to IMPORTS.bac syntax converter ! you can convert hundreds at a time but this just focuses on the entry widget at the moment you start with some code like this pure gtk3 GtkWidget * gtk_entry_new (void);
GtkWidget * gtk_entry_new_with_buffer (GtkEntryBuffer *buffer);
run a bash script with perl one liners and it then looks like TYPE long gtk_entry_new (void); TYPE long gtk_entry_new_with_buffer (long); then a pure perl script to get the final IMPORTS IMPORT "gtk_entry_new(void)" FROM "libgtk-3.so.0" TYPE long IMPORT "gtk_entry_new_with_buffer(long)" FROM "libgtk-3.so.0" TYPE long IMPORT "gtk_entry_get_buffer(long)" FROM "libgtk-3.so.0" TYPE long IMPORT "gtk_entry_set_buffer(long,long)" FROM "libgtk-3.so.0" TYPE void IMPORT "gtk_entry_set_text(long,char*)" FROM "libgtk-3.so.0" TYPE void IMPORT "gtk_entry_get_text(long)" FROM "libgtk-3.so.0" TYPE char* IMPORT "gtk_entry_get_text_length(long)" FROM "libgtk-3.so.0" TYPE int decodegtk3.tar.gz (3.23 KB) Joe
|
|
|
Post by vovchik on Oct 30, 2017 19:16:16 GMT 1
Dear Joe, Thanks. Now off to do some testing and converting. With kind regards, vovchik
|
|
|
Post by bigbass on Oct 30, 2017 20:44:13 GMT 1
Hey vovchik
At the moment its just the Entry widget but all the types Are there and perl will let you Split up the gtk function name Also if needed its just matter Of going through the new functions for gtk3
I will add them in as I go Through more widgets but From here on its easy
Joe
|
|
|
Post by bigbass on Nov 9, 2017 18:33:46 GMT 1
Hey Guys
Alex in another post used etern then gtk using g++
and I was curious to see if we could do it in C and get rid of IMPORTS and PROTO to have less typing and conversions this seems simple shortens a lot just sandwich the USEC with a hybrid IMPORT
seems much easier for me to read and understand and I have code to auto generate the new syntax
hey vovchik notice the extra long I had to force in the callback for 64bit
PRAGMA LDFLAGS `pkg-config --libs gtk+-3.0` PRAGMA OPTIONS `pkg-config --cflags gtk+-3.0` PRAGMA COMPILER gcc PRAGMA LDFLAGS -L. PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith OPTION PARSE FALSE PRAGMA BACONLIB
USEC void gtk_init(int*,void*); long gtk_window_new(int); void g_signal_connect_data(long,char*,long,long,long,int); void gtk_widget_show_all(long); void gtk_main(); void gtk_main_quit(); ENDUSEC
gtk_init(0,0) window = gtk_window_new(0) gtk_widget_show_all(window) '---Connecting the clicked signal to the callback function g_signal_connect_data (window, "destroy",(long) gtk_main_quit,0,0,0) gtk_main()
|
|
|
Post by vovchik on Nov 9, 2017 19:26:44 GMT 1
Dear Joe, Thanks. That's very transparent, simple and terse. I like it. With kind regards, vovchik
|
|
|
Post by bigbass on Jun 16, 2018 16:19:28 GMT 1
Hey vovchik
here is some more hybrid code *.bac a short hand way to port code from gtk while in the testing stage or a stand alone widget example
wow only the callback needs to be IMPORTED!
PRAGMA LDFLAGS `pkg-config --libs gtk+-3.0` PRAGMA OPTIONS `pkg-config --cflags gtk+-3.0` PRAGMA COMPILER gcc 'PRAGMA LDFLAGS -L. PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith PRAGMA OPTIONS -Wno-implicit OPTION PARSE FALSE 'PRAGMA BACONLIB
'--- look only these needs to be hybrid IMPORTED USEC void gtk_main_quit(); void g_signal_connect_data(long,char*,long,long,long,int);
ENDUSEC
'--- header of GUI code gtk_init(0,0) window = gtk_window_new(0)
'--- body of GUI code gtk_window_set_title (window, "BaCon LinkButton") gtk_window_set_default_size (window, 250, 50)
linkbutton = gtk_link_button_new ("Link to The BaCon Website!") gtk_link_button_set_uri (linkbutton, "http://www.basic-converter.org/") gtk_container_add (window, linkbutton)
'--- footer of GUI code gtk_widget_show_all(window)
'--- Connecting the clicked signal to the callback function '--- note extra (long) cast for gtk_main_quit this is the fix! g_signal_connect_data (window, "destroy",(long) gtk_main_quit,0,0,0) gtk_main()
|
|
|
Post by vovchik on Jun 16, 2018 17:27:24 GMT 1
Dear Joe,
Excellent work - works and compiles fine and allows for very quick and dirty testing. I get much faster compilation speeds by commenting out two buts at the top:
PRAGMA LDFLAGS `pkg-config --libs gtk+-3.0` PRAGMA OPTIONS `pkg-config --cflags gtk+-3.0` PRAGMA COMPILER gcc 'PRAGMA LDFLAGS -L. PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith PRAGMA OPTIONS -Wno-implicit OPTION PARSE FALSE 'PRAGMA BACONLIB
libbacon.a is in /usr/lib, so it gets found, I think, but still have to test.
With kind regards, vovchik
|
|
|
Post by bigbass on Jun 16, 2018 17:34:42 GMT 1
Hey vovchik
thanks will comment them out
look again only the callback needs to be IMPORTED that makes it much easier while testing an idea and only 24.1 kB
Joe
|
|
|
Post by bigbass on Jan 24, 2020 20:13:06 GMT 1
Hello still testing the new bacon 4.0 wanted to see if any changes were needed to some older code demos and experimental code in this thread there are examples of using IMPORT,PROTO now a hybrid way also which is nice for testing ideas since we don't have an official gtk3 IMPORTS list yet all seems fine so far compiling with bacon 4.0 here is a hybrid way of using gtk3 and the source code is here and has the screenshot of the GUI developer.gnome.org/gnome-devel-demos/unstable/checkbutton.c.html.en
PRAGMA LDFLAGS `pkg-config --libs gtk+-3.0` PRAGMA OPTIONS `pkg-config --cflags gtk+-3.0` PRAGMA COMPILER gcc PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith PRAGMA OPTIONS -Wno-implicit OPTION PARSE FALSE
'--- hybrid shortened form of declaring imports USEC void gtk_init(int*,void*); long gtk_window_new(int); void g_signal_connect_data(long,char*,long,long,long,int); void gtk_widget_show_all(long); void gtk_main(); void gtk_main_quit();
long gtk_check_button_new(void); long gtk_check_button_new_with_label(char* ,char*); long gtk_check_button_new_with_mnemonic(char* ,char*);
ENDUSEC
'--- simplified signal handler for the CheckButton SUB toggled_cb ( )
IF (gtk_toggle_button_get_active (checkbutton)) THEN gtk_window_set_title (window, "Checked title") PRINT "checked in terminal" ELSE gtk_window_set_title (window, "Unchecked title") PRINT "unchecked in terminal"
END IF END SUB
gtk_init(0,0) window = gtk_window_new(0) gtk_window_set_title(window, "CheckButton") gtk_window_set_default_size(window, 400, 100) checkbutton = gtk_check_button_new_with_label ("a check box",0) gtk_toggle_button_set_active(checkbutton, 1) g_signal_connect_data (checkbutton, "toggled",(long)toggled_cb, window,0,0) gtk_container_add (window, checkbutton) gtk_widget_show_all(window) '---Connecting the clicked signal to the callback function g_signal_connect_data (window, "destroy",(long) gtk_main_quit,0,0,0) gtk_main()
|
|