Jump to content

Detect if Window is 'busy'


adamski
 Share

Recommended Posts

I have a small script to copy DXL code from Crimson Editor into my Doors applications code window and press run. It then copys any output and uses consolewrite to put it into Crimson Editors Output pane. Additionally it will ok a runtime error mesage box if there is one.

It all worked fine until I wrote some DXL to export alot of data. Because it was slow, the autoit script coppied the output before it had all been writen. The only indication that the code has not finished is that the window has a busy icon (hourglass) and the controls are unclickable. Is there a way to detect this and when it stops? I don't want to use a delay as then it takes that long to show the output with fast scripts.

On a vaguely related note:

Does anyone have DXL config files for SciTe so I can ditch Crimson Editor? - Or know how to convert the Crimson Editor ones?

$CrimsonWindow = "Crimson Editor - ["
$DoorsWindow = "DXL Interaction - DOORS"

If WinExists($CrimsonWindow) Then

    If WinExists($DoorsWindow) Then 
        
        $CrimsonText = WinGetText($CrimsonWindow)
        $CrimsonTextLine = StringSplit ($CrimsonText, @LF)
        $IncludeString = "#include <" & $CrimsonTextLine[1] & ">"
        
        ControlSetText($DoorsWindow, "", "[CLASS:RichEdit20W; INSTANCE:2]", $IncludeString)
    
        ControlClick($DoorsWindow, "", "[CLASS:Button; INSTANCE:8]")
    
        $DXLOutputText = WinGetText($DoorsWindow)
        $DXLOutputTextLine = StringSplit ($DXLOutputText, @LF)
        
        ConsoleWrite(@LF)
        For $i = 10 To $DXLOutputTextLine[0]-3
            ConsoleWrite($DXLOutputTextLine[$i] & @LF)
        Next
    
        $ErrorWindow = "DOORS report"

        If WinExists($ErrorWindow) Then

            ControlClick($ErrorWindow, "", "[CLASS:Button; INSTANCE:1]")
            ConsoleWrite(@LF & "************************************************************" & @LF)
            ConsoleWrite("Runtime Error!" & @LF)
            ConsoleWrite(@LF & "************************************************************" & @LF)
        
        EndIf
    Else
        ConsoleWrite(@LF & "************************************************************" & @LF)
        ConsoleWrite("Doors DXL code window '" & $DoorsWindow & "' is not open!" & @LF)
        ConsoleWrite(@LF & "************************************************************" & @LF)
    EndIf
Else
    MsgBox(0, "Error", "Crimson Editor must be open with a file loaded!")
EndIf
Edited by adamski
Link to comment
Share on other sites

May loop while GUICtrlGetState(ID) = $GUI_DISABLE ?

Thanks, I'll give it a go at work tomorrow but I'm not convinced it will work. The controls aren't disabled (grayed out), they just cant be clicked - I guess because of the window state. Your suggestion led me to WinGetState so I'll give that a go too.

Link to comment
Share on other sites

For anybody who is interested:

I managed to solve the problem (eventually) with the use of ControlSend.

After the window is 'busy' I use ControlSend to write some text to the end of an editable control. I then read the control in a loop until it has been written. This is when the window is released and clickable again.

Before this I tried many other methods which all failed:

Activate returned sucess whatever the state of the window. WinGetState didn't change throughout. Focus couldn't be used.

It seems that ControlSetText works instantly as does ControlClick. A MouseClick only happens when the window is released so that worked but then I had the mouse flying across the screen to the window which was anoying.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.12.1
 Author:         Adam Cadamally

 Script Function:
    Run the file in Crimson Editor as an included DXL code file in the DOORS DXL Interaction window.
    Copy any Doors DXL output to Crimson Editors output pane.
    OK a runtime error message box if there is one.

#ce ----------------------------------------------------------------------------

; MAIN PROGRAM

$CrimsonWindow = "Crimson Editor - ["
$DoorsWindow = "DXL Interaction - DOORS"

If WinExists($CrimsonWindow) Then

    If WinExists($DoorsWindow) Then 
        
        $CrimsonText = WinGetText($CrimsonWindow)
        $CrimsonTextLine = StringSplit ($CrimsonText, @LF)
        $IncludeString = "#include <" & $CrimsonTextLine[1] & ">"
        
        ControlSetText($DoorsWindow, "", "[CLASS:RichEdit20W; INSTANCE:2]", $IncludeString)
    
        ControlClick($DoorsWindow, "", "[CLASS:Button; INSTANCE:8]")
        
        ControlSend ($DoorsWindow, "", "[CLASS:RichEdit20W; INSTANCE:2]", "{END}{ENTER}// ENDED")
        
        $DXLOutputText = WinGetText($DoorsWindow)
        
        ConsoleWrite(@LF)
        
        If StringRight($DXLOutputText, 2) <> ">" & @LF Then
            
            $DXLOutputTextLine = StringSplit ($DXLOutputText, @LF)
            
            For $i = 10 To $DXLOutputTextLine[0]-4
                ConsoleWrite($DXLOutputTextLine[$i] & @LF)
            Next
        
        Else
            
            $OutputLineNumber = 11
            
            While StringRight($DXLOutputText, 2) == ">" & @LF
                
                $DXLOutputTextLine = StringSplit ($DXLOutputText, @LF)
                
                For $i = $OutputLineNumber-1 To $DXLOutputTextLine[0]-4
                    ConsoleWrite($DXLOutputTextLine[$i] & @LF)
                Next
                
                $OutputLineNumber = $DXLOutputTextLine[0]-2
            
                Sleep(2000)
                
                $DXLOutputText = WinGetText($DoorsWindow)
            
            WEnd
            
            $DXLOutputTextLine = StringSplit ($DXLOutputText, @LF)
        
            For $i = $OutputLineNumber-1 To $DXLOutputTextLine[0]-4
                ConsoleWrite($DXLOutputTextLine[$i] & @LF)
            Next
        
        EndIf
        
        $ErrorWindow = "DOORS report"

        If WinExists($ErrorWindow) Then

            ControlClick($ErrorWindow, "", "[CLASS:Button; INSTANCE:1]")
            ConsoleWrite(@LF & "************************************************************" & @LF)
            ConsoleWrite("Runtime Error!" & @LF)
            ConsoleWrite(@LF & "************************************************************" & @LF)
        
        EndIf
    Else
        ConsoleWrite(@LF & "************************************************************" & @LF)
        ConsoleWrite("Doors DXL code window '" & $DoorsWindow & "' is not open!" & @LF)
        ConsoleWrite(@LF & "************************************************************" & @LF)
    EndIf
Else
    MsgBox(0, "Error", "Crimson Editor must be open with a file loaded!")
EndIf
Edited by adamski
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...