How to use Spinner

Post

Posted
Rating:
#1 (In Topic #399)
Trainee
 Hello,
I want to launch the Spinner at the start of a Shell operation and stop it at the end of this operation, but when I call the start () function of the Spinner before the Shell line, the Spinner does not start until after the end of the shell command, how to fix this problem.
Thank you
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
Gambas can only do one thing at a time so you need to use a 'Task' to get this to work. Have a look at this example
Online now: No Back to the top

Post

Posted
Rating:
#3
Trainee
Thank you very much Cogier
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
Serban is in the usergroup ‘Regular’

cogier said

Gambas can only do one thing at a time so you need to use a 'Task' to get this to work. Have a look at this example

Hi!
Would it be too much to ask you to write a snippet on that?

See here what I mean:

https://forum.gambas.o…/viewtopic.php?f=13&t=845

Greetings!

The only thing necessary for the triumph of evil is for good men to do nothing.”― Edmund Burke;
It's easy to die for an idea. It is way harder to LIVE for your idea! (Me)
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Guru
cogier is in the usergroup ‘Guru’
I presume you are after an explanation to: - 'Gambas can only do one thing at a time'.

Gambas, in normal use, only uses one processor so in this case while waiting for a 'Shell' command to finish not much else can happen. If you follow this thread you will see the way you can get around this limitation using 'Task'.
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Regular
Godzilla is in the usergroup ‘Regular’
I don't use the spinner control in my applications. But this thread caught my attention due to the suggestion of using "Task" to remedy the OP's problem. I use "Task" extensively. For living room super-computing, its a godsend.

Out of curiosity, I threw this code together to see if using a spinner control, along with shell, would cause the spinner to not start until the shell operation was completed. From there, I planned to see how I could implement "Task" to fix the problem. I purposely used a shell operation that would take some time.

But for me, the spinner didn't freeze and worked as expected, without the need for "Task". It spins happily while the shell is executing and listing files in the textarea. Though it does freeze for the last 7 or so seconds of the shell's operation. I don't see that as much of a problem.

Maybe the OP is using spinner + shell in a different way that I'm not understanding. Here's my code, if it helps. Its a simple form with controls: Spinner1, TextArea1, and two Buttons (cmdGo + cmdExit):

Code (gambas)

  1. ' Gambas class file
  2.  
  3. Public Sub cmdExit_Click()
  4.  
  5.  
  6.  
  7. Public Sub cmdGo_Click()
  8.  
  9.   Dim TheProcess As Process  
  10.  
  11.   TextArea1.Text = Null
  12.  
  13.   Spinner1.Start
  14.  
  15.   ' this shell command finds all files >99 Mb and <100 Mb and lists them in the TextArea1 control  
  16.   TheProcess = Shell "find / -size -100M -and -size +99M 2>&1 | grep -v 'Permission denied'" For Input Output As "Executing"
  17.  
  18.   Do
  19.     Try Wait 0.5    
  20.   Loop Until TheProcess.State = 0
  21.  
  22.   Spinner1.Stop  
  23.  
  24.   TheProcess = Null
  25.  
  26.  
  27. Public Sub Executing_Read()
  28.  
  29.   Dim sLine As String
  30.  
  31.   Read #Last, sLine, -256
  32.  
  33.   TextArea1.Text &= sLine
  34.  
  35.  
  36. Public Sub Executing_Kill()
  37.  
  38.   TextArea1.Text &= Chr$(10) & "Done."
  39.  
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
 I tried you program and the spinner did keep spinning while it was running, but it stopped after I got about 100 errors in the console and the text area.

testSpinner:26163): Gtk-CRITICAL **: 14:33:22.484: gtk_text_buffer_emit_insert:
 assertion 'g_utf8_validate (text, len, NULL)' failed

then it stopped spinning
Online now: No Back to the top

Post

Posted
Rating:
#8
Avatar
Regular
Godzilla is in the usergroup ‘Regular’

grayghost4 said

I tried you program and the spinner did keep spinning while it was running, but it stopped after I got about 100 errors in the console and the text area.

testSpinner:26163): Gtk-CRITICAL **: 14:33:22.484: gtk_text_buffer_emit_insert:
 assertion 'g_utf8_validate (text, len, NULL)' failed

then it stopped spinning

Oh yeah, focusing on the spinner, I didn't really take the textarea's buffer into account. That's probably the reason the spinner stops spinning on my computer near the end of my search, too. Though I don't get any console messages indicating errors like you did. Probably because I used a QT form instead of GTK. QT should indicate these kind of errors in the console, too. Maybe there's a setting somewhere that I don't know about?

Much of the text filling the buffer is all the "permission denied" messages, due to the "find" command preferably needing a SUDO password to search properly. For me, proper didn't matter. All i was interested in was a quick simple read-only command shell can run that doesn't finish in an instant. To give the spinner plenty of time to spin.

So after some research, I found a way to suppress all the "permission denied" messages. Thus, leaving plenty of space for the buffer. And to be on the safe side, I narrowed the search range to a much smaller window that should yield few, if any results.

After doing this, the spinner operates for me 100% as expected, without any freezes near the end of the shell operation.

Code (gambas)

  1. TheProcess = Shell "find / -size -100M -and -size +99M 2>&1 | grep -v 'Permission denied'" For Input Output As "Executing"

 I'll also try to edit my original post with this much more functional code.

grayghost4, thank you for your feedback my friend.
Online now: No Back to the top
1 guest and 0 members have just viewed this.