It is currently Wed Jun 19, 2013 3:52 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Underscore with buttons and other gadgets
PostPosted: Sat Jun 23, 2012 10:24 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Jul 21, 2009 11:11 am
Posts: 195
Location: Netherlands
I got this snippet from this forum and adjusted it a bit to have an underscore with the button text.
Code:
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?

_________________
PureBasic 4.61 | Debian Squeeze 6.05 | Windows XP SP3
Why I use PureBasic? Because it is the best cross-platform BASIC-like programming language!


Last edited by Frarth on Sun Jun 24, 2012 9:35 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Underscore with buttons
PostPosted: Sat Jun 23, 2012 10:58 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2506
Location: New Zealand
you can do this so it works with the PB event loop

Code:
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



Top
 Profile  
 
 Post subject: Re: Underscore with buttons
PostPosted: Sun Jun 24, 2012 8:39 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Jul 21, 2009 11:11 am
Posts: 195
Location: Netherlands
Thanks a lot idle!

_________________
PureBasic 4.61 | Debian Squeeze 6.05 | Windows XP SP3
Why I use PureBasic? Because it is the best cross-platform BASIC-like programming language!


Top
 Profile  
 
 Post subject: Re: Underscore with buttons and other gadgets
PostPosted: Sun Jun 24, 2012 9:36 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Jul 21, 2009 11:11 am
Posts: 195
Location: Netherlands
Is there a similar approach for checkboxes and radio buttons?

_________________
PureBasic 4.61 | Debian Squeeze 6.05 | Windows XP SP3
Why I use PureBasic? Because it is the best cross-platform BASIC-like programming language!


Top
 Profile  
 
 Post subject: Re: Underscore with buttons and other gadgets
PostPosted: Sun Jun 24, 2012 9:26 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2506
Location: New Zealand
Yes the checkbox and radio are inherited from button

Code:
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


Top
 Profile  
 
 Post subject: Re: Underscore with buttons and other gadgets
PostPosted: Mon Jun 25, 2012 7:49 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Jul 21, 2009 11:11 am
Posts: 195
Location: Netherlands
Where would one be without this forum!

Thanks again idle! :D

_________________
PureBasic 4.61 | Debian Squeeze 6.05 | Windows XP SP3
Why I use PureBasic? Because it is the best cross-platform BASIC-like programming language!


Top
 Profile  
 
 Post subject: Re: Underscore with buttons and other gadgets
PostPosted: Mon Jun 25, 2012 9:06 am 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2506
Location: New Zealand
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


Top
 Profile  
 
 Post subject: Re: Underscore with buttons and other gadgets
PostPosted: Mon Jun 25, 2012 9:23 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Jul 21, 2009 11:11 am
Posts: 195
Location: Netherlands
Interestingly, if I check 'Create unicode executable' the button labels are no longer visible! Is this a known bug?

_________________
PureBasic 4.61 | Debian Squeeze 6.05 | Windows XP SP3
Why I use PureBasic? Because it is the best cross-platform BASIC-like programming language!


Top
 Profile  
 
 Post subject: Re: Underscore with buttons and other gadgets
PostPosted: Mon Jun 25, 2012 10:38 am 
Offline
Enthusiast
Enthusiast

Joined: Sat Dec 20, 2003 6:19 pm
Posts: 467
Location: Switzerland
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: viewtopic.php?f=14&t=43681&hilit=gir2pb

_________________
Athlon64 3700+, 1024MB Ram, Radeon X1600


Top
 Profile  
 
 Post subject: Re: Underscore with buttons and other gadgets
PostPosted: Mon Jun 25, 2012 11:26 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Jul 21, 2009 11:11 am
Posts: 195
Location: Netherlands
Thanks remi_meier, I'll give it a try.

_________________
PureBasic 4.61 | Debian Squeeze 6.05 | Windows XP SP3
Why I use PureBasic? Because it is the best cross-platform BASIC-like programming language!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye