Double click in file selection clicks in page


Recommended Posts

The attached shows a page with a file selection dialog overlaid. The file selection dialog works correctly. After opening I can click a file name and then press the Open button, or just double click on the filename and it's opened immediately. Problem is, if I (or the user) double clicks, the second click is passed through and triggers an event for an element behind the filename. How do I disable the event while the dialog is open, or ignore these clicks?

Click_through_to_page.bmp

Link to comment
Share on other sites

Thanks, that should work.

What causes the click to be passed through in the first place, the possibility that multiple pages may be showing at once events on all of them need access to mouse clicks? And why only the second click but not the first one?

Link to comment
Share on other sites

OK, I guess it doesn't work after all. I seem to have a hard time waiting long enough before resetting the flag variable for the event not to trigger. In a button quick sequence I have

DialogOpen = 1
RecFileName = File.FileOpenDialog("", "X:\mmi\", "*.csv", "Open Recipe File")
//DialogOpen = 0
if (!IsEmpty(RecFileName))
   beginseq(OpenRecipe)
   endif
delay(2.0)
DialogOpen = 0

The event is:

if(DialogOpen)

return

endif

private x = LOC[0][0]
private y = LOC[0][1] - RecipeEntryTop
private col = search(x < RecipeEntryCols, 0)
if((col % 2) && (y > 0) && (y % RecipeEntryVCtr < RecipeEntryVSz))
   private row = floor(y / RecipeEntryVCtr)
   if (row <= (NumRows(NumRecord)-1))
	  if (CurrentUserEntryOK == 1)
		 switch
			case (col == 1)
			   strTemp = system.EntryDialog("Recipe Component " + DoubleToStr(row + 1) + " Name")
			   if (IsEmpty(strTemp) == 0)
				  strNames[row] = left(LTrim(strTemp),20)
				  endif
			default
			   col = col / 2 - 0.5
			   temp = system.EntryDialog("Recipe Component " + DoubleToStr(row + 1) + " " + RecipePrompts[col] + " " \
				  + Chr(40) + DoubleToStr(RecipeEntryMin[col]) + " to " + DoubleToStr(RecipeEntryMax[col]) + Chr(41), RecipeEntryMin[col], RecipeEntryMax[col])
			   if (IsEmpty(temp) == 0)
				  numRecord[row][col-1] = temp
				  endif
			endcase
		 else
			page.Access_Denied.PopupModal()
		 endif
	  endif
   endif

"DialogOpen = 0" immediately after the return from System.EntryDialog() didn't work, so I moved it to the end after it calls the other OpenRecipe sequence. Still runs the event. Added the "delay(2.0)" and it takes a hell of a long time before closing the dialog, but it STILL activates the event.

Link to comment
Share on other sites

Yeah, that's because everything is running in the same thread, namely the primary thread of the app. So, the click event of the control runs, then the event runs, so no matter how long the delay, the flag is set to 0 before the other event triggers. You never want delay() in a click event because it will cause the app to appear hung as you saw. The way around this is to create a simple sequence with two lines:

delay(2)

dialogOpen = 0

then call beginseq(mysequence) at the end of the first script. This will cause the delay() to run in a separate thread, and keep the other event from triggering.

Speaking of, the first script I presume is a quick sequence on a component? What is the event attached to? The same control? The page?

Link to comment
Share on other sites

Why does the dialog trap the first click (if you click on the file name and use the "Open" button), but will pass through one click if you double click on the file name? Also, I take it that the dialog stays open till the end of the quick sequence, rather than closing after the FileOpenDialog() returns?

Link to comment
Share on other sites

The dialog closes when the user hits OK or Cancel, which is when FileOpenDialog() returns.

I don't think it does, at least not in the sense that I meant. When I add the delay(2.0), that delay expires before the dialog is removed. I assumed that the dialog would be removed before the following statements were executed. Your answer about the user hitting OK or Cancel made me realize that my problem occurred when using a third method of exiting the dialog (double clicking the file name), and thought I might be seeing a backup mechanism to clean up the dialog by the end of the calling sequence at the latest. I tried single-clicking and hitting OK, but it still stays open till after the expiration of the delay().

It passes events through to all components at the mouse click. It probably will do the same thing if you hit cancel.

I'm not really following that statement. Can you elaborate? I can single click and OK, and the single click doesn't get passed through to the event, but if I select the file by double clicking, then after completion of the dialog, the other component reacts as if I had clicked it once.

Link to comment
Share on other sites

OK, well, I was trying to save you from more details: the reason it appears to not close is because the Windows message pump doesn't get serviced until after your event script finishes, and the command to close the dialog is sitting on the message queue waiting to be processed. This is also why adding a delay(2) causes DAQFactory to appear hung. The message pump handles all messages for the UI that go to DAQFactory, and if its not serviced, nothing UI related happens, including clicks, screen refreshes, closing dialogs, etc.

As for my other comment, I suppose the second click is what is triggering the event. I don't know why Windows is passing it through. Do you have your explorer settings for single click open?

Link to comment
Share on other sites

OK, well, I was trying to save you from more details: the reason it appears to not close is because the Windows message pump doesn't get serviced until after your event script finishes, and the command to close the dialog is sitting on the message queue waiting to be processed. This is also why adding a delay(2) causes DAQFactory to appear hung. The message pump handles all messages for the UI that go to DAQFactory, and if its not serviced, nothing UI related happens, including clicks, screen refreshes, closing dialogs, etc.

Oh, OK, that makes sense (I guess sometimes more detail makes stuff easier to understand). And BTW, doing a beginseq() to spawn a new thread and putting the delay() in there works good as long as the delay is at least 0.08 - 0.10 seconds. Any shorter and the flag is cleared by the time the time the event gets the phantom click.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.