User Tools

Site Tools


k16:k16.19:start

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 16.19.1.1: Properties of the class spinner

16.19.2 Methods

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

MethodDescription
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 16.19.2.1: 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 https://gitlab.com/gambas/gambas/repository/stable/archive.tar.bz2, the Progressbar is replaced by a spinner.

B3

Figure 16.19.3.1: 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()  
 
  CreateDirectory(txbArchivDirectory.Text)
 
  If txbCodeSourceURL.Text Begins "https://" Then
     sArchivFileName = File.Name(Replace(txbCodeSourceURL.Text, "https://", ""))
  Else
     sArchivFileName = File.Name(txbCodeSourceURL.Text)
  Endif
 
  txaMessages.Clear()  
  txaMessages.Insert(gb.NewLine)  
  txaMessages.Insert("Quelle: " & gb.Tab & txbCodeSourceURL.Text & gb.NewLine)
  txaMessages.Insert("Ziel: " & gb.Tab & txbArchivDirectory.Text &/ sArchivFileName & gb.NewLine)
  txaMessages.Insert(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."))
         txaMessages.Insert(gb.NewLine)
      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)
         SizeTimer.Start() 
         Spinner1.Label = True
         Spinner1.Start() 
      Endif ' sElement Begins "Länge:" ?      
 
      If sElement Like "*gespeichert*" Or sElement Like "*saved*" Then
         txaMessages.Insert(("Download finished!") & gb.NewLine)
         SizeTimer.Stop()
         Spinner1.Stop() 
         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()

B4

Figure 16.19.3.2: Unpacking the archive file without progress indicator in the spinner

B5

Figure 16.19.3.3.3: Achieved: The archive has been unpacked and saved.

Download

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