#PB_EventType_Change doesn't trigger on a checkbox change

Everything else that doesn't fall into one of the other PB categories.
TRS-Eric
User
User
Posts: 14
Joined: Thu Apr 23, 2020 7:42 pm

#PB_EventType_Change doesn't trigger on a checkbox change

Post by TRS-Eric »

This would be most helpful to me if it could trigger when a checkbox is changed!

See example:

Code: Select all

  If OpenWindow(0, 0, 0, 270, 160, "CheckBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    StringGadget  (0, 10,  10, 150, 20, "String Gadget")
    CheckBoxGadget(1, 10,  40, 250, 20, "CheckBox checked"): SetGadgetState(1, #PB_Checkbox_Checked)
    CheckBoxGadget(2, 10,  70, 250, 20, "CheckBox three state", #PB_CheckBox_ThreeState): SetGadgetState(2, #PB_Checkbox_Inbetween)
    CheckBoxGadget(3, 10, 100, 250, 20, "CheckBox right", #PB_CheckBox_Right)
    CheckBoxGadget(4, 10, 130, 250, 20, "CheckBox center", #PB_CheckBox_Center)
    
    
    Repeat
      ex_event = WaitWindowEvent()
      ex_event_type = EventType()
      If ex_event_type = #PB_EventType_Change
        Debug "Changed!"
      EndIf
      
    Until ex_event = #PB_Event_CloseWindow
  EndIf

---
BASIC related discord: https://discord.gg/KS4en5y5j4
infratec
Always Here
Always Here
Posts: 6869
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: #PB_EventType_Change doesn't trigger on a checkbox chang

Post by infratec »

This is not a bug.

It is more a feature request.

But it generates an event, like a button:

Code: Select all

If OpenWindow(0, 0, 0, 270, 160, "CheckBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  StringGadget  (0, 10,  10, 150, 20, "String Gadget")
  CheckBoxGadget(1, 10,  40, 250, 20, "CheckBox checked"): SetGadgetState(1, #PB_Checkbox_Checked)
  CheckBoxGadget(2, 10,  70, 250, 20, "CheckBox three state", #PB_CheckBox_ThreeState): SetGadgetState(2, #PB_Checkbox_Inbetween)
  CheckBoxGadget(3, 10, 100, 250, 20, "CheckBox right", #PB_CheckBox_Right)
  CheckBoxGadget(4, 10, 130, 250, 20, "CheckBox center", #PB_CheckBox_Center)
  
  
  Repeat
    ex_event = WaitWindowEvent()
    
    Select ex_event
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1 To 4
            Debug "Changed"
        EndSelect
    EndSelect
    
  Until ex_event = #PB_Event_CloseWindow
EndIf
So it was more a coding question :wink:
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 625
Joined: Mon May 09, 2011 9:36 am

Re: #PB_EventType_Change doesn't trigger on a checkbox chang

Post by VB6_to_PBx »

Code: Select all

  If OpenWindow(0, 0, 0, 270, 160, "CheckBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    StringGadget  (0, 10,  10, 150, 20, "String Gadget")
    CheckBoxGadget(1, 10,  40, 250, 20, "CheckBox checked"): SetGadgetState(1, #PB_Checkbox_Checked)
    CheckBoxGadget(2, 10,  70, 250, 20, "CheckBox three state", #PB_CheckBox_ThreeState): SetGadgetState(2, #PB_Checkbox_Inbetween)
    CheckBoxGadget(3, 10, 100, 250, 20, "CheckBox right", #PB_CheckBox_Right)
    CheckBoxGadget(4, 10, 130, 250, 20, "CheckBox center", #PB_CheckBox_Center)
   
   
    Repeat
      ex_event = WaitWindowEvent()
      Select EventGadget()
      Case 1 : Debug "CheckBoxGadget # 1 was Changed! GadgetState = " + Str(GetGadgetState(1))
      Case 2 : Debug "CheckBoxGadget # 2 was Changed! GadgetState = " + Str(GetGadgetState(2))
      Case 3 : Debug "CheckBoxGadget # 3 was Changed! GadgetState = " + Str(GetGadgetState(3))
      Case 4 : Debug "CheckBoxGadget # 4 was Changed! GadgetState = " + Str(GetGadgetState(4))
      EndSelect
    Until ex_event = #PB_Event_CloseWindow
  EndIf
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
TRS-Eric
User
User
Posts: 14
Joined: Thu Apr 23, 2020 7:42 pm

Re: #PB_EventType_Change doesn't trigger on a checkbox chang

Post by TRS-Eric »

I don't think I would call that a feature request. From this list it seems to me that checkmarks should trigger #PB_EventType_Change, how else would one know that the checkbox had changed other than checking on every #PB_Event_Gadget event (and having a very large list of if/then statements to check each checkmark)? At the very least this should be mentioned in the documentation.

Code: Select all

The following values are possible, if an event of the type #PB_Event_Gadget (library Gadget) or #PB_Event_SysTray (library Systray) occurs: 
  #PB_EventType_LeftClick       : Left mouse button click
  #PB_EventType_RightClick      : right mouse button click
  #PB_EventType_LeftDoubleClick : Left mouse button double click
  #PB_EventType_RightDoubleClick: Right mouse button double click
  #PB_EventType_Focus           : Get the focus.
  #PB_EventType_LostFocus       : Lose the focus.
  #PB_EventType_Change          : Content change.
  #PB_EventType_DragStart       : The user tries to start a Drag & Drop operation.

---
BASIC related discord: https://discord.gg/KS4en5y5j4
infratec
Always Here
Always Here
Posts: 6869
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: #PB_EventType_Change doesn't trigger on a checkbox chang

Post by infratec »

No, it is nowhere written that the CheckBoxGadget() supports EventType()

This is written at every Gadget who supports it.
Also at the help of EventType() it is not listed.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: #PB_EventType_Change doesn't trigger on a checkbox chang

Post by IdeasVacuum »

Why do you need an event triggered when a Checkbox is changed?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: #PB_EventType_Change doesn't trigger on a checkbox chang

Post by kenmo »

Hello. I think some of the responses have been confusing.

1. CheckBoxGadget DOES generate an event when it changes. It just doesn't specify EventType()... because Change is the only type it would possibly generate!

2. You don't need to hard-code out all the gadgets to check for. Try it, minimal change to your original code:

Code: Select all

If OpenWindow(0, 0, 0, 270, 160, "CheckBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  StringGadget  (0, 10,  10, 150, 20, "String Gadget")
  CheckBoxGadget(1, 10,  40, 250, 20, "CheckBox checked"): SetGadgetState(1, #PB_Checkbox_Checked)
  CheckBoxGadget(2, 10,  70, 250, 20, "CheckBox three state", #PB_CheckBox_ThreeState): SetGadgetState(2, #PB_Checkbox_Inbetween)
  CheckBoxGadget(3, 10, 100, 250, 20, "CheckBox right", #PB_CheckBox_Right)
  CheckBoxGadget(4, 10, 130, 250, 20, "CheckBox center", #PB_CheckBox_Center)
 
 
  Repeat
    ex_event = WaitWindowEvent()
    If (ex_event = #PB_Event_Gadget)
      If (EventGadget() <> -1) ; because it seems to fire some Gadget = -1 events, which IS perhaps a bug...
        Debug "Gadget " + Str(EventGadget())
      EndIf
    EndIf
   
  Until ex_event = #PB_Event_CloseWindow
EndIf
3. This is not a "bug". That gadget doesn't claim to use EventType(), and as I said in (1) it doesn't need to. "Change" is the only type.

4. This could be a Feature Request (which I would support!) that CheckBoxGadget() should indicate #PB_EventType_Change along with its events.
BarryG
Addict
Addict
Posts: 3320
Joined: Thu Apr 18, 2019 8:17 am

Re: #PB_EventType_Change doesn't trigger on a checkbox chang

Post by BarryG »

TRS-Eric wrote:From this list it seems to me that checkmarks should trigger #PB_EventType_Change
Nope - you didn't read the manual just above that list, which clearly states: The following gadgets support EventType(), and CheckboxGadgets() are NOT included.
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 625
Joined: Mon May 09, 2011 9:36 am

Re: #PB_EventType_Change doesn't trigger on a checkbox chang

Post by VB6_to_PBx »

Code: Select all

If OpenWindow(0, 0, 0, 270, 160, "CheckBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  StringGadget  (0, 10,  10, 150, 20, "String Gadget")
  CheckBoxGadget(1, 10,  40, 250, 20, "CheckBox checked"): SetGadgetState(1, #PB_Checkbox_Checked)
  CheckBoxGadget(2, 10,  70, 250, 20, "CheckBox three state", #PB_CheckBox_ThreeState): SetGadgetState(2, #PB_Checkbox_Inbetween)
  CheckBoxGadget(3, 10, 100, 250, 20, "CheckBox right", #PB_CheckBox_Right)
  CheckBoxGadget(4, 10, 130, 250, 20, "CheckBox center", #PB_CheckBox_Center)
  
  Repeat
    ex_event = WaitWindowEvent()
    If (ex_event = #PB_Event_Gadget)
       If (EventGadget() <> -1) ;<<--- because it seems to fire some Gadget = -1 events, which IS perhaps a bug...
          Debug "CheckBoxGadget # " + Str(EventGadget()) + " was Changed! GadgetState = " + Str(GetGadgetState(EventGadget()))
          SetWindowTitle(0,Str(EventGadget()) + " GadgetState = " + Str(GetGadgetState(EventGadget())))
       EndIf
    EndIf
   
  Until ex_event = #PB_Event_CloseWindow
EndIf

 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: #PB_EventType_Change doesn't trigger on a checkbox chang

Post by TI-994A »

Just roll your own:

Code: Select all

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 
If OpenWindow(0, 0, 0, 270, 160, "CheckBoxGadget", wFlags)
  StringGadget  (0, 10,  10, 250, 20, "String Gadget")
  CheckBoxGadget(1, 10,  40, 250, 20, "CheckBox checked")
  CheckBoxGadget(2, 10,  70, 250, 20, "CheckBox three state", #PB_CheckBox_ThreeState)
  CheckBoxGadget(3, 10, 100, 250, 20, "CheckBox right", #PB_CheckBox_Right)
  CheckBoxGadget(4, 10, 130, 250, 20, "CheckBox center", #PB_CheckBox_Center)
  SetGadgetState(2, #PB_Checkbox_Inbetween)
    
  Repeat
    
    Select WaitWindowEvent()
        
      Case #PB_Event_CloseWindow
        appQuit = #True
        
      Case #PB_Event_Gadget        
        event_gadget = EventGadget()        
        If IsGadget(event_gadget)
          
          Select GadgetType(event_gadget)
              
            Case #PB_GadgetType_CheckBox  ;for checkbox gadgets              
              Select event_gadget
                  
                Case 1
                  SetGadgetText(0, "CheckBox gadget 1 state: " + GetGadgetState(1))
                  
                Case 2               
                  SetGadgetText(0, "CheckBox gadget 2 state: " + GetGadgetState(2))
                  
                Case 3
                  SetGadgetText(0, "CheckBox gadget 3 state: " + GetGadgetState(3))
                  
                Case 4
                  SetGadgetText(0, "CheckBox gadget 4 state: " + GetGadgetState(4))
                  
              EndSelect            
              
            Default  ;for all other gadget types              
              Select event_gadget
                  
                Case 0
                  Debug "String gadget 0 change/focus event..."
                  
              EndSelect
              
          EndSelect
          
        EndIf
        
    EndSelect
    
  Until appQuit
  
EndIf
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
Post Reply