In that last post, I also added the `--time-remaining` flag, which estimates how much longer it will take to complete the process. This code also allows you to change the size of the progress bar window.
Code: (Select All)
Option Explicit
$NoPrefix
Declare CustomType Library
Function popen%& (cmd As String, type As String)
Sub fwrite (ptr As String, Byval size As _Offset, Byval nmemb As _Offset, Byval stream As _Offset)
Sub fflush (ByVal stream As _Offset)
Sub pclose (ByVal stream As _Offset)
End Declare
Dim As Offset p: p = zProgressBar("RUNNING!", 320, 100, 0)
Dim As Long x
For x = 1 To 100
Delay 0.1
zStepProgressBar p, x, Str$(x) + "% completed...Please wait"
If x = 100 Then zStepProgressBar p, x, "DONE!"
Next
zCloseProgressBar p
Function zProgressBar%& (__title As String, __width As Long, __height As Long, __autoClose As Long)
Dim As String cmd: cmd = "zenity --progress --no-cancel --time-remaining --width=" + _Trim$(Str$(__width)) + " --height=" + _Trim$(Str$(__height))
If __title <> "" Then cmd = cmd + " --title='" + __title + "'"
If __autoClose <> 0 Then cmd = cmd + " --auto-close"
Dim As _Offset stream: stream = popen(cmd + Chr$(0), "w" + Chr$(0))
If stream Then zProgressBar = stream Else zProgressBar = 0
End Function
Sub zStepProgressBar (__pHandle As _Offset, __newValue As Long, __message As String)
Dim As String buf
buf = _Trim$(Str$(__newValue)) + Chr$(0)
fwrite buf, 1, Len(buf), __pHandle
fflush __pHandle
If __message <> "" Then
buf = "# " + __message + Chr$(0)
fwrite buf, 1, Len(buf), __pHandle
End If
End Sub
Sub zCloseProgressBar (__pHandle As _Offset)
pclose __pHandle
End Sub