Show message box action: changing the default payload after timeout

If you have a question or need help, this is the place to be.
Post Reply
blaher
Experienced User
Posts: 494
Joined: Thu Nov 17, 2011 1:27 am

Show message box action: changing the default payload after timeout

Post by blaher » Thu Apr 30, 2020 3:21 am

I'm looking to automate shutting my computer down, if the user doesn't abort the timer after a certain period.

Code: Select all

eg.plugins.EventGhost.ShowMessageBox(u'Shutting Down', u"Shutting Down in 5s\n\nSelect 'Cancel' to abort.", u'', u'shutdown', True, 28737, 1, 5)
The problem is that when the timer runs out, it issues a cancel as the default. I want the default to be OK, when it times out.

i.e. at the moment I'm getting an event at the end of the countdown that says:

MessageBox.Shutting Down.CANCEL u"shutdown"

But I want:

MessageBox.Shutting Down.OK u"shutdown"

Any ideas how to change this, please?

User avatar
kgschlosser
Site Admin
Posts: 5498
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Show message box action: changing the default payload after timeout

Post by kgschlosser » Thu Apr 30, 2020 10:46 pm

OK so in the action there are some choices as to what buttons you want to appear. If you have the dialog open and have it set to ask a question with a choice between Yes or No for buttons will solve your problem.

The dialog is always going to close with wx.ID_CANCEL if the timer expires. but if you have a yes and a no button then you will get wx.ID_YES if the user presses the yes button and wx.ID_NO if the user presses the no button. This will allow you to tell between the timer expiring and a user actually not wanting to reboot.

So these are the events you will end up with

MessageBox.Shutting Down.CANCEL u"shutdown"
MessageBox.Shutting Down.YES u"shutdown"
MessageBox.Shutting Down.NO u"shutdown"
If you like the work I have been doing then feel free to Image

blaher
Experienced User
Posts: 494
Joined: Thu Nov 17, 2011 1:27 am

Re: Show message box action: changing the default payload after timeout

Post by blaher » Fri May 01, 2020 5:16 am

Thank you, that did the trick. Perhaps in the future a different event could be triggered for the cancel button, as opposed to the time ending.

User avatar
kgschlosser
Site Admin
Posts: 5498
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Show message box action: changing the default payload after timeout

Post by kgschlosser » Sat May 02, 2020 5:03 pm

I am thinking the same thing. maybe also include the wx.ID_ in a payload this way it can be tested using a script if needs be.
If you like the work I have been doing then feel free to Image

Post Reply