Reputation: 424
Is it possible to create a popup with a "moving" progressbar?
Here is an example of what I tried, but it'll only display the popup after the the loop is complete. I'd like to have it visible while doing it.
import time
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.progressbar import ProgressBar
from kivy.uix.popup import Popup
databases = range(5)
class testApp(App):
def launch_popup(self, instance):
print("Button pressed for popup: {0}".format(instance))
import time
pb = ProgressBar() #100
popup = Popup(title='Syncing Databases', content=pb, size_hint=(0.7, 0.3))
popup.open()
for i in databases:
time.sleep(1) #simulate syncing database
pb.value += 100/len(databases)
print("Progressbar is on {0}%".format(pb.value))
def build(self):
btn = Button(text="Popup", on_press=self.launch_popup)
return btn
testApp().run()
Or should I use threads/a custom widget, if so how would I implement that?
Many thanks already!
Upvotes: 1
Views: 2407
Reputation: 29450
Your problem is that the for loop blocks not just the popup, but everything else in your app - it runs in the same thread as kivy's eventloop, so kivy can't do anything at all until it's finished.
You should instead run your for loop in a separate thread or break it up into smaller components that can be scheduled with Clock.schedule_once or Clock.schedule_interval. This will let kivy perform its normal tasks in between running the bits of your code.
Upvotes: 2