Sign in to follow this  
Followers 0
unexpectedpanda

[Solved] Ensuring a GUI button always works for force quit

10 posts in this topic

#1 ·  Posted (edited)

Hi all,

I've embarked on a huge clean up of my code project, trying to properly name variables, fix functions, remove bloat etc. The project is designed to return a bloatware and crapware filled laptop to as clean as possible, and to remove any processes that may interrupt a following script that benchmarks the machine.

Throughout the project, there's a status bar displayed at the top left, with a big "stop script" button under it. Ideally, that button should run the function _QuitAutoIt() immediately regardless of what the situation is on screen.

There is one particular bit though, where the stop script button simply doesn't work. I believe it's related to interrupting a function, but I can't seem to get this to work, and the functions that need to be interrupted can't really be put inside a handy loop to execute as per the examples. For now, I've had to fall back on a keyboard shortcut (CTRL+ALT+Q) that does succesfully terminate the program whenever I like.

I've included some sample code. It's been excised from the rest of the codebase and some function placeholders have been put in so it's easier for other people to view. As such, there's likely some variables and functions hanging around that aren't used, but can be safely ignored.

When the code is run, it first loads the progress bar, then a GUI asking which program to remove. At this point, the stop script button works. Click one of the program buttons though, and stop script button stops working. Take in mind than when you press a button, a function is executed that is a once off process -- it can't be looped.

_GetDPI is just a support file, the rest of the _ files are where the action happens. The main script file is example.au3.

I'd love some help here if possible. Thanks for your time, if you're kind enough to give it :)

example.zip

Edited by unexpectedpanda

Share this post


Link to post
Share on other sites



unexpectedpanda,

Are you sure you want to interrupt the removal process before it terminates? Surely that could leave the system in a very unstable state and you would be better served waiting until the removal had finished. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

An excellent point!

I'd just like to terminate my AutoIt script in this instance. The removal programs are separate .exes (automated by the script) that I'm happy to allow to continue so things don't break, or for the user to manually cancel.

Share this post


Link to post
Share on other sites

unexpectedpanda,

In that case I suggest (based on the scripts you posted) that you change the "removal" functions to read something like this :

Func _RemoveProgramOne()
    ;Dummy function for forums example
    If WinExists("Program removal") Then GUIDelete($hRemoveProgramGUI)
    _ProgressStatus("Removing Program One", 1)
    Run("RemoveProgOne.exe") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< May need more parameters ;)
EndFunc   ;==>_RemoveProgramOne

That way the removal app runs in a separate thread and your button enables you to quit the main AutoIt script at any time while leaving the removal app running to completion. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks Melba -- if only it were so simple though. The full version of the AutoIt script interacts with the removal programs, waiting for certain window titles to appear, clicking buttons, sometimes even moving the mouse.

I can post exact code if you like, I'm just conscious that I'm shutting down things like antivirus and I don't really want to be responsible for putting code out into public that people could use maliciously.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Okay, I've come up with a benign compromise, I think :) If I can interrupt this with the stop script button:

Func _RemoveProgramOne()
;Dummy function for forums example
If WinExists("Program removal") Then GUIDelete($hRemoveProgramGUI)
_ProgressStatus("Removing Program One", 1)
Run("calc.exe")
WinWait("Calculator")
WinActivate("Calculator")
ControlClick("Calculator","","[CLASS:Button; INSTANCE:9]")
ControlClick("Calculator","","[CLASS:Button; INSTANCE:23]")
ControlClick("Calculator","","[CLASS:Button; INSTANCE:10]")
Sleep(2000)
WinActivate("Calculator")
Send("{Enter}")
MsgBox(0,"","Hello!")
While 1
Sleep(20000)
WEnd
EndFunc ;==>_RemoveProgramOne

Then all will be solved :) If it's not possible, I shall have to find a workaround :huh:

Edited by unexpectedpanda

Share this post


Link to post
Share on other sites

unexpectedpanda,

This is getting complex. :wacko:

I suggest that you try to do something like this:

- Run the removal app in a separate thread as shown above allowing the button to become active, setting a "Running" flag to show that it is active.

- If the button is pressed then:

-- If the "Running" flag is set, hide the various GUIs making it look as if the script has ended and set another "Exit" flag to show that the button has been pressed.

-- If the "Running" flag is not set, then exit immediately

- Once the removal app has ended along with that part of the script, check the "Exit" flag and exit the script (all the tidying up runs at this point) if it is set. If it is not set then clear the "Running" flag and continue.

How does that sound? Now you appear to exit at once if the button is pressed, but in reality the script continues to a suitable break point if required. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

It is complex, I agree. Moreso since the removal apps need user interaction.

Looks like we'll have to work around the issue, I'll give your suggestions a shot. Thanks for your help Melba :)

Share this post


Link to post
Share on other sites

unexpectedpanda,

Glad I could help. I use something similar to the "flag" solution I proposed in one of my scripts and I have found it a reliable way to deal with the situation. Do come back if you run into any problems. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Got the stop script button working by implementing a flag as suggested and moving all of the commands after the program execution out of the function, and into the main script. Thanks again Melba :)

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