Jump to content

(Re)Using a GUI button while in another function


Recommended Posts

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

  • Moderators

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

 

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.  

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...