Jump to content

Using a gui button to control togglepause


Recommended Posts

I want to start my script paused and when I click the pause button I want it to unpause the script. I would also like the pause button to say unpaused when the script is not paused.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $Paused
$Paused = $Paused

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 377, 280, 192, 114)
$Input1 = GUICtrlCreateInput("10", 24, 40, 49, 21)
$Input2 = GUICtrlCreateInput("", 24, 72, 49, 21)
$Input3 = GUICtrlCreateInput("", 24, 104, 49, 21)
$Input4 = GUICtrlCreateInput("", 24, 136, 49, 21)
$Input5 = GUICtrlCreateInput("23", 24, 168, 49, 21)
$Input6 = GUICtrlCreateInput("", 240, 40, 49, 21)
$Input7 = GUICtrlCreateInput("", 240, 72, 49, 21)
$Input8 = GUICtrlCreateInput("", 240, 104, 49, 21)
$Input9 = GUICtrlCreateInput("", 240, 136, 49, 21)
$Input10 = GUICtrlCreateInput("", 240, 168, 49, 21)

$Pause = GUICtrlCreateButton("Pause", 24, 216, 97, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

TogglePause()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Pause
            TogglePause()
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func TogglePause()                    ;<==========================Here
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Paused', 0, 0)
    WEnd
    ToolTip("")
EndFunc

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

HotKeySet("{Esc}", "_Exit")

$hGui = GUICreate("Gui Pause Button Example", 300, 80)
$hPause = GUICtrlCreateButton("Pause", 120, 24, 60)
GUISetState()

Global $Counter = 0 ; Not needed, just for demonstration purpose.

_Pause()

While 3
    ;Your code starts in this main loop
    ; Note that the below is just to show script is running, and might look odd due to nature of msg loop.
    $Counter += 1
    If $Counter >= 300 Then
        ConsoleWrite("Running" & @LF)
        $Counter = 0
    EndIf

    Switch GUIGetMsg()
        Case -3 ; $GUI_EVENT_CLOSE
            Exit
        Case $hPause ; Pause button
            ConsoleWrite("!Pause" & @LF)
            _Pause()
    EndSwitch
WEnd

Func _Pause()
    GUICtrlSetData($hPause, "Resume")
    While 3
        Switch GUIGetMsg()
            Case -3 ; $GUI_EVENT_CLOSE need to be able to exit while paused.
                Exit
            Case $hPause ; Pause button
                ExitLoop
        EndSwitch
    WEnd
    GUICtrlSetData($hPause, "Pause")
    ConsoleWrite("+Resume" & @LF)
EndFunc   ;==>_Pause

Func _Exit()
    Exit
EndFunc   ;==>_Exit

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

Monkey's are, like, natures humans.

Link to comment
Share on other sites

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

HotKeySet("{PAUSE}","TogglePause")
Global $Paused
$Paused = $Paused

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 377, 280, 192, 114)
$Input1 = GUICtrlCreateInput("10", 24, 40, 49, 21)
$Input2 = GUICtrlCreateInput("", 24, 72, 49, 21)
$Input3 = GUICtrlCreateInput("", 24, 104, 49, 21)
$Input4 = GUICtrlCreateInput("", 24, 136, 49, 21)
$Input5 = GUICtrlCreateInput("23", 24, 168, 49, 21)
$Input6 = GUICtrlCreateInput("", 240, 40, 49, 21)
$Input7 = GUICtrlCreateInput("", 240, 72, 49, 21)
$Input8 = GUICtrlCreateInput("", 240, 104, 49, 21)
$Input9 = GUICtrlCreateInput("", 240, 136, 49, 21)
$Input10 = GUICtrlCreateInput("", 240, 168, 49, 21)

$Pause = GUICtrlCreateButton("Pause", 24, 216, 97, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Send("{PAUSE}")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Pause
            Send("{PAUSE}")
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

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

This worked but I feel like its a shoehorn fit.

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

  • Moderators

computergroove,

Try something like this: :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

Global $Paused
$Paused = $Paused

$Form1 = GUICreate("Form1", 377, 280, 192, 114)

$Pause = GUICtrlCreateButton("Pause", 24, 216, 97, 25)

$cTest = GUICtrlCreateButton("Test", 24, 116, 97, 25)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()

    ; Run these all the time
    Switch $nMsg
        Case $Pause
            ; Toggle pause
            $Paused = Not $Paused
            If $Paused Then
                ToolTip('Paused', 0, 0)
                GUICtrlSetData($Pause, "Unpause")
            Else
                 ToolTip("")
                 GUICtrlSetData($Pause, "Pause")
            EndIf

        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; Only run these if not paused
    If Not $Paused Then
        Switch $nMsg
            Case $cTest
                MsgBox($MB_SYSTEMMODAL, "Hi", "Running")
        EndSwitch
    EndIf

WEnd
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

computergroove,

Try something like this: :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

Global $Paused
$Paused = $Paused

$Form1 = GUICreate("Form1", 377, 280, 192, 114)

$Pause = GUICtrlCreateButton("Pause", 24, 216, 97, 25)

$cTest = GUICtrlCreateButton("Test", 24, 116, 97, 25)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()

    ; Run these all the time
    Switch $nMsg
        Case $Pause
            ; Toggle pause
            $Paused = Not $Paused
            If $Paused Then
                ToolTip('Paused', 0, 0)
                GUICtrlSetData($Pause, "Unpause")
            Else
                 ToolTip("")
                 GUICtrlSetData($Pause, "Pause")
            EndIf

        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; Only run these if not paused
    If Not $Paused Then
        Switch $nMsg
            Case $cTest
                MsgBox($MB_SYSTEMMODAL, "Hi", "Running")
        EndSwitch
    EndIf

WEnd
M23

 

I tried this but I dont see where the script sleeps when paused. Did I miss something?

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

  • Moderators

computergroove,

If you want the script itself to sleep, how do you intend the GUI button to reawaken it given that the entire script is inactive? I have offered you a way to keep the button active while nothing else can operate - if that is not what you want them just ignore my suggestion. :)

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

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...