From babac7ae2ea4c26d7f494f21aebcb0b9b396cfd6 Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Wed, 1 Apr 2015 12:01:29 -0400 Subject: [PATCH] File update interval switched to NumericProperty; changed do_update on PlotWidget to run a scheduled clock interval, default to every 5 seconds --- main.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index c35558a..7319717 100644 --- a/main.py +++ b/main.py @@ -376,6 +376,9 @@ class PlotWidget(Image): show_protease = BooleanProperty(True) show_betaamylase = BooleanProperty(True) show_alphaamylase = BooleanProperty(True) + file_write_interval = NumericProperty(15) + image_update_interval = NumericProperty(5) + # Common data that we should only instantiate once # Source : http://www.howtobrew.com/section3/chapter14-1.html @@ -402,9 +405,16 @@ class PlotWidget(Image): self.image_data = None self._image_raw_data = None self.reference_profile = None + Clock.schedule_interval(self.do_update, self.image_update_interval) self.do_update() + def on_image_update_interval(self, *args): + # Reschedule the update function. + Clock.unschedule(self.do_update, True) + Clock.schedule_interval(self.do_update, self.image_update_interval) + + def update_patches(self, tmax = None): items = [ (self.show_betaglucan, self.betaglucan_vertices), @@ -444,7 +454,7 @@ class PlotWidget(Image): self.do_update() - def do_update(self): + def do_update(self, *args): image_data = self.to_image_data() # We can't use ImageLoaders since they assume it's a file on disk. # This replicates code from ImageLoaderPygame.load() and ImageLoaderBase.populate() @@ -466,6 +476,7 @@ class PlotWidget(Image): # @TODO Add in an update interval so the disk isn't hammered on every single update self.update_output_files() + def to_image_data(self): # Add in polygons for hilightning particular temperature ranges of interest. plot_args = [] @@ -515,7 +526,7 @@ class PlotWidget(Image): def update_output_files(self, force = False): # Do this only once every 15 seconds to avoid hitting the disk frequently Logger.debug('update_output_files called') - if force or time.time() - self.lastSave > 15: + if force or time.time() - self.lastSave > self.file_write_interval: Logger.debug('update_output_files going ahead') self.update_raw_data_output_file() self.update_image_output_file() @@ -559,13 +570,12 @@ class PlotWidget(Image): #Logger.debug('self.data: ' + str(self.data)) #Logger.debug('newpoint: ' + str(newpoint)) self.data = numpy.vstack((self.data, newpoint)) - self.do_update() def on_reference_profile_file(self, *args, **kwargs): Logger.debug('PlotWidget: on_reference_profile_file ' + str(self.reference_profile_file)) self.load_reference_profile() - self.do_update() + Clock.schedule_once(self.do_update) def load_reference_profile(self):