From 8f198ddb55ec724f4f120721b9b6d36e3150c505 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 10 Dec 2020 10:20:52 +0100 Subject: [PATCH] Clockify module converted to new module --- pype/modules/__init__.py | 2 + pype/modules/clockify/__init__.py | 8 ++- pype/modules/clockify/clockify.py | 89 ++++++++++++++----------------- 3 files changed, 45 insertions(+), 54 deletions(-) diff --git a/pype/modules/__init__.py b/pype/modules/__init__.py index aacd541e18..4f6b5f44c8 100644 --- a/pype/modules/__init__.py +++ b/pype/modules/__init__.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- from .base import PypeModule +from .clockify import ClockifyModule __all__ = ( "PypeModule", + "ClockifyModule", ) diff --git a/pype/modules/clockify/__init__.py b/pype/modules/clockify/__init__.py index 8e11d2f5f4..e4ca2611c4 100644 --- a/pype/modules/clockify/__init__.py +++ b/pype/modules/clockify/__init__.py @@ -1,7 +1,5 @@ from .clockify import ClockifyModule -CLASS_DEFINIION = ClockifyModule - - -def tray_init(tray_widget, main_widget): - return ClockifyModule(main_widget, tray_widget) +__all__ = ( + "ClockifyModule", +) diff --git a/pype/modules/clockify/clockify.py b/pype/modules/clockify/clockify.py index 9658e178e4..03f357b793 100644 --- a/pype/modules/clockify/clockify.py +++ b/pype/modules/clockify/clockify.py @@ -2,35 +2,47 @@ import os import threading import time -from pype.api import Logger from .clockify_api import ClockifyAPI -from .constants import CLOCKIFY_FTRACK_USER_PATH +from .constants import ( + CLOCKIFY_FTRACK_USER_PATH, + CLOCKIFY_FTRACK_SERVER_PATH +) +from pype.modules import ( + PypeModule, + ITrayModule, +) -class ClockifyModule: - workspace_name = None +class ClockifyModule( + PypeModule, + ITrayModule, +): + name = "Clockify" - def __init__(self, main_parent=None, parent=None): - if not self.workspace_name: - raise Exception("Clockify Workspace is not set in config.") + def initialize(self, modules_settings): + clockify_settings = modules_settings[self.name] + self.enabled = clockify_settings["enabled"] + self.workspace_name = clockify_settings["workspace_name"] - os.environ["CLOCKIFY_WORKSPACE"] = self.workspace_name + if self.enabled and not self.workspace_name: + raise Exception("Clockify Workspace is not set in settings.") self.timer_manager = None self.MessageWidgetClass = None + self.message_widget = None self.clockapi = ClockifyAPI(master_parent=self) - self.log = Logger().get_logger(self.__class__.__name__, "PypeTray") - self.tray_init(main_parent, parent) + def get_global_environments(self): + return { + "CLOCKIFY_WORKSPACE": self.workspace_name + } - def tray_init(self, main_parent, parent): + def tray_init(self, tray_widget, main_window): from .widgets import ClockifySettings, MessageWidget self.MessageWidgetClass = MessageWidget - self.main_parent = main_parent - self.parent = parent self.message_widget = None self.widget_settings = ClockifySettings(self.clockapi) self.widget_settings_required = None @@ -56,43 +68,25 @@ class ClockifyModule: self.set_menu_visibility() - def process_modules(self, modules): - if 'FtrackModule' in modules: - current = os.environ.get('FTRACK_ACTIONS_PATH', '') - if current: - current += os.pathsep - os.environ['FTRACK_ACTIONS_PATH'] = ( - current + CLOCKIFY_FTRACK_USER_PATH - ) + def tray_exit(self, *_a, **_kw): + return - if 'AvalonApps' in modules: - actions_path = os.path.join( - os.path.dirname(__file__), - 'launcher_actions' - ) - current = os.environ.get('AVALON_ACTIONS', '') - if current: - current += os.pathsep - os.environ['AVALON_ACTIONS'] = current + actions_path + def get_plugin_paths(self): + """Implementaton of IPluginPaths to get plugin paths.""" + actions_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "launcher_actions" + ) + return { + "actions": [actions_path] + } - if 'TimersManager' in modules: - self.timer_manager = modules['TimersManager'] - self.timer_manager.add_module(self) - def start_timer_manager(self, data): - self.start_timer(data) + def connect_with_modules(self, *_a, **_kw): + return - def stop_timer_manager(self): - self.stop_timer() - - def timer_started(self, data): - if self.timer_manager: - self.timer_manager.start_timers(data) - - def timer_stopped(self): + def clockify_timer_stopped(self): self.bool_timer_run = False - if self.timer_manager: - self.timer_manager.stop_timers() def start_timer_check(self): self.bool_thread_check_running = True @@ -110,7 +104,6 @@ class ClockifyModule: self.thread_timer_check = None def check_running(self): - while self.bool_thread_check_running is True: bool_timer_run = False if self.clockapi.get_in_progress() is not None: @@ -118,7 +111,7 @@ class ClockifyModule: if self.bool_timer_run != bool_timer_run: if self.bool_timer_run is True: - self.timer_stopped() + self.clockify_timer_stopped() elif self.bool_timer_run is False: actual_timer = self.clockapi.get_in_progress() if not actual_timer: @@ -160,8 +153,6 @@ class ClockifyModule: def stop_timer(self): self.clockapi.finish_time_entry() - if self.bool_timer_run: - self.timer_stopped() def signed_in(self): if not self.timer_manager: