Jump to content
VollachR

Progress bar for silently run program

Recommended Posts

VollachR

Hi,

I'd like to show a progress bar for an operation performed by an external program my script is running silently, I want to show it in a GUI I created using the GUICtrlCreateProgress but I have no idea how to do it.

The important thing to point out is that there's no way of knowing how long the external program will run, as it is a file splitter and it depends on the size of file it splits and the split parts size.

Can someone point me in the right direction or give me an example how to do so?

This is my RunWait command:

RunWait($MYFILES1 & '\fsplit.exe -split ' & $Size & ' mb ' & $File & " -f " & $File & "." & $extension)

It uses multiple variables declared and set earlier in the script, how will I got about having the progress of that command shown using GUICtrlCreateProgress ? Is it possible?

Thank you.


Ron Vollach
Microsoft Certified Professional (MCP)
Creator of Ultimate Conversion Compressor (UCC)
UCC Wikia

Share this post


Link to post
Share on other sites
AutoBert

RunWait pauses your script until fsplit.exe has finished, so i suggest using the style Marquee for the progressbar. Here a small example:

#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <ProgressConstants.au3>


$Form1 = GUICreate("Form1", 545, 125, 5, 5);, $WS_POPUP, $WS_EX_TOOLWINDOW)
$Button1 = GUICtrlCreateButton('&STOP Marquee', 5, 5, 200)
$Timer = GUICtrlCreateLabel('Zeit: ', 470, 5, 70)
$Progress1 = GUICtrlCreateProgress(0, 95, 545, 25, $PBS_MARQUEE)
$hProgress = GUICtrlGetHandle($Progress1)
_SendMessage($hProgress, $PBM_SETMARQUEE, True, 10)
GUISetState(@SW_SHOW)
$dtStart = TimerInit()


AdlibRegister('Timer', 1000)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            If GUICtrlRead($Button1) = '&STOP Marquee' Then
                _SendMessage($hProgress, $PBM_SETMARQUEE, False, 10)
                GUICtrlSetData($Button1, '&Resume Marquee')
            Else
                _SendMessage($hProgress, $PBM_SETMARQUEE, True, 10)
                GUICtrlSetData($Button1, '&STOP Marquee')
            EndIf
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func Timer()
    Local $Time = TimerDiff($dtStart) / 1000
    Local $HOUR = Int($Time / 3600)
    Local $MIN = Int(($Time - $HOUR * 3600) / 60)
    Local $SEC = $Time - $HOUR * 3600 - $MIN * 60
    GUICtrlSetData($Timer, StringFormat("%02i:%02i:%02i", $HOUR, $MIN, $SEC))
EndFunc   ;==>Timer

If fsplit in console mode is writing progress to console you can use Run and StdoutRead for updating the real progress.

  • Thanks 1

Share this post


Link to post
Share on other sites
VollachR
Posted (edited)

 

4 hours ago, AutoBert said:

RunWait pauses your script until fsplit.exe has finished, so i suggest using the style Marquee for the progressbar. Here a small example:

#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <ProgressConstants.au3>


$Form1 = GUICreate("Form1", 545, 125, 5, 5);, $WS_POPUP, $WS_EX_TOOLWINDOW)
$Button1 = GUICtrlCreateButton('&STOP Marquee', 5, 5, 200)
$Timer = GUICtrlCreateLabel('Zeit: ', 470, 5, 70)
$Progress1 = GUICtrlCreateProgress(0, 95, 545, 25, $PBS_MARQUEE)
$hProgress = GUICtrlGetHandle($Progress1)
_SendMessage($hProgress, $PBM_SETMARQUEE, True, 10)
GUISetState(@SW_SHOW)
$dtStart = TimerInit()


