User Tools

Site Tools


16.19 Class Spinner

The class Spinner (gb. form) implements a control that shows an animation in two variants:

B1 B2

Figure 16.19.1: Spinner variant with activated progress indicator (Gambas 3.7.1 and Gambas > 3.8.0)

16.19.1 Properties

The class Spinner has these relevant characteristics:

PropertyData typeDescription
BorderBooleanSpecifies whether a frame should be set or not. Use the border class for a list of constants.
EnabledBooleanShows whether the control is enabled or not.
LabelBooleanSpecifies whether a progress value should be displayed or not.
ValueFloatReturns a progress value between 0 (0%) and 1.0 (100%). You can also set the value within the range of values [0|1]. The progress value is only displayed if the Label property is set to True.

Table Properties of the class spinner

16.19.2 Methods

The first two methods are particularly important for the use of the class spinners:

StartStarts the animation.
StopStop the animation.
WaitCalls the event loop and ensures that the event loop is not called more often than every 200 milliseconds.

Table Methods of the class Spinner

16.19.3 Project

The ArchivDownLoadGIT project adopts the program idea from the FileDownLoad project in? chapter 17.1, where the archive file (gambas source code) is loaded from a server into a specific directory in a certain version and then unpacked. To display the download progress of the archive file on, the Progressbar is replaced by a spinner.


Figure Downloading the archive file from the server (GB 3.10.0)

The wget program is used to download the archive file. The outputs of the program wget are evaluated via a suitable process variable hWGETProcess As Process.

Public Sub btnGetArchivFile_Click()  
  If txbCodeSourceURL.Text Begins "https://" Then
     sArchivFileName = File.Name(Replace(txbCodeSourceURL.Text, "https://", ""))
     sArchivFileName = File.Name(txbCodeSourceURL.Text)
  txaMessages.Insert("Quelle: " & gb.Tab & txbCodeSourceURL.Text & gb.NewLine)
  txaMessages.Insert("Ziel: " & gb.Tab & txbArchivDirectory.Text &/ sArchivFileName & gb.NewLine)
  GetArchiv(txbCodeSourceURL.Text, txbArchivDirectory.Text &/ sArchivFileName) 
  txaMessages.Insert(Subst("&1 '&2' &3", ("The archive"), sArchivFileName, ("will be unpacked!")) & "\n"
  Wait 2 
  UnPackArchiv(txbArchivDirectory.Text &/ sArchivFileName)
End ' btnGetFile_Click()

In the error event hWGETProcess_Error (sOutput As String), these outputs provide not only the start and end of the download, but also the download progress and the size of the archive on the server, because all outputs of program' wget' come via the standard error output:

Public Sub hWGETProcess_Error(sOutput As String)
  Dim aMatrix, aListe As String[]
  Dim sElement As String
  Dim iSizeMB As Float
  aMatrix = Split(sOutput, gb.newline)
  For Each sElement In aMatrix
      If sElement Ends "200 OK" Then
         txaMessages.Insert(("The connection to the server was successfully established."))
      Endif ' sElement Ends "200 OK" ?      
      If sElement Begins "Länge:" Or sElement Begins "Length:" Then
         aListe = Split(sElement, " ")
         iArchivSize = CInteger(aListe[1])
         iSizeMB = Round((iArchivSize / 1000000) * 0.953674316, -1)
         txaMessages.Insert(("Archive size = ") & Str(iArchivSize) & " Byte » (" & Str(iSizeMB) & " MiB )")
         txaMessages.Insert(gb.NewLine & "Download aktiv ..." & gb.NewLine)
         Spinner1.Label = True
      Endif ' sElement Begins "Länge:" ?      
      If sElement Like "*gespeichert*" Or sElement Like "*saved*" Then
         txaMessages.Insert(("Download finished!") & gb.NewLine)
         Spinner1.Visible = False
      Endif ' LIKE ?
  Next ' sElement  
End ' hWGETProcess_Error(..)

While the archive file is being downloaded, the download progress (in percent) should be displayed in the spinner. To do this, you need the size of the archive file on the server before you download it. You also need to specify the percentage of the archive file that has already been loaded or the current size of the local archive file. In the project, the second variant is implemented with a timer:

Public Sub SizeTimer_Timer()
  Dim iCurrentFileSize As Integer
  iCurrentFileSize = Stat(txbArchivDirectory.Text &/ sArchivFileName).Size
  Spinner1.Value = iCurrentFileSize / iArchivSize
End ' Timer1_Timer()


Figure Unpacking the archive file without progress indicator in the spinner


Figure Achieved: The archive has been unpacked and saved.


The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k16/k16.19/start.txt · Last modified: 29.09.2023 by emma

Page Tools