|
Post by bigbass on May 18, 2013 8:11:13 GMT 1
scale-gtk2-proto.bacall callbacks are working now just had to switch the order of the attach statements 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"
'-- 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 PRINT "QUIT" gtk_exit(0) 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, "scale PROTO") table = gtk_table_new(15, 15, 1) gtk_container_add(window, table) Hscale = gtk_hscale_new_with_range(0,1000,1)
button = gtk_button_new_from_stock("gtk-quit")
gtk_table_attach_defaults(table, button, 10, 14, 12, 14) gtk_table_attach_defaults(table,Hscale, 1, 14, 3, 14)
'--- Use as callback the defined SUB g_signal_connect_data(button, "clicked",exit_prog, 0, 0, 0) g_signal_connect_data(Hscale, "value-changed", Changed ,0, 0, 0) g_signal_connect_data(window, "delete-event", exit_prog, 0, 0, 0)
'--- Show whole GUI gtk_widget_show_all(window)
gtk_main
|
|
|
Post by bigbass on May 18, 2013 19:45:08 GMT 1
scrolled-gtk3-proto.bachaving many widgets as stand alone code makes it easy to add when needed Joe replaced outdated code gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), image)
gtk_container_add(GTK_CONTAINER (scrolled_window), image)
PRAGMA OPTIONS `pkg-config --cflags gtk+-3.0` PRAGMA LDFLAGS `pkg-config --libs gtk+-3.0` PRAGMA INCLUDE gtk-3.0/gtk/gtk.h
'image used 'http://bigbass-porteus.googlecode.com/files/images.jpeg
PROTO gtk_container_add PROTO gtk_container_set_border_width PROTO gtk_scrolled_window_add_with_viewport PROTO gtk_scrolled_window_set_policy PROTO gtk_widget_show_all PROTO gtk_window_set_default_size PROTO gtk_window_set_title PROTO gtk_image_new_from_file PROTO gtk_scrolled_window_new PROTO gtk_window_new
PROTO gtk_init PROTO gtk_main PROTO g_signal_connect_data PROTO gtk_main_quit
'--- Declare variables DECLARE *window, *scrolled_window, *image TYPE GtkWidget
'===================== 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), "Scrolled Window Example") gtk_window_set_default_size (GTK_WINDOW (window), 230, 200) g_signal_connect_data(window, "delete-event", exit_prog, 0, 0, 0)
'--- Create the scrolled window. Usually 0 is passed for both parameters so '--- that it creates the horizontal/vertical adjustments automatically. Setting '--- the scrollbar policy to automatic allows the scrollbars to only show up '--- when needed.
scrolled_window = gtk_scrolled_window_new (0, 0) '--- Set the border width gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 10) '--- Extract our desired image from a file that we have image = gtk_image_new_from_file ("images.jpeg") '--- And add it to the scrolled window gtk_container_add(GTK_CONTAINER (scrolled_window), image) '--- Set the policy of the horizontal and vertical scrollbars to automatic. '--- What this means is that the scrollbars are only present if needed.
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), \ GTK_POLICY_AUTOMATIC, \ GTK_POLICY_AUTOMATIC)
gtk_container_add (GTK_CONTAINER (window), scrolled_window)
gtk_widget_show_all (window)
gtk_main
|
|
|
Post by bigbass on May 19, 2013 7:49:08 GMT 1
This gets "any key " pressed in the window to the terminal
very interesting many apps can use this feature easily
simple but does the job
look at this line we can do stuff like that in PROTO g_printerr("%s\n", gdk_keyval_name (event->keyval))
UPDATED to show key press in the title
keypress-proto.bac
PRAGMA LDFLAGS `pkg-config --cflags --libs gtk+-2.0` PRAGMA INCLUDE gtk-2.0/gtk/gtk.h
'--- GTK PROTO gtk_init PROTO gtk_main PROTO gtk_widget_show PROTO gtk_window_new PROTO gtk_exit PROTO gtk_window_set_title
'---extras PROTO g_signal_connect_data PROTO g_printerr
'--- GDK PROTO gdk_keyval_name
'--- Declare variables DECLARE *window TYPE GtkWidget DECLARE *event TYPE GdkEventKey
FUNCTION key_event(GtkWidget *widget, GdkEventKey *event)
g_printerr("%s\n", gdk_keyval_name (event->keyval)) keypressed$ = gdk_keyval_name (event->keyval) gtk_window_set_title(GTK_WINDOW(window), keypressed$ ) RETURN FALSE END FUNCTION
'--- Callback for closing window SUB exit_prog PRINT "QUIT" gtk_exit(0) END SUB
gtk_init (0, 0) window = gtk_window_new (GTK_WINDOW_TOPLEVEL) gtk_window_set_title(GTK_WINDOW(window), "get key press")
'--- Use as callback the defined SUB/FUNCTIONS g_signal_connect_data(window, "delete-event", exit_prog, 0, 0, 0) g_signal_connect_data(window, "key-release-event", G_CALLBACK(key_event) ,0, 0, 0) gtk_widget_show (window) gtk_main
|
|
|
Post by alexfish on May 19, 2013 8:41:21 GMT 1
Hi Joe
Tremendous , just what we need
+ a most welcome addition for Goo Canvas
BR Alex
|
|
|
Post by alexfish on May 23, 2013 6:37:10 GMT 1
Hi Joe
Had another look at this GTK-3 scale with adjustment
The best I came up with is this , use the IMPORT instead line PROTO
'PROTO gtk_adjustment_get_value IMPORT gtk_adjustment_get_value FROM "libgtk-3.so" TYPE double
Then set the adjustments with the doubles like so
Hscale_adjustment = gtk_adjustment_new((double)10,(double)0,(double)100,(double)5,(double)10,(double)0)
then to get the values Example of the sub
SUB get_bits LOCAL val TYPE double val=gtk_adjustment_get_value(Hscale_adjustment) PRINT val END SUB
Note this will return a value with a decimal place so will have to make the adjusments a per the c code example.
Think possible to look at the PROPERTIES settings for the ADJUSTMENT . then see if can refine what is returned by the values
AGH! think just found it
PROTO gtk_scale_set_digits
gtk_scale_set_digits(Hscale,0)
HTH
Alex
|
|
|
Post by bigbass on May 23, 2013 15:54:04 GMT 1
Hey alex that was brilliant getting the callbacks to work for the gtk3 slider ! I made some small adjustments" just for having a widget example " following the gnome example but not exactly Yes ,It is better to have digits and I made the vscale start at 0 also *some tech notes only. IMPORT wasn't needed but the call back you did will work with just PROTO Thank you very much for your help alex Joe 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
PROTO gtk_scale_set_digits PROTO gtk_adjustment_get_value
'--- 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 *Hscale_adjustment TYPE GtkAdjustment GLOBAL *Vscale_adjustment TYPE GtkAdjustment
'--- This is the callback function. It is a handler function which '--- reacts to the signal. with hscale and vscale
'============== SUB get_bits_hscale '============== LOCAL val TYPE double val=gtk_adjustment_get_value(Hscale_adjustment) PRINT val END SUB
'============== SUB get_bits_vscale '============== LOCAL val TYPE double val=gtk_adjustment_get_value(Vscale_adjustment) PRINT val END SUB
'============== 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 GTK3") 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.
Hscale_adjustment = gtk_adjustment_new((double)0,(double)0,(double)100,(double)5,(double)10,(double)0)
Vscale_adjustment = gtk_adjustment_new((double)0,(double)0,(double)100,(double)5,(double)10,(double)0)
'--- Create the Horizontal scale, making sure the '---digits used have no decimals.
h_scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, Hscale_adjustment) 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", get_bits_hscale, 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, Vscale_adjustment) gtk_scale_set_digits (GTK_SCALE (v_scale), 0)
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", get_bits_vscale, 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 alexfish on May 23, 2013 19:11:21 GMT 1
Hi Joe
Well done , also had quick glance of the code .. ' NO IMPORT ' in site
Think this Important , I am Logging this one , also hope to see it on your Site ,just in case I lose it ;D
BR
Alex
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on May 23, 2013 22:54:48 GMT 1
If these Gtk functions were given a dummy return value, you wouldn't have to use PROTO to define them. Just saying ...
|
|
|
Post by bigbass on May 24, 2013 15:33:40 GMT 1
Hey Alex
almost there .... I reworked the gtk2 example and removed one more IMPORT still one to go to be IMPORT free , pointer free and gtk.h free which makes for more portable code
I used your idea of getting the double and it worked here too Hscale = gtk_hscale_new_with_range((double)0,(double)1000,(double)1)
the problem "might be" with getting the type declared correctly as a double or still something else I can't see at the moment
could you try and remove the last IMPORT
@ or anyone else that likes a challenge
maybe to define a little bit clearer I am focusing on using the power of The BaCon compiler and using all the BaCon commands with gtk cleanly embedded (when possible)
cleanly = meaning in loose terms no pointers no re importing the function again and having the declares in plain view all of this (*when possible*) I am happy with just working code but example code looks nicer without mix and match
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" 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 TYPE double get = gtk_range_get_value(Hscale) PRINT get END SUB
'--- Main program starts here gtk_init(0, 0)
window = gtk_window_new(0)
gtk_window_set_title(window, "GTK2 slider") table = gtk_table_new(15, 15, 1) gtk_container_add(window, table)
Hscale = gtk_hscale_new_with_range((double)0,(double)1000,(double)1)
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) gtk_table_attach_defaults(table,Hscale, 1, 14, 3, 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 26, 2013 0:46:31 GMT 1
Well what if you like HUG looking syntax but you coded in PROTO It is documented but wasn't used like this before look carefully at the code what is it ? it was just a fun test example using ALIAS proto-alias.bac PRAGMA LDFLAGS `pkg-config --cflags --libs gtk+-3.0`
PROTO "gtk_init" ALIAS START PROTO "gtk_window_new" ALIAS WINDOW PROTO gtk_main_quit PROTO "g_signal_connect_data" ALIAS CALLBACK PROTO "gtk_main" ALIAS DISPLAY PROTO "gtk_container_add" ALIAS CONTAINER_ADD PROTO "gtk_container_set_border_width" ALIAS CONTAINER_BORDER PROTO "gtk_widget_show_all" ALIAS SHOW_ALL PROTO "gtk_window_set_default_size" ALIAS WINDOW_SIZE PROTO "gtk_window_set_title" ALIAS TITLE PROTO "gtk_entry_get_text" ALIAS GET PROTO "gtk_entry_new" ALIAS ENTRY
'======================= 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 grab the '---text input from the entry box and print out a line to the user. '---when you press enter
'======================= SUB on_activate '======================= name$ = (char *)GET(entry_box) PRINT name$ END SUB
START(0, 0)
'---Create a window with a title, a default size, '---and a set border width
window = WINDOW () TITLE (window, "To get the entry press enter") WINDOW_SIZE(window, 350, 100) CONTAINER_BORDER (window, 10) CALLBACK(window, "destroy", EXIT_PROG, 0, 0, 0)
'---Create a new entry box, and add it to the window entry_box = ENTRY () CONTAINER_ADD(window, entry_box)
'---Connecting the activate signal to the callback CALLBACK (entry_box, "activate", on_activate,0,0,0)
SHOW_ALL (window) DISPLAY
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on May 26, 2013 6:33:02 GMT 1
Joe,
I like the direction your going with ALIAS. If you can wrap that concept into an INCLUDE file, working with Gtk and BaCon could be less of a chore.
John
|
|
|
Post by vovchik on May 26, 2013 9:49:09 GMT 1
Dear Joe,
That was simple and brilliant...and opens up lots of possibilities. Great that you experimented!
With kind regards, vovchik
|
|
|
Post by vovchik on May 26, 2013 18:03:45 GMT 1
Coudn't help myself. Here is a little pdf viewer (less than 10k UPX'd), source and a demo pdf that makes use of Joe's ALIASes and libpoppler. You need to pass the pdf's full filespec to the viewer to see it run, because the program wants the full file name and you might be running it as bpdf-alias dobedobe1.pdf. To use a short filespec - e.g. dobedobedo1.pdf, it will run properly using the attached script. Have fun, vovchik PS. Maybe somebody wants to add zoom, page forwards and backwards and print features? Attachments:
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on May 26, 2013 19:25:45 GMT 1
I get the following error trying to run the example on Ubuntu 12.04 64 bit.
jrs@laptop:~/BaCon/V2B1/bpdf_alias$ ./bpdf-alias dobedobe1.pdf ./bpdf-alias: error while loading shared libraries: libpoppler-glib.so.4: cannot open shared object file: No such file or directory jrs@laptop:~/BaCon/V2B1/bpdf_alias$
|
|
|
Post by vovchik on May 26, 2013 19:37:26 GMT 1
Dear jrs, I am still running 32-bit although I have a quad-core (you figure). My pkg-config obviously points to libpoppler-glib.so.4, so you should have something pointing to libpoppler somewhere (which comes in 32 and 64-bit versions) if it is indeed installed, and, if so, then try making a symlink to xxx.so.4 and see what happens.... With kind regards, vovchik
|
|