0

In my project , I use the MDSpinner class from KivyMD to show loading status of a widget. The code is as follows:

KV file( relevant part)

    MDSpinner:
        id: spinner
        size_hint: None, None
        size: dp(46), dp(46)
        pos_hint: { 'center_x': .5, 'center_y': .9 }
        active: True if app.processing else False

I have a Boolean property processing and the corresponding on_processing function as follows

class Mark2MarketApp(MDApp):
    processing = BooleanProperty(defaultValue=False)

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        start = time.time()
        Builder.load_file("RootWidget.kv")
        self.screen_manager = ScreenManager()
        addMainScreen(self.screen_manager, self)
        self.screen_manager.current = "Main"
        self.current = "Main"
        self.processing = False
        self.manager_open = False
        self.filePath = ""
        self.symbol = []
        self.qty = []
        self.cost = []
        self.side = []
        Window.bind(on_keyboard=self.events)
        self.file_manager = MDFileManager(
            exit_manager=self.exit_manager,
            select_path=self.select_path,
        )
        self.file_manager.ext = ['.csv', '.CSV', '.xlsx', '.XLSX']
        self.popup = self.get_popup()
        self.no_data_popup = self.no_data_popup()
        end = time.time()
        print('elapsed time for startup is %d seconds ' % (end - start))

    def on_processing(self, instance, value):
        print('instance, value', instance, value)

I set the processing variable before and after code that does some heavy lifting as follows

  def gain_loss(self):
        self.processing = True
        try:
            gl = self.screen_manager.get_screen('GainLoss')
            gl.add_widgets()
        except ScreenManagerException:
            gl = GainLossScreen(self.screen_manager, name='GainLoss')
            self.screen_manager.add_widget(gl)
            gl.add_widgets()
        if len(tryout.product_dict) == 0:
            self.no_data_popup.open()
        else:
            self.screen_manager.current = 'GainLoss'
        self.processing = False

However, the spinner doesnt get activated. I debugged the MDSpinner source code and it does call the activation.start method when processing is set to True and stops the animation when processing is set to false. But the spinner just doesnt spin!.

Interestingly, if I comment out the last line self.processing = False, then the spinner starts spinning .

Thanks in advance

2
  • 2
    If you are running the gain_loss() method on the main thread, then the MDSpinner will not be activated/deactivated until that method completes. Nov 4, 2020 at 13:48
  • Thanks! That did the trick! Much appreciated
    – srajan
    Nov 4, 2020 at 14:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.