Jump to content
FlexScott

(Re)Using a GUI button while in another function

Recommended Posts

FlexScott

I've created an GUI to run a test program, and I'd like the operator to still be able to use the exit button while in one of the functions called from the GUI.  I'm able to change the label and enable/disable the button while in another function, but I'm not having any luck detecting the button click.  I've added the "global" designations recently (just guessing at a potential solution), but that didn't seem to make any difference.  How do I check for the button click events related to this GUI outside of the initial While loop?  Thanks for your help!

autoit_example.txt

Share this post


Link to post
Share on other sites
Earthshine

how about a hot pause key kind of thing? modify to make it exit maybe? just a thought. Control-X is usually an exit from an console app.

#include <Timers.au3>

; Create a hot key. I'm using the "Pause/Break" key typically located near the number pad on the keyboard. The keycode for this key is simply "{PAUSE}"
HotKeySet("{PAUSE}", "_togglePause")

; Create a Boolean (True of False variable) to tell your program whether or not your program is paused or unpaused. Set it equal to 'False' so the script is running by default.
Global $isPaused = False


; #FUNCTION# ====================================================================================================================
; Name ..........: _togglePause
; Description ...: Pause your scripts during execution for debug
; Syntax ........: togglePause ()
; Parameters ....: None
; Return values .: None
; Author ........: root
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================; Create the togglePause function to stop/start the script
Func _togglePause ()
    ; When this function is initiated, the code on the next line 'toggles' the variable to True/False. If the script is unpaused (the $isPaused variable is set to 'False') then the next line will change it to 'True' and vice versa.
    $isPaused = NOT $isPaused
    ; Create a while loop to stall the program
    ; The line below is the same thing as "While $isPaused == True"
    While $isPaused
        ; This code will run constantly until the $isPaused variable is set to 'True'. To make the script do nothing, simply add a sleep command.
        Sleep(100)
    WEnd
EndFunc

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Earthshine

and, your code posted does not compile. you can attach an .au3 file too, no need for text. also you can post code here using the CODE <> tags

 


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Melba23

FlexScott,

Welcome to the AutoIt forums.

To detect button presses while functions are running, take a look at the Interrupting a running function tutorial in the Wiki.

M23

 

 

  • Like 1

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
FlexScott
2 hours ago, FlexScott said:

I've created an GUI to run a test program, and I'd like the operator to still be able to use the exit button while in one of the functions called from the GUI.  I'm able to change the label and enable/disable the button while in another function, but I'm not having any luck detecting the button click.  I've added the "global" designations recently (just guessing at a potential solution), but that didn't seem to make any difference.  How do I check for the button click events related to this GUI outside of the initial While loop?  Thanks for your help!

autoit_example.txt

Thanks Melba!   That looks like what I need to know.  Hopefully I can meld aspects of the MessageLoop and OnEvent modes.  Now to experiment...  Thanks very much!

Share this post


Link to post
Share on other sites
Melba23

FlexScott,

Quote

Hopefully I can meld aspects of the MessageLoop and OnEvent modes

Be very careful here - it would be much better to have just the one mode throughout the script. Come back if you have 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
FlexScott

I don't actually want to interrupt a running function, I just need to be able to check to see if the button has been clicked at certain points so I can control the actual exit(s).  The machine being tested has lots of motors and sensors, so I don't want to just bail at any time leaving it in an indeterminate state.  But I want to give the operator the option to detour out at certain points.  Thanks again!

Share this post


Link to post
Share on other sites
FlexScott

Sorry, I meant to add that I was able to enable and disable (gray-out) the button from the various test functions, so I can make it clear to the operator when this is an option.  I just couldn't figure out how to determine if the button had been clicked at the potential exit points.  

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

×