Sign in to follow this  
Followers 0
Squirrely1

Custom Progress Flickers

4 posts in this topic

#1 ·  Posted (edited)

My customizable progress bar flickers when it should not. Also it requires .bmp's in the same folder to work. Can someone improve this function? Download and unzip "Progress.zip" that is attached. A test harness is already included so you can then just double-click on the "Progress.au3". Requires the AutoIt beta because of "GuiCtrlCreateGraphic()".

Here is the code for "Progress.au3" but you need the image files included in the zip to see it work:

#include-once

#Region Syntax_&_Notes

#cs
    
;Makes a progress bar control that lasts a given duration in seconds
    
;Syntax:
;Start_Progress_Bar ( duration, left, top [, width [, height [, colorName [, durationFinal [, hexBkColor [, hexBorderColor ]]]]]] )
;Specify a default parameter with -1
;Durations are given in seconds and should not be in quotes (can have decimal fractions)
;Default width is 300, default height is 12
;"colorName" is "blue", "yellow", "green", "red", "cyan", or -1
;"durationFinal" is the number of seconds to continue displaying after "duration" has completed. (default is 1.4)
    
;Notes:
;Requires AutoIt beta for GuiCtrlCreateGraphic (on line number 147)
;Any given height or width of the progress bar less than 7 will be replaced with 7 (the minimum)
;Created for use with SciTe
;If any of these options is set to other than the default, there might be problems:
    Opt("Color Mode", 0)
    Opt("GUICoordMode", 0)
    Opt("GUIOnEventMode", 0)
    Opt("PixelCoordMode", 0)
    
;Problems: the progress bar display flashes and this function requires image files.
    
#ce


#EndRegion Syntax_&_Notes
;


#Region INIT

#include <GUIConstants.au3>

Global $PicLeft, $PicTop, $PicWidth, $PicHeight
Global $t_empDir, $wdir
Global $ProgressMade, $progTrial
Global $e_nd_Disp

;Controls
Global $_Progress_Graphic, $_Progress_Pic


#EndRegion INIT
;


#Region Test_harness

;#cs
#include <GUIConstants.au3>
Opt("MustDeclareVars", 1)
Global $Jane, $msg
$Jane = GUICreate("Progress", 340, 60)
Start_Progress_Bar(20.000, 20, 20, -1, 13, "cyan", 1.8)

GUISetState()
While 1
    
    $msg = GUIGetMsg()
    If $msg == $GUI_EVENT_CLOSE Then
        ExitLoop
    EndIf
    
WEnd
Exit
;#ce


#EndRegion Test_harness
;


