Sign in to follow this  
Followers 0
Matz

Script progress bar

8 posts in this topic

Hi.

Anyone got a tip for how to make a progress bar to show the progress of the whole script?

I have a script that checks file size and date attributes on 3 files, and copies them under given terms. And I would like to have a progress bar that shows the progress of the entire script.

:whistle:

Share this post


Link to post
Share on other sites



If you want something like what the OS does with FileCopy, then have a look here.

Share this post


Link to post
Share on other sites

Yes I saw that one. Very nice.

But I also want a progress bar that shows the progress of the script itself.

Share this post


Link to post
Share on other sites

Yes I saw that one. Very nice.

But I also want a progress bar that shows the progress of the script itself.

I don't see a way of doing it with a compiled script, but if you wrap the script you are tracking, you can get the number of lines using normal text file operations. Then, use the run command to start the script you are tracking in a second process. Inside that script, write @ScriptLineNumber to a registry key that the first script watches in a while loop and updates its display (@ScriptLineNumber/$TotalLines = $PercentComplete).

I suppose you could pass the second script file as an argument to the first, and have a reusable construct...

Would that work for you?

Share this post


Link to post
Share on other sites

Yes I saw that one. Very nice.

But I also want a progress bar that shows the progress of the script itself.

I think you need to define "progress of the script" for your particular script. If you mean progress by time of execution, then you need to calculate the time expected to be required to perform the functions and you can update by TimerInit()/TimerDiff() calls. If the script's main purpose is copying things, then you can calculate Data-Transferred/Data-To-Transfer. If it installs a sequences of patches, you can go by Completed-patches/Total-patches, etc...

One of my scripts determines a required data collection (150 to 350GB total) and then copies that data collection over up to four hours. The progress bar I designed for it uses the count of top level directories (in the hundreds) to determine progress, and has a nice multi-color feature. It starts out with a fully RED bar at 0%, smoothly transitions to fully BLUE at 50%, and then to fully GREEN at 100%.

This is the demo I posted for it a while back (plus a vital fix from gafrost, at the time):

#include <GuiConstants.au3>

DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)

$GuiHandle = GUICreate("Progress Bar Test", 300, 130)
$ProgBar_1 = GUICtrlCreateProgress(10, 10, 280, 30, $PBS_Smooth)
$UpButton = GUICtrlCreateButton("UP", 15, 50, 76, 40)
$DownButton = GUICtrlCreateButton("Down", 112, 50, 76, 40)
$StopButton = GUICtrlCreateButton("STOP", 209, 50, 76, 40)
$Label_1 = GUICtrlCreateLabel("Red = 0, Green = 0, Blue = 0, Color = 0xFF0000", 10, 100, 280, 20, $SS_Center)
GUISetState()

$Progress = 0; Will be 0 thru 1000
$Increment = 0
While(1)
    $GuiMsg = GUIGetMsg()
    Select
        Case $GuiMsg = $GUI_EVENT_CLOSE
            Exit
        Case $GuiMsg = $UpButton
            $Increment = +1
        Case $GuiMsg = $DownButton
            $Increment = -1
        Case $GuiMsg = $StopButton
            $Increment = 0
        EndSelect
    _SetProgColor()
WEnd

Func _SetProgColor()
    $Progress = $Progress + $Increment
    If $Progress < 0 Then $Progress = 0
    If $Progress > 1000 Then $Progress = 1000
    GUICtrlSetData($ProgBar_1, Int($Progress / 10))
    
    $Redness = Int(255 - ($Progress / 1000 * 512))
    If $Redness < 0 Then $Redness = 0
        
    $Greeness = Int(($Progress / 1000 * 512) - 257)
    If $Greeness < 0 Then $Greeness = 0
        
    $Blueness = Int(255 - ($Redness + $Greeness))
    
    $ProgColor = ($Redness * 256 * 256) + ($Greeness * 256) + $Blueness
    GUICtrlSetData($Label_1, "Red = " & $Redness & ", Green = " & $Greeness & ", Blue = " & $Blueness & ", Color = 0x" & Hex($ProgColor, 6))
    GUICtrlSetColor($ProgBar_1, $ProgColor)
EndFunc

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

if it is a large script.. or slow...

i like two progess bars working

you can use a function similar to this throughout your script

#include <GUIConstants.au3>

Dim $t, $i, $progressbar2

GUICreate("My GUI Progressbar", 220, 100, 100, 200)
$progressbar1 = GUICtrlCreateProgress(10, 10, 200, 20)
GUICtrlSetColor(-1, 32250); not working with Windows XP Style
$progressbar2 = GUICtrlCreateProgress(10, 40, 200, 20, $PBS_SMOOTH)
$button = GUICtrlCreateButton("Start", 75, 70, 70, 20)
GUISetState()

While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then Exit
    If $msg = $button Then
        GUICtrlSetData($progressbar1, 0)
        GUICtrlSetData($progressbar2, 0)
        AdlibEnable("set_process")
        $i = 0
        $t = 0
    EndIf
    If $t >= 99 Then
        $t = 1
        $i = $i + 20
        If $i >= 100 Then AdlibDisable()
        GUICtrlSetData($progressbar1, $i)
    EndIf
    
WEnd

Func set_process()
    $t = $t + 5
    GUICtrlSetData($progressbar2, $t)
EndFunc ;==>set_process

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Great :nuke: Thanks for the code :P

I also found something that might work, and with less code using:

GuiCreate("Test", "300", "150", -1, -1)
GUISetState ()
GUICtrlCreateProgress(100, 100, 100, 10)

And putting this code on some points through the script, changing the Percentage...

GUICtrlSetData( -1, 10)

A little bit more manual, and inacurate, but should work :)

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
Sign in to follow this  
Followers 0