Jump to content

How do I combine a GUI with a timed function?


 Share

Recommended Posts

So I have created a GUI that runs different functions, and I've already got a separate script that checks my machine for errors every ~30seconds, and if there's a error it runs the error fixing function. I would like to combine these two scripts.. I don't know how to run a script in a loop while having a gui still react to button clicks during that time.. is there a way? Should I just leave them seperate? I was trying to combine them to clean things on my machine up a bit, I've got three different autoit programs running at a given time on that machine, I would like to combine these two. Unfortunately I left the scripts on my work computer so I can't give an example.. but I hope I explained the problem clearly. 

Link to comment
Share on other sites

  • Moderators

BatMan22,

Some form of timer would seem to be the answer - look at TimerInit/Diff in the Help file.

An example - even bare-bones - would be helpful in suggesting exactly how to incorporate it into your script.

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

@Melba23 I posted the examples of my code below, first is the GUI, second is the loop that checks the machine for errors. Also I will look at TimerInit later today (just got to work). 

GUI: 
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\SetupCache\Extended\Graphics\SysReqMet.ico
#AutoIt3Wrapper_Res_Fileversion=0.0.0.5
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Run_Au3Stripper=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <Date.au3>
#include <File.au3>
#include <Misc.au3>
#RequireAdmin
#include <Array.au3>
#include <WinAPISys.au3>
#include <String.au3>
#include <ScreenCapture.au3>



Global $sBetweenme = "Ch2" & @LF ; basically what channel to search
Global $sAndme = @LF & "mV" ; millivolts
Global $Limit = 55 ; Panic over this value
Global $aMDIWindows[0]
Global $sParentWindowTitle = "Queue Editor" ; Program name, shouldn't ever change but Just In Case!
Global $jpgsavelocation = "\\Ic2\PUBLIC\MacroShare\FML.jpg" ; Where to save screenshot!
Global $quewindowprefix = "C:\Program Files\Metrohm\IC Net 2.2\IC Net\" ; Just the prefix before the xxxxxx.que
Global $fullsystempathandname = "C:\Program Files\Metrohm\IC Net 2.2\IC Net\Systems\HPUV\HPuv_0405_ASFIXED.smt" ; FULL PATH AND SYSTEM NAME THAT YOU ARE USING!
Global $systemnameonly = "HPUV\HPuv_0405_ASFIXED.smt" ; Just your system name
Global $pumpnamewindow = "DPC Pump(HPUV\HPuv_0405_ASFIXED.smt)" ; Name of window when you double click pump
Global $secondtopurgeDPCpump = "20000" ; 20 seconds
$sServerPath = "\\Ic2\PUBLIC\MacroShare" ;Initial path for selecting txt file - OpenFile() function
$sLeftFile = $sServerPath & "\IC2.txt"
$sRightFile = $sServerPath & "\IC2A.txt"
Global $DFSelect[0]
Global $JFlag = ""


AutoItSetOption('SendKeyDelay', 1)

HotKeySet("^!a", "CutLeft")
HotKeySet("^!s", "CutRight")
HotKeySet("^!z", "ReportSingle")
HotKeySet("^!u", "ReportRepeatUp")
HotKeySet("^!z", "ReportSingle")

$Form1 = GUICreate("Queue Selection", 670, 283, -1, -1, -1, -1, WinGetHandle($sParentWindowTitle))
$FileList = GUICtrlCreateList("", 8, 8, 297, 201, BitOR($LBS_EXTENDEDSEL, $WS_VSCROLL))
$MoveLeft = GUICtrlCreateButton(">", 316, 7, 30, 25)
$MoveLeftAll = GUICtrlCreateButton(">>", 316, 40, 31, 25)
$MoveRight = GUICtrlCreateButton("<", 317, 73, 31, 25)
$MoveRightAll = GUICtrlCreateButton("<<", 317, 106, 32, 25)
$ProcessList = GUICtrlCreateList("", 352, 8, 241, 201, BitOR($LBS_EXTENDEDSEL, $WS_VSCROLL))
$Clear = GUICtrlCreateButton("Clear List", 8, 217, 75, 25)
$Cancel = GUICtrlCreateButton("Cancel", 8, 249, 75, 25)
$Load = GUICtrlCreateButton("Load", 96, 217, 499, 33)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
;~ $Label1 = GUICtrlCreateLabel("DF", 600, 8, 26, 24) ; Replaced with X1 DF ie Checkbox 13
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Checkbox13 = GUICtrlCreateCheckbox("x1", 600, 16, 97, 17)
$Other = GUICtrlCreateInput("Other", 240, 256, 273, 21)
$Checkbox1 = GUICtrlCreateCheckbox("J-FLAG", 528, 256, 57, 17)
$Checkbox2 = GUICtrlCreateCheckbox("x2", 600, 40, 33, 17)
$Checkbox3 = GUICtrlCreateCheckbox("x3", 600, 64, 33, 17)
$Checkbox4 = GUICtrlCreateCheckbox("x4", 600, 88, 33, 17)
$Checkbox5 = GUICtrlCreateCheckbox("x5", 600, 112, 33, 17)
$Checkbox6 = GUICtrlCreateCheckbox("x10", 600, 136, 41, 17)
$Checkbox7 = GUICtrlCreateCheckbox("x20", 600, 160, 41, 17)
$Checkbox8 = GUICtrlCreateCheckbox("x40", 600, 184, 41, 17)
$Checkbox9 = GUICtrlCreateCheckbox("x50", 600, 208, 41, 17)
$Checkbox10 = GUICtrlCreateCheckbox("x100", 600, 232, 49, 17)
$Checkbox11 = GUICtrlCreateCheckbox("x200", 600, 256, 49, 17)
$Checkbox12 = GUICtrlCreateCheckbox("Custom DF", 160, 256, 73, 17)

;Create hotkeys which are only active when the GUI has focus.
$OpenFile = GUICtrlCreateDummy()
$LoadFile = GUICtrlCreateDummy()
Dim $aHotKeys[2][2] = [["{F4}", $OpenFile], ["{F5}", $LoadFile]]
GUISetAccelerators($aHotKeys, $Form1)

;Determine location of GUI and system tray and move GUI to bottom right corner, above tray.
$aWin = WinGetPos($Form1)
$aTaskbar = WinGetPos("[CLASS:Shell_TrayWnd]", "")
$X = @DesktopWidth - $aWin[2] - 4
$Y = @DesktopHeight - $aWin[3] - $aTaskbar[3] - 4
WinMove($Form1, "", $X, $Y)
GUISetState(@SW_SHOW)

;OpenFile()
LoadFile()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MoveLeft
            Move($FileList, $ProcessList)
        Case $MoveLeftAll
            MoveAll($FileList, $ProcessList)
        Case $MoveRight
            Move($ProcessList, $FileList)
        Case $MoveRightAll
            MoveAll($ProcessList, $FileList)
        Case $Load

            If GUICtrlRead($Checkbox13) = 1 Then
                _ArrayAdd($DFSelect, "")
            EndIf

            If GUICtrlRead($Checkbox2) = 1 Then
                _ArrayAdd($DFSelect, GUICtrlRead($Checkbox2, 1))
            EndIf
            If GUICtrlRead($Checkbox3) = 1 Then
                _ArrayAdd($DFSelect, GUICtrlRead($Checkbox3, 1))
            EndIf
            If GUICtrlRead($Checkbox4) = 1 Then
                _ArrayAdd($DFSelect, GUICtrlRead($Checkbox4, 1))
            EndIf
            If GUICtrlRead($Checkbox5) = 1 Then
                _ArrayAdd($DFSelect, GUICtrlRead($Checkbox5, 1))
            EndIf
            If GUICtrlRead($Checkbox6) = 1 Then
                _ArrayAdd($DFSelect, GUICtrlRead($Checkbox6, 1))
            EndIf
            If GUICtrlRead($Checkbox7) = 1 Then
                _ArrayAdd($DFSelect, GUICtrlRead($Checkbox7, 1))
            EndIf
            If GUICtrlRead($Checkbox8) = 1 Then
                _ArrayAdd($DFSelect, GUICtrlRead($Checkbox8, 1))
            EndIf
            If GUICtrlRead($Checkbox9) = 1 Then
                _ArrayAdd($DFSelect, GUICtrlRead($Checkbox9, 1))
            EndIf
            If GUICtrlRead($Checkbox10) = 1 Then
                _ArrayAdd($DFSelect, GUICtrlRead($Checkbox10, 1))
            EndIf
            If GUICtrlRead($Checkbox11) = 1 Then
                _ArrayAdd($DFSelect, GUICtrlRead($Checkbox11, 1))
            EndIf
            If GUICtrlRead($Checkbox12) = 1 Then
                _ArrayAdd($DFSelect, GUICtrlRead($Other))
            EndIf

            If GUICtrlRead($Checkbox1) = 1 Then
                Process(" J-FLAG")
            Else
                Process()
            EndIf

        Case $Cancel
            Exit
        Case $Clear
            ClearFile()
            ;Case $OpenFile ;F4 Choose new file
            ;   ChooseFile()
        Case $LoadFile ;F5 Refresh current file
            LoadFile()
    EndSwitch
WEnd

Functions.. blah blah blah.
Loop that checks the machine for errors: 

#RequireAdmin
#include <Array.au3>
#include <WinAPISys.au3>
#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <String.au3>
#include <ScreenCapture.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <WinAPIFiles.au3>
#include <Date.au3>
#include <File.au3>


Global $sBetweenme = "Ch2" & @LF ; basically what channel to search
Global $sAndme = @LF & "mV" ; millivolts
Global $Limit= 55 ; Panic over this value
Global $aMDIWindows[0]
Global $sParentWindowTitle = "IC Net" ; Program name, shouldn't ever change but Just In Case!
Global $jpgsavelocation = "\\Ic2\PUBLIC\MacroShare\FML.jpg" ; Where to save screenshot!
Global $quewindowprefix = "C:\Program Files\Metrohm\IC Net 2.2\IC Net\" ; Just the prefix before the xxxxxx.que
Global $fullsystempathandname = "C:\Program Files\Metrohm\IC Net 2.2\IC Net\Systems\HPUV\HPuv_0405_ASFIXED.smt" ; FULL PATH AND SYSTEM NAME THAT YOU ARE USING!
Global $systemnameonly = "HPUV\HPuv_0405_ASFIXED.smt"; Just your system name
Global $pumpnamewindow = "DPC Pump(HPUV\HPuv_0405_ASFIXED.smt)" ; Name of window when you double click pump
Global $secondtopurgeDPCpump = "30000" ; 20 seconds

_GetICNetMDIWindows(); first window grab

Local $i = 0
While $i = 0
    Sleep(30000) ; Check every X milliseconds! 1000 = 1second
    CheckValue()
 WEnd

;~  PumpFix()


 Func CheckValue()

    Local $sText =  ControlGetText(_GetMDIHandlebyTitle("Watch window"), "", "MLCRangeColor7")
;~  If $sText = "" Then
;~     _GetICNetMDIWindows()
;~     ConsoleWrite("Error happened again!")
;~     Local $sText =  ControlGetText(_GetMDIHandlebyTitle("Watch window"), "", "MLCRangeColor7")
;~     ConsoleWrite("but data is now: ")
;~  EndIf
       ConsoleWrite($sText & "      ")
    If $sText > $Limit Then
    _ScreenCapture_Capture($jpgsavelocation)
    PumpFix()
    Sleep(30000)
    EndIf
EndFunc   ;==>Example

Func _SendEx($ss, $warn = "") ; prevent stuck keys!
    Local $iT = TimerInit()

    While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")
        If $warn <> "" And TimerDiff($iT) > 1000 Then
            MsgBox($MB_TOPMOST, "Warning", $warn)
        EndIf
        Sleep(50)
    WEnd
    Send($ss)
 EndFunc;==>_SendEx

Func PumpFix()

_GetICNetMDIWindows() ;this will get All the required MDI Childs windows
;~ _ArrayDisplay($aMDIWindows);show all the Childs windows

If Not IsArray($aMDIWindows) Then Exit MsgBox(0, "Error", "IC Net isn't open sucka?")

