Underscore with buttons and other gadgets

Linux specific forum
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

Underscore with buttons and other gadgets

Post 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?
Last edited by Frarth on Sun Jun 24, 2012 9:35 am, edited 1 time in total.
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
User avatar
idle
Always Here
Always Here
Posts: 5915
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Underscore with buttons

Post 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 

Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

Re: Underscore with buttons

Post by Frarth »

Thanks a lot idle!
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

Re: Underscore with buttons and other gadgets

Post by Frarth »

Is there a similar approach for checkboxes and radio buttons?
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
User avatar
idle
Always Here
Always Here
Posts: 5915
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Underscore with buttons and other gadgets

Post 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 
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

Re: Underscore with buttons and other gadgets

Post by Frarth »

Where would one be without this forum!

Thanks again idle! :D
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
User avatar
idle
Always Here
Always Here
Posts: 5915
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Underscore with buttons and other gadgets

Post by idle »

Frarth wrote:Where would one be without this forum!

Thanks again idle! :D
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
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

Re: Underscore with buttons and other gadgets

Post by Frarth »

Interestingly, if I check 'Create unicode executable' the button labels are no longer visible! Is this a known bug?
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

Re: Underscore with buttons and other gadgets

Post 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
Athlon64 3700+, 1024MB Ram, Radeon X1600
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

Re: Underscore with buttons and other gadgets

Post by Frarth »

Thanks remi_meier, I'll give it a try.
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
Post Reply