Page 1 of 1
Underscore with buttons and other gadgets
Posted: Sat Jun 23, 2012 10:24 pm
by Frarth
I got this snippet from this forum and adjusted it a bit to have an underscore with the button text.
Code: Select all
Define *Window.GtkWidget
Define *Button.GtkWidget
Global Count = 0
ProcedureC ButtonClicked(*Button.GtkWidget,*MyData.l)
Debug PeekS(*MyData) + " pressed " + Str(Count) + " time(s)."
Count + 1
EndProcedure
gtk_init_(0, 0)
*Window = gtk_window_new_(GTK_WINDOW_TOPLEVEL)
*Button = gtk_button_new_with_mnemonic_("_Hello world!")
gtk_container_add_(*Window,*Button)
g_signal_connect_(*Button,"clicked",@ButtonClicked(),"Button 1")
gtk_widget_show_(*Button)
gtk_widget_show_(*Window)
gtk_main_()
End 0
Has anybody tried to implement this with PB's window's gadget list and make it cross platform as possible?
Re: Underscore with buttons
Posted: Sat Jun 23, 2012 10:58 pm
by idle
you can do this so it works with the PB event loop
Code: Select all
OpenWindow(0,0,0,60,30,"")
ButtonGadget(1,0,0,60,30,"")
gtk_button_set_use_underline_(GadgetID(1),1)
gtk_button_set_label_(GadgetID(1),"_Hello")
Repeat
ev = WaitWindowEvent()
evg = EventGadget()
If ev
If evg = 1
Debug "button 1 pressed"
EndIf
EndIf
Until ev = #PB_Event_CloseWindow
Re: Underscore with buttons
Posted: Sun Jun 24, 2012 8:39 am
by Frarth
Thanks a lot idle!
Re: Underscore with buttons and other gadgets
Posted: Sun Jun 24, 2012 9:36 am
by Frarth
Is there a similar approach for checkboxes and radio buttons?
Re: Underscore with buttons and other gadgets
Posted: Sun Jun 24, 2012 9:26 pm
by idle
Yes the checkbox and radio are inherited from button
Code: Select all
OpenWindow(0,0,0,60,90,"")
ButtonGadget(1,0,0,60,30,"")
gtk_button_set_use_underline_(GadgetID(1),1)
gtk_button_set_label_(GadgetID(1),"_Hello")
CheckBoxGadget(2,0,30,60,30,"")
gtk_button_set_use_underline_(GadgetID(2),1)
gtk_button_set_label_(GadgetID(2),"_Check")
OptionGadget(3,0,60,60,30,"")
gtk_button_set_use_underline_(GadgetID(3),1)
gtk_button_set_label_(GadgetID(3),"_Mate")
Repeat
ev = WaitWindowEvent()
evg = EventGadget()
If ev
If evg = 1
Debug "button 1 pressed"
EndIf
If evg = 2
Debug "Check"
EndIf
If evg = 3
Debug "Mate"
EndIf
EndIf
Until ev = #PB_Event_CloseWindow
Re: Underscore with buttons and other gadgets
Posted: Mon Jun 25, 2012 7:49 am
by Frarth
Where would one be without this forum!
Thanks again idle!

Re: Underscore with buttons and other gadgets
Posted: Mon Jun 25, 2012 9:06 am
by idle
Frarth wrote:Where would one be without this forum!
Thanks again idle!

I can second that!
I didn't know how to do it either but if you ever get stuck with gtk stuff
http://developer.gnome.org/gtk/2.24/index.html
Re: Underscore with buttons and other gadgets
Posted: Mon Jun 25, 2012 9:23 am
by Frarth
Interestingly, if I check 'Create unicode executable' the button labels are no longer visible! Is this a known bug?
Re: Underscore with buttons and other gadgets
Posted: Mon Jun 25, 2012 10:38 am
by remi_meier
Yes, gtk_button_set_label_() wants a UTF8 string, but
PB just passes an UCS-2 one instead.
Try the imports from
http://remi.secretly.de/downloads/gtk2.pbi
Generated by this tool:
http://www.purebasic.fr/english/viewtop ... lit=gir2pb
Re: Underscore with buttons and other gadgets
Posted: Mon Jun 25, 2012 11:26 am
by Frarth
Thanks remi_meier, I'll give it a try.