ray306 Posted February 8, 2007 Posted February 8, 2007 Hi all: I need to discern a way to exit the following function based on external input. It is an application that displays pictures and the data associated with them. In automatic mode it cycles that the data but the process can take a few minutes, during that time I cannot stop the operation. I tried using exitloop with an external variable that the script checks at every iteration but ifI try to change that variable the script waits until the job it;s working on is complete. An input or help appreciated Ray CODEFunc StartClick() GUICtrlSetState ( $Start, $GUI_DISABLE ) GUICtrlSetState($Stop,$Gui_ENABLE) $placeholder = 1 Dim $index[$highIndex];gets the highest index value in the DataArray for $x in $index $index[$x] = 0 Next $dir = 0; Thisection below randomizes the sequence of pics While $placeholder <= $highIndex + 1 $val = Random(1,$highIndex);make a random number cap of the size of the highest index If $index[$val] = 0 Then $index[$val] = 1 Else While $index[$val] = 0;indicates a 1 (TRUE) value If $dir = 0 Then $val = $val +1 If $val > $highIndex Then $val = 1 Else $val = $val -1 If $val < 2 Then $val = $highIndex EndIf Wend $index[$val]=1 EndIf If $dir = 0 Then ;when randomly looking for an element has been used it looks for one that has not been used $dir =1 Else $dir = 0 EndIf if Not $DataArray[$val][7] ="C:\NoImage.jpg" then statsHide() EndIf populate($Val);writes new values Sleep($speedVal) statsShow() $placeholder = $placeholder + 1 Sleep($speedVal) Wend GUICtrlSetState ( $Start, $GUI_ENABLE ) GUICtrlSetState ( $Stop, $GUI_DISABLE ) EndFunc
/dev/null Posted February 8, 2007 Posted February 8, 2007 expandcollapse popupHotKeySet("^e","_StopProcessing") Global $stop_processing = 0 Func _StopProcessing() $stop_processing = 1 EndFunc Func StartClick() GUICtrlSetState($Start, $GUI_DISABLE) GUICtrlSetState($Stop, $Gui_ENABLE) $placeholder = 1 Dim $index[$highIndex];gets the highest index value in the DataArray For $x In $index $index[$x] = 0 Next $dir = 0; Thisection below randomizes the sequence of pics While $placeholder <= $highIndex + 1 ;***************************************************************** If $stop_processing then ExitLoop ; <<== ADDED THIS ;***************************************************************** $val = Random(1, $highIndex);make a random number cap of the size of the highest index If $index[$val] = 0 Then $index[$val] = 1 Else While $index[$val] = 0;indicates a 1 (TRUE) value If $dir = 0 Then $val = $val + 1 If $val > $highIndex Then $val = 1 Else $val = $val - 1 If $val < 2 Then $val = $highIndex EndIf WEnd $index[$val] = 1 EndIf If $dir = 0 Then ;when randomly looking for an element has been used it looks for one that has not been used $dir = 1 Else $dir = 0 EndIf If Not $DataArray[$val][7] = "C:\NoImage.jpg" Then statsHide () EndIf populate ($val);writes new values Sleep($speedVal) statsShow () $placeholder = $placeholder + 1 Sleep($speedVal) WEnd GUICtrlSetState($Start, $Gui_ENABLE) GUICtrlSetState($Stop, $GUI_DISABLE) EndFunc ;==>StartClick __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
ray306 Posted February 8, 2007 Author Posted February 8, 2007 Thanks for the reply. I'm afraid that it does not work though. Since the GUI is in "onEvent" mode, once it is involved in processing an event(running the Func) it will not process the next event until it has completed the event it is working on. I think I need to come up with a scheme to have it reply to the events while in the function Thanks Ray expandcollapse popupHotKeySet("^e","_StopProcessing") Global $stop_processing = 0 Func _StopProcessing() $stop_processing = 1 EndFunc Func StartClick() GUICtrlSetState($Start, $GUI_DISABLE) GUICtrlSetState($Stop, $Gui_ENABLE) $placeholder = 1 Dim $index[$highIndex];gets the highest index value in the DataArray For $x In $index $index[$x] = 0 Next $dir = 0; Thisection below randomizes the sequence of pics While $placeholder <= $highIndex + 1 ;***************************************************************** If $stop_processing then ExitLoop ; <<== ADDED THIS ;***************************************************************** $val = Random(1, $highIndex);make a random number cap of the size of the highest index If $index[$val] = 0 Then $index[$val] = 1 Else While $index[$val] = 0;indicates a 1 (TRUE) value If $dir = 0 Then $val = $val + 1 If $val > $highIndex Then $val = 1 Else $val = $val - 1 If $val < 2 Then $val = $highIndex EndIf WEnd $index[$val] = 1 EndIf If $dir = 0 Then ;when randomly looking for an element has been used it looks for one that has not been used $dir = 1 Else $dir = 0 EndIf If Not $DataArray[$val][7] = "C:\NoImage.jpg" Then statsHide () EndIf populate ($val);writes new values Sleep($speedVal) statsShow () $placeholder = $placeholder + 1 Sleep($speedVal) WEnd GUICtrlSetState($Start, $Gui_ENABLE) GUICtrlSetState($Stop, $GUI_DISABLE) EndFunc ;==>StartClick
/dev/null Posted February 8, 2007 Posted February 8, 2007 Thanks for the reply. I'm afraid that it does not work though. Since the GUI is in "onEvent" mode, once it is involved in processing an event(running the Func) it will not process the next event until it has completed the event it is working on. I think I need to come up with a scheme to have it reply to the events while in the functionThanksRayGUI Events??? You know you have to press CTRL-e to stop your function StartClick()? Did you actually try my modification? __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
ray306 Posted February 8, 2007 Author Posted February 8, 2007 I have to humbly apologize. You are correct, I did not implement your suggestion properly. It works as you showed it. One other question, just trying to understand the theory here. It will work with the hot key but my stop button on the GUI itself doesn't do the same job, even when routed to the same event processing Func. Why is that? Thanks again for the help Ray
/dev/null Posted February 8, 2007 Posted February 8, 2007 I have to humbly apologize. You are correct, I did not implement your suggestion properly. It works as you showed it. One other question, just trying to understand the theory here. It will work with the hot key but my stop button on the GUI itself doesn't do the same job, even when routed to the same event processing Func. Why is that? Thanks again for the help Ray I can only speculate without knowing your script, but most probably the effect you have already described. When you are in GUI Event mode, you can trigger an Event (by pressing a button), however, that event will only run the associated function when the currently running function has been finished! I think you will have to redesign you code. See the following example: expandcollapse popup#include <GUIConstants.au3> Opt("GUIOnEventMode", 1) ; Change to OnEvent mode $mainwindow = GUICreate("Hello World", 200, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUICtrlCreateLabel("Hello world! How are you?", 30, 10) $stopbutton = GUICtrlCreateButton("STOP", 110, 50, 60) $runbutton = GUICtrlCreateButton("RUN", 20, 50, 60) GUICtrlSetOnEvent($stopbutton, "StoppButton") GUICtrlSetOnEvent($runbutton, "RunButton") GUISetState(@SW_SHOW) Global $glb_stop = 0 Global $glb_run = 0 Global $n_button_pressed = 0 While 1 Sleep(1000) ; Idle around if $glb_run Then $glb_run = 0 RunFunction() EndIf WEnd Func StoppButton() $glb_stop = 1 $n_button_pressed +=1 MsgBox(0, "INFO", "Stopp Button pressed " & $n_button_pressed & " times") EndFunc ;==>StoppButton Func RunButton() $glb_run = 1 MsgBox(0, "INFO", "Run Button pressed") EndFunc ;==>RunButton Func RunFunction() MsgBox(0, "INFO", "Run function") $glb_stop = 0 While 1 Sleep(500) If $glb_stop Then ExitLoop WEnd MsgBox(0, "INFO", "Running function stopped") EndFunc ;==>RunButton Func CLOSEClicked() ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, ;and @GUI_WINHANDLE would equal $mainwindow MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...") Exit EndFunc ;==>CLOSEClicked __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now