I guess this has been answered in other links but I am still unable to put together a solution since I am a Kivy newbie. I have made a simple Kivy App which does some word parsing calculation but unfortunately, that takes about 5 mins to complete (when this function call is made - srs_object.gather_srs). I don't want my app to freeze during that time. Can someone let me know an elegant solution for the same. Thanks in advance!
from _cffi_backend import callback
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from ExtractTestName import ExtractTestName
from ExtractTestProtocols import ExtractTestProtocols
from SRSGathering import SRSGathering
from WriteToExcel import WriteToExcel
class GridLayout(GridLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.rows = 2
self.cols = 2
self.text1 = TextInput(text='Enter SRS Path', multiline=False)
self.add_widget(self.text1)
self.text2= TextInput(text='Enter TP Path', multiline=False)
self.add_widget(self.text2)
self.btn1 = Button(text = 'Calculate RTM')
self.btn1.bind(on_press = self.callback)
self.add_widget(self.btn1)
self.btn2 = Button(text='Clear text')
self.btn2.bind(on_press= self.callback2)
self.add_widget(self.btn2)
def callback(self, elem):
# This function call takes 5 mins to complete
srs_object = SRSGathering(self.text1.text)
srs = srs_object.gather_srs()
excel_obj = WriteToExcel('SRS.xlsx', srs)
excel_obj.writetoexcel_DF()
def callback2(self, elem):
self.text1.text = ""
self.text2.text = ""
class DemoApp(App):
def build(self):
return GridLayout()
Just run that method in another Thread
:
def callback(self, elem):
threading.Thread(target=self.do_callback).start()
def do_callback(self):
# This function call takes 5 mins to complete
srs_object = SRSGathering(self.text1.text)
srs = srs_object.gather_srs()
excel_obj = WriteToExcel('SRS.xlsx', srs)
excel_obj.writetoexcel_DF()