Opened 16 years ago

Last modified 16 years ago

#379 closed Bug

Tray OnEvents ignored — at Version 1

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

Change History (1)

comment:1 Changed 16 years ago by Valik

  • Description modified (diff)
Note: See TracTickets for help on using tickets.