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
How to use Spinner
- cogier
- Site Admin
- Posts: 1129
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: How to use Spinner
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
Re: How to use Spinner
Thank you very much Cogier
Re: How to use Spinner
Hi!
Would it be too much to ask you to write a snippet on that?
See here what I mean:
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)
It's easy to die for an idea. It is way harder to LIVE for your idea! (Me)
- cogier
- Site Admin
- Posts: 1129
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: How to use Spinner
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'.
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'.
Re: How to use Spinner
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):
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):
' Gambas class file
Public Sub cmdExit_Click()
Me.Close
End
Public Sub cmdGo_Click()
Dim TheProcess As Process
TextArea1.Text = Null
Spinner1.Start
' this shell command finds all files >99 Mb and <100 Mb and lists them in the TextArea1 control
TheProcess = Shell "find / -size -100M -and -size +99M 2>&1 | grep -v 'Permission denied'" For Input Output As "Executing"
Do
Try Wait 0.5
Loop Until TheProcess.State = 0
Spinner1.Stop
TheProcess = Null
End
Public Sub Executing_Read()
Dim sLine As String
Read #Last, sLine, -256
TextArea1.Text &= sLine
End
Public Sub Executing_Kill()
TextArea1.Text &= Chr$(10) & "Done."
End
Last edited by Godzilla on Tuesday 21st April 2020 11:08pm, edited 1 time in total.
- grayghost4
- Posts: 187
- Joined: Wednesday 5th December 2018 5:00am
- Location: Marengo, Illinois usa
Re: How to use Spinner
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
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
Re: How to use Spinner
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?grayghost4 wrote: ↑Tuesday 21st April 2020 9:38pm 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
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.
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.