AdlibRegister('Timer', 1000)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            If GUICtrlRead($Button1) = '&STOP Marquee' Then
                _SendMessage($hProgress, $PBM_SETMARQUEE, False, 10)
                GUICtrlSetData($Button1, '&Resume Marquee')
            Else
                _SendMessage($hProgress, $PBM_SETMARQUEE, True, 10)
                GUICtrlSetData($Button1, '&STOP Marquee')
            EndIf
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func Timer()
    Local $Time = TimerDiff($dtStart) / 1000
    Local $HOUR = Int($Time / 3600)
    Local $MIN = Int(($Time - $HOUR * 3600) / 60)
    Local $SEC = $Time - $HOUR * 3600 - $MIN * 60
    GUICtrlSetData($Timer, StringFormat("%02i:%02i:%02i", $HOUR, $MIN, $SEC))
EndFunc   ;==>Timer

If fsplit in console mode is writing progress to console you can use Run and StdoutRead for updating the real progress.

Well, fsplit does usually run in a command prompt, I intend to eventually set it to start hidden but it does show some kind of progress in the command line console by default, so I think maybe StdoutRead can be used but I'm not sure.

The progress it shows is not percentage but actually text line telling which part is is being created.

Anyway, here's a sample of the GUI I created, I need the progress to be shown in it and I need the OK button to become clickable only after the fsplit command ended.

#Region ### START Koda GUI section ### Form=
$Form13 = GUICreate("TITLE", 615, 500, 192, 124)
GUISetBkColor(0x0871AB)
GUISetIcon("UCC.ico")
$Text = GUICtrlCreateLabel("LINE1" & @CRLF & "LONG TEXT" & @CRLF & @CRLF & "LINE" & @CRLF & "TEXT" & @CRLF & "LINE" & @CRLF & @CRLF & "TEXT" & @CRLF & @CRLF, 15, 15, 600, 230)
GUICtrlSetFont($Text, 10, 400, 0, "Arial Rounded MT Bold")
GUICtrlSetColor($Text, 0xC5D3ED)
$Text2 = GUICtrlCreateLabel("LINE" & @CRLF & "TEXT" & @CRLF & "Part of the " & "TEXT" & " (UCC) Tool by " & "AUTHOR" & @CRLF & "LINE" & @CRLF & @CRLF & _
"STEP " & "Number" & ": Splitting " & "Filename" & " into " & "Size" & " Parts" & @CRLF & @CRLF & "Please Wait..." , 15 , 230, 500,170)
GUICtrlSetFont($Text2, 10, 400, 0, "Arial Rounded MT Bold")
GUICtrlSetColor($Text2, 0xC5D3ED)
$Logo = GUICtrlCreatePic(@TempDir & "\UCC\GUILogo.jpg", 490, 5, 130, 130)
GUICtrlSetState($Logo, $GUI_DISABLE)
$SplitProgressL = GUICtrlCreateLabel("Progres Bar:", 15, 400, 520, 15)
GUICtrlSetFont(-1, 10, 400, 0, "Arial Rounded MT Bold")
GUICtrlSetColor(-1, 0xC5D3ED)
$SplitProgress = GUICtrlCreateProgress(15, 415, 580, 15)
$btnOK = GUICtrlCreateButton("OK", 510, 470, 100, 23)
GUISetState() ; display the GUI
#EndRegion ### END Koda GUI section ###
While 1
            $Msg = GUIGetMsg()
            Sleep(10)
            Switch $Msg
                Case $GUI_EVENT_CLOSE, $btnOK
                    GUIDelete()
                    ExitLoop
            EndSwitch
        WEnd

I of course removed all the variable I actually used from this sample for the example purpose, anyway, I would I go about making that GUI progress bar work with the fsplit command? 

I don't really care the type of progress bar animation, as long as it is shown within the GUI window and it works.

BTW, I'm attaching an image showing the fsplit CMD console output.

28582953138_95f920326f_o.png

 

Edited by VollachR
Added more info

