|
Post by bigbass on May 3, 2013 17:43:40 GMT 1
This is the first example I used pointers and included the gtk.h the first time in about 20 examples (I hope to later convert it to pointer free code ) but that may take some time I am just happy it works as is PRAGMA LDFLAGS `pkg-config --cflags --libs gtk+-2.0` PRAGMA INCLUDE gtk-2.0/gtk/gtk.h
PROTO gtk_window_set_title PROTO gtk_box_pack_start PROTO gtk_container_add PROTO gtk_init PROTO gtk_main PROTO gtk_widget_show PROTO gtk_widget_show_all PROTO gtk_adjustment_new PROTO gtk_button_new_with_label PROTO gtk_hbox_new PROTO gtk_label_new PROTO gtk_spin_button_get_value_as_int PROTO gtk_spin_button_new PROTO gtk_window_new PROTO gtk_main_quit PROTO g_signal_connect_data PROTO gtk_window_set_default_size
GLOBAL *window TYPE GtkWidget GLOBAL *button TYPE GtkWidget GLOBAL *label TYPE GtkWidget GLOBAL *box TYPE GtkWidget GLOBAL *spin TYPE GtkWidget
GLOBAL *adjustment TYPE GtkObject
'============== SUB EXIT_PROG '============== gtk_main_quit END SUB
'============== SUB button_event '============== value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin)) PRINT value END SUB
gtk_init(0, 0) window = gtk_window_new(GTK_WINDOW_TOPLEVEL) gtk_window_set_default_size (GTK_WINDOW(window), 270, 50)
'---Connecting the clicked signal to the callback function g_signal_connect_data(window, "destroy", EXIT_PROG, 0, 0, 0)
box = gtk_hbox_new(FALSE, 0) gtk_container_add(GTK_CONTAINER(window), box)
adjustment = gtk_adjustment_new(2013, 1900, 2100, 1, 1, 0) spin = gtk_spin_button_new(GTK_ADJUSTMENT(adjustment), 0.5, 0) gtk_box_pack_start(GTK_BOX(box), spin, TRUE, TRUE, 5) gtk_widget_show(spin)
label = gtk_label_new("year") gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0) gtk_widget_show(label)
button = gtk_button_new_with_label("button") gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0)
g_signal_connect_data(button, "clicked", button_event, 0, 0, 0) gtk_widget_show(button)
gtk_widget_show(box) gtk_widget_show(window)
gtk_main
|
|
|
Post by vovchik on May 3, 2013 17:57:06 GMT 1
Dear Joe, Nice job - and it works Thanks and kind regards, vovchik
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on May 3, 2013 20:33:02 GMT 1
Keep this up Joe and you will be considered as competition by the IUP project. ;D
|
|
|
Post by bigbass on May 4, 2013 7:22:41 GMT 1
original code ported and modified developer.gnome.org/gnome-devel-demos/stable/spinbutton.c.html.enWe need more GTK3 examples for BaCon there are still many more to convertand adjust the buttons are different and the code too for this widget I got the value by pressing enter because the default way gave a value every time you adjusted the numbers @jrs we can modify the widgets add/remove stuff or make custom widgets I see this as extending the options and a great test of the compiler ! It amazes me when it finally compiles without warnings or errors PRAGMA LDFLAGS `pkg-config --cflags --libs gtk+-3.0` PRAGMA INCLUDE gtk-3.0/gtk/gtk.h
PROTO gtk_label_set_text PROTO gtk_container_add PROTO gtk_container_set_border_width PROTO gtk_grid_attach PROTO gtk_grid_set_column_homogeneous PROTO gtk_grid_set_column_spacing PROTO gtk_widget_set_hexpand PROTO gtk_widget_show_all PROTO gtk_window_set_default_size PROTO gtk_window_set_title PROTO gtk_adjustment_new PROTO gtk_application_new PROTO gtk_window_new PROTO gtk_grid_new PROTO gtk_label_new PROTO gtk_spin_button_get_value_as_int PROTO gtk_spin_button_new PROTO gtk_init PROTO gtk_main PROTO g_signal_connect_data PROTO gtk_main_quit
'--- Declare variables GLOBAL *window TYPE GtkWidget GLOBAL *label TYPE GtkWidget GLOBAL *grid TYPE GtkWidget GLOBAL *spin_button TYPE GtkWidget GLOBAL *adjustment TYPE GtkAdjustment
'============== SUB EXIT_PROG '============== gtk_main_quit END SUB
'--- This is the callback function. '--- It is a handler function which reacts to the signal. '--- In this case, it will notify the user the value of their spinbutton '============== SUB spin_clicked '============== value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spin_button)) PRINT value END SUB
gtk_init(0, 0)
'--- Create a window with a title, a border width, and a default size window = gtk_window_new(GTK_WINDOW_TOPLEVEL) gtk_window_set_title (GTK_WINDOW (window), "SpinButton Example") gtk_window_set_default_size (GTK_WINDOW (window), 270, 70) gtk_container_set_border_width (GTK_CONTAINER (window), 5)
'---Connecting the clicked signal to the callback function g_signal_connect_data(window, "destroy", EXIT_PROG, 0, 0, 0)
'--- Create a label to be shown in the window label = gtk_label_new ("Press enter to get the value")
'--- Create an adjustment representing an adjustable bounded value adjustment = gtk_adjustment_new (0, 0, 100, 1, 0, 0)
'--- Create a spin button that is to be as wide as possible spin_button = gtk_spin_button_new (adjustment, 1, 0) gtk_widget_set_hexpand (spin_button, TRUE)
'--- Connecting the "value-changed" signal for the spinbutton '--- to the appropriate callback function. g_signal_connect_data(spin_button, "activate", spin_clicked, 0, 0, 0)
'--- Create a grid and arrange everything accordingly grid = gtk_grid_new () gtk_grid_set_column_spacing (GTK_GRID (grid), 10) gtk_grid_set_column_homogeneous (GTK_GRID (grid), TRUE) gtk_grid_attach (GTK_GRID (grid), spin_button, 0, 0, 1, 1) gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1)
gtk_container_add (GTK_CONTAINER (window), grid) gtk_widget_show_all (window) gtk_main
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on May 5, 2013 4:19:16 GMT 1
That's the best part of any proof of concept project, seeing it work.
|
|
|
Post by bigbass on May 6, 2013 17:36:12 GMT 1
this is the file chooser in GTK3 no pointers or gtk.h that removes casting to keep everything as stand alone code for the button selections connecting to the callbacks had to use exit (1) to close app because in gtk3 gtk_exit is old code and doesnt work official GTK3 code ported and modified for PROTO *original code was incomplete* developer.gnome.org/gtk3/3.0/GtkFileChooserDialog.htmlthis will give us more widgets for BaCon ! PRAGMA LDFLAGS pkg-config --cflags --libs gtk+-3.0
PROTO gtk_file_chooser_dialog_new PROTO gtk_dialog_run PROTO gtk_file_chooser_get_filename PROTO gtk_widget_destroy PROTO gtk_init PROTO gtk_main PROTO g_signal_connect_data PROTO gtk_main_quit PROTO exit
'--- low level button signals CONST GTK_RESPONSE_OK = -5 CONST GTK_RESPONSE_CANCEL = -6 CONST GTK_RESPONSE_CLOSE = -7 CONST GTK_RESPONSE_DELETE_EVENT = -4 CONST GTK_RESPONSE_ACCEPT = -3 CONST GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER = 3 CONST GTK_FILE_CHOOSER_ACTION_OPEN = 0 CONST GTK_FILE_CHOOSER_ACTION_SAVE = 1 CONST GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER = 2 CONST GTK_STOCK_CANCEL = "gtk-cancel" CONST GTK_STOCK_OPEN = "gtk-open"
'===================== SUB exit_prog '=====================
PRINT "HERE" exit (1) gtk_main_quit END SUB
'===================== SUB file_ok_sel() '===================== '--- Get the selected filename and print it to the console
PRINT "you got to the call back file_ok_sel" filename$ =(char *) gtk_file_chooser_get_filename (dialog) PRINT filename$ END SUB
gtk_init (0, 0)
dialog = gtk_file_chooser_dialog_new ("Open File", \ dialog, \ GTK_FILE_CHOOSER_ACTION_OPEN, \ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, \ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, \ NULL)
'--- GTK_RESPONSE_ACCEPT '--- major work around to connect buttons using the reponses '--- after a modified callback using just the callback name
IF gtk_dialog_run(dialog) = GTK_RESPONSE_ACCEPT THEN filename = gtk_file_chooser_get_filename (dialog) PRINT "The low level OK button was pressed " file_ok_sel END IF
'--- GTK_RESPONSE_CANCEL '--- major work around to connect buttons using the reponses '--- after a modified callback using just the callback name IF gtk_dialog_run(dialog ) = GTK_RESPONSE_CANCEL THEN PRINT "The low level CANCEL button was pressed " PRINT "close main window" exit_prog END IF
g_signal_connect_data(dialog, "destroy", exit_prog, 0, 0, 0)
gtk_widget_destroy (dialog) gtk_main
PRINT "The top level window of the application was closed...Exiting the program"
|
|
|
Post by bigbass on May 14, 2013 16:11:05 GMT 1
how to connect the signals to the low level ok button and cancel button that is built in the main GTK C code using PROTO and no pointers it is a workaround but works! This may seem strange at first but it will make sense when you try to connect any signals this produces clean stand alone code for each widget and as an added advantage you see whats happening at every point in the code without any wrappers UPDATE added vovchik's gtk_exit sub to close cleanly in gtk2 note gtk3 has a different way to close cleanly fsel-gtk2-proto.bac
PRAGMA LDFLAGS pkg-config --cflags --libs gtk+-2.0
PROTO gtk_file_selection_set_filename PROTO gtk_init PROTO gtk_main PROTO gtk_widget_show PROTO gtk_file_selection_new PROTO g_signal_connect_data PROTO gtk_main_quit PROTO gtk_dialog_run PROTO gtk_widget_destroy PROTO g_timeout_add PROTO gtk_exit
'--- low level button signals CONST GTK_RESPONSE_OK = -5 CONST GTK_RESPONSE_CANCEL = -6 CONST GTK_RESPONSE_CLOSE = -7 CONST GTK_RESPONSE_DELETE_EVENT = -4
'===================== SUB exit_prog() '=====================
PRINT "HERE" gtk_exit(0) END SUB
'===================== SUB file_ok_sel() '===================== '--- Get the selected filename and print it to the console
PRINT "you got to the call back file_ok_sel" selected$ = (char *)gtk_file_selection_get_filename (filew) PRINT selected$ END SUB
gtk_init (0, 0)
'--- Create a new file selection widget filew = gtk_file_selection_new ("File selection")
'--- Lets set the filename, as if this were a save dialog, and we are giving a default filename gtk_file_selection_set_filename (filew, "penguin.png")
'--- GTK_RESPONSE_OK '--- major work around to connect buttons using the reponses '--- after a modified callback using just the callback name IF gtk_dialog_run(filew ) = GTK_RESPONSE_OK THEN PRINT "The low level OK button was pressed " file_ok_sel END IF
'--- GTK_RESPONSE_CANCEL '--- major work around to connect buttons using the reponses '--- after a modified callback using just the callback name IF gtk_dialog_run(filew ) = GTK_RESPONSE_CANCEL THEN PRINT "The low level CANCEL button was pressed " PRINT "close main window" exit_prog END IF
g_signal_connect_data(filew, "destroy", exit_prog, 0, 0, 0)
gtk_widget_show (filew) gtk_main
PRINT "The top level window of the application was closed...Exiting the program"
|
|
|
Post by bigbass on May 15, 2013 18:01:39 GMT 1
I am going to post this GTK3 slider demo even though the call back doesnt yet display the changing numbers it is still a good example of the C code converted to PROTO developer.gnome.org/gnome-devel-demos/3.6/scale.c.html.en*any help with the call back to display the numbers is welcomed this works without the numbers displaying in the terminal
PRAGMA LDFLAGS `pkg-config --cflags --libs gtk+-3.0` PRAGMA INCLUDE gtk-3.0/gtk/gtk.h
PROTO gtk_label_set_text PROTO gtk_container_add PROTO gtk_container_set_border_width PROTO gtk_grid_attach PROTO gtk_grid_set_column_homogeneous PROTO gtk_grid_set_column_spacing PROTO gtk_scale_set_digits PROTO gtk_widget_set_hexpand PROTO gtk_widget_set_valign PROTO gtk_widget_set_vexpand PROTO gtk_widget_show_all PROTO gtk_window_set_default_size PROTO gtk_window_set_title PROTO gtk_adjustment_new PROTO gtk_application_new PROTO gtk_window_new PROTO gtk_grid_new PROTO gtk_label_new PROTO gtk_range_get_value PROTO gtk_scale_new
'--- added after PROTO gtk_init PROTO gtk_main PROTO g_signal_connect_data PROTO gtk_main_quit PROTO gtk_scale_get_value_pos PROTO gtk_range_get_value
'--- This is the second callback function. It is a handler function which '--- reacts to the signal. It does the same thing as the function above, except with '--- the vertical scale.
'============== SUB vscale_moved () '============== PRINT "there" END SUB
'============== SUB hscale_moved () '============== PRINT "here" END SUB
'--- Declare variables GLOBAL *window TYPE GtkWidget GLOBAL *h_scale TYPE GtkWidget GLOBAL *v_scale TYPE GtkWidget GLOBAL *hlabel TYPE GtkWidget GLOBAL *vlabel TYPE GtkWidget GLOBAL *grid TYPE GtkWidget
GLOBAL *scale TYPE GtkPositionType GLOBAL *pos TYPE GtkPositionType
'--- The Adjustment object represents a value '--- which has an associated lower and upper bound. GLOBAL *hadjustment TYPE GtkAdjustment GLOBAL *vadjustment TYPE GtkAdjustment
'============== SUB EXIT_PROG '============== gtk_main_quit END SUB
gtk_init(0, 0)
'--- Create a window with a title and a default size window = gtk_window_new (0) gtk_window_set_title (GTK_WINDOW (window), "Scale Example") gtk_window_set_default_size (GTK_WINDOW (window), 400, 300) gtk_container_set_border_width (GTK_CONTAINER (window), 5) '---Connecting the clicked signal to the callback function g_signal_connect_data(window, "destroy", EXIT_PROG, 0, 0, 0)
'--- Two labels to be shown in the window hlabel = gtk_label_new ("Move the scale handle...") vlabel = gtk_label_new ("Move the scale handle...")
'--- gtk_adjustment_new takes six parameters, three of which '--- may be difficult to understand: '--- step increment- move the handle with the arrow keys on your keyboard to see. '--- page increment - move the handle by clicking away from it '--- on the scale to see. '--- page size - not used here.
hadjustment = gtk_adjustment_new (0, 0, 100, 5, 10, 0) vadjustment = gtk_adjustment_new (50, 0, 100, 5, 10, 0)
'--- Create the Horizontal scale, making sure the '---digits used have no decimals.
h_scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, hadjustment) gtk_scale_set_digits (GTK_SCALE (h_scale), 0)
'--- Allow it to expand horizontally (if there's space), and '--- set the vertical alignment
gtk_widget_set_hexpand (h_scale, TRUE) gtk_widget_set_valign (h_scale, GTK_ALIGN_START)
'--- Connecting the "value-changed" signal for the horizontal scale '--- to the appropriate callback function. '---take note that GtkRange is part of GtkScale's Object Hierarchy.
g_signal_connect_data (h_scale, "value-changed", hscale_moved, 0, 0, 0)
'--- Create the Vertical scale. This time, we will see what happens '--- when the digits arent initially set.
v_scale = gtk_scale_new (GTK_ORIENTATION_VERTICAL, vadjustment)
gtk_widget_set_vexpand (v_scale, TRUE)
'--- Connecting the "value-changed" signal for the vertical scale to '--- the appropriate callback function.
g_signal_connect_data (v_scale, "value-changed", vscale_moved, 0, 0, 0)
'--- Create a grid and arrange everything accordingly grid = gtk_grid_new () gtk_grid_set_column_spacing (GTK_GRID (grid), 10) gtk_grid_set_column_homogeneous (GTK_GRID (grid), TRUE) gtk_grid_attach (GTK_GRID (grid), h_scale, 0, 0, 1, 1) gtk_grid_attach (GTK_GRID (grid), v_scale, 1, 0, 1, 1) gtk_grid_attach (GTK_GRID (grid), hlabel, 0, 1, 1, 1) gtk_grid_attach (GTK_GRID (grid), vlabel, 1, 1, 1, 1)
gtk_container_add (GTK_CONTAINER (window), grid)
gtk_widget_show_all (window)
gtk_main
|
|
|
Post by bigbass on May 16, 2013 15:56:34 GMT 1
I found this simplified slider example that works in C but when I convert I get the same problem of not seeing the values change in the terminal I wasnt lazy I did convert this to PROTO below
I think that since its an easier example it might make sense to someone else why the value doesnt display have a feeling its a declaring type problem for value
#include <gtk/gtk.h>
static gboolean cb_change_value( GtkRange *range, GtkScrollType scroll, gdouble value, gpointer data ) { g_message( "VALUE UPDATE: %f", value ); return( FALSE ); }
static gboolean cb_update_pos( GtkRange *range ) { static gint direction = 1; gdouble value;
value = gtk_range_get_value( range ); if( ( value + direction ) > 100 ) direction = -1; else if( ( value + direction ) < 0 ) direction = 1;
gtk_range_set_value( range, value + direction );
return( TRUE ); }
int main( int argc, char **argv ) { GtkWidget *window, *scale;
gtk_init( &argc, &argv );
window = gtk_window_new( GTK_WINDOW_TOPLEVEL ); gtk_window_set_default_size( GTK_WINDOW( window ), 300, 100 ); g_signal_connect( G_OBJECT( window ), "destroy", G_CALLBACK( gtk_main_quit ), NULL );
scale = gtk_hscale_new_with_range( 0, 100, 1 ); g_signal_connect( G_OBJECT( scale ), "change-value", G_CALLBACK( cb_change_value ), NULL ); gtk_container_add( GTK_CONTAINER( window ), scale );
gtk_widget_show_all( window );
gtk_main();
return( 0 ); }
PRAGMA LDFLAGS `pkg-config --cflags --libs gtk+-2.0` PRAGMA INCLUDE gtk-2.0/gtk/gtk.h
PROTO gtk_container_add PROTO gtk_init PROTO gtk_main PROTO gtk_range_set_value PROTO gtk_widget_show_all PROTO gtk_window_set_default_size PROTO gtk_hscale_new_with_range PROTO gtk_range_get_value PROTO gtk_window_new PROTO gtk_main_quit PROTO g_signal_connect_data
PROTO g_message
DECLARE *window TYPE GtkWidget DECLARE *scale TYPE GtkWidget DECLARE *range TYPE GtkRange DECLARE scroll TYPE GtkScrollType DECLARE value TYPE gdouble DECLARE data TYPE gpointer
'============== SUB EXIT_PROG '============== gtk_main_quit END SUB
SUB cb_change_value
g_message( "VALUE UPDATE: %f", value )
PRINT value END SUB
SUB cb_update_pos()
direction = 1 value = gtk_range_get_value( range ) IF ( ( value + direction ) > 100 ) THEN direction = -1 END IF IF ( (value + direction ) < 0 ) THEN direction = 1 END IF
gtk_range_set_value( range, value + direction )
END SUB gtk_init( 0, 0 )
window = gtk_window_new( GTK_WINDOW_TOPLEVEL ) gtk_window_set_default_size( GTK_WINDOW( window ), 300, 100 ) '---Connecting the clicked signal to the callback function g_signal_connect_data(window, "destroy", EXIT_PROG, 0, 0, 0)
scale = gtk_hscale_new_with_range( 0, 100, 1 )
g_signal_connect_data ( scale, "change-value", cb_change_value , 0, 0,0) gtk_container_add( GTK_CONTAINER( window ), scale )
gtk_widget_show_all( window )
gtk_main
|
|
|
Post by alexfish on May 16, 2013 20:28:36 GMT 1
Hi Joe
Have look at your code , tried to set values TYPE of slider to double /
but get problem getting the values , so at a loss
HUG works so decided to get old demo from main site
here have added a slider and the bits to
Do not know if this will help
but it does work , so I be mystified why proto not working
Can U try and replicate this in proto
REM REM GTK example with BACON REM March 2009 - PvE. REM Adapted November 2009. adapted for Hscale 2013 REM TRAP LOCAL CATCH GOTO print_error
CONST Gtk$ = "libgtk-x11-2.0.so.0" CONST Gobject$ = "libgobject-2.0.so.0"
REM Get needed functions from GTK 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_table_attach_defaults(long,long,int,int,int,int)" FROM Gtk$ TYPE void IMPORT "gtk_container_add(long,long)" FROM Gtk$ TYPE void IMPORT "gtk_button_new_from_stock(char*)" FROM Gtk$ TYPE long IMPORT "gtk_label_new(char*)" FROM Gtk$ TYPE long IMPORT "gtk_widget_show_all(long)" FROM Gtk$ TYPE void IMPORT "gtk_hscale_new_with_range(double,double,double)" FROM Gtk$ TYPE long IMPORT "gtk_range_get_value(long)" FROM Gtk$ TYPE double
IMPORT "gtk_main" FROM Gtk$ TYPE void IMPORT "gtk_exit(int)" FROM Gtk$ TYPE void IMPORT "g_signal_connect_data(long,char*,long,long,long,int)" FROM Gobject$ TYPE void REM Callback for closing window SUB exit_prog gtk_exit(0) ENDSUB
SUB Changed LOCAL get get = gtk_range_get_value( Hscale ) PRINT " CHANGED ",get END SUB
REM 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) Hscale=gtk_hscale_new_with_range(0,1000,1) gtk_table_attach_defaults(table,Hscale, 1, 14, 3, 14) g_signal_connect_data( Hscale, "value-changed", ADDRESS(Changed) ,0, 0, 0)
button = gtk_button_new_from_stock("gtk-quit") gtk_table_attach_defaults(table, button, 10, 14, 12, 14)
REM Show whole GUI gtk_widget_show_all(window)
REM Use as callback the defined SUB g_signal_connect_data(window, "delete-event", ADDRESS(exit_prog), 0, 0, 0) g_signal_connect_data(button, "clicked", ADDRESS(exit_prog), 0, 0, 0)
REM Endless event handling by GTK gtk_main
REM Error handling LABEL print_error PRINT "GTK library ", Gtk$, " is not available on this platform!" END
BR
Alex
PS : if find a solution before , will post it
ADDED : may be able to pass values with ?
Hscale=gtk_hscale_new_with_range((double)0,(double)1000,(double)1)
ADD:: tidy up format
|
|
|
Post by vovchik on May 16, 2013 20:39:43 GMT 1
|
|
|
Post by bigbass on May 17, 2013 16:50:39 GMT 1
Hey alexfish a very big thank you ! alexfish thanks for posting the slider example in HUG it is very useful and I was able to convert it to PROTO /PRAGMA/ IMPORT this seems like the cleanest way since we don't redeclare anything using PROTO PRAGMA and when we have some sticky problems lets say with low level pointers we can redeclare them as a different type using IMPORT notice this time pointer free and ADDRESS isn't needed We still may be able to figure this out in PROTO later after seeing where it chokes and why so its a marriage now using the strength of both (PROTO and IMPORT) as a team *the button call back needs work but I have a lot of work today will fix it tonight or if you beat me to it [smiling] PRAGMA LDFLAGS `pkg-config --cflags --libs gtk+-2.0`
'--- '--- GTK example with BACON '--- March 2009 - PvE. '--- Adapted November 2009. adapted for Hscale 2013 alexfish '--- Ported to PROTO/PRAGMA/IMPORT syntax 2013 bigbass
'--- Get needed functions from GTK
PROTO gtk_table_attach_defaults PROTO gtk_window_set_title PROTO gtk_button_new_from_stock 'PROTO gtk_range_get_value PROTO gtk_table_new PROTO gtk_window_new PROTO gtk_container_add PROTO gtk_exit 'PROTO gtk_hscale_new_with_range PROTO gtk_init PROTO gtk_label_new PROTO gtk_widget_show_all PROTO gtk_main
PROTO g_signal_connect_data
'---------------------------------------------------- ' get around low level pointers USING IMPORT '---------------------------------------------------- CONST Gtk$ = "libgtk-x11-2.0.so.0" CONST Gobject$ = "libgobject-2.0.so.0"
'-- Get needed functions from GTK using IMPORT IMPORT "gtk_hscale_new_with_range(double,double,double)" FROM Gtk$ TYPE long IMPORT "gtk_range_get_value(long)" FROM Gtk$ TYPE double
'----------------------------------------------------
'--- Callback for closing window SUB exit_prog gtk_exit(0) PRINT "QUIT" END SUB
SUB Changed LOCAL get get = gtk_range_get_value( Hscale ) PRINT " CHANGED ",get 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) Hscale = gtk_hscale_new_with_range(0,1000,1) gtk_table_attach_defaults(table,Hscale, 1, 14, 3, 14) g_signal_connect_data( Hscale, "value-changed", Changed ,0, 0, 0)
button = gtk_button_new_from_stock("gtk-quit") gtk_table_attach_defaults(table, button, 10, 14, 12, 14)
'--- Show whole GUI gtk_widget_show_all(window)
'--- Use as callback the defined SUB g_signal_connect_data(window, "delete-event", exit_prog, 0, 0, 0) g_signal_connect_data(button, "clicked", exit_prog, 0, 0, 0)
gtk_main
|
|
|
Post by bigbass on May 17, 2013 17:30:38 GMT 1
Hey vovchik
WOW ! thats some HEAVY lifting converting goo canvas to PROTO /PRAGMA a fine example I will add it to the examples page !
a lot of good PROTO examples are there in the code you posted for goo how to get the needed values and pointer types to make it all work *Will have to take some time to study that one
Joe
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on May 17, 2013 18:35:29 GMT 1
Joe,
Sounds like the PROTO team is making good progress on all fronts. I'm still somewhat confused about when someone would use this method of Gtk programming rather than using HUG. I'm assuming the advantage is that the PROTO snippets are actually working encapsulated widgets you can plug into your application rather than including the HUG library.
Thanks for any clarification you can offer.
John
|
|
|
Post by bigbass on May 18, 2013 7:43:30 GMT 1
Hey jrs
I guess for a general statement HUG is the default official way to use a GUI in BaCon to allow for the simplified "basic look" syntax for the end user this is the goal Peter maintains HUG to keep it stable and easy to use
I ran out of widget examples to add to the HUG tutorial so PROTO allowed for me to test some new ideas for widgets
what comes to mind when I think of PROTO is just that a way to proto type ideas and make special widgets that are not part of HUG yet the code looks like GTK but without the casting and pointers most of the time the functions use the original intent of GTK without redefining any TYPES this may be nice for those that want to Port / convert code to BaCon quickly and it is nice to see what is happening all in one place coding in one way is easier because there is a lot of GTK code out there and at the same time a bit ugly because it looks like GTK
this can also be a pre step to proto type ideas that may get added in HUG at a later time
I guess the only way to define is there are many ways to get a result BaCon is flexible , powerful and fun I like doing widgets Joe
|
|