Sign in to follow this  
Followers 0
cookiekiller89

TogglePause Closing script

16 posts in this topic

hi all,

I've recently come across a few setbacks in my script while building my GUI, please excuse me if this is in the wrong forum, i think it could be in both, feel free to move

well let me get started

when I don't have any GUI code in my script begins off of f5, i have

func

 

func

 

func

they are all _IE funcs at this point _IE create then _IEtagname

i then have this at the bottom of my script

Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc   ;==>

now this works fine and pauses perfects whenever i want to use it, but my problem is I've recently made sections of my script my own functions

so i've assigned these functions to start off buttons on the GUI.

So i have _IE create

         _IEget tag name and all off that which works fine

and as my script allows users to navigate through a site it has more then one link. so i've made functions to acquire each link. and then for whatever purpose they want weather they want to search or goto

a home page there's a specific function for it, they just choose from GUI "start button"; search "start button"; homepage it's the only way i could think to do it without my script running everything at once

as im new to this.

sorry i dont have any code to show im on site with work computers.

so i have my GUI with the buttons, i click it and script runs reasonably fine, my problem is when i pause the script, it exits the hole thing, it doesn't take it back to the GUI or anything

now my only thinking behind this is it has to do with GUI_@show and when paused it's pausing the gui code as well to be shown which inturn just closes everything...

now im kind of at a loss as to what to do, im not sure if i can add togglepause func inside my other funcs so when called it just pauses the specific functions it's inside, i would have no idea how to do this...

'cause im also having problems, with GUI event close... I can close my script when script isnt running from GUI selection,but once ive chosen script and its running it wont close by the X button in the top right, and my only logic behind that is that it wont interupt the current function 'cause it's on a loop to repeat certain actions for the user

anyway there's a couple of questions, im mainly worried about the pause func if anyone cangive me some insight into a few things like with my functions that'd be great

Share this post


Link to post
Share on other sites



It's a bit hard (nee impossible) to tell without your code, so the only advice I can give, is that you need to nest things correctly .... certain elements must be within others, like loops within loops.

So long as the GUI code itself, is in the outer loop, then everything should continue as expected after exiting Pause ... providing of course, that you haven't used the Exit command ... or an injudiciously placed ExitLoop.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

It's a bit hard (nee impossible) to tell without your code, so the only advice I can give, is that you need to nest things correctly .... certain elements must be within others, like loops within loops.

So long as the GUI code itself, is in the outer loop, then everything should continue as expected after exiting Pause ... providing of course, that you haven't used the Exit command ... or an injudiciously placed ExitLoop.

By exiting pause do u mean just pressing the pause function, as i have it linked to hotkey pause and when pressed it exits script.

also i do have the exit command as a function, could that be it? because I have linked with GUI EVENT CLOSE in the paremetres im pretty sure... but saying that i also tried removing the exit function

and pausing and i dont think it worked...

 

Edited by cookiekiller89

Share this post


Link to post
Share on other sites

If you are talking about the actual PAUSE key on your physical keyboard, then you must understand, that it is also a BREAK key.

At least it is on mine, and all the keyboards I recall.

This is often used to exit stuff, that is caught in an infinite loop, so you are probably and obviously unknowingly exiting your script by using it. Sometimes though, like with DOS batch files, you also need to use the CTRL key in combination with it. PAUSE usually only works with certain programs, or the Command Prompt window.

Don't know if you can alter it's behavior when your script is running?

Maybe you need to use a different key/combo .... perhaps Ctrl-Alt-P


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

perhaps, but the pause key works fine without sny GUI code present

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

perhaps, but the pause key works fine without sny GUI code present

No it's not, if it's doing a Break Interrupt of your script.

It might seem like it's pausing, but in reality it is probably doing anything but, by just exiting the program.

I very much doubt a Window's key is going to do anything in an AutoIt script, unless you code for it.

Then again, if you are saying that it pauses normal AutoIt code and then resumes, then probably ignore the above, and someone who knows more about these things will have to help you, as you have gone beyond my realm of expertize ... especially as I'm not currently setup to test anything.

Then again, without seeing your code, who knows really for sure, where the problem may reside?

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

Show an example code where your pause does not work.

Here's how these things normally work.

You strip down your own code to give an example of it not working.

While you are doing that, nine times out of ten, you realize the problem.

If not, you have code to show that is not acting as you expect.

More words are no good, only code.

1 person likes this

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

yeah it works then resumes. as it's a potential business idea i can't reveal too much of the im scripting for in public

im using my laptop and have break key on pgup and pause on pagedown...

so i dont see how it's a break problem.

#include <IE.au3>

HotKeySet("{PAUSE}", "TogglePause")


