Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Activity Monitor
-
Hello, I am new to Python and loving Pythonista. Here's my problem: I am writing an app that implements finite element modeling, and even at a very basic level, the calculations take a few seconds to complete. The UI is completely blocked in that time, and I wanted to show a spinning wheel to make the user aware that the calculations are being done. I know this should be done using multi-threading, but I don't know where to start. Do you guys have any sample code / resources I can look at? Thanks!
-
Here you go, hope this helps!
# coding: utf-8 import time, console, ui @ui.in_background#this function decorator tells the device to run this function in a seperate thread from the ui, this allows the ui to not be blocked during this time def long_complicated_action(sender): console.show_activity() time.sleep(5)#this line would be replaced with your long, complicated code console.hide_activity() view = ui.View(background_color = 'white') button = ui.Button(frame = (0, 0, 80, 32)) button.action = long_complicated_action button.title = 'Press me!' view.add_subview(button) slider = ui.Slider(frame = (0, 80, 200, 32)) view.add_subview(slider)#the slider is here to show that the ui is not blocked view.present()
-
I should also note that the
ui.in_background
decorator is the only way to use things likeconsole.alert
,console.input_alert
,photos.capture_image
, andphotos.pick_image
. -
Hey, thanks a lot! I will try this later today and let you know, but it looks very promising, neat, and simple! :)
-
Just tried out and it works like a charm! I actually modified it a bit in roder to have a custom view appearing instead the activity monitor! Again, thanks a lot!!