Double events

Just starting out? Need help? Post your questions and find answers here.
User avatar
bfernhout
Enthusiast
Enthusiast
Posts: 130
Joined: Mon Feb 26, 2018 10:41 pm
Location: Netherlands
Contact:

Double events

Post by bfernhout »

I am not a very good programmere but i am using PB for a long time now. And are happy with it. But i notice a little thing afther creating a form and then converting it to a PB file. No problem there. Write some extra code and the code is running.
Now i notice that the eventgadget gives a double signal back on one event (I mean all eventgadget give back the double signal)

Code: Select all

Enumeration FormWindow
  #Window_test
EndEnumeration

Enumeration FormGadget
  #Text_trough_file_Inserter
  #Button_Done
  #Text_1
EndEnumeration


Procedure OpenWindow_test(x = 0, y = 0, width = 495, height = 255)
  OpenWindow(#Window_test, x, y, width, height, "", #PB_Window_SystemMenu)
  StringGadget(#Text_trough_file_Inserter, 115, 50, 240, 30, "")
  ButtonGadget(#Button_Done, 200, 150, 100, 40, "")
  TextGadget(#Text_1, 120, 35, 155, 25, "Click once")
EndProcedure

Procedure Window_test_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #True

    Case #PB_Event_Menu
      Select EventMenu()
      EndSelect
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Text_trough_file_Inserter
          Debug "Hit Text"
        Case #Button_Done
          ProcedureReturn #True
      EndSelect
  EndSelect
  ProcedureReturn #False
EndProcedure

OpenWindow_test()
Repeat
  
  If Window_test_Events(WaitWindowEvent())
    End
  EndIf
  
ForEver
On the debug screen its showing
Hit Text
Hit Text

Click on the button Done and the debug window show 4 time the text.

Normaly this is no problem. But i created a form with more then one StringGadgets. This is done to make a database.
And here is the problem. I click on the #Text_trough_file_Inserter and it got the focus.
But in my program i need to click again on the other line to get the focus on that line. Casue the Eventgadget returned the focus back to the first StringGadget again.
From my first self made computer till now I stil like computers.
User avatar
bfernhout
Enthusiast
Enthusiast
Posts: 130
Joined: Mon Feb 26, 2018 10:41 pm
Location: Netherlands
Contact:

Double events

Post by bfernhout »

Sorry clicked on the Submit button.

Here some extra information. There is something wrong here.

BTW: when i clicked on the StringGadget it's add some text to a String variable. (Not replacing it) The contains of the Gadget is inserted double too. This is a unwant side effect of it.

bart.
From my first self made computer till now I stil like computers.
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Double events

Post by Marc56us »

Gadgets always return two events: the window and the gadget. If we process only one, PB considers two actions.
In the case of a StringGadget, it allows to do several things and not only one click. (The possibilities are: Single right/left click, double right/left click, focus, lost focus, drop)
In most cases, we don't bother to separate the two actions.
(I don't know if I'm explaining it right :oops: )

Try this to see some actions (select, type text, then use TAB)

Code: Select all

Enumeration FormWindow
    #Window_test
EndEnumeration

Enumeration FormGadget
    #Text_trough_file_Inserter
    #Button_Done
    #Text_1
EndEnumeration


Procedure OpenWindow_test(x = 0, y = 0, width = 495, height = 255)
    OpenWindow(#Window_test, x, y, width, height, "", #PB_Window_SystemMenu)
    StringGadget(#Text_trough_file_Inserter, 115, 50, 240, 30, "")
    ButtonGadget(#Button_Done, 200, 150, 100, 40, "")
    TextGadget(#Text_1, 120, 35, 155, 25, "Click once")
EndProcedure

Procedure Window_test_Events(event)
    Select event
        Case #PB_Event_CloseWindow
            ProcedureReturn #True
            
        Case #PB_Event_Menu
            Select EventMenu()
            EndSelect
            
        Case #PB_Event_Gadget
            Select EventGadget()
                Case #Text_trough_file_Inserter
                    Select EventType() 
                        Case #PB_EventType_Focus
                            Debug "String have focus"   
                        Case #PB_EventType_Change       
                            Debug "Text has changed"
                        Case #PB_EventType_LostFocus ; (hit Tab to test)
                            Debug "Focus lost"
                    EndSelect
                    
                Case #Button_Done
                    ProcedureReturn #True
            EndSelect
    EndSelect
    ProcedureReturn #False
EndProcedure

OpenWindow_test()
Repeat
    
    If Window_test_Events(WaitWindowEvent())
        End
    EndIf
    
ForEver
:wink:
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Double events

Post by netmaestro »

This looks like a bug to me. The string gadget is reporting two events: 14000 = #PB_EventType_Focus and 256 = ? According to the doc there is no event type constant = 256. Why report an event which has no functional meaning?
BERESHEIT
User avatar
bfernhout
Enthusiast
Enthusiast
Posts: 130
Joined: Mon Feb 26, 2018 10:41 pm
Location: Netherlands
Contact:

Re: Double events

Post by bfernhout »

Thanks for the reply.

I did not know that there was a EventType. This make the double event reduce to a single event.
I did not know that windows return always a double one. I did tested my program on a win 8, 10 and 11 system. They all give the same result. Now i using this on the result of getting the focus. Copy the string inside so i can restore infomation is needed.
Thanks a lot.

The manuals is so huges that its almost impossible the know it all.
From my first self made computer till now I stil like computers.
User avatar
bfernhout
Enthusiast
Enthusiast
Posts: 130
Joined: Mon Feb 26, 2018 10:41 pm
Location: Netherlands
Contact:

Re: Double events

Post by bfernhout »

hello netmaestro

I tested this on differend machines and using 3 differend versions of PB. i don't think this is a bug. But you never can tell, if it's do. But if all versions do the same, i think that PB is just reading the information Windows is troughwing. So if windows is giving a double event, the solution on the second example is just a good solution to this problem. Because the EventType is giving just one event. And that is good.

But if this is a real bug, Then i hope that this will solved in the new release of PB.
From my first self made computer till now I stil like computers.
infratec
Always Here
Always Here
Posts: 7658
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Double events

Post by infratec »

According to the help of StringGadget:

Code: Select all

#PB_EventType_Change
#PB_EventType_Focus
#PB_EventType_LostFocus
The values are:

Code: Select all

768
14000
14001
Help of EventType():

Code: Select all

#PB_EventType_LeftClick
#PB_EventType_RightClick
#PB_EventType_LeftDoubleClick
#PB_EventType_RightDoubleClick
#PB_EventType_Focus
#PB_EventType_LostFocus
#PB_EventType_Change
#PB_EventType_DragStart
The values:

Code: Select all

0
1
2
3
14000
14001
768
14002
The additional returned EventType 256 is not known.

But I don't see it as a bug, because for the StringGadget you need always to check the EventType()
And only the listed three are 'official' available.
So you can only count on them. (And you have to check for them)
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Double events

Post by Marc56us »

For 256 WM_KEYFIRST / WM_KEYDOWN (?)

Code: Select all

; Re: Event chain For windows And gadgets
; Post by mk-soft » Mon Feb 18, 2019 9:58 pm 
; http://forums.purebasic.com/english/viewtopic.php?p=533086
Debug "#WM_KEYDOWN                    : " + #WM_KEYDOWN
Debug "#WM_KEYFIRST                   : " + #WM_KEYFIRST

; PB Help
Debug "#PB_EventType_LeftClick        : " + #PB_EventType_LeftClick   
Debug "#PB_EventType_RightClick       : " + #PB_EventType_RightClick  
Debug "#PB_EventType_LeftDoubleClick  : " + #PB_EventType_LeftDoubleClick
Debug "#PB_EventType_RightDoubleClick : " + #PB_EventType_RightDoubleClick
Debug "#PB_EventType_Focus            : " + #PB_EventType_Focus       
Debug "#PB_EventType_LostFocus        : " + #PB_EventType_LostFocus   
Debug "#PB_EventType_Change           : " + #PB_EventType_Change      
Debug "#PB_EventType_DragStart        : " + #PB_EventType_DragStart   
User avatar
bfernhout
Enthusiast
Enthusiast
Posts: 130
Joined: Mon Feb 26, 2018 10:41 pm
Location: Netherlands
Contact:

Re: Double events

Post by bfernhout »

Thank you all for the extra information.

It's helped me a lot.

bart.
From my first self made computer till now I stil like computers.
Post Reply