From 463c574e883712a3b1aa91b90c89ae3096b8d53c Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Wed, 6 Mar 2019 12:53:02 +0100 Subject: [PATCH] added thread that check each 5 seconds if any timer is running --- pype/clockify/clockify.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/pype/clockify/clockify.py b/pype/clockify/clockify.py index 8710bf56eb..1a67eeba92 100644 --- a/pype/clockify/clockify.py +++ b/pype/clockify/clockify.py @@ -1,4 +1,5 @@ import os +import threading from app import style from app.vendor.Qt import QtWidgets from pype.clockify import ClockifySettings, ClockifyAPI @@ -12,7 +13,9 @@ class ClockifyModule: self.clockapi = ClockifyAPI() self.widget_settings = ClockifySettings(main_parent, self) + self.thread_timer_check = None # Bools + self.bool_thread_check_running = False self.bool_api_key_set = False self.bool_workspace_set = False self.bool_timer_run = False @@ -24,17 +27,39 @@ class ClockifyModule: return workspace = os.environ.get('CLOCKIFY_WORKSPACE', None) - print(workspace) self.bool_workspace_set = self.clockapi.set_workspace(workspace) if self.bool_workspace_set is False: # TODO show message to user print("Nope Workspace: clockify.py - line 29") return - if self.clockapi.get_in_progress() is not None: - self.bool_timer_run = True + + self.bool_thread_check_running = True + self.start_timer_check() self.set_menu_visibility() + def change_timer_run(self, bool_run): + self.bool_timer_run = bool_run + self.set_menu_visibility() + + def start_timer_check(self): + if self.thread_timer_check is None: + self.thread_timer_check = threading.Thread( + target=self.check_running + ) + self.thread_timer_check.daemon = True + self.thread_timer_check.start() + + def check_running(self): + import time + while self.bool_thread_check_running is True: + if self.clockapi.get_in_progress() is not None: + self.bool_timer_run = True + else: + self.bool_timer_run = False + self.set_menu_visibility() + time.sleep(5) + def stop_timer(self): self.clockapi.finish_time_entry()