CheckBox doesn't support #PB_EventType_Change

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
mk-soft
Always Here
Always Here
Posts: 6246
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: CheckBox doesn't support #PB_EventType_Change

Post by mk-soft »

Why should this be corrected? It's fine the way it is.
They are constants that Fred has defined, just as you can create constants for your purposes in your programme.
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
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: CheckBox doesn't support #PB_EventType_Change

Post by jacdelad »

mestnyi wrote: Sun Nov 10, 2024 6:31 pm
mk-soft wrote: Sat Nov 09, 2024 11:54 pm EventType() = #Null is ...

Code: Select all

Debug #PB_EventType_LeftClick
That's true, but Fred doesn't want to fix this situation in any way. moreover, I do not understand how the event value can be zero. :D
Since you firstly check the #PB_Event_... value, there's no problem when it's zero.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: CheckBox doesn't support #PB_EventType_Change

Post by mestnyi »

mk-soft wrote: Sun Nov 10, 2024 7:02 pm Why should this be corrected? It's fine the way it is.
They are constants that Fred has defined, just as you can create constants for your purposes in your programme.
yes, at least because it is illogical why this theme was created, and because it is more logical that there should be a change in the event rather than a click event. I have a counter question, why was the loop banned inside bindevent?
why is the value 0 incorrect, for example, such use is not possible

Code: Select all

if eventtype() 
; 
endif
User avatar
Demivec
Addict
Addict
Posts: 4267
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: CheckBox doesn't support #PB_EventType_Change

Post by Demivec »

mestnyi wrote: Mon Nov 11, 2024 8:26 pm
mk-soft wrote: Sun Nov 10, 2024 7:02 pm Why should this be corrected? It's fine the way it is.
They are constants that Fred has defined, just as you can create constants for your purposes in your programme.
yes, at least because it is illogical why this theme was created, and because it is more logical that there should be a change in the event rather than a click event. I have a counter question, why was the loop banned inside bindevent?
why is the value 0 incorrect, for example, such use is not possible

Code: Select all

if eventtype() 
; 
endif
The EventType() value of zero for a checkbook gadget is incorrect because the defined event types for a checkbox is the empty set not the set containing zero.
AZJIO
Addict
Addict
Posts: 2191
Joined: Sun May 14, 2017 1:48 am

Re: CheckBox doesn't support #PB_EventType_Change

Post by AZJIO »

mestnyi wrote: Mon Nov 11, 2024 8:26 pm

Code: Select all

if eventtype() 
; 
endif
Faulty logic. If there is no event, then its type does not exist. If an event has arrived, then it must have a type. Defining an event by the absence of a type is absurd. If you assume that you would like to check for the absence of a type before checking 5 different types in order to speed up the code, then the disappointment is that even if there was a value that determines the absence of a type, it still would not help you, since the number is not a the absence of a type and it would still force you to make checks with all five types. Roughly speaking, if you want to ignore an event by type, then simply call EventGadget() first, and if there is no event, then there will be no type.
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: CheckBox doesn't support #PB_EventType_Change

Post by mestnyi »

AZJIO wrote: Mon Nov 11, 2024 9:48 pm
mestnyi wrote: Mon Nov 11, 2024 8:26 pm

Code: Select all

if eventtype() 
; 
endif
Faulty logic. If there is no event, then its type does not exist. If an event has arrived, then it must have a type. Defining an event by the absence of a type is absurd. If you assume that you would like to check for the absence of a type before checking 5 different types in order to speed up the code, then the disappointment is that even if there was a value that determines the absence of a type, it still would not help you, since the number is not a the absence of a type and it would still force you to make checks with all five types. Roughly speaking, if you want to ignore an event by type, then simply call EventGadget() first, and if there is no event, then there will be no type.
This is exactly the same infallible logic. :D
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: CheckBox doesn't support #PB_EventType_Change

Post by BarryG »

First post edited to better clarify what I'm requesting. :)
Psych
Enthusiast
Enthusiast
Posts: 239
Joined: Thu Dec 18, 2008 3:35 pm
Location: Wales, UK

Re: CheckBox doesn't support #PB_EventType_Change

Post by Psych »

