Modify

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#379 closed Bug (No Bug)

Tray OnEvents ignored

Reported by: corz Owned by:
Milestone: Component: AutoIt
Version: 3.2.12.0 Severity: None
Keywords: menu, event, TrayItemSetOnEvent, ignore Cc:

Description (last modified by Valik)

In the following proof of concept, fire the DoRun() function via the GUI button, the HotKey, or the keyboard modifier, and everything works perfectly; pause, resume, and exit tray menus all work as they should. Pause and resume can be activated multiple times, no problems.

Fire DoRun() via the tray, and suddenly all the other tray menu items stop working, and their events buffer and back-up until the entire loop is complete. code..

#include <GUIConstants.au3>
#include <Constants.au3>

AutoItSetOption("TrayMenuMode", 9)
AutoItSetOption("TrayOnEventMode", 1)
AutoItSetOption("GUIOnEventMode", 1)

global $pause = 0 
; some example stuff to do in the loop..
global $commands[5] = [4, "compact.exe /C /S I:\work\documents\reports\*.log", "compact.exe /U /S I:\work\documents\reports\*.log", _
						"compact.exe /C /S I:\work\documents\reports\*.log", "compact.exe /U /S I:\work\documents\reports\*.log"]
global $trayrun, $traypause, $trayresume, $trayexit

MakeTray()
HotKeySet("^r", "HK_DoRun")

$gui = GUICreate("My GUI", 200, 40)
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitScript")

$butt = GUICtrlCreateButton("&Run", 5, 5, 190)
GuiCtrlSetOnEvent(-1, "DoRun")
GUISetState()


while 1
    Sleep(10)
wend

exit


func DoRun()

	$pause = 0

	for $i = 1 to $commands[0]
