tolyasher Posted October 5, 2009 Posted October 5, 2009 (edited) Hi guys, Is it possible to Start / Stop and pause scripting from the GUI? For example I have a GUI with GUIOnEventMode=True. And I have a buttons "Run" (should start scripting, writing any data to the file for example), "Stop" (should stop writing data to the file, but after pressing "Run" it should start writing again from previous position). While 1 FileWriteLine("Line 1") FileWriteLine("Line 2") FileWriteLine("Line 3") FileWriteLine("Line 4") WEnd Local $Stop = GUICtrlCreateButton("Stop", 172, 47, 30, 25, $WS_GROUP) GUICtrlSetOnEvent($Button1, "StopButtonclick") Local $Start = GUICtrlCreateButton("Start", 172, 80, 31, 25, $WS_GROUP) GUICtrlSetOnEvent($Button2, "StartButtonclick") Func StopButtonclick() ;Script should stop perform 'While' loop after pressing 'Stop' button. If it stopped between 'Line 2' and 'Line 3' then after next pressing 'Start' it should start from 'Line 3' EndFunc Func StartButtonclick() ;Script should start perform 'While' loop after pressing 'Start' button EndFunc p.s. thank you in advance Edited October 5, 2009 by tolyasher
tolyasher Posted October 5, 2009 Author Posted October 5, 2009 (edited) I found that I can add next code and did it with hotkeys. So it will be like combination of the hotkeyes and GUI events : Global $Paused HotKeySet("{PAUSE}", "TogglePause") HotKeySet("{ESC}", "Terminate") Func TogglePause() $Paused = NOT $Paused While $Paused sleep(100) WEnd EndFunc Func Terminate() Exit 0 EndFunc Func StartButtonclick() $Paused = NOT $Paused EndFunc Func StopButtonclick() ; ??? TogglePause() will not work here :(( EndFunc May be another way here ? ... without hotkeys "TogglePause" working fine after hotkey but as in the part of the "StopButtonclick" it is not OK. But I still could not find the way how to start perform 'While' loop after pressing button 'Run' (but not automatically as default) Edited October 5, 2009 by tolyasher
Hawkwing Posted October 6, 2009 Posted October 6, 2009 (edited) You're making it too hard. Just change a single variable that the while loop can check. HotKeySet("{esc}", "playpause") $go = 1 While 1 If $go = 1 Then ;~ do some stuff EndIf WEnd Func playpause() $go = $go * -1 + 1 EndFunc Edited October 6, 2009 by Hawkwing The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.
tolyasher Posted October 6, 2009 Author Posted October 6, 2009 (edited) Yes, this way used hotkeys. What about GUI buttons ? Start/Stop and Pause/Continue ? How to start loop While 1 ;Some stuff WEnd from the GUI, 'Pause' it and the 'Continue' from GUI. For example, I need to test some application and need to do some operations with application. Therefore I should firstly configure my script and then start to perform (Start button).Then while in the process of the testing (performing script operations) I need to perform some additional configuration of the script (enable or disable some checkboxes in the GUI that administrate my testing script (script will recognize it as adding or removing some instructions)). Therefore I need to pause script ('Pause' button), reconfigure script and then 'Continue' scripting. So, in a few words I need to write certain Administrator program for testing some applications. Edited October 6, 2009 by tolyasher
Hawkwing Posted October 6, 2009 Posted October 6, 2009 (edited) Set Opt("guioneventmode", 1) and take a look at GUICtrlSetOnEvent. Edited October 6, 2009 by Hawkwing The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.
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