Checkboxes, as far as I am aware, just fire as a GadgetEvent, EventGadget() tells you the checkbox, and the event is ALWAYS a change of state (and even if by some weird situation it isn't, what harm would that do?)

So just check for that.
----------------------------------------------------------------------------
Commenting your own code is admitting you don't understand it.
----------------------------------------------------------------------------
User avatar
Piero
Addict
Addict
Posts: 923
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: CheckBox doesn't support #PB_EventType_Change

Post by Piero »

Would this work?

Code: Select all

Enumeration CheckBoxes
   #__CheckBox_index_start = 1000
   #myCheckBox1
   #myCheckBox2
   #__CheckBox_index_end
EndEnumeration

If OpenWindow(0,0,0,270,170,"CheckBoxGadget",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
   
   CheckBox_index = #__CheckBox_index_end
   CheckBoxGadget(CheckBox_index, 10,70,250,20,~"\"runtime CheckBox\"")
   CheckBox_index+1
   CheckBoxGadget(CheckBox_index, 10,100,250,20,~"\"runtime CheckBox\"")
   CheckBox_index+1
   
   CheckBoxGadget(#myCheckBox1,   10,10,250,20,"standard CheckBox")
   CheckBoxGadget(#myCheckBox2,   10,40,250,20,"standard CheckBox")
   StringGadget(0,10,130,250,20,"")
   Repeat
      ev=WaitWindowEvent()
      If ev=#PB_Event_Gadget
         if EventType() = #PB_EventType_Change or EventGadget() > #__CheckBox_index_start
            Debug "Gadget changed: " + EventGadget()
         EndIf
      EndIf
   Until ev=#PB_Event_CloseWindow
EndIf
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: CheckBox doesn't support #PB_EventType_Change

Post by ChrisR »

I have no problem on my side with checkboxes without EventType(),
But on the other hand, the same question deserves to be asked for optionGadget. If an option is already enabled and we click on it, there is no status change but yet we receive an event that is useless.
Either we should have #PB_EventType_Change, or an event only if there is a real status change.

Code: Select all

Define GadgetChanged
If OpenWindow(0, 0, 0, 270, 100, "Changed", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CheckBoxGadget(0, 10, 10, 250, 20, "CheckBox standard")
  StringGadget(1, 10, 40, 250, 20, "")
  OptionGadget(2, 10, 70, 120, 20, "Option 1")
  OptionGadget(3, 140, 70, 120, 20, "Option 2")
  Repeat
    ev=WaitWindowEvent()
    If ev=#PB_Event_Gadget And IsGadget(EventGadget())
      Select GadgetType(EventGadget())
        Case #PB_GadgetType_ComboBox, #PB_GadgetType_Date, #PB_GadgetType_Editor, #PB_GadgetType_ExplorerList, #PB_GadgetType_ExplorerTree,
             #PB_GadgetType_Image, #PB_GadgetType_ListIcon, #PB_GadgetType_Spin, #PB_GadgetType_String, #PB_GadgetType_Tree  ;#PB_GadgetType_Panel
          If EventType()=#PB_EventType_Change
            GadgetChanged = #True
          EndIf
        Case #PB_GadgetType_CheckBox
          GadgetChanged = #True
        Case #PB_GadgetType_Option
          ;State = GetGadgetState(EventGadget())
          ; it can't be done like this, because we don't receive an event if we click on another option of the same group 
          ;If State <> GetGadgetData(EventGadget()) 
          ;  SetGadgetData(EventGadget(), State)
             GadgetChanged = #True
          ;EndIf
      EndSelect
      If GadgetChanged
        Debug "Either a CheckBox or StringGadget changed"
        GadgetChanged=0  ;Reset for testing other changes in this example
      EndIf
    EndIf
  Until ev= #PB_Event_CloseWindow
EndIf
AZJIO
Addict
Addict
Posts: 2191
Joined: Sun May 14, 2017 1:48 am

Re: CheckBox doesn't support #PB_EventType_Change

Post by AZJIO »

ChrisR wrote: Fri Feb 07, 2025 1:41 am

Code: Select all

    If ev=#PB_Event_Gadget And IsGadget(EventGadget())
      Select GadgetType(EventGadget())
Can the result of EventGadget() change when it is repeated? I’ll ask differently: is the call of WaitwindowEvent() filling a certain structure, after which the functions of the EventGadget() and EventType() functions and others simply receive data from this structure?
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: CheckBox doesn't support #PB_EventType_Change

Post by ChrisR »

I don't think EventGadget(), EventType(),... changes.
They are sent for each Event as in PostEvent(Event [, Window, Object [, Type [, Data]]])
AZJIO
Addict
Addict
Posts: 2191
Joined: Sun May 14, 2017 1:48 am

Re: CheckBox doesn't support #PB_EventType_Change

Post by AZJIO »

However, WaitwindowEvent () returns a new event each time. If it is logically reasoning, then other functions should not return the codes from other events, given that even the mouse movement can create a dozen events per second. So the function cachs the value associated with the captured event.
User avatar
Demivec
Addict
Addict
Posts: 4267
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: CheckBox doesn't support #PB_EventType_Change

Post by Demivec »

AZJIO wrote: Fri Feb 07, 2025 3:09 am However, WaitwindowEvent () returns a new event each time. If it is logically reasoning, then other functions should not return the codes from other events, given that even the mouse movement can create a dozen events per second. So the function cachs the value associated with the captured event.
New events are retrieved from the event queue only when WaitWindowEvent() or WindowEvent() is called. The event retrieved becomes the most recent event.

If an event is bound with a Bind function then the assigned handling procedure for the binding will be executed. After all triggered procedures associated with bindings for the most recent event execution then continues with the next statement after the function that retrieved the event (eitherWaitWindowEvent() or WindowEvent()).

All of the informational functions for events ( i.e. Event(); EventData(); EventGadget(); EventMenu(); EventTimer(); EventType(); EventWindow(); EventlParam(); EventwParam() ), return information for only the most recent event. As long as there isn't a new event retrieved from the event queue with eitherWaitWindowEvent() or WindowEvent().

The informational functions for events are available for use both inside and outside the event handling procedures that are assigned with a Bind function.
User avatar
Piero
Addict
Addict
Posts: 923
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: CheckBox doesn't support #PB_EventType_Change

Post by Piero »

So it would be useful to know if the OptionGadget GROUP changed…

PS:
I had forgot IsGadget and GadgetType… :oops:
It's all clearer now, even how/where to find the right "events stuff" on Help…
Thanks!
Post Reply