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

    • Blois
      By Blois
      Hi Guis,
       
      I need to create keyboard shortcut to navigate the tabs and activate them, but I could not use the code below:
      #include <TabConstants.au3> #include <WindowsConstants.au3> #include <GuiTab.au3> #include <GUIConstantsEx.au3> HotKeySet("^{TAB}", "_TabRight") HotKeySet("^+{TAB}", "_TabLeft") $gui = GUICreate("test",450, 300) $Tab1 = GUICtrlCreateTab(20, 24, 425, 201) $TabSheet1 = GUICtrlCreateTabItem("Tabsheet 1") $lbContagemGrupos2 = GUICtrlCreateLabel("aaaa", 50, 50) GUICtrlSetColor(-1, 0x0000FF) GUICtrlCreateTabItem("") $TabSheet2 = GUICtrlCreateTabItem(" ") $TabSheet3 = GUICtrlCreateTabItem(" ") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func _TabRight() $CurPos = _GUICtrlTab_GetCurSel($Tab1) _GUICtrlTab_SetCurSel($Tab1, $CurPos + 1) $tab = "$TabSheet" & $CurPos GUICtrlSetState($TabSheet1 + $CurPos, $GUI_SHOW) Return EndFunc Func _TabLeft() $CurPos = _GUICtrlTab_GetCurSel($Tab1) _GUICtrlTab_SetCurSel($Tab1, $CurPos - 1) $tab = "$TabSheet" & $CurPos GUICtrlSetState($TabSheet1 + $CurPos, $GUI_SHOW) Return EndFunc Exit  
      can you help me?
    • RamDemon
      By RamDemon
      Hi,
      Did anyone tried to  use Redis  with AutoIT as store DB ?
       Redis <-- more about it
      Mladen
    • nooneclose
      By nooneclose
      Hey. I'm working on a new project and was wondering if there is a better way to "update" my Column E array. 
      Here is my code: 
      Local $nI  = 0                                                            ;Creates a name index of 0: nI = Name index Local $nII = 1                                                            ;Creates a name index of 1 for second loop: nII = Name Index 2 For    $iN = 0 To $IndexRows Step 1                                       ;Checks the roster for any names that appear twice      For $iN2 = 0 To $IndexRows Step 1          if $d_Names[$nI] == $d_Names[$nII] And $d_Names[$nII] <> "" Then              Local $timeSheetName = _ArraySearch($e_Names, $d_Names[$nI], 0, 0, 0, 0, 1)              ;MsgBox($MB_SYSTEMMODAL, "Found it", $d_Names[$nI] & " In column E on Row " & $timeSheetName)              Local $eI  = $timeSheetName + 1              ;ConsoleWrite($timeSheetName & @CRLF)              ;ConsoleWrite($eI & @CRLF)              ;ConsoleWrite(@CRLF)              _Excel_RangeInsert($OpenWorkbook.ActiveSheet, "E" & $eI & ":F" & $eI, $xlShiftDown)                                                                          ;Inserts a empty cell in columns E and F.              _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $d_Names[$nII], "E" & $eI)                                                                         ;Fills the empty cell in columns E with the doubled name              $aArray_Index = 2                                           ;Array element counter              For $Index = 2 To $IndexRows Step 1                        ;Loops through every row in the Excel file unto no rows are found or a null row is found                  $Array_Value_E = _Excel_RangeRead($OpenWorkbook, Default, "E"&$Index)                  $e_names[$aArray_Index] = $Array_Value_E                ;While the code loops every value in column E is stored in the E array (updating the array)                  $aArray_Index += 1              Next              ExitLoop          EndIf      Next      $nI  += 1      $nII += 1 Next Basically, It checks a roster for people whose name appears twice then inserts a new "row" for that person because they work in two different departments.
      I have to find that name however in Column E if two appear in column D. My code works but I think it is not as efficient as it could be. 
      Any ideas on how to improve the "update" for my array?
      (once it finds the double names in Column D it then searches for that name by going name by name in the Column E array and once it finds it inserts a new row. However, the E array doesn't have that new row stored in it so I have to "update" the array to properly find the next name)
      Any and all tips would be greatly appreciated. 
       
      NOTE: Just assume I'm opening the excel file properly please do not add that code in, it only complicates your answer. 
    • Miliardsto
      By Miliardsto
      Hello Im wondering if using this https://ohtejera.github.io/ImperiusAutoIt/#started
      UDF can i make that I can control my windows application with phone?
      like for example click button Start on android phone and then something would be done in my windows app?
    • nooneclose
      By nooneclose
      How do I properly convert this to Autoit? This is a VBA macro that I recorded in Excel.
       ActiveSheet.Outline.ShowLevels RowLevels:=2 I need this to close my subtotal once it is finished. 
      any help will be greatly appreciated. 
×