Ron Vollach
Microsoft Certified Professional (MCP)
Creator of Ultimate Conversion Compressor (UCC)
UCC Wikia

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

  • Similar Content

    • nooneclose
      By nooneclose
      Good morning everyone, I thought I had already solved this issue but it turns out I did not. 
      My code finds unread emails with this specific subject line of "request" but when I change the subject to SKIPPED + "request" = ("SKIPPED request") the program still finds the email and tries to process it. I only want to process emails with the exact match subject of "request".
      Here is my code that "finds" the unread emails with the subject of "request" or so I thought. 
      Func ListUnreadEmails() ;******************************************************************************* ; Lists all unread E-mails from the folder Outlook-UDF-Test ;******************************************************************************* ; Stores all the unRead emails into an array Global $aItems = _OL_ItemFind($oOutlook, "*\Outlook-UDF-Test", $olMail, _ "[UnRead]=True", "Subject", "request", "EntryID,Subject", "", 1) ; Displays the array of unRead emails If IsArray($aItems) Then ;_ArrayDisplay($aItems, "OutlookEX UDF: _OL_ItemFind - Unread mails") Else MsgBox(48, "OutlookEX UDF: _OL_ItemFind Example Script", _ "Could not find an unread mail. @error = " & @error & ", @extended: " & @extended) EndIf ; Gets the number of unread emails Global $numberOfUnRead = UBound($aItems, $UBOUND_ROWS) - 1 ;MsgBox("", "Number of Unread emails", $numberOfUnRead) EndFunc It acts as if any part of the subject containing the word "request" and the email is unread that it will try to process it. (I think)
    • KhalidAnsari
      By KhalidAnsari
      Hi,
      I need to automate Java application using AutoIt, I have refer forum for the same, as per forum I am using Java Access Bridge to finding control name. But could not set value to control. Below is my sample code 
      Send("#r")
      sleep(1500)
      Send("D:\javaapplication\javaapplication\Hello.jar{Enter}")
      WinActivate("Penjumlahan")
      sleep(1500)
      ControlSetText("Penjumlahan", "", "Name:  A :", "demo")
      Java Application and Java Ferret screen

    • QaisBsharat
      By QaisBsharat
      Hello, 
      May i know how can i automation qt application?
      Using controlclick not mouse and positions
       
      Thanks
    • nooneclose
      By nooneclose
      Good afternoon, I am in need of some help. I am sure this is a stupid question requiring only one or two lines of code. However, I would greatly appreciate the help I cannot figure this out. I also tried searching for the answer on the internet but no one except me apparently seems to be having a hard time figuring this out and or is asking about it. 
      I simply want to change the "status" of an email from unread to read once I have processed it. My code is over 500 lines and I would like not to clutter this post with it. Assume I have all my includes and connections properly defined and stuff. 
      Here is the bit of code where I am trying to change the email that was used from unread to read:
      Func ChangeEmailStatus() ;******************************************************************************* ; changes the status of an email from unread to Read ;******************************************************************************* Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (Before Change)", $iRows) _OL_ItemModify($oOutlook,$aItems[$i][0], Default, "Read=True") MsgBox("", "Array Display 1", $aItems[1][0]) MsgBox("", "Array Display 2", $aItems[2][0]) Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (After Change)", $iRows) EndFunc  
    • SharpDressedMan
      By SharpDressedMan
      Hello,
      Is there any way to check for validity of a pointer to a DllStruct ?
      In the above code, a DllStruct is created from an invalid pointer. How to prevent from doing this ?
      local $tStruct = DllStructCreate("int i") DllStructSetData($tStruct, "i", 123) local $pStruct = DllStructGetPtr($tStruct) $tStruct = 0 ; destroy DllStruct ==> $pStruct becomes invalid ; how to check here for validity of $pStruct and prevent from doing the following ? $tStruct = DllStructCreate("int i", $pStruct) ; create DllStruct from invalid pointer... MsgBox(0, @ScriptName, @error) ; displays '0' : invalid pointer is not detected by DllStructCreate() MsgBox(0, @ScriptName, IsDllStruct($tStruct)) ; displays '1' : tStruct is assumed as a valid DllStruct object, which is not Thanks for help
×