[solved] Option gadgets (OS X) - what am I doing wrong?

Just starting out? Need help? Post your questions and find answers here.
User avatar
SparrowhawkMMU
User
User
Posts: 44
Joined: Fri Jan 17, 2014 8:55 pm
Location: UK

[solved] Option gadgets (OS X) - what am I doing wrong?

Post by SparrowhawkMMU »

Hello,

here is a simplified extract from a program I'm working on - what should happen is that when the PureBasic option is selected, the checkbox should be enabled, and when the SpiderBasic checkbox is selected it should be disabled

On first call, it works, but after that the code is reporting that both options are selected. I'm clearly missing something very basic but can't figure out what

Can anyone shed some light? Thanks!

PB 5.50
OS X 10.11.6

Code: Select all

; the following line is required for XCode 8.x +
Import "-stdlib=libc++ -mmacosx-version-min=10.7" : EndImport

EnableExplicit

Define eventNumber.i

Enumeration Controls
	#CONTROL_IncludePBFormsCheck	
	#CONTROL_PureBasicOption
	#CONTROL_SpiderBasicOption
EndEnumeration		

Procedure LanguageChanged()
	
	Debug "PB option state: " + Str(GetGadgetState(#CONTROL_PureBasicOption))
	Debug "SB option state: " + Str(GetGadgetState(#CONTROL_SpiderBasicOption))
	
	If GetGadgetState(#CONTROL_PureBasicOption)
		DisableGadget(#CONTROL_IncludePBFormsCheck, #False)
	Else
		DisableGadget(#CONTROL_IncludePBFormsCheck, #True)
	EndIf
	
EndProcedure

OpenWindow(0, 300,300, 600, 300, "Test")

OptionGadget(#CONTROL_PureBasicOption, 100, 50, 102, 25, "PureBasic")
OptionGadget(#CONTROL_SpiderBasicOption, 210, 50, 100, 25, "SpiderBasic")
SetGadgetState(#CONTROL_SpiderBasicOption, #True)
CheckBoxGadget(#CONTROL_IncludePBFormsCheck, 100, 80, 170, 25, "Include PureBasic Forms?")

LanguageChanged()

BindGadgetEvent(#CONTROL_PureBasicOption, @LanguageChanged())
BindGadgetEvent(#CONTROL_SpiderBasicOption, @LanguageChanged())

Repeat	
	
	eventNumber = WaitWindowEvent()
	
	If eventNumber = #PB_Event_Menu And EventMenu() = #PB_Menu_Quit
		PostEvent(#PB_Event_CloseWindow)
	EndIf
	
Until eventNumber = #PB_Event_CloseWindow

End
Last edited by SparrowhawkMMU on Thu Nov 24, 2016 9:54 am, edited 1 time in total.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8434
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Option gadgets - what am I doing wrong?

Post by netmaestro »

Code: Select all

; the following line is required for XCode 8.x +
Import "-stdlib=libc++ -mmacosx-version-min=10.7" : EndImport

EnableExplicit

Define eventNumber.i

Enumeration Controls
   #CONTROL_IncludePBFormsCheck   
   #CONTROL_PureBasicOption
   #CONTROL_SpiderBasicOption
EndEnumeration      

Procedure LanguageChanged()
   
   Debug "PB option state: " + Str(GetGadgetState(#CONTROL_PureBasicOption))
   Debug "SB option state: " + Str(GetGadgetState(#CONTROL_SpiderBasicOption))
   
   If GetGadgetState(#CONTROL_PureBasicOption)
     DisableGadget(#CONTROL_IncludePBFormsCheck, #False)
   Else
      SetGadgetState(#CONTROL_IncludePBFormsCheck, #PB_Checkbox_Unchecked)
      DisableGadget(#CONTROL_IncludePBFormsCheck, #True)
   EndIf
   
EndProcedure

OpenWindow(0, 300,300, 600, 300, "Test")

OptionGadget(#CONTROL_PureBasicOption, 100, 50, 102, 25, "PureBasic")
OptionGadget(#CONTROL_SpiderBasicOption, 210, 50, 100, 25, "SpiderBasic")
SetGadgetState(#CONTROL_SpiderBasicOption, #True)
CheckBoxGadget(#CONTROL_IncludePBFormsCheck, 100, 80, 170, 25, "Include PureBasic Forms?")

LanguageChanged()

BindGadgetEvent(#CONTROL_PureBasicOption, @LanguageChanged())
BindGadgetEvent(#CONTROL_SpiderBasicOption, @LanguageChanged())

Repeat   
   
   eventNumber = WaitWindowEvent()
   
   ;If eventNumber = #PB_Event_Menu And EventMenu() = #PB_Menu_Quit
   ;   PostEvent(#PB_Event_CloseWindow)
   ;EndIf
   
Until eventNumber = #PB_Event_CloseWindow

End
BERESHEIT
mestnyi
Addict
Addict
Posts: 1001
Joined: Mon Nov 25, 2013 6:41 am

Re: Option gadgets - what am I doing wrong?

Post by mestnyi »

Maybe because he wants?

Code: Select all

; the following line is required for XCode 8.x +
Import "-stdlib=libc++ -mmacosx-version-min=10.7" : EndImport

EnableExplicit

Define eventNumber.i

Enumeration Controls
   #CONTROL_IncludePBFormsCheck   
   #CONTROL_PureBasicOption
   #CONTROL_SpiderBasicOption
EndEnumeration      

Procedure LanguageChanged()
  Static checked
  
   Debug "PB option state: " + Str(GetGadgetState(#CONTROL_PureBasicOption))
   Debug "SB option state: " + Str(GetGadgetState(#CONTROL_SpiderBasicOption))
   
   If GetGadgetState(#CONTROL_PureBasicOption)
     SetGadgetState(#CONTROL_IncludePBFormsCheck, checked)
      DisableGadget(#CONTROL_IncludePBFormsCheck, #False)
   Else
      checked = GetGadgetState(#CONTROL_IncludePBFormsCheck)
      SetGadgetState(#CONTROL_IncludePBFormsCheck, #PB_Checkbox_Unchecked)
      DisableGadget(#CONTROL_IncludePBFormsCheck, #True)
   EndIf
   
EndProcedure

OpenWindow(0, 300,300, 600, 300, "Test")

OptionGadget(#CONTROL_PureBasicOption, 100, 50, 102, 25, "PureBasic")
OptionGadget(#CONTROL_SpiderBasicOption, 210, 50, 100, 25, "SpiderBasic")
SetGadgetState(#CONTROL_SpiderBasicOption, #True)
CheckBoxGadget(#CONTROL_IncludePBFormsCheck, 100, 80, 170, 25, "Include PureBasic Forms?")

LanguageChanged()

BindGadgetEvent(#CONTROL_PureBasicOption, @LanguageChanged())
BindGadgetEvent(#CONTROL_SpiderBasicOption, @LanguageChanged())

Repeat   
   
   eventNumber = WaitWindowEvent()
   
   ;If eventNumber = #PB_Event_Menu And EventMenu() = #PB_Menu_Quit
   ;   PostEvent(#PB_Event_CloseWindow)
   ;EndIf
   
Until eventNumber = #PB_Event_CloseWindow

End
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Option gadgets - what am I doing wrong?

Post by TI-994A »

SparrowhawkMMU wrote:...what should happen is that when the PureBasic option is selected, the checkbox should be enabled, and when the SpiderBasic checkbox is selected it should be disabled...
While it appears to be working fine under Windows, the issue seems to be with binding multiple option buttons with a single callback under OSX. If the same were performed in the event loop or with separate callbacks for each option button, then it works as expected. Furthermore, under OSX, there appears to be some lag in registering the status change.

This has been modified to include two separate callbacks for the two option buttons, and utilises a post event to report the status:

Code: Select all

; the following line is required for XCode 8.x +
;Import "-stdlib=libc++ -mmacosx-version-min=10.7" : EndImport

EnableExplicit

Define eventNumber.i

#optionReport = #PB_Event_FirstCustomValue

Enumeration Controls
  #CONTROL_IncludePBFormsCheck   
  #CONTROL_PureBasicOption
  #CONTROL_SpiderBasicOption
EndEnumeration      

Procedure LanguageChanged1()
  If GetGadgetState(#CONTROL_SpiderBasicOption)
    DisableGadget(#CONTROL_IncludePBFormsCheck, #True)
  EndIf
  PostEvent(#optionReport)
EndProcedure

Procedure LanguageChanged2()
  If GetGadgetState(#CONTROL_PureBasicOption)
    DisableGadget(#CONTROL_IncludePBFormsCheck, #False)
  EndIf
  PostEvent(#optionReport)  
EndProcedure

OpenWindow(0, 300,300, 600, 300, "Test")

OptionGadget(#CONTROL_PureBasicOption, 100, 50, 102, 25, "PureBasic")
OptionGadget(#CONTROL_SpiderBasicOption, 210, 50, 100, 25, "SpiderBasic")
SetGadgetState(#CONTROL_SpiderBasicOption, #True)
CheckBoxGadget(#CONTROL_IncludePBFormsCheck, 100, 80, 170, 25, "Include PureBasic Forms?")

LanguageChanged1()
LanguageChanged2()

BindGadgetEvent(#CONTROL_PureBasicOption, @LanguageChanged2())
BindGadgetEvent(#CONTROL_SpiderBasicOption, @LanguageChanged1())

Repeat   
  
  eventNumber = WaitWindowEvent()
  
  If eventNumber = #optionReport
    Debug "PB option state: " + Str(GetGadgetState(#CONTROL_PureBasicOption))
    Debug "SB option state: " + Str(GetGadgetState(#CONTROL_SpiderBasicOption))    
  EndIf  
  
Until eventNumber = #PB_Event_CloseWindow
It could either be a bug, or simply an OSX thing.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
SparrowhawkMMU
User
User
Posts: 44
Joined: Fri Jan 17, 2014 8:55 pm
Location: UK

Re: Option gadgets - what am I doing wrong?

Post by SparrowhawkMMU »

@everyone: Thanksfor helping out. :)

@Ti994a, thank you for checking that it works under Windows. It does strike me as odd that one would have to explicitly set the state of a radio button even though the UI had clearly registered the changed state itself. I've never had to do that in any other environment. But glad that there is a solution at least.

I will go with the two callbacks approach for now.

@fred (if you are monitoring) If it's not a bug, it would be good if the documentation could be updated for OS X / macOS users.
Post Reply