It is currently Thu Sep 19, 2019 3:26 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: [Solved] OptionGadgets and ampersand
PostPosted: Mon Sep 02, 2019 2:00 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 264
How can I make all three OptionGadgets below show their respective number of ampersands? That is, I specifically want to see "1&" for the first one, "2&&" for the second, and "3&&&" for the third. Reason is that the OptionGadget text has to match exactly what is in the clipboard, and sometimes the clipboard has "&&" or "&&&" in it.

Code:
If OpenWindow(0, 300, 200, 140, 110, "OptionGadgets", #PB_Window_SystemMenu)
  OptionGadget(0, 30, 20, 100, 20, "Option 1&")
  OptionGadget(1, 30, 45, 100, 20, "Option 2&&")
  OptionGadget(2, 30, 70, 100, 20, "Option 3&&&")
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Image


Last edited by BarryG on Tue Sep 03, 2019 4:50 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: OptionGadgets and ampersand
PostPosted: Mon Sep 02, 2019 2:18 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Apr 25, 2003 7:09 pm
Posts: 247
Location: (Madrid) Spain
I am testing PB 5.71 on MAC OS and do it well.
What is your version?

_________________
[:: PB Registered ::]

Win10 Intel core i5-3330 8GB RAM Nvidia GTX 1050Ti


Top
 Profile  
Reply with quote  
 Post subject: Re: OptionGadgets and ampersand
PostPosted: Mon Sep 02, 2019 2:31 pm 
Offline
User
User

Joined: Sat May 14, 2011 10:39 am
Posts: 53
Code:
If OpenWindow(0, 300, 200, 140, 110, "OptionGadgets", #PB_Window_SystemMenu)
  OptionGadget(0, 30, 20, 100, 20, "Option 1&&")
  OptionGadget(1, 30, 45, 100, 20, "Option 2&&&&")
  OptionGadget(2, 30, 70, 100, 20, "Option 3&&&&&&")
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: OptionGadgets and ampersand
PostPosted: Mon Sep 02, 2019 3:29 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Apr 25, 2003 7:09 pm
Posts: 247
Location: (Madrid) Spain
Sirius-2337 wrote:
Code:
If OpenWindow(0, 300, 200, 140, 110, "OptionGadgets", #PB_Window_SystemMenu)
  OptionGadget(0, 30, 20, 100, 20, "Option 1&&")
  OptionGadget(1, 30, 45, 100, 20, "Option 2&&&&")
  OptionGadget(2, 30, 70, 100, 20, "Option 3&&&&&&")
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf


In MAC this not fix the problem.
Works this in a different way in Mac and Windows?

_________________
[:: PB Registered ::]

Win10 Intel core i5-3330 8GB RAM Nvidia GTX 1050Ti


Top
 Profile  
Reply with quote  
 Post subject: Re: OptionGadgets and ampersand
PostPosted: Mon Sep 02, 2019 3:39 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Jul 23, 2011 1:13 am
Posts: 215
Location: Germany
Yes, it's a windows issue.

I could have sworn "&" was used in Menus to underscore a character to show the key associated with a command. Apparently that's not the case anymore in windows 10.
The function is still there, though.

Open the Menu in this code and hit the keys N, O or X.

Code:
If OpenWindow(0, 300, 200, 140, 150, "OptionGadgets", #PB_Window_SystemMenu)
   CreateMenu(0, WindowID(0))
   MenuTitle("Menu")
   MenuItem(1, "Option 1 Press &N")
   MenuItem(2, "Option 2 Press &O")
   MenuItem(3, "Option 3 Press &X")
   
   OptionGadget(0, 30, 20, 100, 25, "Option 1 Press &A")
   OptionGadget(1, 30, 45, 100, 25, "Option 2 Press &B")
   OptionGadget(2, 30, 70, 100, 25, "Option 3 Press &C")
   Repeat
      e=WaitWindowEvent()   
      If e=#PB_Event_Menu
         Select EventMenu()
            Case 1: MessageRequester("Menu", "Option 1 / N")
            Case 2: MessageRequester("Menu", "Option 2 / O")
            Case 3: MessageRequester("Menu", "Option 3 / X")
         EndSelect
      EndIf
   Until e= #PB_Event_CloseWindow
EndIf


I thought maybe it's a relict of that time.
The way it is now, is useless, though (still works with menus but no visual cue, and doesn't do anything for the Option Gadget)

I'm just not sure if PB can do anything about it.


Top
 Profile  
Reply with quote  
 Post subject: Re: OptionGadgets and ampersand
PostPosted: Tue Sep 03, 2019 12:56 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 264
Sirius-2337, so I just have to double the count when using them with OptionGadgets? That works, but it's a shame there's no simple flag or something for the OptionGadget to avoid having to do a string operation each time.

Code:
Procedure.s KeepAmpersands(text$)
  ProcedureReturn ReplaceString(text$,"&","&&")
EndProcedure

If OpenWindow(0, 300, 200, 140, 110, "OptionGadgets", #PB_Window_SystemMenu)
  OptionGadget(0, 30, 20, 100, 20, KeepAmpersands("Option 1&"))
  OptionGadget(1, 30, 45, 100, 20, KeepAmpersands("Option 2&&"))
  OptionGadget(2, 30, 70, 100, 20, KeepAmpersands("Option 3&&&"))
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Image


Top
 Profile  
Reply with quote  
 Post subject: Re: OptionGadgets and ampersand
PostPosted: Tue Sep 03, 2019 2:27 am 
Offline
Addict
Addict
User avatar

Joined: Tue Dec 23, 2003 3:54 am
Posts: 1650
Yes, it's different on Windows and Mac. That's something to be aware of for cross-platform GUIs.

No, it's not useless!

On Windows you use "&" to underline the next character. As Derren said, in a menu, it also sets what key will trigger that item.

To display an ampersand character, you double it to "&&".

The underline used to always be visible (a long time ago). Since Windows 7 (or maybe earlier) it's hidden by default, you can show the underlined letters by activating the menu by keyboard (press Alt).
(You can also enable the underlines all the time: https://www.groovypost.com/howto/make-w ... tcut-keys/ )

In an OptionGadget, it doesn't automatically add a hotkey. But it's still useful to indicate keyboard shortcuts (which you add manually). Microsoft Excel uses this.

If you don't want to underline anything, you can easily write a function that turns "&" to "&&" on Windows:
Code:
Procedure.s GUIEscape(Text.s)
  CompilerIf (#PB_Compiler_OS = #PB_OS_Windows)
    ProcedureReturn (ReplaceString(Text, "&", "&&"))
  CompilerElse
    ProcedureReturn (Text)
  CompilerEndIf
EndProcedure


If OpenWindow(0, 300, 200, 140, 110, "OptionGadgets", #PB_Window_SystemMenu)
  OptionGadget(0, 30, 20, 100, 20, GUIEscape("Option 1&"))
  OptionGadget(1, 30, 45, 100, 20, GUIEscape("Option 2&&"))
  OptionGadget(2, 30, 70, 100, 20, GUIEscape("Option 3&&&"))
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf



EDIT: Yeah, you figured it out

_________________
On GitHub: PB Includes - IDE Tools - Color Themes


Top
 Profile  
Reply with quote  
 Post subject: Re: OptionGadgets and ampersand
PostPosted: Tue Sep 03, 2019 4:51 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 264
kenmo wrote:
you figured it out

Sorry, yes. Post title changed to solved.


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


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

 


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