Dieuz Posted July 15, 2007 Share Posted July 15, 2007 (edited) Hi, I know the basic function to pause a script but this "basic" function doesnt work when there's a Gui because the Gui window became disabled when I pause the script. The same thing happen when I call another function, the gui just dont work anymore. expandcollapse popup#include <GuiConstants.au3> #Include <Misc.au3> HotKeySet("{F2}", "_Pause") GLobal $Paused, $Count $Count = 0 Opt("TrayIconDebug", 1) GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Loop = GuiCtrlCreateButton("Run Loop", 250, 260, 80, 40) $Test = GuiCtrlCreateButton("Test if Gui Window is Working", 20, 260, 200, 40) GuiCtrlCreateGroup("", 30, 20, 340, 230) GuiSetstate() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $Test MsgBox(0,"YAY", "Gui window is working") EndSelect If $msg = $Loop Then _Looptime() WEnd Func _Looptime() While 1 SplashTextOn ("", "Count: " & $Count, 290, 20, 0, 30, 1, "", 10) sleep(500) If $Count = 20 Then $Count = 0 Else $Count += 1 EndIf WEnd EndFunc Func _Pause() ; Pause the script $Paused = NOT $Paused While $Paused sleep(100) WEnd EndFunc ;==> Pause How can I set it so the Gui window will work at anytime (when paused and when the count increase)? EDIT: I forgot to tell that I need to use functions and I cannot put every actions under a "Case" statement. Edited July 15, 2007 by Dieuz Link to comment Share on other sites More sharing options...
TK_Incorperate Posted July 15, 2007 Share Posted July 15, 2007 (edited) Edit: just realised i put the same stuff you put, dunno what it is, works for me lol Edited July 15, 2007 by TK_Incorperate Link to comment Share on other sites More sharing options...
Dieuz Posted July 15, 2007 Author Share Posted July 15, 2007 (edited) I already have this function in my script (see above) and the Gui doesnt work when I call it. Also, I need to use an hotkey. Edited July 15, 2007 by Dieuz Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 15, 2007 Share Posted July 15, 2007 There is no returning from your _LoopTime() function, it's a trap. Once the "Run Loop" button is clicked, there is no way out of the _LoopTime() function, so it never gets back to checking GuiGetMsg(). If you want the GUI to stay responsive while _LoopTime() is being used, have the GUI message loop call it for one cycle per call and then return. Stop using Sleep(), and get with TimerInit()/TimerDiff() for the delay. Another method would be AdLibEnable(). How ever you do it, you have to get back to checking the GUI message loop a few times per second at least, or the GUI is dead. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
someone Posted July 15, 2007 Share Posted July 15, 2007 OK, where to start with this one... I'm a little thrown for a loop (no pun intended) by the whole problem. I think a lot of people will be confused with what you are trying to achieve without reading that other topic so here is the link for it..http://www.autoitscript.com/forum/index.ph...15&start=15That being said, the workaround I gave you in the original topic was no thing of beauty and as I said there it may not work for you but I don't get how you took that and adapted the code you have here. The whole point of that workaround was to enclose your GUI in a function that would be called by a hotkey. Here you don't have that, yet you added in the pause function that will pause your whole script not just the looptime function.As for a solution, it sounds like the only way to go is to run 2 scripts, the first being your GUI and the second being your large loop. While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd Link to comment Share on other sites More sharing options...
TK_Incorperate Posted July 15, 2007 Share Posted July 15, 2007 (edited) Try this, didn't test it, but in theory it should work. Added this part to it: Func _Looptime() $Looped = NOT $Looped While $Looped SplashTextOn ("", "Count: " & $Count, 290, 20, 0, 30, 1, "", 10) sleep(500) If $Count = 20 Then $Count = 0 Else $Count += 1 EndIf WEnd EndFunc expandcollapse popup#include <GuiConstants.au3> #Include <Misc.au3> HotKeySet("{F2}", "_Pause") GLobal $Paused, $Count $Count = 0 Opt("TrayIconDebug", 1) GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Loop = GuiCtrlCreateButton("Run Loop", 250, 260, 80, 40) $Test = GuiCtrlCreateButton("Test if Gui Window is Working", 20, 260, 200, 40) GuiCtrlCreateGroup("", 30, 20, 340, 230) GuiSetstate() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $Test MsgBox(0,"YAY", "Gui window is working") EndSelect If $msg = $Loop Then _Looptime() WEnd Func _Looptime() $Looped = NOT $Looped While $Looped SplashTextOn ("", "Count: " & $Count, 290, 20, 0, 30, 1, "", 10) sleep(500) If $Count = 20 Then $Count = 0 Else $Count += 1 EndIf WEnd EndFunc Func _Pause() ; Pause the script $Paused = NOT $Paused While $Paused sleep(100) WEnd EndFunc;==> Pause Edited July 15, 2007 by TK_Incorperate Link to comment Share on other sites More sharing options...
Zedna Posted July 15, 2007 Share Posted July 15, 2007 expandcollapse popup#include <GuiConstants.au3> #Include <Misc.au3> Opt("TrayIconDebug", 1) HotKeySet("{F2}", "_Pause") Global $Paused, $Count $Count = 0 GUICreate("MyGUI", 392, 316, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Loop = GUICtrlCreateButton("Run Loop", 250, 260, 80, 40) $Test = GUICtrlCreateButton("Test if Gui Window is Working", 20, 260, 200, 40) GUICtrlCreateGroup("", 30, 20, 340, 230) GUISetState() While 1 _ProcesGUIMessages() WEnd Func _Looptime() While 1 SplashTextOn("", "Count: " & $Count, 290, 20, 0, 30, 1, "", 10) Sleep(500) If $Count = 20 Then $Count = 0 Else $Count += 1 EndIf WEnd EndFunc ;==>_Looptime Func _Pause() ; Pause the script $Paused = Not $Paused While $Paused _ProcesGUIMessages() WEnd EndFunc ;==>_Pause Func _ProcesGUIMessages() $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $Test MsgBox(0, "YAY", "Gui window is working") EndSelect If $msg = $Loop Then _Looptime() EndFunc Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
Jfish Posted July 15, 2007 Share Posted July 15, 2007 I had a similar problem and was helped out by Valuater using the AdlibEnable() function. See: http://www.autoitscript.com/forum/index.php?showtopic=49241 for the string. Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
Dieuz Posted July 16, 2007 Author Share Posted July 16, 2007 TK_Incorperate, Zedna: Both of your script doesnt work. Zedna it works well when the script is paused and that's a plus but when the count is increasing, the Gui window doesnt work.Jfish: I forgot to tell that I am already using an Adlidenable for another thing in my script and it's why I cant use that.someone: IMO, using 2 scripts is way to complicated. I'm sure there's a workaround (you found one for my last problem) I still need help on this one. Link to comment Share on other sites More sharing options...
enaiman Posted July 16, 2007 Share Posted July 16, 2007 The code Zedna gave you is working - it pause and unpause the script as intended. Why it looks like bugged sometimes: because of that extra button to check if the window is working or not. Why do you actually need it??? You can see the state pause/unpause by looking at the counter - if it stops=pause, counting=running If you click on your button while the counter is working - obvious - it won't do anything but to "keep in mind" that a button was pressed and it will display that messagebox once it has the time to do it (out of the loop). SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
enaiman Posted July 16, 2007 Share Posted July 16, 2007 Finally I got it working as you want - I had to change the mode to OnEvent though. here is the script: expandcollapse popup#include <GuiConstants.au3> #Include <Misc.au3> Opt("TrayIconDebug", 1) Opt("GUIOnEventMode", 1) HotKeySet("{F2}", "_Pause") Global $Paused, $Count, $start = 0 $Count = 0 GUICreate("MyGUI", 392, 316, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) GUISetOnEvent($GUI_EVENT_CLOSE, "Close") $Loop = GUICtrlCreateButton("Run Loop", 250, 260, 80, 40) GUICtrlSetOnEvent(-1, "_Looptime") $Test = GUICtrlCreateButton("Test if Gui Window is Working", 20, 260, 200, 40) GUICtrlSetOnEvent(-1, "_buttonhit") GUICtrlCreateGroup("", 30, 20, 340, 230) GUISetState() While 1 Sleep(100) If $start = 1 Then SplashTextOn("", "Count: " & $Count, 290, 20, 0, 30, 1, "", 10) Sleep(500) If $Count = 20 Then $Count = 0 Else $Count += 1 EndIf EndIf WEnd Func _ButtonHit() Switch @GUI_CtrlId Case $Test MsgBox(0, "YAY", "Gui window is working") EndSwitch EndFunc Func _Looptime() $start = 1 EndFunc ;==>_Looptime Func _Pause() ; Pause the script $Paused = Not $Paused While $Paused Sleep(100) WEnd EndFunc ;==>_Pause Func Close() Exit EndFunc You can work to improve it but now you have the idea. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
Dieuz Posted July 16, 2007 Author Share Posted July 16, 2007 enaiman: Thanks for helping me and yes your script work as a charm but like you said it use OnEvent mode and thats very unfriendly to me because all my script is based on a Gui with Seletc,Case Statement. This little example (unmodified as first) was exactly the same patern as my original script. Yes it's working now but the Gui window is very unfunctional if I want to add other options ot it. I know I seem like someone that say "Please do it for me" but Im not. I am just looking for something that will fit my need and will keep the same patern as my original post. You script work perfectly but wont go far with me.Lets be more specific, there's really nothing that let you keep the control of the Gui Window when paused ONLY? Link to comment Share on other sites More sharing options...
enaiman Posted July 16, 2007 Share Posted July 16, 2007 (edited) There is not such a big difference between the 2 modes - the modifications are small enough to worth the change ... if you really want it. About being ... unfunctional? sorry but you're wrong ... it is very functional and to prove it, I just added 2 new controls in this example which works no matter if the counter is paused or is working. I guess you haven't tested it properly. Look at what I've added (controls and functions) and you will see that you can add anything to your GUI. If you still consider this ... unfunctional - this is your choice Maybe you can find a better idea. At least I did everything I could to help - to continue or not is your call. EDITED: forgot to add the code expandcollapse popup#include <GuiConstants.au3> #Include <Misc.au3> Opt("TrayIconDebug", 1) Opt("GUIOnEventMode", 1) HotKeySet("{F2}", "_Pause") Global $Paused, $Count, $start = 0 $Count = 0 GUICreate("MyGUI", 392, 316, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) GUISetOnEvent($GUI_EVENT_CLOSE, "Close") $Loop = GUICtrlCreateButton("Run Loop", 290, 260, 80, 40) GUICtrlSetOnEvent(-1, "_Looptime") $test1 = GUICtrlCreateButton("Test1",200, 260, 50, 20) GUICtrlSetOnEvent(-1, "Test1") $chkb = GUICtrlCreateCheckbox("Test check", 200, 282, 75, 20) GUICtrlSetOnEvent(-1, "TestCheck") $Test = GUICtrlCreateButton("Test if Gui Window is Working", 20, 260, 150, 40) GUICtrlSetOnEvent(-1, "_buttonhit") GUICtrlCreateGroup("", 30, 20, 340, 230) GUISetState() While 1 Sleep(100) If $start = 1 Then SplashTextOn("", "Count: " & $Count, 290, 20, 0, 30, 1, "", 10) Sleep(500) If $Count = 20 Then $Count = 0 Else $Count += 1 EndIf EndIf WEnd Func _ButtonHit() Switch @GUI_CtrlId Case $Test MsgBox(0, "YAY", "Gui window is working") EndSwitch EndFunc Func Test1() MsgBox(0, "Here comes the test", "It works") EndFunc Func TestCheck() If GUICtrlRead($chkb) = $GUI_CHECKED Then MsgBox (0, "Status", "Checked") Else MsgBox (0, "Status", "UnChecked") EndIf EndFunc Func _Looptime() $start = 1 EndFunc ;==>_Looptime Func _Pause() ; Pause the script $Paused = Not $Paused While $Paused Sleep(100) WEnd EndFunc ;==>_Pause Func Close() Exit EndFunc Edited July 16, 2007 by enaiman SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
Sardith Posted July 16, 2007 Share Posted July 16, 2007 enaiman: Thanks for helping me and yes your script work as a charm but like you said it use OnEvent mode and thats very unfriendly to me because all my script is based on a Gui with Seletc,Case Statement. This little example (unmodified as first) was exactly the same patern as my original script. Yes it's working now but the Gui window is very unfunctional if I want to add other options ot it. I know I seem like someone that say "Please do it for me" but Im not. I am just looking for something that will fit my need and will keep the same patern as my original post. You script work perfectly but wont go far with me.Lets be more specific, there's really nothing that let you keep the control of the Gui Window when paused ONLY?That method that Enaiman posted works fine. One thing that is unfriendly, is the fact that you didn't post the full code. Not sure how you can ask for help, without doing so. What interval(MS) is your Adlidenable being checked at? [font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font] Link to comment Share on other sites More sharing options...
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