Jump to content
Sign in to follow this  
tolyasher

Start / Stop / Pause scripting

Recommended Posts

tolyasher

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 by tolyasher

Share this post


Link to post
Share on other sites
tolyasher

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 by tolyasher

Share this post


Link to post
Share on other sites
Hawkwing

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 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.

Share this post


Link to post
Share on other sites
tolyasher

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 by tolyasher

Share this post


Link to post
Share on other sites
Hawkwing

Set Opt("guioneventmode", 1) and take a look at GUICtrlSetOnEvent.

Edited 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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.