Another way to see it for the GTK dyslexic !
Mar 21, 2013 16:19:44 GMT 1
Post by bigbass on Mar 21, 2013 16:19:44 GMT 1
Well Guys I have been using BaCon for awhile
and for some reason there was a missing puzzle piece
for me to get started converting GTK examples to BaCon
I finally broke the hurdle
what confused me was the how to get the correct values
that the functions needed for some reason if the IMPORTS
weren't in the exact order as the main program I got lost trying to follow what
was happening when scrolling up and down
Joe
so just for a test example I placed the IMPORTS
together with the main code and bingo! it all made sense ;D
*and the code works and compiles correctly too
after you can make the code look pretty by moving the imports to the
top of the script
now I hope to get my hands on all the great examples you guys posted
and start having some fun
Joe
original code source
www.basic-converter.org/gtk-demo.bac.html
another way to see it for the gtk dyslexic
fixed IMPORT so ADDRESS not needed
now put it back together with imports on top
and cleaned up code
you need this for more examples of the IMPORTS
www.basic-converter.org/gtk.bac
a great example to see how to use GTK is the source.bac
for the GUI www.basic-converter.org/source.bac.html
its very advanced but you can find examples for almost everything
there
and for some reason there was a missing puzzle piece
for me to get started converting GTK examples to BaCon
I finally broke the hurdle
what confused me was the how to get the correct values
that the functions needed for some reason if the IMPORTS
weren't in the exact order as the main program I got lost trying to follow what
was happening when scrolling up and down
Joe
so just for a test example I placed the IMPORTS
together with the main code and bingo! it all made sense ;D
*and the code works and compiles correctly too
after you can make the code look pretty by moving the imports to the
top of the script
now I hope to get my hands on all the great examples you guys posted
and start having some fun
Joe
original code source
www.basic-converter.org/gtk-demo.bac.html
another way to see it for the gtk dyslexic
fixed IMPORT so ADDRESS not needed
'---
'--- GTK example with BACON
'--- March 2009 - PvE.
'--- Adapted November 2009.
'--- http://www.basic-converter.org/gtk-demo.bac.html
'--- demo2.bac used as a getting started example pre step
'--- another way to see how BaCon works step by step
'--- only joined IMPORTS to functions to show what values are needed
'--- when code is working move the IMPORTS to the top of the code
TRAP LOCAL
CONST Gtk$ = "libgtk-x11-2.0.so.0"
CONST Gobject$ = "libgobject-2.0.so.0"
'--- Callback for closing window
IMPORT "gtk_main_quit(void)" FROM Gtk$ TYPE void
SUB exit_prog
gtk_main_quit
END SUB
'--- Main program starts here
IMPORT "gtk_init(int*,void*)" FROM Gtk$ TYPE void
gtk_init(0, 0)
IMPORT "gtk_window_new(int)" FROM Gtk$ TYPE long
window = gtk_window_new(0)
IMPORT "gtk_window_set_title(long,char*)" FROM Gtk$ TYPE void
gtk_window_set_title(window, "Hello world")
IMPORT "gtk_table_new(int,int,int)" FROM Gtk$ TYPE long
table = gtk_table_new(15, 15, 1)
IMPORT "gtk_container_add(long,long)" FROM Gtk$ TYPE void
gtk_container_add(window, table)
IMPORT "gtk_label_new(char*)" FROM Gtk$ TYPE long
label = gtk_label_new("Bacon and GTK example!")
IMPORT "gtk_table_attach_defaults(long,long,int,int,int,int)" FROM Gtk$ TYPE void
gtk_table_attach_defaults(table, label, 1, 8, 3, 7)
IMPORT "gtk_button_new_from_stock(char*)" FROM Gtk$ TYPE long
button = gtk_button_new_from_stock("gtk-quit")
'--- notice here already IMPORTED before do it only once
gtk_table_attach_defaults(table, button, 10, 14, 12, 14)
'--- Show whole GUI
IMPORT "gtk_widget_show_all(long)" FROM Gtk$ TYPE void
gtk_widget_show_all(window)
'--- Use as callback the defined SUB
'--- fixed IMPORT so ADDRESS not needed
IMPORT "g_signal_connect_data(long,char*,void*,long,long,int)" FROM Gobject$ TYPE void
g_signal_connect_data(window, "delete-event", exit_prog, 0, 0, 0)
g_signal_connect_data(button, "clicked", exit_prog, 0, 0, 0)
'--- Endless event handling by GTK
IMPORT "gtk_main" FROM Gtk$ TYPE void
gtk_main
now put it back together with imports on top
and cleaned up code
'---
'--- GTK example with BACON
'--- March 2009 - PvE.
'--- Adapted November 2009.
'--- http://www.basic-converter.org/gtk-demo.bac.html
'--- demo3.bac used as a getting started example pre step
'--- when code is working move the IMPORTS to the top of the code
TRAP LOCAL
CONST Gtk$ = "libgtk-x11-2.0.so.0"
CONST Gobject$ = "libgobject-2.0.so.0"
IMPORT "gtk_main_quit(void)" FROM Gtk$ TYPE void
IMPORT "gtk_init(int*,void*)" FROM Gtk$ TYPE void
IMPORT "gtk_window_new(int)" FROM Gtk$ TYPE long
IMPORT "gtk_window_set_title(long,char*)" FROM Gtk$ TYPE void
IMPORT "gtk_table_new(int,int,int)" FROM Gtk$ TYPE long
IMPORT "gtk_container_add(long,long)" FROM Gtk$ TYPE void
IMPORT "gtk_label_new(char*)" FROM Gtk$ TYPE long
IMPORT "gtk_table_attach_defaults(long,long,int,int,int,int)" FROM Gtk$ TYPE void
IMPORT "gtk_button_new_from_stock(char*)" FROM Gtk$ TYPE long
IMPORT "gtk_widget_show_all(long)" FROM Gtk$ TYPE void
IMPORT "g_signal_connect_data(long,char*,void*,long,long,int)" FROM Gobject$ TYPE void
IMPORT "gtk_main" FROM Gtk$ TYPE void
'--- Callback for closing window
SUB exit_prog
gtk_main_quit
END SUB
'--- Main program starts here
gtk_init(0, 0)
window = gtk_window_new(0)
gtk_window_set_title(window, "Hello world")
table = gtk_table_new(15, 15, 1)
gtk_container_add(window, table)
label = gtk_label_new("Bacon and GTK example!")
gtk_table_attach_defaults(table, label, 1, 8, 3, 7)
button = gtk_button_new_from_stock("gtk-quit")
'--- notice here already IMPORTED before do it only once
gtk_table_attach_defaults(table, button, 10, 14, 12, 14)
'--- Show whole GUI
gtk_widget_show_all(window)
'--- Use as callback the defined SUB
'--- fixed IMPORT so ADDRESS not needed
g_signal_connect_data(window, "delete-event", exit_prog, 0, 0, 0)
g_signal_connect_data(button, "clicked", exit_prog, 0, 0, 0)
'--- Endless event handling by GTK
gtk_main
you need this for more examples of the IMPORTS
www.basic-converter.org/gtk.bac
a great example to see how to use GTK is the source.bac
for the GUI www.basic-converter.org/source.bac.html
its very advanced but you can find examples for almost everything
there