Double Click & Single Click

Just starting out? Need help? Post your questions and find answers here.
AMpos
Enthusiast
Enthusiast
Posts: 128
Joined: Fri Jun 05, 2020 12:47 am

Double Click & Single Click

Post by AMpos »

-I have Window A
-It open over it Window B (and get A disabled)
-Window B is waiting for a double click on a iconlist
-When user double click, it closes Window B and enable again Window A
-The problem is that Window A get a SingleClick (when you double click, 3 events are generated, a Left+double+left)

How can I "delete" this last LeftClick event (or all events in the queue, I don't care) before returning to Window A?
Last edited by AMpos on Fri Jul 31, 2020 11:19 am, edited 1 time in total.
User avatar
NicTheQuick
Addict
Addict
Posts: 1226
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: DOUBLE CLICK & SINGLE CLICK

Post by NicTheQuick »

You should consider showing us an example code which demonstrates that unexpected behaviour.

Furthermore, capital letters are understood as screams.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 636
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: Double Click & Single Click

Post by captain_skank »

Have you got a single event handler loop for all windows.

Without code it's hard to help.
AMpos
Enthusiast
Enthusiast
Posts: 128
Joined: Fri Jun 05, 2020 12:47 am

Re: Double Click & Single Click

Post by AMpos »

Ok, I will try to do a code, but... is it possible to clean the event queue, or a loop to wait until it is clear?

Something like

Code: Select all

REPEAT
 event=eventwindow()
UNTIL event=0
User avatar
NicTheQuick
Addict
Addict
Posts: 1226
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Double Click & Single Click

Post by NicTheQuick »

Are you serious? That's no example code that runs out of the box and shows the issue.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
AMpos
Enthusiast
Enthusiast
Posts: 128
Joined: Fri Jun 05, 2020 12:47 am

Re: Double Click & Single Click

Post by AMpos »

Of course it is not a sample code!!!!!

I am just asking this:

Is there a way to clean the (pb) event queue, or can a loop be created to wait until it is empty?
BarryG
Addict
Addict
Posts: 3322
Joined: Thu Apr 18, 2019 8:17 am

Re: Double Click & Single Click

Post by BarryG »

AMpos wrote: is it possible to clean the event queue, or a loop to wait until it is clear?
Yes, like this:

Code: Select all

While WindowEvent() : Wend
AMpos
Enthusiast
Enthusiast
Posts: 128
Joined: Fri Jun 05, 2020 12:47 am

Re: Double Click & Single Click

Post by AMpos »

BarryG wrote:
AMpos wrote: is it possible to clean the event queue, or a loop to wait until it is clear?
Yes, like this:

Code: Select all

While WindowEvent() : Wend
Thank you, will try if it fixes my problem.
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: Double Click & Single Click

Post by Marc56us »

-I have Window A
-It open over it Window B (and get A disabled)
-Window B is waiting for a double click on a iconlist
-When user double click, it closes Window B and enable again Window A
-The problem is that Window A get a SingleClick (when you double click, 3 events are generated, a Left+double+left)
The system always returns two pieces of information per event: the event itself and the window that generated the event.
When working with a single window, only one piece of information is used, but when working with several windows, both pieces of information must be used.

Either before

Code: Select all

Select EventWindow()
    Case #Win_A
    Case #Win_B

Either in terms of events

Code: Select all

If EventType() = ... And EventWindow() =       
This way the events in one window do not influence the other windows. No need to empty the event queue.

Of course we can mix that up with the events common to all the windows.

:wink:
AMpos
Enthusiast
Enthusiast
Posts: 128
Joined: Fri Jun 05, 2020 12:47 am

Re: Double Click & Single Click

Post by AMpos »

Here you have the Example Code.

Code: Select all

OpenWindow(0,000,000,400,400,"Window A")
ListIconGadget(0,10,10,380,380,"TEST",100)
OpenWindow(1,40,40,320,320,"Window B")
ListIconGadget(1,10,10,300,300,"test 2",100)

DisableWindow(0,1)

Repeat
	event=WaitWindowEvent()
	Select EventGadget()
		Case 1
			Select EventType()	
				Case #PB_EventType_LeftDoubleClick
					Debug "Click Twice at Window B"
					CloseWindow(1)
					DisableWindow(0,0)
					SetActiveWindow(0)
					Break
			EndSelect
			
	EndSelect	
Until event=#PB_Event_CloseWindow

;While WindowEvent() : Wend

Repeat
	event=WaitWindowEvent()
	Select EventGadget()
		Case 0
			Select EventType()	
				Case #PB_EventType_LeftClick
					Debug "Click Once at Window A"
			EndSelect
			
	EndSelect	
Until event=#PB_Event_CloseWindow
If you DoubleClick on Window B, never should be a "Left Click" on Window A.

Code: Select all

While WindowEvent() : Wend
This code does not clear the queue. In fact, with this line disabled, WIndow A receives 2 single Clicks. Enable it, and it receives 1.
AMpos
Enthusiast
Enthusiast
Posts: 128
Joined: Fri Jun 05, 2020 12:47 am

Re: Double Click & Single Click

Post by AMpos »

I ahve made another version, checking if the event was in Window A, and it does not work, also:

Code: Select all

OpenWindow(0,000,000,400,400,"Window A")
ListIconGadget(0,10,10,380,380,"TEST",100)
OpenWindow(1,40,40,320,320,"Window B")
ListIconGadget(1,10,10,300,300,"test 2",100)

DisableWindow(0,1)

Repeat
	event=WaitWindowEvent()
	Select EventGadget()
		Case 1
			Select EventType()	
				Case #PB_EventType_LeftDoubleClick
					Debug "Click Twice at Window B"
					CloseWindow(1)
					DisableWindow(0,0)
					SetActiveWindow(0)
					Break
			EndSelect
			
	EndSelect	
Until event=#PB_Event_CloseWindow

Repeat
	event=WaitWindowEvent()
	Select EventGadget()
		Case 0
			If EventType()=#PB_EventType_LeftClick And EventWindow()=0
				Debug "Click Once at Window A"
			EndIf			
	EndSelect	
Until event=#PB_Event_CloseWindow
BarryG
Addict
Addict
Posts: 3322
Joined: Thu Apr 18, 2019 8:17 am

Re: Double Click & Single Click

Post by BarryG »

[Removed, mistake on my part]
Last edited by BarryG on Sat Aug 01, 2020 8:35 am, edited 1 time in total.
User avatar
mk-soft
Always Here
Always Here
Posts: 5401
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Double Click & Single Click

Post by mk-soft »

Your evaluation of the events is not complete.

Always use only one EventLoop with WaitWindowEvent(). Otherwise you get confused and you wonder why one event does not arrive.

Code: Select all

Procedure Open1()
  If OpenWindow(0,000,000,400,400,"window a", #PB_Window_SystemMenu)
    ListIconGadget(0,10,10,380,380,"test",100)
    ProcedureReturn #True
  Else
    ProcedureReturn #False
  EndIf
EndProcedure

Procedure Open2()
  If OpenWindow(1,40,40,320,320,"window b", #PB_Window_SystemMenu, WindowID(0))
    ListIconGadget(1,10,10,300,300,"test 2",100)
    ProcedureReturn #True
  Else
    ProcedureReturn #False
  EndIf
  
EndProcedure

Procedure MainLoop()
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Select EventWindow()
          Case 0
            Break ; leave the event loop
            
          Case 1
            DisableWindow(0,0)
            SetActiveWindow(0)
            CloseWindow(1)
            
        EndSelect
        
      Case #PB_Event_Menu
        Select EventMenu()
            ;    
        EndSelect
        
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0
            Select EventType()   
              Case #PB_EventType_LeftDoubleClick
                Debug "click twice at list a"
                If Open2()
                  DisableWindow(0, 1)
                EndIf
            EndSelect
          Case 1
            Select EventType()   
              Case #PB_EventType_LeftDoubleClick
                Debug "click twice at list b"
            EndSelect
            
        EndSelect   
        
    EndSelect
    
  ForEver
  
EndProcedure

If Open1()
  If Open2()
    DisableWindow(0,1)
  EndIf
  
  MainLoop()
  
EndIf

End

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
AMpos
Enthusiast
Enthusiast
Posts: 128
Joined: Fri Jun 05, 2020 12:47 am

Re: Double Click & Single Click

Post by AMpos »

mk-soft wrote:Your evaluation of the events is not complete.

Always use only one EventLoop with WaitWindowEvent(). Otherwise you get confused and you wonder why one event does not arrive.

Code: Select all

...

It doesnt work. Window B has to be closed after a double click. And Window A only has to respond to Sinlge Left Click.

I tryied to add "close window..." part to the LeftDoubleClick and change the first Left to DoubleLeft and it keeps closing and opening Window B, and detecting also a LeftClick on Window A.
BarryG
Addict
Addict
Posts: 3322
Joined: Thu Apr 18, 2019 8:17 am

Re: Double Click & Single Click

Post by BarryG »

[Removed, mistake on my part]
Last edited by BarryG on Sat Aug 01, 2020 8:35 am, edited 1 time in total.
Post Reply