WinActivate(_GetMDIHandlebyTitle($quewindowprefix));activate the Que window
Sleep(300)
;~ ControlClick(_GetMDIHandlebyTitle($quewindowprefix), "", "Button4", "left", 1) ; Pause The Sequence
WinMenuSelectItem(_GetMDIHandlebyTitle($quewindowprefix), "", "&Control", "Pause...") ; Pause The Sequence
Sleep(300)
WinActivate("IC Net")
WinMenuSelectItem("IC Net", "", "&File", "&Open", "&System"); Open System just in case it's closed
Sleep(300)
_SendEx($fullsystempathandname)
Sleep(300)
_SendEx("{Enter}")
;~ MouseClick("primary", 572, 59, 1)
;~ Sleep(500)
_GetICNetMDIWindows() ;Refresh Open Windows
Sleep(450)
WinActivate(_GetMDIHandlebyTitle($systemnameonly));activate the System window
Sleep(400)
;~ MsgBox(0,0,"HPUV Activated")
WinActivate(_GetMDIHandlebyTitle($systemnameonly));activate the System window
Sleep(400)
WinMenuSelectItem(_GetMDIHandlebyTitle($systemnameonly), "", "&Control", "Sto&p determination") ; Stop Determination, duh.
;~ _SendEx("!cp"); Stop Single Run
Sleep(400)
ControlClick(_GetMDIHandlebyTitle($systemnameonly), "", "CCBitmap8", "left", 2) ; Open Pump
Sleep(1000)
_GetICNetMDIWindows() ;Refresh Open Windows
Sleep(1000)
WinActivate(_GetMDIHandlebyTitle($pumpnamewindow))
Sleep(1000)
ControlSetText(_GetMDIHandlebyTitle($pumpnamewindow),  "", "Edit3", "5.0") ; Set Pump to 5.0 Speed
Sleep(1000)
ControlClick(_GetMDIHandlebyTitle("Settings"), "", "Button6", "left", 1) ; ClickSetInthe"Settings"window
Sleep($secondtopurgeDPCpump)
ControlSetText(_GetMDIHandlebyTitle($pumpnamewindow),  "", "Edit3", "0.2") ; Set Pump to 5.0 Speed
Sleep(1000)
ControlClick(_GetMDIHandlebyTitle("Settings"), "", "Button6", "left", 1) ; ClickSetInthe"Settings"window
Sleep(1000)
ControlClick(_GetMDIHandlebyTitle($quewindowprefix), "", "Button3", "left", 1) ; Start The Sequence
Sleep(1000)
_SendEx("!n")
EndFunc

Func _GetICNetMDIWindows()
    Local $hParentWindow = WinActivate("IC Net")
    Local $aData = _WinAPI_EnumChildWindows($hParentWindow)
;~ _ArrayDisplay($aData)

    If IsArray($aData) Then
        ReDim $aMDIWindows[$aData[0][0]][2] ;handle;title
        Local $iIndexBound = 0
        For $i = 1 To $aData[0][0]
            If StringInStr($aData[$i][1], "#32770") Then
;~          ConsoleWrite(WinGetTitle($aData[$i][0]) & @CRLF)
                $aMDIWindows[$iIndexBound][0] = $aData[$i][0]
                $aMDIWindows[$iIndexBound][1] = WinGetTitle($aData[$i][0])
                $iIndexBound += 1
            EndIf
        Next
        ReDim $aMDIWindows[$iIndexBound][2]
        If Not UBound($aMDIWindows) Then $aMDIWindows = 0
    EndIf
EndFunc   ;==>_GetICNetMDIWindows


Func _GetMDIHandlebyTitle($sTitle)
    Local $iFind = _ArraySearch($aMDIWindows, $sTitle, 0, 0, 0, 1)
    If $iFind > -1 Then
        Return $aMDIWindows[$iFind][0]
    Else
        Return 0
    EndIf
EndFunc   ;==>_GetMDIHandlebyTitle

 

Link to comment
Share on other sites

7 minutes ago, kylomas said:

Batman22,

An easy solution is setting an adlib timer in the gui (driver) script to run your 2nd script every 30 minutes...

Kylomas

You know I'll look into that, I was thinking that the adlib timer was too limited in it's functionality.. but I guess all I really would need it to do would be to execute the .exe that checks to see if the machine is working ok and change the machine checking script so that it no longer loops every X seconds. The reason why I wasn't going to use that function initially was because of the warning in the adlib help page.. But I guess if I semi-combine them by having one function just run an exe.. that should work :)

 

Warning on help page: "The adlib function should be kept simple as it is executed often and during this time the main script is paused. Also, the time parameter should be used carefully to avoid CPU load. You can not register a function using parameters.

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