Func Start_Progress_Bar($du_ration, $ProgressLeft, $ProgressTop, $ProgressWidth = 300, $ProgressHeight = 12, $ColorName = "cyan", $end_Time = 1.4, $hexBkColor = 0xFFFFFF, $hexBorderColor = 0x000000)
    
    Local $t_empDir, $milliSecs, $proPic
    
    If $ProgressWidth = -1 Then
        $ProgressWidth = 300
    EndIf
    
    If $ProgressHeight = -1 Then
        $ProgressHeight = 12
    EndIf
    
    If $ColorName = -1 Then
        $ColorName = "cyan"
    EndIf
    
    If $hexBkColor = -1 Then
        $hexBkColor = 0xFFFFFF
    EndIf
    
    If $hexBorderColor = -1 Then
        $hexBorderColor = 0x000000
    EndIf
    
    $e_nd_Disp = $end_Time * 1000
    
    $t_empDir = @TempDir
    If Not FileExists($t_empDir) Then
        $t_empDir = @HomeDrive & "\Temp"
        If Not FileExists($t_empDir) Then
            DirCreate($t_empDir)
        EndIf
    EndIf
    
    FileChangeDir(@ScriptDir)
    Select
        Case $ColorName = "red"
            FileInstall("ProgressRed.bmp", $t_empDir & "\", 1)
            $proPic = $t_empDir & "\ProgressRed.bmp"
            
        Case $ColorName = "green"
            FileInstall("ProgressGreen.bmp", $t_empDir & "\", 1)
            $proPic = $t_empDir & "\ProgressGreen.bmp"
            
        Case $ColorName = "yellow"
            FileInstall("ProgressYellow.bmp", $t_empDir & "\", 1)
            $proPic = $t_empDir & "\ProgressYellow.bmp"
            
        Case $ColorName = "blue"
            FileInstall("ProgressBlue.bmp", $t_empDir & "\", 1)
            $proPic = $t_empDir & "\ProgressBlue.bmp"
            
        Case Else
            FileInstall("ProgressCyan.bmp", $t_empDir & "\", 1)
            $proPic = $t_empDir & "\ProgressCyan.bmp"
            
    EndSelect
;Sleep(1300)
    
    $PicLeft = $ProgressLeft + 3
    $PicTop = $ProgressTop + 3
    $PicWidth = $ProgressWidth - 6
    $PicHeight = $ProgressHeight - 6
    
    $ProgressMade = 0
    $progTrial = $PicWidth + 1
    $milliSecs = Int(($du_ration * 1000) / $PicWidth) / 1.128
    
    $_Progress_Graphic = GUICtrlCreateGraphic($ProgressLeft, $ProgressTop, $ProgressWidth, $ProgressHeight, ($SS_SIMPLE + $SS_GRAYFRAME))
    GUICtrlSetBkColor($_Progress_Graphic, $hexBkColor); background-color
    GUICtrlSetColor($_Progress_Graphic, $hexBorderColor); border-color
    GUICtrlSetState($_Progress_Graphic, $GUI_DISABLE)
    
    $_Progress_Pic = GUICtrlCreatePic($proPic, $PicLeft, $PicTop, $ProgressMade, $PicHeight)
    GUICtrlSetState($_Progress_Pic, $GUI_DISABLE)
    
    AdlibEnable("Update_Progress", $milliSecs)
    
EndFunc;==>Start_Progress_Bar


Func Update_Progress()
    
    $ProgressMade += 1
    If $ProgressMade < $progTrial Then
        GUICtrlSetPos($_Progress_Pic, $PicLeft, $PicTop, $ProgressMade, $PicHeight)
    Else
        End_Progress_Bar()
    EndIf
    
EndFunc;==>Update_Progress


Func End_Progress_Bar()
    
    AdlibDisable()
    
    $ProgressMade = $progTrial - 1
    GUICtrlSetPos($_Progress_Pic, $PicLeft, $PicTop, $ProgressMade, $PicHeight)
    Sleep($e_nd_Disp)
    
    GUICtrlDelete($_Progress_Graphic)
    GUICtrlDelete($_Progress_Pic)
    
EndFunc;==>End_Progress_Bar

By the way, did you know that in SciTe you can press Ctrl-T and then press Indent+Proper+Doc and when Tidy is done, a list of all the variables in your program comes up: Scroll to the bottom of the Notepad window that comes up and see. :D

Edited by Squirrely1

Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Lazycat, you are truly fast and bulbous. You must know all about how to get in good will all the alley-cat ladies too! You fixed my module and made the work that it was worth the time.

:D

For those interested the lines he is replacing in the original functions are shown here:

Func Update_Progress()
    
    $ProgressMade += 1
    If $ProgressMade < $progTrial Then
               ;Lazycat fixed:
        ControlMove($Jane, "", $_Progress_Pic, $PicLeft, $PicTop, $ProgressMade, $PicHeight)
;GUICtrlSetPos($_Progress_Pic, $PicLeft, $PicTop, $ProgressMade, $PicHeight)
    Else
        End_Progress_Bar()
    EndIf
    
EndFunc;==>Update_Progress

Func End_Progress_Bar()
    
    AdlibDisable()
    
    $ProgressMade = $progTrial - 1
;Lazycat fixed:
    ControlMove($Jane, "", $_Progress_Pic, $PicLeft, $PicTop, $ProgressMade, $PicHeight)
;GUICtrlSetPos($_Progress_Pic, $PicLeft, $PicTop, $ProgressMade, $PicHeight)
    Sleep($e_nd_Disp)
    
    GUICtrlDelete($_Progress_Graphic)
    GUICtrlDelete($_Progress_Pic)
    
EndFunc ;==>End_Progress_Bar

Finished colored progress bar (that still requires the zipped images):

Edited by Squirrely1

Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites

By the way, did you know that in SciTe you can press Ctrl-T and then press Indent+Proper+Doc and when Tidy is done, a list of all the variables in your program comes up: Scroll to the bottom of the Notepad window that comes up and see. :wacko:

Yep, amazing what some JdeB magic does.... :D

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