class MainCarousel(Carousel): """Main cinfdata class. Contains the current settings and provides an interface to the cinfdata information """ def __init__(self, **kwargs): super(MainCarousel, self).__init__(**kwargs) # Initiate cinfdata and bind properties self.cinfdata = Cinfdata(self, creds.username, creds.password) # Add a reference to cinfdata to page selection self.ids.page_selection.cinfdata = self.cinfdata self.ids.main_image.cinfdata = self.cinfdata # Initiate date plot options and add cinfdata reference #self.dateplot_options = DatePlotOptions() #self.dateplot_options.cinfdata = self.cinfdata self.waiting_png = CoreImage('data/waiting.png') def on_index(self, *args): """Update image when switcing into the middle carousel part on_index is called the caroudel is turned into a new position """ super(MainCarousel, self).on_index(*args) Logger.debug('MainCarousel: index: {}'.format(args[1])) if args[1] == 1: # First time on_index is called, there is no cinfdata object yet if not hasattr(self, 'cinfdata'): print("no cindata yet") return # Also we switch back to if self.cinfdata.selected_plot is None: return self.ids.main_image.update_image(self.waiting_png) Clock.schedule_once(self._get_image_and_update) def _get_image_and_update(self, _): """Get image from cinfdata and update main image""" data = self.cinfdata.get_plot() self.ids.main_image.update_image(data) def change_plot(self, setup_and_link): """Change the plot settings widget when a new plot is selected""" #Logger.debug("Change plot %s", setup_and_link[0]) #Logger.debug("Change plot %s", setup_and_link[1]) _, link = setup_and_link if link['pagetype'] == 'dateplot': self.ids.plot_settings.clear_widgets() dateplot_options = DatePlotOptions(setup_and_link) dateplot_options.cinfdata = self.cinfdata self.ids.plot_settings.add_widget(dateplot_options) else: message = 'Support for the \'{}\' plot type is not yet implemented'\ .format(link['pagetype']) raise NotImplementedError(message)
class MainCarousel(Carousel): """Main cinfdata class. Contains the current settings and provides an interface to the cinfdata information """ def __init__(self, **kwargs): super(MainCarousel, self).__init__(**kwargs) self.waiting_png = CoreImage('data/waiting.png') Clock.schedule_once(self._after_init) def _after_init(self, _): """Get password""" username = password = None if creds is not None: username, password = creds.username, creds.password # Implement using password managers if username is None: # username, password = password.get_creds() pass # If we git creds from creds module or password managers, set callback if username is not None: callback = partial(self._after_password, username, password) Clock.schedule_once(callback) return # Otherwise, ask for them (PasswordOpen will call _after_password) pw = PasswordPopup(self) pw.open() def _after_password(self, username, password, _): """After password has been received, initialize cinfdata""" # Initiate cinfdata and bind properties self.cinfdata = Cinfdata(self, username, password) # FIXME, check password somehow and think about how to come # back to _after_init # Add a reference to cinfdata to page selection self.ids.page_selection.cinfdata = self.cinfdata self.ids.main_image.cinfdata = self.cinfdata def on_index(self, *args): """Update image when switcing into the middle carousel part on_index is called the caroudel is turned into a new position """ super(MainCarousel, self).on_index(*args) Logger.debug('MainCarousel: index: {}'.format(args[1])) if args[1] == 1: # First time on_index is called, there is no cinfdata object yet if not hasattr(self, 'cinfdata'): print("no cindata yet") return # Also we switch back to if self.cinfdata.selected_plot is None: return self.ids.main_image.update_image(self.waiting_png) Clock.schedule_once(self._get_image_and_update) def _get_image_and_update(self, _): """Get image from cinfdata and update main image""" data = self.cinfdata.get_plot() self.ids.main_image.update_image(data) def change_plot(self, setup_and_link): """Change the plot settings widget when a new plot is selected""" #Logger.debug("Change plot %s", setup_and_link[0]) #Logger.debug("Change plot %s", setup_and_link[1]) _, link = setup_and_link if link['pagetype'] == 'dateplot': self.ids.plot_settings.clear_widgets() dateplot_options = DatePlotOptions(setup_and_link) dateplot_options.cinfdata = self.cinfdata self.ids.plot_settings.add_widget(dateplot_options) else: message = 'Support for the \'{}\' plot type is not yet implemented'\ .format(link['pagetype']) raise NotImplementedError(message)