AutoHotkey: Show elapsed / remaining / total / start / finish times in title bar of progress dialogs: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(Added category AutoHotkey scripts) |
||
Line 423: | Line 423: | ||
</br> | </br> | ||
Back to [[AutoHotkey]] | Back to [[AutoHotkey]] | ||
[[Category:AutoHotkey scripts|Show elapsed / remaining / total / start / finish times in title bar of progress dialogs]] |
Revision as of 23:54, 31 May 2008
This script was inspired by an AutoIt script made by user van Dusen. All credit for the original idea goes to him. The script is activated by pressing Shift when a progress dialog window is active in TC.
AssignWindowTitles: ; The options for the title of windows with one progress bar are: ; ; Elapsed time: %ElapsedTimeString1% ; Elapsed time with hours shown: %ElapsedTimeStringHours1% ; Remaining time: %RemainingTimeString1% ; Remaining time with hours shown: %RemainingTimeStringHours1% ; Total time: %TotalTimeString1% ; Total time with hours shown: %TotalTimeStringHours1% ; ; Time when process started: %StartTimeString1% ; Time when process will finish: %EndTimeString1% ; ; Example: ; OneProgressBarWindowTitle = Remaining time: %RemainingTimeString1% (%EndTimeString1%) OneProgressBarWindowTitle = Remaining time: %RemainingTimeString1% (%EndTimeString1%) ; The options for the title of windows with two progress bars are: ; ; - First progress bar: ; Elapsed time: %ElapsedTimeString1% ; Elapsed time with hours shown: %ElapsedTimeStringHours1% ; Remaining time: %RemainingTimeString1% ; Remaining time with hours shown: %RemainingTimeStringHours1% ; Total time: %TotalTimeString1% ; Total time with hours shown: %TotalTimeStringHours1% ; ; Time when process started: %StartTimeString1% ; Time when process will finish: %EndTimeString1% ; ; - Second progress bar: ; Elapsed time: %ElapsedTimeString2% ; Elapsed time with hours shown: %ElapsedTimeStringHours2% ; Remaining time: %RemainingTimeString2% ; Remaining time with hours shown: %RemainingTimeStringHours2% ; Total time: %TotalTimeString2% ; Total time with hours shown: %TotalTimeStringHours2% ; ; Time when process started: %StartTimeString2% ; Time when process will finish: %EndTimeString2% ; ; Example: ; TwoProgressBarsWindowTitle = Current left: %RemainingTimeString1% Total left: %RemainingTimeString2% (%EndTimeString2%) TwoProgressBarsWindowTitle = Current left: %RemainingTimeString1% Total left: %RemainingTimeString2% (%EndTimeString2%) Return ; Activate by pressing the Shift key ~$Shift:: { ; If we weren't called from a TC progress dialog then exit IfWinNotActive, ahk_class TDLG2FILEACTIONMIN Return ; Get the ID of the progress window for later use WinGet, WindowID ; Set absolute coordinate mode so we can use PixelSearch even when the window is inactive CoordMode, Pixel, Screen ; Get the progress bar color from registry RegRead, HilightColor, HKEY_CURRENT_USER, Control Panel\Colors, Hilight If ErrorLevel MsgBox, Error trying to read registry value HKEY_CURRENT_USER\Control Panel\Colors\Hilight StringSplit, RGB, HilightColor, %A_Space% ProgressBarColor := (RGB1 << 16) + (RGB2 << 8) + (RGB3) ; Init variables Percent1 = 0 LastPercent1 = 0 Percent2 = 0 LastPercent2 = 0 ; We will loop as long as the progress window exists Loop { IfWinExist, ahk_id %WindowID% { ; Find window and get coordinates of first progress bar WinGetPos, WinPosX, WinPosY, , , ahk_id %WindowID% ControlGetPos, X, Y, Width, Height, TPercentPanel1, ahk_id %WindowID% LeftX := WinPosX + X + 1 RightX := LeftX + Width - 2 Y := WinPosY + Y + 1 ;Get progress bar position PixelSearch, PosX, PosY, RightX, Y, LeftX, Y, %ProgressBarColor%, , RGB ; If Time1 has already been set, then set LastTime to its value before we ; assign the current time to Time1 IfNotEqual, Time1, LastTime1 = %Time1% ; Assign current time to Time1 Time1 = %A_Now% ; In case we didn't find the progress bar, there are two possibilities: ; - it wasn't painted yet (0%), or ; - it is behind some other window ; We cannot distinguish between these two cases (at least I don't know of any ; easy way how, except perhaps enumerating the positions of all other ; windows, and somehow getting their Z position), so we check if there is ; already some info shown for ElapsedTime and RemainingTime (we do this by ; checking if LastTime was assigned a value already) and we increase ; ElapsedTime and decrease RemainingTime by one second each second If (ErrorLevel <> 0) AND (LastTime1 <> "") { IfNotEqual, ElapsedTime1, { Diff = %Time1% EnvSub, Diff, %LastTime1%, Seconds ElapsedTime1 := ElapsedTime1 + Diff Hours := ElapsedTime1 // 3600 Minutes := Mod(ElapsedTime1, 3600) // 60 MinutesOnly := ElapsedTime1 // 60 Seconds := Mod(ElapsedTime1, 60) If Strlen(Minutes) = 1 Minutes = 0%Minutes% If Strlen(Seconds) = 1 Seconds = 0%Seconds% ElapsedTimeString1 = %MinutesOnly%:%Seconds% ElapsedTimeStringHours1 = %Hours%:%Minutes%:%Seconds% ; Set variable so we know we have something to update later ; on Update1 = 1 } IfNotEqual, RemainingTime1, { Diff = %Time1% EnvSub, Diff, %LastTime1%, Seconds RemainingTime1 := RemainingTime1 - Diff Hours := RemainingTime1 // 3600 Minutes := Mod(RemainingTime1, 3600) // 60 MinutesOnly := RemainingTime1 // 60 Seconds := Mod(RemainingTime1, 60) If Strlen(Minutes) = 1 Minutes = 0%Minutes% If Strlen(Seconds) = 1 Seconds = 0%Seconds% RemainingTimeString1 = %MinutesOnly%:%Seconds% RemainingTimeStringHours1 = %Hours%:%Minutes%:%Seconds% ; Set variable so we know we have something to update later ; on Update1 = 1 } } ; If we could determine the position of the progress bar, let's do the whole ; stuff IfEqual, ErrorLevel, 0 { ; Get the percent value, one percent is four pixels Percent1 := (PosX - 27 - WinPosX) // 4 ; If FirstPercent and FirstTime have not been set yet, assign current ; values to them, so we know when we started measuring (timewise and ; percentwise) IfEqual, FirstPercent1, FirstPercent1 = %Percent1% IfEqual, FirstTime1, FirstTime1 = %Time1% ; If Percent value has decreased, the progress bar shows progress for ; another file, so we reset FirstPercent and FirstTime to current ; Percent and Time IfLess, Percent1, %LastPercent1% { FirstPercent1 = %Percent1% FirstTime1 = %Time1% } ; Save the current Percent value to LastPercent, so we can compare ; them in the next loop (see above) LastPercent1 = %Percent1% ; Main calculations SinceFirstTime := Time1 EnvSub, SinceFirstTime, %FirstTime1%, Seconds SinceFirstPercent := Percent1 - FirstPercent1 TotalTime := Round((SinceFirstTime * 100) / (SinceFirstPercent)) Hours := TotalTime // 3600 Minutes := Mod(TotalTime, 3600) // 60 MinutesOnly := TotalTime // 60 Seconds := Mod(TotalTime, 60) If Strlen(Minutes) = 1 Minutes = 0%Minutes% If Strlen(Seconds) = 1 Seconds = 0%Seconds% TotalTimeString1 = %MinutesOnly%:%Seconds% TotalTimeStringHours1 = %Hours%:%Minutes%:%Seconds% ElapsedTime1 := Round((SinceFirstTime * Percent1) / (SinceFirstPercent)) Hours := ElapsedTime1 // 3600 Minutes := Mod(ElapsedTime1, 3600) // 60 MinutesOnly := ElapsedTime1 // 60 Seconds := Mod(ElapsedTime1, 60) If Strlen(Minutes) = 1 Minutes = 0%Minutes% If Strlen(Seconds) = 1 Seconds = 0%Seconds% ElapsedTimeString1 = %MinutesOnly%:%Seconds% ElapsedTimeStringHours1 = %Hours%:%Minutes%:%Seconds% RemainingTime1 := Round((SinceFirstTime * (100 - Percent1)) / SinceFirstPercent) Hours := RemainingTime1 // 3600 Minutes := Mod(RemainingTime1, 3600) // 60 MinutesOnly := RemainingTime1 // 60 Seconds := Mod(RemainingTime1, 60) If Strlen(Minutes) = 1 Minutes = 0%Minutes% If Strlen(Seconds) = 1 Seconds = 0%Seconds% RemainingTimeString1 = %MinutesOnly%:%Seconds% RemainingTimeStringHours1 = %Hours%:%Minutes%:%Seconds% StartTime = %Time1% EnvAdd, StartTime, -%ElapsedTime1%, Seconds FormatTime, StartTimeString1, %StartTime%, HH:mm:ss EndTime = %Time1% EnvAdd, EndTime, %RemainingTime1%, Seconds FormatTime, EndTimeString1, %EndTime%, HH:mm:ss Update1 = 1 } ; Check if there is a second progress bar ; If yes, perform same operations as for the first one (see above) ControlGetPos, X, Y, Width, Height, TPercentPanel2, ahk_id %WindowID% IfNotEqual, X, { ProgressBars = 2 ; Find window and get coordinates of first progress bar WinGetPos, WinPosX, WinPosY, , , ahk_id %WindowID% ControlGetPos, X, Y, Width, Height, TPercentPanel2, ahk_id %WindowID% LeftX := WinPosX + X + 1 RightX := LeftX + Width - 2 Y := WinPosY + Y + 1 ;Get progress bar position PixelSearch, PosX, PosY, RightX, Y, LeftX, Y, %ProgressBarColor%, , RGB IfNotEqual, Time2, LastTime2 = %Time2% Time2 = %A_Now% If (ErrorLevel <> 0) AND (LastTime2 <> "") { IfNotEqual, ElapsedTime2, { Diff = %Time2% EnvSub, Diff, %LastTime2%, Seconds ElapsedTime2 := ElapsedTime2 + Diff Hours := ElapsedTime2 // 3600 Minutes := Mod(ElapsedTime2, 3600) // 60 MinutesOnly := ElapsedTime2 // 60 Seconds := Mod(ElapsedTime2, 60) If Strlen(Minutes) = 1 Minutes = 0%Minutes% If Strlen(Seconds) = 1 Seconds = 0%Seconds% ElapsedTimeString2 = %MinutesOnly%:%Seconds% ElapsedTimeStringHours2 = %Hours%:%Minutes%:%Seconds% Update2 = 1 } IfNotEqual, RemainingTime2, { Diff = %Time2% EnvSub, Diff, %LastTime2%, Seconds RemainingTime2 := RemainingTime2 - Diff Hours := RemainingTime2 // 3600 Minutes := Mod(RemainingTime2, 3600) // 60 MinutesOnly := RemainingTime2 // 60 Seconds := Mod(RemainingTime2, 60) If Strlen(Minutes) = 1 Minutes = 0%Minutes% If Strlen(Seconds) = 1 Seconds = 0%Seconds% RemainingTimeString2 = %MinutesOnly%:%Seconds% RemainingTimeStringHours2 = %Hours%:%Minutes%:%Seconds% Update2 = 1 } } IfEqual, ErrorLevel, 0 { Percent2 := (PosX - 27 - WinPosX) // 4 IfEqual, FirstPercent2, FirstPercent2 = %Percent2% IfEqual, FirstTime2, FirstTime2 = %Time2% IfLess, Percent2, %LastPercent2% { FirstPercent2 = %Percent2% FirstTime2 = %Time2% } LastPercent2 = %Percent2% SinceFirstTime := Time2 EnvSub, SinceFirstTime, %FirstTime2%, Seconds SinceFirstPercent := Percent2 - FirstPercent2 TotalTime := Round((SinceFirstTime * 100) / (SinceFirstPercent)) Hours := TotalTime // 3600 Minutes := Mod(TotalTime, 3600) // 60 MinutesOnly := TotalTime // 60 Seconds := Mod(TotalTime, 60) If Strlen(Minutes) = 1 Minutes = 0%Minutes% If Strlen(Seconds) = 1 Seconds = 0%Seconds% TotalTimeString2 = %MinutesOnly%:%Seconds% TotalTimeStringHours2 = %Hours%:%Minutes%:%Seconds% ElapsedTime2 := Round((SinceFirstTime * Percent2) / (SinceFirstPercent)) Hours := ElapsedTime2 // 3600 Minutes := Mod(ElapsedTime2, 3600) // 60 MinutesOnly := ElapsedTime2 // 60 Seconds := Mod(ElapsedTime2, 60) If Strlen(Minutes) = 1 Minutes = 0%Minutes% If Strlen(Seconds) = 1 Seconds = 0%Seconds% ElapsedTimeString2 = %MinutesOnly%:%Seconds% ElapsedTimeStringHours2 = %Hours%:%Minutes%:%Seconds% RemainingTime2 := Round((SinceFirstTime * (100 - Percent2)) / SinceFirstPercent) Hours := RemainingTime2 // 3600 Minutes := Mod(RemainingTime2, 3600) // 60 MinutesOnly := RemainingTime2 // 60 Seconds := Mod(RemainingTime2, 60) If Strlen(Minutes) = 1 Minutes = 0%Minutes% If Strlen(Seconds) = 1 Seconds = 0%Seconds% RemainingTimeString2 = %MinutesOnly%:%Seconds% RemainingTimeStringHours2 = %Hours%:%Minutes%:%Seconds% StartTime = %Time2% EnvAdd, StartTime, -%ElapsedTime2%, Seconds FormatTime, StartTimeString2, %StartTime%, HH:mm:ss EndTime = %Time2% EnvAdd, EndTime, %RemainingTime2%, Seconds FormatTime, EndTimeString2, %EndTime%, HH:mm:ss Update2 = 1 } } ; If some time related variables have been updated (as indicated by ; the Update1 and Update2 variables), update the title bar If (Update1 = 1) OR (Update2 = 1) { GoSub, AssignWindowTitles IfNotEqual, ProgressBars, 2 WinSetTitle, ahk_id %WindowID%, , %OneProgressBarWindowTitle% Else WinSetTitle, ahk_id %WindowID%, , %TwoProgressBarsWindowTitle% Update1 = 0 Update2 = 0 } } else Break Sleep, 700 } ; Reset variables Percent1 = FirstPercent1 = LastPercent1 = Time1 = FirstTime1 = ElapsedTime1 = RemainingTime1 = LastTime1 = Percent2 = FirstPercent2 = LastPercent2 = Time2 = FirstTime2 = ElapsedTime2 = RemainingTime2 = LastTime2 = ProgressBars = ; Reset coordinate mode to the default relative mode ; in case we're part of some other script, that relies on it CoordMode, Pixel, Relative }
Back to AutoHotkey