ConsoleWrite(".\" & @ScriptName & " (" & @ScriptLineNumber & ") : ==> " & "pause: " & $pause & @LF)
		while $pause = 1
			Sleep(250)
		wend
		$return_code = RunWait($commands[$i])
	next
	MsgBox(0, "all done", "all done")
endfunc

func MakeTray()
	$trayrun = TrayCreateItem("Run")
	TrayItemSetOnEvent(-1,"DoRun")
	TrayCreateItem("")
	$traypause = TrayCreateItem("Pause")
	TrayItemSetOnEvent(-1,"DoPause")
	$trayresume = TrayCreateItem("Resume")
	TrayItemSetOnEvent(-1,"DoResume")
	TrayItemSetState(-1, $TRAY_DISABLE)
	TrayCreateItem("")
	$trayexit = TrayCreateItem("Exit")
	TrayItemSetOnEvent(-1,"ExitScript")
	TraySetClick(8)
	TraySetState()
endfunc

func DoPause()
ConsoleWrite(".\" & @ScriptName & " (" & @ScriptLineNumber & ") : ==> " & "PAUSING: " & @LF)
    $pause = 1
    TrayItemSetState($traypause, $TRAY_DISABLE)
    TrayItemSetState($trayresume, $TRAY_ENABLE)
	GUICtrlSetState($butt, $GUI_DISABLE)
	WinSetTitle("My GUI", "", "paused")
endfunc

func DoResume()
    $pause = 0
    TrayItemSetState($traypause, $TRAY_ENABLE)
    TrayItemSetState($trayresume, $TRAY_DISABLE)
	GUICtrlSetState($butt, $GUI_ENABLE)
	WinSetTitle("paused", "", "My GUI")
endfunc


func HK_DoRun()
	if WinActive($gui) then
		DoRun()
	else
		HotKeySet("^r")
		Send("^r")
		HotKeySet( "^r" , "HK_DoRun")
	endif
endfunc

func ExitScript()
    exit
endfunc

; end

It seems really weird to me, and I can't find an explanation anywhere.

Is this a bug? Or what?

;o)
(or

Attachments (0)

Change History (10)

comment:1 Changed 16 years ago by Valik

  • Description modified (diff)

comment:2 Changed 16 years ago by Valik

Create a better example. All those RunWait() commands, do you actually think we can run those? And do they even matter at all to the bug you're trying to report? Example scripts are supposed to be the bare minimum required to reproduce a bug and to me that looks like quite a bit more than the bare minimum.

comment:3 Changed 16 years ago by anonymous

I put them there simply so that you have something to pause *between*. Any command that takes a second or two will do the trick.

You should have no problem running compact.exe on any Win 2K+ system, though obviously the paths would need to be changed.

I can easily replace those with something else for the sake of an example, but I can't think of anything else off-hand that would take "a second or more" to complete, to give you enough time to play with the pause/resume, what would you suggest?

;o)
(or

comment:4 Changed 16 years ago by anonymous

How about this..

#include <GUIConstants.au3>
#include <Constants.au3>

AutoItSetOption("TrayMenuMode", 9)
AutoItSetOption("TrayOnEventMode", 1)
AutoItSetOption("GUIOnEventMode", 1)

global $pause = 0
; some example stuff to do in the loop..
global $trayrun, $traypause, $trayresume, $trayexit

MakeTray()
HotKeySet("r", "HK_DoRun")

$gui = GUICreate("My GUI", 200, 40)
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitScript")

$butt = GUICtrlCreateButton("&Run", 5, 5, 190)
GuiCtrlSetOnEvent(-1, "DoRun")
GUISetState()

while 1

Sleep(10)

wend

exit

func DoRun()

$pause = 0

for $i = 1 to 6

ConsoleWrite(".\" & @ScriptName & " (" & @ScriptLineNumber & ") : ==> " & "pause: " & $pause & @LF)

while $pause = 1

Sleep(250)

wend

for $x = 1 to 100

sleep(1)
; do nothing.

next

next
MsgBox(0, "all done", "all done")

endfunc

func MakeTray()

$trayrun = TrayCreateItem("Run")
TrayItemSetOnEvent(-1,"DoRun")
TrayCreateItem("")
$traypause = TrayCreateItem("Pause")
TrayItemSetOnEvent(-1,"DoPause")
$trayresume = TrayCreateItem("Resume")
TrayItemSetOnEvent(-1,"DoResume")
TrayItemSetState(-1, $TRAY_DISABLE)
TrayCreateItem("")
$trayexit = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"ExitScript")
TraySetClick(8)
TraySetState()

endfunc

func DoPause()
ConsoleWrite(".\" & @ScriptName & " (" & @ScriptLineNumber & ") : ==> " & "PAUSING: " & @LF)

$pause = 1
TrayItemSetState($traypause, $TRAY_DISABLE)
TrayItemSetState($trayresume, $TRAY_ENABLE)

GUICtrlSetState($butt, $GUI_DISABLE)
WinSetTitle("My GUI", "", "paused")

endfunc

func DoResume()

$pause = 0
TrayItemSetState($traypause, $TRAY_ENABLE)
TrayItemSetState($trayresume, $TRAY_DISABLE)

GUICtrlSetState($butt, $GUI_ENABLE)
WinSetTitle("paused", "", "My GUI")

endfunc

func HK_DoRun()

if WinActive($gui) then

DoRun()

else

HotKeySet("r")
Send("
r")
HotKeySet( "r" , "HK_DoRun")

endif

endfunc

func ExitScript()

exit

endfunc

; end

;o)
(or

comment:5 Changed 16 years ago by corz

Apologies, here's it inside a code block..

#include <GUIConstants.au3>
#include <Constants.au3>

AutoItSetOption("TrayMenuMode", 9)
AutoItSetOption("TrayOnEventMode", 1)
AutoItSetOption("GUIOnEventMode", 1)

global $pause = 0 
; some example stuff to do in the loop..
global $trayrun, $traypause, $trayresume, $trayexit

MakeTray()
HotKeySet("^r", "HK_DoRun")

$gui = GUICreate("My GUI", 200, 40)
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitScript")

$butt = GUICtrlCreateButton("&Run", 5, 5, 190)
GuiCtrlSetOnEvent(-1, "DoRun")
GUISetState()


while 1
    Sleep(10)
wend

exit


func DoRun()

	$pause = 0

	for $i = 1 to 6
ConsoleWrite(".\" & @ScriptName & " (" & @ScriptLineNumber & ") : ==> " & "pause: " & $pause & @LF)
		while $pause = 1
			Sleep(250)
		wend

		for $x = 1 to 100
			sleep(1)
			; do nothing.
		next

	next
	MsgBox(0, "all done", "all done")
endfunc

func MakeTray()
	$trayrun = TrayCreateItem("Run")
	TrayItemSetOnEvent(-1,"DoRun")
	TrayCreateItem("")
	$traypause = TrayCreateItem("Pause")
	TrayItemSetOnEvent(-1,"DoPause")
	$trayresume = TrayCreateItem("Resume")
	TrayItemSetOnEvent(-1,"DoResume")
	TrayItemSetState(-1, $TRAY_DISABLE)
	TrayCreateItem("")
	$trayexit = TrayCreateItem("Exit")
	TrayItemSetOnEvent(-1,"ExitScript")
	TraySetClick(8)
	TraySetState()
endfunc

func DoPause()
ConsoleWrite(".\" & @ScriptName & " (" & @ScriptLineNumber & ") : ==> " & "PAUSING: " & @LF)
    $pause = 1
    TrayItemSetState($traypause, $TRAY_DISABLE)
    TrayItemSetState($trayresume, $TRAY_ENABLE)
	GUICtrlSetState($butt, $GUI_DISABLE)
	WinSetTitle("My GUI", "", "paused")
endfunc

func DoResume()
    $pause = 0
    TrayItemSetState($traypause, $TRAY_ENABLE)
    TrayItemSetState($trayresume, $TRAY_DISABLE)
	GUICtrlSetState($butt, $GUI_ENABLE)
	WinSetTitle("paused", "", "My GUI")
endfunc


func HK_DoRun()
	if WinActive($gui) then
		DoRun()
	else
		HotKeySet("^r")
		Send("^r")
		HotKeySet( "^r" , "HK_DoRun")
	endif
endfunc

func ExitScript()
    exit
endfunc

; end

;o)
(or

comment:6 follow-up: Changed 16 years ago by Jon

I think this is because your tray event for DoRun() never "returns" and we only let one tray event run at once (and indeed one gui event).

I _think_ this is by design but JP will be able to confirm.

comment:7 Changed 16 years ago by corz

An interesting limitation! (I'm surprised I've not run into it before, especially with regular GUI events) But if that's the reason (AHA!), something like this will make a reasonable workaround..

func MenuDoRun()
	AdlibEnable ("DoRun")
endfunc

.. with an AdlibDisable() immediately inside the DoRun() function.

;o)
(or

ps. I'd still like to know if this really is by design, and maybe why.

comment:8 in reply to: ↑ 6 Changed 16 years ago by Jpm

Replying to Jon:

I think this is because your tray event for DoRun() never "returns" and we only let one tray event run at once (and indeed one gui event).

I _think_ this is by design but JP will be able to confirm.

I confirm, ythe same thing is true if you have 2 buttons when the corresponding event routine is blocking. click run and next run1, you will see the run1 will be executed only after run terminate.
the gui and tray events work the same.

#include <GUIConstants.au3>
#include <Constants.au3>

AutoItSetOption("TrayMenuMode", 9)
AutoItSetOption("TrayOnEventMode", 1)
AutoItSetOption("GUIOnEventMode", 1)

global $pause = 0 
; some example stuff to do in the loop..
global $trayrun, $traypause, $trayresume, $trayexit

MakeTray()
HotKeySet("^r", "HK_DoRun")

$gui = GUICreate("My GUI", 200, 40)
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitScript")

$butt = GUICtrlCreateButton("&Run", 5, 5, 90)
GuiCtrlSetOnEvent(-1, "DoRun")
$butt1 = GUICtrlCreateButton("&Run1", 105, 5, 90)
GuiCtrlSetOnEvent(-1, "DoRun1")
GUISetState()


while 1
    Sleep(10)
wend

exit


func DoRun()

	$pause = 0

	for $i = 1 to 6
ConsoleWrite(".\" & @ScriptName & " (" & @ScriptLineNumber & ") : ==> " & "pause: " & $pause & @LF)
		while $pause = 1
			Sleep(250)
		wend

		for $x = 1 to 100
			sleep(1)
			; do nothing.
		next

	next
	MsgBox(0, "all done", "all done")
endfunc

func DoRun1()

	$pause = 0

	for $i = 1 to 6
ConsoleWrite(".\" & @ScriptName & " (" & @ScriptLineNumber & ") : ==> " & "pause1: " & $pause & @LF)
		while $pause = 1
			Sleep(250)
		wend

		for $x = 1 to 100
			sleep(1)
			; do nothing.
		next

	next
	MsgBox(0, "all done1", "all done1")
endfunc

func MakeTray()
	$trayrun = TrayCreateItem("Run")
	TrayItemSetOnEvent(-1,"DoRun")
	TrayCreateItem("")
	$traypause = TrayCreateItem("Pause")
	TrayItemSetOnEvent(-1,"DoPause")
	$trayresume = TrayCreateItem("Resume")
	TrayItemSetOnEvent(-1,"DoResume")
	TrayItemSetState(-1, $TRAY_DISABLE)
	TrayCreateItem("")
	$trayexit = TrayCreateItem("Exit")
	TrayItemSetOnEvent(-1,"ExitScript")
	TraySetClick(8)
	TraySetState()
endfunc

func DoPause()
ConsoleWrite(".\" & @ScriptName & " (" & @ScriptLineNumber & ") : ==> " & "PAUSING: " & @LF)
    $pause = 1
    TrayItemSetState($traypause, $TRAY_DISABLE)
    TrayItemSetState($trayresume, $TRAY_ENABLE)
	GUICtrlSetState($butt, $GUI_DISABLE)
	WinSetTitle("My GUI", "", "paused")
endfunc

func DoResume()
    $pause = 0
    TrayItemSetState($traypause, $TRAY_ENABLE)
    TrayItemSetState($trayresume, $TRAY_DISABLE)
	GUICtrlSetState($butt, $GUI_ENABLE)
	WinSetTitle("paused", "", "My GUI")
endfunc


func HK_DoRun()
	if WinActive($gui) then
		DoRun()
	else
		HotKeySet("^r")
		Send("^r")
		HotKeySet( "^r" , "HK_DoRun")
	endif
endfunc

func ExitScript()
    exit
endfunc

; end


comment:9 Changed 16 years ago by Jpm

  • Resolution set to No Bug
  • Status changed from new to closed

comment:10 Changed 16 years ago by anonymous

Once you know about this "limitation", it's easy enough to work around it. But if it was in the documentation somewhere; it would have save a lot of searching. I'm guessing there must be some internal reason why this happens, which would be good to know. Because even if you say it isn't; it does looks and act remarkably like a bug (or rather, two bugs).

The real issue with this behaviour is that you can fire the control multiple times, and receive no indication that the clicks are actually being accepted and stored, to be run, all-at-once, after the "block" is complete. It seems to contradict the whole idea of "events", don't you think?

So, is there any chance that a) it might go in the documentation somewhere, and b) the secret will be revealed as to why this happens at all?

Or better yet, is there any chance this limitation will be removed some time?

;o)
(or

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.