popup button losing focus after Ask dialog

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
trevix
Posts: 1077
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

popup button losing focus after Ask dialog

Post by trevix » Fri Oct 29, 2021 11:31 am

I have a group that acts as a Popup button, both for desktop and mobile. It is invisible and acts only if the button is kept down for 4 seconds.
I use it in order to access a secret debug card that the users should not be allowed in.
The group is transparent and it is made with 2 buttons, "BtnDebug" and a invisible "DebugPop".
It works fine. Below, find the code.

I decided to add a password check (ask password) and I noticed that now on desktop it trows an error on the line "popup tLongPop", but only if i move the mouse to the Ask dialog.
Somehow the "Ask" dialog interfere with the process.
Focusing on the button doesn't change a thing.

Can someone share a light on this? Thanks

Code: Select all

On MouseDown
     ---for debug show the test button
     ask "Password?"
     if it <> "SomePassword" then exit MouseDown
     send "CheckForDebug" to me in 4 seconds
end MouseDown

Command  CheckForDebug
     if the mouse is down then
          put the long name of button "DebugPop" of the owner of me into tLongPop
          
          put the cList of button id 1235 of stack "SegnaPunto" into tList
          if environment() = "mobile" then
               mobilePick tList, 1, "cancelDone"
               put the result into tResult
               put line tResult of tList into tResult
               send "menuPick tResult" to tLongPop --btn "DebugPop" of the owner of  me 
          else
               focus on tLongPop
               get flushEvents("Mouseup")
               set the text of tLongPop to tList --btn "DebugPop" of the owner of me to tList
               popup tLongPop
          end if
     end if
end CheckForDebug
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: popup button losing focus after Ask dialog

Post by dunbarx » Fri Oct 29, 2021 12:36 pm

Hi.

To simplify for me. I made a button and a field, and put this in the button script:

Code: Select all

On MouseDown
   ask "Password?"
   if it <> "x" then exit MouseDown
   send "CheckForDebug" to me in  50
end MouseDown


Command  CheckForDebug
   if the mouse is down then  put random(888) into fld 1
end CheckForDebug
It works fine, but is awkward. As you wrote it, you must click on the button and make sure you keep holding the mouse down while you type an "x" and hit return. Is that what you intended?

Craig

trevix
Posts: 1077
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Re: popup button losing focus after Ask dialog

Post by trevix » Fri Oct 29, 2021 2:49 pm

Thanks but, as you said, it doesn't work.
The Ask dialog must be in the "CheckForDebug" script, after the "if the mouse is down".
Beside, putting a blue in a field would't be a problem. The problem is the "PopUp" command that doesn't work anymore if the focus has been moved to the Ask dialog.
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: popup button losing focus after Ask dialog

Post by mwieder » Sat Oct 30, 2021 5:56 pm

trevix-

Not quite sure what you mean here... the "ask" dialog is modal, so it will go away when you click dismiss it. Only then does the "send" command come into play, so you can no longer move the mouse over the dialog.

In any event, the "focus on tLongPop" line is wrong. You can't focus on a button. If you remove that line it should work as I think you intend.

trevix
Posts: 1077
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Re: popup button losing focus after Ask dialog

Post by trevix » Sat Oct 30, 2021 9:35 pm

The menu appears in my example only if the user keep the button pressed fo 4 seconds: this is the intended working.
The password entering can be done only having lifted the finger, so Dunbarx script does not fit to me.

As for the focus, i tried to add it just to solve the problem: if you remove the line I still get the problem.
Try the the attached example stack
Attachments
ExampleOfProblem.livecode.zip
(2.92 KiB) Downloaded 157 times
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: popup button losing focus after Ask dialog

Post by mwieder » Sat Oct 30, 2021 10:51 pm

The code in that sample stack is different from what you posted in some significant ways.
Nonetheless, I can confirm the problem you're seeing and I can "fix" it with the following workaround:

Code: Select all

         set the text of tLongPop to tList --btn "DebugPop" of the owner of me to tList
         wait 0 milliseconds with messages
         popup tLongPop
And this works if you move the cursor over the ask dialog, if you hit return, or if you press the OK button.
As to the why of what's going on, I can only imagine it's hidden deep in the recesses of the system's ask dialog.

trevix
Posts: 1077
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Re: popup button losing focus after Ask dialog

Post by trevix » Sun Oct 31, 2021 11:11 am

Thanks.
Sometimes, finding a solution requires intuition as well as experience.
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: popup button losing focus after Ask dialog

Post by mwieder » Sun Oct 31, 2021 4:47 pm

Well, I think of this as more of a workaround kludge than an actual "solution" but it seems to do the trick.

My guess is that moving the cursor to the ask dialog changes the stack/control focus and the system needs a finite amount of time to process the change in focus back to your topstack before the popup command is invoked. And that's why you were getting the "can't find stack" error. So the "with messages" statement allows the script to yield pending events like a change in focus before moving on to the popup command.

That's all guesswork, but that's what prompted me to insert the wait command.

Post Reply