|
Post by Pjot on Mar 6, 2013 21:54:58 GMT 1
Small GTK example:
PRAGMA LDFLAGS `pkg-config --cflags --libs gtk+-2.0` PRAGMA INCLUDE gtk-2.0/gtk/gtk.h
PROTO gtk_init, gtk_window_new, gtk_window_set_title, gtk_window_set_position, gtk_widget_set_size_request PROTO g_signal_connect_data, gtk_table_new, gtk_container_add, gtk_button_new_with_label PROTO gtk_table_attach_defaults, gtk_widget_show_all, gtk_main
LOCAL *win,*grid,*button TYPE GtkWidget
gtk_init(0, 0)
win = gtk_window_new(GTK_WINDOW_TOPLEVEL) gtk_window_set_title(GTK_WINDOW(win), "GTK demo") gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER) gtk_widget_set_size_request(win, 300, 350) g_signal_connect_data(win, "delete-event", G_CALLBACK(gtk_exit), 0, 0, 0)
grid = gtk_table_new(55, 50, 1) gtk_container_add(GTK_CONTAINER(win), grid)
button = gtk_button_new_with_label("Quit") gtk_table_attach_defaults(GTK_TABLE(grid), button, 41, 49, 44, 50) g_signal_connect_data(button, "clicked", G_CALLBACK(gtk_exit), 0, 0, 0)
gtk_widget_show_all(win)
gtk_main
|
|
|
Post by SunBurnt on Mar 9, 2013 4:48:05 GMT 1
Peter, the first line errors for me in Puppy ( Big Surprise...).
Puppy has /usr/bin/pkg-config, and find returned this: # find /usr |grep gtk+-2.0 /usr/lib/pkgconfig/gtk+-2.0.pc /usr/share/vala-0.14/vapi/gtk+-2.0.deps /usr/share/vala-0.14/vapi/gtk+-2.0.vapi
As it`s not part of hug, more widgets and properties are needed to make it useful. Perhaps new external GTK import libraries for GRID and MENUBAR ? At least a starting framework that others can add widgets and properties to. Kind of an on-going community project to supplement hug.
|
|
|
Post by bigbass on Mar 9, 2013 5:40:37 GMT 1
Just some more feedback
saved it as emb.bac complied using
bacon emb.bac
on slackware 14 it compiled and worked as expected
Joe
|
|
|
Post by Pjot on Mar 9, 2013 8:46:06 GMT 1
What version of BaCon are you using? Note that the PRAGMA statement appears in BaCon b29 and later... BR, Peter
|
|
|
Post by vovchik on Mar 9, 2013 9:57:03 GMT 1
Dear Terry,
It worked for me in Puppy Lucid. I used the latest beta and the latest HUG.
With kind regards, vovchik
|
|
|
Post by bigbass on Mar 23, 2013 17:53:05 GMT 1
PRAGMA LDFLAGS `pkg-config --cflags --libs gtk+-2.0`
PROTO gtk_init, gtk_message_dialog_new
CONST GTK_STOCK_OK = 1
gtk_init(0, 0) x = gtk_dialog_run(gtk_message_dialog_new(0, 0, 0, GTK_STOCK_OK,"Greetings from BaCon!"))
fixed! remove this line and it compiles without warnings PRAGMA INCLUDE gtk-2.0/gtk/gtk.hHere is a very simple example that was used in the widget tutorial from Pjot basic-converter.proboards.com/index.cgi?action=gotopost&board=doc&thread=263&post=1988 mobeus found an undocumented way to use GTK now embedded to test this new idea using the PROTO command and PRAGMA ' this is the same way I used for iup but now just gtk Thanks for this new way to use GTK Joe
|
|
|
Post by bigbass on Mar 23, 2013 20:36:17 GMT 1
Getting the hang of this ! PROTO is much easier to use than IMPORT *I wouldn't have understood this if I didn't try the iup examples first with proto so thanks jrs too PRAGMA LDFLAGS `pkg-config --cflags --libs gtk+-2.0`
TRAP LOCAL
PROTO gtk_init,gtk_main_quit,gtk_window_new, gtk_window_set_default_size PROTO gtk_window_set_title,gtk_table_new,gtk_container_add PROTO gtk_table_attach_defaultsgtk_button_new_from_stock, gtk_table_attach_defaults PROTO g_signal_connect_data, gtk_widget_show_all, gtk_main
SUB exit_prog gtk_main_quit END SUB
gtk_init(0, 0) window = gtk_window_new() gtk_window_set_default_size(window, 200, 200) 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") gtk_table_attach_defaults(table, button, 10, 14, 12, 14)
g_signal_connect_data(window, "delete-event", exit_prog, 0, 0, 0) g_signal_connect_data(button, "clicked", exit_prog, 0, 0, 0) gtk_widget_show_all(window) gtk_main
|
|
|
Post by bigbass on Mar 24, 2013 16:42:18 GMT 1
I started with a snippet taken from Peter's source.bac from an error message dialog at line number at 468 of source.bac
reduced it down to an easier message for testing
note that CONST is not needed
PRAGMA LDFLAGS `pkg-config --cflags --libs gtk+-2.0`
TRAP LOCAL
PROTO gtk_init, gtk_message_dialog_new , gtk_dialog_run GTK_MESSAGE_WARNING = 1 GTK_MESSAGE_ERROR = 3 GTK_STOCK_CLOSE = 2
gtk_init(0, 0)
mess = gtk_message_dialog_new(0, 0, GTK_MESSAGE_WARNING, GTK_STOCK_CLOSE, "The BaCon website cannot be reached!\n\n\tCheck your network settings.") dialog = gtk_dialog_run(mess)
Joe
|
|
|
Post by bigbass on Mar 26, 2013 17:25:24 GMT 1
Well I thought to try this with some C code and convert it So as not to jump any steps here is original GTK code that will be used as an easy example this will be ported to BaCon GTK later www.cs.dartmouth.edu/~xy/cs23/gtk.htmllook at Figure 3: screenshot of hello2.c now port it to BaCon embedded GTK simplified and a callback added look carefully what was done to get a working example a lot of code can be cut out and reduced down some notes: gtk_widget_show gets replaced by gtk_widget_show_allGTK_WINDOW(window) gets replaced with just window,the call back gets replaced also for a SUB g_signal_connect gets replaced by g_signal_connect_datamaybe later some conversion tool could be made Thank you Peter for this having fun again ! ported hello2.c now hello2gtk.bac hello2gtk.bac '--- set up for compiling embedded library GTK PRAGMA LDFLAGS `pkg-config --cflags --libs gtk+-2.0`
'--- this replaces the need for IMPORT. the TYPE is not needed '--- place all the functions that you will use here
PROTO gtk_init PROTO gtk_window_new PROTO gtk_window_set_title PROTO g_signal_connect_data, PROTO g gtk_widget_show_all PROTO gtk_main PROTO gtk_main_quit
' get the needed missing values GTK_WINDOW_TOPLEVEL = 0
'=============== SUB exit_prog '=============== gtk_main_quit END SUB
gtk_init(0, 0)
window = gtk_window_new(GTK_WINDOW_TOPLEVEL) gtk_window_set_title(window, "Hello World!")
/* Connect the main window to the destroy ---> replace with SUB exit_prog */ g_signal_connect_data(window, "delete-event", exit_prog, 0, 0, 0) gtk_widget_show_all(window) gtk_main
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Mar 26, 2013 18:11:10 GMT 1
Well, there you go, a happy ending to another sad story.
|
|
|
Post by bigbass on Mar 28, 2013 9:16:55 GMT 1
remove this line and it compiles without warnings PRAGMA INCLUDE gtk-2.0/gtk/gtk.hthis took me a few hours but it works !
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Mar 28, 2013 18:04:07 GMT 1
This is what BASIC is all about.
|
|
|
Post by bigbass on Mar 29, 2013 19:27:18 GMT 1
will port another original C code example for label to the new PROTO PRAGMA format maybe I will finally be able to add GTK to bacon code after all
PRAGMA LDFLAGS `pkg-config --libs gtk+-3.0` PRAGMA OPTIONS `pkg-config --cflags gtk+-3.0` PRAGMA COMPILER gcc
OPTION PARSE FALSE
' '--- set up for compiling embedded library GTK
'ported from http://www.cs.dartmouth.edu/~xy/cs23/gtk.html 'layout.c now call it layout-proto.bac by bigbass
'--- this replaces the need for IMPORT. the TYPE is not needed '--- place all the functions that you will use here
PROTO gtk_init PROTO gtk_window_new PROTO gtk_window_set_title PROTO gtk_window_set_position PROTO gtk_window_set_default_size PROTO gtk_label_new PROTO gtk_hbox_new PROTO gtk_box_pack_start PROTO gtk_container_add PROTO g_signal_connect_data, PROTO g gtk_widget_show_all PROTO gtk_main PROTO gtk_main_quit
' get the needed missing values GTK_WINDOW_TOPLEVEL = 0 GTK_WIN_POS_CENTER = 1
'=============== SUB exit_prog '=============== gtk_main_quit END SUB
gtk_init(0, 0)
window = gtk_window_new(GTK_WINDOW_TOPLEVEL) gtk_window_set_title(window, "Layout") gtk_window_set_position(window, GTK_WIN_POS_CENTER) gtk_window_set_default_size(window, 300, 200) g_signal_connect_data(window, "delete-event", exit_prog, 0, 0, 0) label1 = gtk_label_new("Label 1") label2 = gtk_label_new("Label 2") label3 = gtk_label_new("Label 3")
hbox = gtk_hbox_new(TRUE, 5) vbox = gtk_vbox_new(FALSE, 10)
gtk_box_pack_start(vbox, label1, TRUE, FALSE, 5) gtk_box_pack_start(vbox, label2, TRUE, FALSE, 5) gtk_box_pack_start(hbox, vbox, FALSE, FALSE, 5) gtk_box_pack_start(hbox, label3, FALSE, FALSE, 5)
gtk_container_add(window, hbox) gtk_widget_show_all(window) gtk_main
simplified and converted to the PROTO format removed the pointers
' '--- set up for compiling embedded library GTK PRAGMA LDFLAGS `pkg-config --cflags --libs gtk+-2.0`
'ported from http://www.cs.dartmouth.edu/~xy/cs23/gtk.html 'layout.c now call it layout-proto.bac by bigbass
'--- this replaces the need for IMPORT. the TYPE is not needed '--- place all the functions that you will use here
PROTO gtk_init PROTO gtk_window_new PROTO gtk_window_set_title PROTO gtk_window_set_position PROTO gtk_window_set_default_size PROTO gtk_label_new PROTO gtk_hbox_new PROTO gtk_box_pack_start PROTO gtk_container_add PROTO g_signal_connect_data, PROTO g gtk_widget_show_all PROTO gtk_main PROTO gtk_main_quit
' get the needed missing values GTK_WINDOW_TOPLEVEL = 0 GTK_WIN_POS_CENTER = 1
'=============== SUB exit_prog '=============== gtk_main_quit END SUB
gtk_init(0, 0)
window = gtk_window_new(GTK_WINDOW_TOPLEVEL) gtk_window_set_title(window, "Layout") gtk_window_set_position(window, GTK_WIN_POS_CENTER) gtk_window_set_default_size(window, 300, 200) g_signal_connect_data(window, "delete-event", exit_prog, 0, 0, 0) label1 = gtk_label_new("Label 1") label2 = gtk_label_new("Label 2") label3 = gtk_label_new("Label 3")
hbox = gtk_hbox_new(TRUE, 5) vbox = gtk_vbox_new(FALSE, 10)
gtk_box_pack_start(vbox, label1, TRUE, FALSE, 5) gtk_box_pack_start(vbox, label2, TRUE, FALSE, 5) gtk_box_pack_start(hbox, vbox, FALSE, FALSE, 5) gtk_box_pack_start(hbox, label3, FALSE, FALSE, 5)
gtk_container_add(window, hbox) gtk_widget_show_all(window) gtk_main
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Mar 29, 2013 20:53:09 GMT 1
Joe,
You may want to remove the C style ; end of statement terminator to give it a more BASIC like look.
John
|
|
|
Post by bigbass on Mar 30, 2013 7:48:00 GMT 1
Thanks jrs
I agree if its extra remove it I went back and edited the example removing the ;
Joe
|
|