Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Progress bars for QB64 (Linux)
#1
Inspired by my code for pipecom for Linux, which uses popen to read from a process, I decided to write up some code for progress bars using Zenity in Linux. I will not post all the code just yet but I wanted to show it at least working. Here is a small recording of a simple progress bar:


Tread on those who tread on you

Reply
#2
(10-06-2023, 02:12 PM)SpriggsySpriggs Wrote: Inspired by my code for pipecom for Linux, which uses popen to read from a process, I decided to write up some code for progress bars using Zenity in Linux. I will not post all the code just yet but I wanted to show it at least working. Here is a small recording of a simple progress bar:

This is dope @spriggsyspriggs ! Well done.

I have no experience with Zenity but it seems like a CLI based widget thing?
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply
#3
Originally Zenity was written to offer "pretty" GTK+ dialog boxes for "bash" scripts on Linux. Which go beyond the realm of "gdialog" or predecessor that relied entirely on text-based "ncurses" library.

There is also Yad, but the syntax for that one could be much more involved because it could support more than one control in one dialog. If you have used the MX Tools on MX Linux, those are replete with Yad.

I'm not sure if there's a "quick" dialog kit which uses Qt framework instead.
Reply
#4
Yeah, I like Zenity. I use it all the time when writing things for Linux. I'm currently working on a dialog library for QB64 that uses Zenity. It will be similar to the tinyfiledialogs backend that QB64 already uses but will have more functionality and more dialogs.
Tread on those who tread on you

Reply
#5
Here is some code to run and try it yourself.

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!", 1)

Dim As Long x
For x = 1 To 100
    Delay 0.25
    zStepProgressBar p, x, Str$(x) + "%"
Next
zCloseProgressBar p

Function zProgressBar%& (__title As String, __autoClose As Long)
    Dim As String cmd: cmd = "zenity --progress --no-cancel --time-remaining"
    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
Tread on those who tread on you

Reply
#6
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

   
Tread on those who tread on you

Reply




Users browsing this thread: 2 Guest(s)