Set an option Gadget without triggering an event?

Just starting out? Need help? Post your questions and find answers here.
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Set an option Gadget without triggering an event?

Post by Lebostein »

How I set option gadgets (for example after loading a user setting) without triggering an gadget event? An gadget event should only happened if the user click the gadget
BarryG
Addict
Addict
Posts: 3324
Joined: Thu Apr 18, 2019 8:17 am

Re: Set an option Gadget without triggering an event?

Post by BarryG »

It doesn't do that by default, so something in your event code is doing it by mistake. Proof:

Code: Select all

If OpenWindow(0, 300, 200, 140, 110, "OptionGadget", #PB_Window_SystemMenu)
  ButtonGadget(0, 10, 20, 120, 20, "Click to set options")
  OptionGadget(1, 10, 45, 120, 20, "Option 1")
  OptionGadget(2, 10, 70, 120, 20, "Option 2")
  Repeat
    Event = WaitWindowEvent()
    If Event = #PB_Event_Gadget
      Select EventGadget()
        Case 0 : n+1 : If n=3 : n=1 : EndIf : SetGadgetState(n,1) ; Button
        Case 1,2 : Debug "This doesn't show when the Button sets it" ; Options
      EndSelect
    EndIf
  Until Event = #PB_Event_CloseWindow
EndIf
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Set an option Gadget without triggering an event?

Post by RASHAD »

Code: Select all

SetGadgetState(10, 1)   ; set option 10 as active one
debug GetGadgetState(10) ;get status of option gadget 10
Egypt my love
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Set an option Gadget without triggering an event?

Post by Lebostein »

Hm... strange. I definitely get an event from this gadget after SetGadgetState() in my code. If I comment the line with SetGadgetState() I do not get an event from the gadget....
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Set an option Gadget without triggering an event?

Post by RASHAD »

I am not sure but you can try
SetGadgetData() - GetGadgetData() 1 for active 0 for no
Still I do not know what is your problem exactly :wink:
Egypt my love
User avatar
mk-soft
Always Here
Always Here
Posts: 5406
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Set an option Gadget without triggering an event?

Post by mk-soft »

HM ...

No Event by SetGadgetState on

PB: v5.73 (x64)
OS: MacOS, Window 7 Pro, Windows 10 Pro (1909), Ubuntu 18.04 LTS

Edit: With own event ...

Code: Select all

If OpenWindow(0, 300, 200, 140, 110, "OptionGadget", #PB_Window_SystemMenu)
  ButtonGadget(0, 10, 20, 120, 20, "Click to set options")
  OptionGadget(1, 10, 45, 120, 20, "Option 1")
  OptionGadget(2, 10, 70, 120, 20, "Option 2")
  Repeat
    Event = WaitWindowEvent()
    If Event = #PB_Event_Gadget
      Select EventGadget()
        Case 0 : n+1 : If n=3 : n=1 : EndIf : SetGadgetState(n,1) : PostEvent(#PB_Event_Gadget, EventWindow(), n, #PB_EventType_FirstCustomValue) ; Button
      Case 1,2 : 
        Debug "OptionGadget " + EventGadget() ; Options
        Select EventType()
          Case #PB_EventType_LeftClick    
            Debug "Change from User"
            
          Case #PB_EventType_FirstCustomValue
            Debug "Change from SetGadgetState"
          
        EndSelect
      EndSelect
    EndIf
  Until Event = #PB_Event_CloseWindow
EndIf
Last edited by mk-soft on Fri Dec 04, 2020 4:13 pm, edited 1 time in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Set an option Gadget without triggering an event?

Post by RASHAD »

Set OptionGadget() status without triggering it's event

Code: Select all

  If OpenWindow(0, 0, 0, 140, 150, "OptionGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    OptionGadget(0, 30, 20, 60, 20, "Option 1")
    OptionGadget(1, 30, 45, 60, 20, "Option 2")
    OptionGadget(2, 30, 70, 60, 20, "Option 3")
    
    ButtonGadget(10,10,110,80,20,"Update")
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Quit = 1
        Case #PB_Event_Gadget
          Select EventGadget()
            Case 1
              Debug "OK"
              
            Case 10
              SetGadgetState(1,1)
          EndSelect
      EndSelect
    Until Quit = 1
  EndIf
Egypt my love
BarryG
Addict
Addict
Posts: 3324
Joined: Thu Apr 18, 2019 8:17 am

Re: Set an option Gadget without triggering an event?

Post by BarryG »

Lebostein wrote:I definitely get an event from this gadget after SetGadgetState() in my code
Without seeing your code, we can't see what you've done wrong. Try to post a small snippet showing the problem.
Post Reply