From 8ec9368988575347ff439f190872a999cd8e71b1 Mon Sep 17 00:00:00 2001 From: jtc42 Date: Fri, 1 Nov 2019 16:11:07 +0000 Subject: [PATCH] Added update_task_progress example --- .../plugins/testing/form_example/plugin.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/openflexure_microscope/plugins/testing/form_example/plugin.py b/openflexure_microscope/plugins/testing/form_example/plugin.py index 8781e6ad..870f45c3 100644 --- a/openflexure_microscope/plugins/testing/form_example/plugin.py +++ b/openflexure_microscope/plugins/testing/form_example/plugin.py @@ -2,7 +2,7 @@ import random import time import os import json -from openflexure_microscope.devel import MicroscopePlugin +from openflexure_microscope.devel import MicroscopePlugin, update_task_progress from .api import DoAPI, TaskAPI @@ -66,8 +66,13 @@ class ExamplePlugin(MicroscopePlugin): def generate_random_numbers_for_a_while(self, run_time: int): self.run_time = run_time vals = [] - for _ in range(run_time): + + for t in range(run_time): vals.append(random.random()) time.sleep(1) + # Update task progress (if running as a task) + percent_complete = int(((t + 1)/run_time)*100) + update_task_progress(percent_complete) + return vals