#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Global $Form1_1 = GUICreate("WORDSEARCH", 615, 438, 192, 124)
Global $Button1 = GUICtrlCreateButton("Start", 224, 160, 129, 25

GUISetState(@SW_SHOW)

FUNC _GUIEXIT()
    Exit
    EndFunc

While 1
    Sleep(100)
WEnd


Global $homepage

Func _Startword()
While 1
$homepage = _IECreate("http://www.google.com", 1) ; see parameters again for mind refresh
if @extended then
    ToolTip("Finding page", 0, 0, "Word Search", 1)
    Sleep(3000)
    ToolTip("")
    Else
    ToolTip("Please wait...creating page...verifying...", 0, 0, "Wordsearch", 1)
    Sleep(3000)
    ToolTip("")
EndIf

EndFunc
wend




#Region Pause Func, will pause when called
Func TogglePause()
    $paused = NOT $paused
    While $paused
        sleep(100)
        ToolTip("Script Paused", 0, 0, "Wordsearch", 1)
    WEnd
    ToolTip(""); (An empty string clears a displaying tooltip)
EndFunc
#EndRegion
Edited by cookiekiller89

Share this post


Link to post
Share on other sites

First of all I'm a newbie at this but I tried your script and it said

$paused = NOT $paused
$paused = NOT ^ ERROR

But I put a Global $Paused at the top of the script somewhere, and it worked fine with no error, and I was able to toggle pause as much as I wanted. Not sure if that is your problem though because you cut out some of your script, and because like I said I'm just a newbie.

Share this post


Link to post
Share on other sites

First of all I'm a newbie at this but I tried your script and it said

$paused = NOT $paused

$paused = NOT ^ ERROR

But I put a Global $Paused at the top of the script somewhere, and it worked fine with no error, and I was able to toggle pause as much as I wanted. Not sure if that is your problem though because you cut out some of your script, and because like I said I'm just a newbie.

 

I see, i just tried what you said and put it above the GUI Code as before it was situated BELOW and it seems to work as expected and as does when no GUI code is present, I wasn't aware the Globals had to be declared before any script I know you have to declare them, but I guess i just got a little confused there. cheers man.

I'm also having troubles exiting the script, i want to exit it from the X, this works when the GUI script is there and not running any functions but as soon as i run a function, i can not hit x on the exit button, is there a return func im missing or am i nesting it wrong from what you can see? i changed it to google the link with a while loop, i realise this will create a lot of pages, but if someone could just give it a quick go, maybe im missing something simple again

Share this post


Link to post
Share on other sites

You could use the AdLib functions, and tie that to the ID number of the button, and fire that off before the function runs.

If you set that up right, then the system will periodically check (you set this duration) if you are clicking the Exit button.

There are a few other ways too, but I'm not in the position to show you an example of that ... but a diligent search of the forum should return an example ... or someone better positioned here, may even supply one.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

That seems like quite a workaround, im sure there must be an obvious solution, i hope someone can give some more insight

Share this post


Link to post
Share on other sites

Plenty of people ask about interrupting a running script or function, so you are sure to find plenty of examples if you do a search while waiting for someone else to respond.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Plenty of people ask about interrupting a running script or function, so you are sure to find plenty of examples if you do a search while waiting for someone else to respond.

yep, im looking, what's the ID for the top right X of the GUI tho?

i know GUI_event_close is a constant, but is that linked to the X?

if i knew what X was i could just add a func to it like any button

ill have a play with something i just found.

cheers :)

Edited by cookiekiller89

Share this post


Link to post
Share on other sites

There isn't an ID that I know of.

However, you may be able to glean something from this Example taken straight form the OnEvent Mode section of the Help file.

#include <GUIConstantsEx.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)
$okbutton = GUICtrlCreateButton("OK", 70, 50, 60)
GUICtrlSetOnEvent($okbutton, "OKButton")

$dummywindow = GUICreate("Dummy window for testing ", 200, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

GUISwitch($mainwindow)
GUISetState(@SW_SHOW)

While 1
  Sleep(1000)  ; Idle around
WEnd

Func OKButton()
  ;Note: at this point @GUI_CTRLID would equal $okbutton
  MsgBox(0, "GUI Event", "You pressed OK!")
EndFunc

Func CLOSEClicked()
  ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE,
  ;@GUI_WINHANDLE will be either $mainwindow or $dummywindow
  If @GUI_WINHANDLE = $mainwindow Then 
    MsgBox(0, "GUI Event", "You clicked CLOSE in the main window! Exiting...")
    Exit
  EndIf 
EndFunc

Not sure if that will help you while in another function though, and I am unable to test at the moment.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

yeah, that's what im looking at now, if that fails i'll look into interrupting functions, cheers for your guidance

1 person likes this

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  
Followers 0