Jump to content

[MATH] A sort of progress


Go to solution Solved by mikell,

Recommended Posts

Posted (edited)

Hi all check my script:

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

$hGUI = GUICreate("", 325, 72, -1, -1)
$Progress = GUICtrlCreateProgress(8, 8, 300, 17, $PBS_SMOOTH)
$Label = GUICtrlCreateLabel("", 8, 30, 1, 17)
GUICtrlSetBkColor(-1, 0xFFFF00)
GUICtrlSetState(-1, $GUI_HIDE)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Local $Count = 10, $Set
            GUICtrlSetState($Label, $GUI_SHOW)
            For $i = 1 To $Count
                $Set = Int($i / ($Count) * 100)
                GUICtrlSetPos($Label, 8, 30, $Set, 17)
                ConsoleWrite("$ProgressSet: " & $Set & @CR)
                GUICtrlSetData($Progress, $Set)
                Sleep(500)
            Next
            Exit
    EndSwitch
WEnd

First I don't know how to calculate the correct size for $Label using $Set, secondly i don't know how to make the process from a size to a new size "smoother", GUICtrlSetPos don't have a speed parameter or similar

Thanks :D

Edited by MyEarth
Posted (edited)

For the first point, i have probably an answer. If $Set = percentage of the progressbar, so the width of $Label is equal to total size minus that percentage, like:

($LabelWidth * $Set) / 100 ; $LabelWidth = 300 in the example on the first post

If isn't right please correct me. Still have no idea for make the "transition" smooth

Edited by MyEarth
Posted

?

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

$width = 300
$hGUI = GUICreate("", 325, 72, -1, -1)
$Progress = GUICtrlCreateProgress(8, 8, $width, 17, $PBS_SMOOTH)
$Label = GUICtrlCreateLabel("", 8, 30, 1, 17)
GUICtrlSetBkColor(-1, 0xFFFF00)
GUICtrlSetState(-1, $GUI_HIDE)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Local $Count = $width, $Set
            GUICtrlSetState($Label, $GUI_SHOW)
            For $i = 1 To $Count 
                $Set = Int($i * 100 / $Count )
                GUICtrlSetPos($Label, 8, 30, $i, 17)
                ConsoleWrite("$ProgressSet: " & $Set & @CR)
                GUICtrlSetData($Progress, $Set)
                Sleep(10)
            Next
            Exit
    EndSwitch
WEnd
Posted

Why did you make $Count = $width? Isn't so easy...

$Count = number of items i need to process, can be 5, 10, 400 or 1.000 who knows but the progress percentage is based on that count, i can't make $Count = $width but for me was obv

Posted

It was not obvious in your first post

You will need a 2nd loop for the smoothness

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

$Count = 50
$width = 300

$hGUI = GUICreate("", 325, 72, -1, -1)
$Progress = GUICtrlCreateProgress(8, 8, $width, 17, $PBS_SMOOTH)
$Label = GUICtrlCreateLabel("", 8, 30, 1, 17)
GUICtrlSetBkColor(-1, 0xFFFF00)
GUICtrlSetState(-1, $GUI_HIDE)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUICtrlSetState($Label, $GUI_SHOW)
            For $i = 1 To $Count
                $Set = Int($i * 100 / $Count )
                ConsoleWrite("$ProgressSet: " & $Set & @CR)
                GUICtrlSetData($Progress, $Set)

                For $j = 1 to $width/$Count
                  GUICtrlSetPos($Label, 8, 30, $Set*($width/100)+$j-($width/$Count), 17)
                  Sleep(20)
                Next
              ;  Sleep(100)  ; smoothness
            Next
            Exit
    EndSwitch
WEnd
WEnd
Posted

If your purpose is to use the label instead of the progress, the calculation is simpler

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

$Count = 50
$width = 300
$ratio = $width/$Count

$hGUI = GUICreate("", 325, 72, -1, -1)
$Progress = GUICtrlCreateProgress(8, 8, $width, 17, $PBS_SMOOTH)
$Label = GUICtrlCreateLabel("", 8, 30, 1, 17)
GUICtrlSetBkColor(-1, 0xFFFF00)
GUICtrlSetState(-1, $GUI_HIDE)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUICtrlSetState($Label, $GUI_SHOW)

            For $i = 1 To $Count 
              ;  $Set = Int($i * 100 / $Count )
              ;  ConsoleWrite("$ProgressSet: " & $Set & @CR)
              ;  GUICtrlSetData($Progress, $Set)

                For $j = 1 to $ratio
               ;   GUICtrlSetPos($Label, 8, 30, $Set*($width/100)+$j-($width/$Count), 17)
                  GUICtrlSetPos($Label, 8, 30, ($i-1)*$ratio+$j, 17)
                  Sleep(20)
                Next
              ;  Sleep(100)  ; smoothness
            Next
            Exit
    EndSwitch
WEnd
Posted (edited)

I was thinking, instead of use the second For-Next ( For $j = 1 to $ratio ) is possible to use AdlibRegister? So i don't have a Sleep(20) in the main loop and the label-progress is a non blocking function. If is not possible i'll use the 2 loops solution. Thanks
 

Edited by MyEarth
  • Solution
Posted (edited)

It's possible  :)
The 'close' gui button can work while the label is progressing, this shows that updating is non blocking

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

$Count = 600
$width = 300
$ratio = $width/$Count
$progress = 0

$hGUI = GUICreate("", 325, 72, -1, -1)
$Label = GUICtrlCreateLabel("", 8, 30, 0, 17)
GUICtrlSetBkColor(-1, 0xFFFF00)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            If $progress = 0 Then
               Adlibregister("_update", 20)
               $progress = 1
           Else
                Exit
           EndIf
    EndSwitch
WEnd


Func _update()
  Local Static $i = 0, $j = 0
  If $j = 0 Then $i += 1
  $j += 1
  GUICtrlSetPos($Label, 8, 30, ($i-1)*$ratio+$j, 17)
ConsoleWrite("$i = " & $i & "  $j = " & $j & @CR)
  If $j >= $ratio Then
      $j = 0
      If $i = $Count Then AdlibUnregister("_update")
  EndIf
EndFunc
Edited by mikell

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
×
×
  • Create New...