|
Post by ptitjoz on Jun 10, 2018 21:43:46 GMT 1
Hello how to make a CALLBACK on a Label?
I'm currently using this strategy but I do not think it's the best solution.
INCLUDE "./../Lib/hug.bac"
CONST url$="http://basic-converter.proboards.com/"
SUB print_url PRINT url$ END SUB
Mainwin = WINDOW( " Test url", 400, 100 )
Button1=BUTTON("",250,30) ATTACH( Mainwin, Button1, 80, 10 ) CALLBACK(Button1, print_url)
My_label = MARK( "<b><i><u><span color=\"blue\">"&url$&"</span></u></i></b> ", 250, 30 ) ATTACH( Mainwin, My_label, 80, 10 )
DISPLAY
Best regards
|
|
|
Post by vovchik on Jun 10, 2018 22:09:29 GMT 1
Dear ptitjoz,
You need to create and EVENT_BOX and register it with HUG. It will then respond to mouse and keyboard events, causing the CALLBACK to execute. In some of my GTK code on the forum, I have used such an EVENT_BOX. I will alsom check my disk and post when I find it...
With kind regards, vovchik
|
|
|
Post by vovchik on Jun 10, 2018 23:09:03 GMT 1
Dear ptitjoz, I found a few things: ' ------------------ FUNCTION FIXED(int hug_xsize, int hug_ysize) ' ------------------ ' create new fixed container for HUG LOCAL widget ' define the widget widget = gtk_fixed_new() ' register it REGISTER(widget, hug_xsize, hug_ysize, "", 0, 0, 0, 0) RETURN widget END FUNCTION
' ------------------ FUNCTION EVENT_LABEL(STRING hug_text$, int hug_xsize, int hug_ysize) ' ------------------ ' create label that is sensitive to mouse events LOCAL label, ebox label = gtk_label_new(NULL) gtk_label_set_markup(label, hug_text$) ebox = gtk_event_box_new() ' add label to event box gtk_container_add(ebox, label) gtk_widget_set_events(ebox, GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_SCROLL_MASK) g_signal_connect_data(ebox, "button-press-event", hug_mouse_event, 20, 0, 0) g_signal_connect_data(ebox, "button-release-event", hug_mouse_event, 0, 0, 0) g_signal_connect_data(ebox, "motion-notify-event", hug_mouse_event, 0, 0, 0) g_signal_connect_data(ebox, "leave-notify-event", hug_mouse_event, 30, 0, 0) IF HUG_WIDGET_SHOW THEN gtk_widget_show_all(ebox) END IF hug_widget_xsize(STR$(ebox)) = hug_xsize hug_widget_ysize(STR$(ebox)) = hug_ysize hug_widget_s_widget(STR$(ebox)) = ebox hug_widget_signal(STR$(ebox)) = 4 hug_widget_type$(STR$(ebox)) = "mark" RETURN ebox END FUNCTION
' ------------------ FUNCTION EVENT_IMAGE(STRING svg$, STRING name$, int hug_xsize, int hug_ysize) ' ------------------ 'LOCAL tmp$ TYPE STRING ' create image that is sensitive to mouse events LOCAL myimage, ebox, mysvg, ok IF NOT(EQUAL(tmp$, svg$)) THEN tmp$ = svg$ ' create a new gtk image object myimage = gtk_image_new_from_pixbuf(SVG_BUFF(tmp$)) ELSE ' create a new gtk image object myimage = gtk_image_new_from_pixbuf(SVG_BUFF(svg$)) END IF gtk_misc_set_padding(myimage, 0, 0) ebox = gtk_event_box_new() ' add image to event box gtk_container_add(ebox, myimage) gtk_widget_set_events(ebox, GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_SCROLL_MASK) g_signal_connect_data(ebox, "button-press-event", hug_mouse_event, 20, 0, 0) g_signal_connect_data(ebox, "button-release-event", hug_mouse_event, 0, 0, 0) g_signal_connect_data(ebox, "motion-notify-event", hug_mouse_event, 0, 0, 0) g_signal_connect_data(ebox, "leave-notify-event", hug_mouse_event, 30, 0, 0) IF HUG_WIDGET_SHOW THEN gtk_widget_show_all(ebox) END IF hug_widget_xsize(STR$(ebox)) = hug_xsize hug_widget_ysize(STR$(ebox)) = hug_ysize hug_widget_s_widget(STR$(ebox)) = ebox hug_widget_signal(STR$(ebox)) = 4 hug_widget_type$(STR$(ebox)) = "image" hug_widget_font(STR$(ebox)) = myimage hug_widget_focus(STR$(ebox)) = myimage hug_widget_image$(STR$(ebox)) = name$ RETURN ebox END FUNCTION
One of these things might server your purposes...(and you need the appropriate IMPORTS or OPTION PARSE FALSE and some PROTOs). Our old friend Bigbass (Joe) has a nice example of connecting a signal to a widget at the bottom of this page: gtk. With kind regards, vovchik
|
|
|
Post by bigbass on Jun 12, 2018 5:54:26 GMT 1
Hello ptitjoz
HUG at the moment doesn't have that widget built in but the idea would look like this code I posted below using pure gtk and HUG IMPORTS
vovchik or Alex both have a lot of practice adding special Functions to HUG they could take this to the next step using HUG
Only Peter could do anything official or a temporary fix with REGISTER / METHOD which I have only seen used one time and forgot how it works that (was done with a spinner widget on page three of mental math )
you compile this as any other *.bac note you cant combine this with HUG it is stand alone code
call it linkgtk2.bac and compile with bacon linkgtk2.bac
'--- link gtk2.bac
'--- bacon website link button '--- a working generic template made from linkbutton.c '--- Ported from the gtk3 gnome offical demo to BaCon IMPORTS in (gtk2) by bigbass
'--- a short IMPORTS list of gtk functions with args HUG styled
IMPORT "gtk_container_add(long,long)" FROM "libgtk-x11-2.0.so.0" TYPE void ALIAS ATTACH IMPORT "gtk_link_button_new(char*)" FROM "libgtk-x11-2.0.so.0" TYPE long ALIAS LINKBUTTON IMPORT "gtk_link_button_set_uri(long,char*)" FROM "libgtk-x11-2.0.so.0" TYPE void ALIAS LINK IMPORT "gtk_widget_show_all(long)" FROM "libgtk-x11-2.0.so.0" TYPE void ALIAS SHOW IMPORT "gtk_window_set_default_size(long,int,int)" FROM "libgtk-x11-2.0.so.0" TYPE void ALIAS WINDOWSIZE IMPORT "gtk_window_set_title(long,char*)" FROM "libgtk-x11-2.0.so.0" TYPE void ALIAS TITLE
'--- a short IMPORTS list of gtk functions with args HUG styled IMPORT "gtk_init(int*,void*)" FROM "libgtk-x11-2.0.so.0" TYPE void ALIAS INIT IMPORT "gtk_main" FROM "libgtk-x11-2.0.so.0" TYPE void ALIAS DISPLAY IMPORT "gtk_main_quit(int)" FROM "libgtk-x11-2.0.so.0" TYPE void ALIAS QUIT IMPORT "gtk_window_new(int)" FROM "libgtk-x11-2.0.so.0" TYPE long ALIAS WINDOW
'--- for the callbacks IMPORT "g_signal_connect_data(long,char*,long,long,long,int)" FROM "libgobject-2.0.so.0" TYPE void ALIAS CALLBACK
'===================== SUB exit_prog '===================== QUIT(0) END SUB
INIT(0, 0) window = WINDOW(0)
TITLE(window, "BaCon LinkButton") WINDOWSIZE(window, 250, 50)
linkbutton = LINKBUTTON("Link to The BaCon Website!") LINK(linkbutton, "http://www.basic-converter.org/") ATTACH (window, linkbutton)
'--- Connecting the delete-event signal to the callback CALLBACK(window, "delete-event", ADDRESS(exit_prog), 0, 0, 0) SHOW(window) DISPLAY
|
|
|
Post by alexfish on Jun 12, 2018 22:10:41 GMT 1
Hi All While working on Pi3 I did some delving into gtk docs and found that the label has a uri feature; some of this work is HEREone can set the Mark in HUG like so The label text: "<a href='http://www.basic-converter.org/'>BaCon basic Converter</a> \nRest Of text goes here with all the triming here\n and further Bits of Blagh Blagh\n <a href='http://www.basic-converter.org/'>BaCon AT</a>" from what I remember when the label has the <a href , then the callback functions without the need for the eventbox, Please Read DOCSBR Alex
|
|
|
Post by bigbass on Jun 13, 2018 19:12:10 GMT 1
Hey guys Here is the new linkbutton widget for HUG! took me awhile to figure out how to add something to HUG but we needed a demo for this anyway (I was waiting for someone else to step in and do it) reference link REGISTERJoe
'--- link2hug.bac
'--- added the gtk linkbutton to HUG '--- Ported from the gtk3 gnome offical demo to BaCon in (gtk2) by bigbass
INCLUDE "hug.bac" '---CONST gtk$ = HUGLIB$("gtk")
OPTION PARSE FALSE
IMPORT "gtk_link_button_new(char*)" FROM "libgtk-x11-2.0.so.0" TYPE long IMPORT "gtk_link_button_set_uri(long,char*)" FROM "libgtk-x11-2.0.so.0" TYPE void
'--- gtk link function added to HUG using REGISTER by bigbass ' --------------------------------------------------------------- FUNCTION LINKBUTTON(int hug_xsize, int hug_ysize, STRING linkname$) ' --------------------------------------------------------------- LOCAL widget ,linkbutton ' create the linkbutton widget = gtk_link_button_new (linkname$) '--- gtk_link_button_set_uri not needed when used with HUG in this example ' register and determine size and signal REGISTER(widget, hug_xsize, hug_ysize, "clicked",0, 0, 0, 0) RETURN widget END FUNCTION
window = WINDOW( "NEW HUG LinkButton", 400 ,300)
linkbutton = LINKBUTTON(300, 50 ,"http://www.basic-converter.org/doc_frame.html") linkbutton2 = LINKBUTTON(300, 50 ,"http://www.basic-converter.proboards.com") linkbutton3 = LINKBUTTON(300, 50 ,"http://www.basic-converter.org/")
'--- fix alignment problems so that you don't need to use negative numbers SETPROPERTY(linkbutton, "xalign", 0) SETPROPERTY(linkbutton2, "xalign", 0) SETPROPERTY(linkbutton3, "xalign", 0)
ATTACH(window,linkbutton,0,10) ATTACH(window,linkbutton2,0,60) ATTACH(window,linkbutton3,0,110) CALLBACK(window,LINKBUTTON)
DISPLAY
|
|
|
Post by vovchik on Jun 13, 2018 22:29:40 GMT 1
Dear Joe and Alex, Thanks for that clear example. I have attached PegSolitaire for HUG, which I wrote in 2012, that uses a FIXED container and also has a clickable URL. It copies the URL into the X-11 buffer for subsequent pasting using a CALLBACK. The code is the the MK_HELP bit. It all works fine, just read the help screen first to find out how peg solitaire is played. And I will have to check out that markup href (thanks, Alex). With kind regards, vovchik Attachments:psol-src.tar.gz (22.36 KB)
|
|
|
Post by ptitjoz on Jun 16, 2018 8:47:30 GMT 1
Hello everyone Thank you very much for all your suggestions.
There are many possibilities to solve this problem.
It's complicated that I had thought! Thank you for the different examples! I will look for the method that will be most appropriate. With my best regards
|
|