mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
Merge pull request #568 from pypeclub/feature/easier_modules_without_qt_in_globals
Modules (few) without qt in globals
This commit is contained in:
commit
5cfedc9124
11 changed files with 87 additions and 81 deletions
|
|
@ -1,9 +1,8 @@
|
||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
|
import time
|
||||||
|
|
||||||
from pype.api import Logger
|
from pype.api import Logger
|
||||||
from avalon import style
|
|
||||||
from Qt import QtWidgets
|
|
||||||
from .widgets import ClockifySettings, MessageWidget
|
|
||||||
from .clockify_api import ClockifyAPI
|
from .clockify_api import ClockifyAPI
|
||||||
from .constants import CLOCKIFY_FTRACK_USER_PATH
|
from .constants import CLOCKIFY_FTRACK_USER_PATH
|
||||||
|
|
||||||
|
|
@ -17,11 +16,21 @@ class ClockifyModule:
|
||||||
|
|
||||||
os.environ["CLOCKIFY_WORKSPACE"] = self.workspace_name
|
os.environ["CLOCKIFY_WORKSPACE"] = self.workspace_name
|
||||||
|
|
||||||
|
self.timer_manager = None
|
||||||
|
self.MessageWidgetClass = None
|
||||||
|
|
||||||
|
self.clockapi = ClockifyAPI(master_parent=self)
|
||||||
|
|
||||||
self.log = Logger().get_logger(self.__class__.__name__, "PypeTray")
|
self.log = Logger().get_logger(self.__class__.__name__, "PypeTray")
|
||||||
|
self.tray_init(main_parent, parent)
|
||||||
|
|
||||||
|
def tray_init(self, main_parent, parent):
|
||||||
|
from .widgets import ClockifySettings, MessageWidget
|
||||||
|
|
||||||
|
self.MessageWidgetClass = MessageWidget
|
||||||
|
|
||||||
self.main_parent = main_parent
|
self.main_parent = main_parent
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.clockapi = ClockifyAPI(master_parent=self)
|
|
||||||
self.message_widget = None
|
self.message_widget = None
|
||||||
self.widget_settings = ClockifySettings(main_parent, self)
|
self.widget_settings = ClockifySettings(main_parent, self)
|
||||||
self.widget_settings_required = None
|
self.widget_settings_required = None
|
||||||
|
|
@ -57,11 +66,10 @@ class ClockifyModule:
|
||||||
)
|
)
|
||||||
|
|
||||||
if 'AvalonApps' in modules:
|
if 'AvalonApps' in modules:
|
||||||
from launcher import lib
|
actions_path = os.path.join(
|
||||||
actions_path = os.path.sep.join([
|
|
||||||
os.path.dirname(__file__),
|
os.path.dirname(__file__),
|
||||||
'launcher_actions'
|
'launcher_actions'
|
||||||
])
|
)
|
||||||
current = os.environ.get('AVALON_ACTIONS', '')
|
current = os.environ.get('AVALON_ACTIONS', '')
|
||||||
if current:
|
if current:
|
||||||
current += os.pathsep
|
current += os.pathsep
|
||||||
|
|
@ -78,12 +86,12 @@ class ClockifyModule:
|
||||||
self.stop_timer()
|
self.stop_timer()
|
||||||
|
|
||||||
def timer_started(self, data):
|
def timer_started(self, data):
|
||||||
if hasattr(self, 'timer_manager'):
|
if self.timer_manager:
|
||||||
self.timer_manager.start_timers(data)
|
self.timer_manager.start_timers(data)
|
||||||
|
|
||||||
def timer_stopped(self):
|
def timer_stopped(self):
|
||||||
self.bool_timer_run = False
|
self.bool_timer_run = False
|
||||||
if hasattr(self, 'timer_manager'):
|
if self.timer_manager:
|
||||||
self.timer_manager.stop_timers()
|
self.timer_manager.stop_timers()
|
||||||
|
|
||||||
def start_timer_check(self):
|
def start_timer_check(self):
|
||||||
|
|
@ -102,7 +110,7 @@ class ClockifyModule:
|
||||||
self.thread_timer_check = None
|
self.thread_timer_check = None
|
||||||
|
|
||||||
def check_running(self):
|
def check_running(self):
|
||||||
import time
|
|
||||||
while self.bool_thread_check_running is True:
|
while self.bool_thread_check_running is True:
|
||||||
bool_timer_run = False
|
bool_timer_run = False
|
||||||
if self.clockapi.get_in_progress() is not None:
|
if self.clockapi.get_in_progress() is not None:
|
||||||
|
|
@ -156,15 +164,14 @@ class ClockifyModule:
|
||||||
self.timer_stopped()
|
self.timer_stopped()
|
||||||
|
|
||||||
def signed_in(self):
|
def signed_in(self):
|
||||||
if hasattr(self, 'timer_manager'):
|
if not self.timer_manager:
|
||||||
if not self.timer_manager:
|
return
|
||||||
return
|
|
||||||
|
|
||||||
if not self.timer_manager.last_task:
|
if not self.timer_manager.last_task:
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.timer_manager.is_running:
|
if self.timer_manager.is_running:
|
||||||
self.start_timer_manager(self.timer_manager.last_task)
|
self.start_timer_manager(self.timer_manager.last_task)
|
||||||
|
|
||||||
def start_timer(self, input_data):
|
def start_timer(self, input_data):
|
||||||
# If not api key is not entered then skip
|
# If not api key is not entered then skip
|
||||||
|
|
@ -197,11 +204,14 @@ class ClockifyModule:
|
||||||
"<br><br>Please inform your Project Manager."
|
"<br><br>Please inform your Project Manager."
|
||||||
).format(project_name, str(self.clockapi.workspace_name))
|
).format(project_name, str(self.clockapi.workspace_name))
|
||||||
|
|
||||||
self.message_widget = MessageWidget(
|
if self.MessageWidgetClass:
|
||||||
self.main_parent, msg, "Clockify - Info Message"
|
self.message_widget = self.MessageWidgetClass(
|
||||||
)
|
self.main_parent, msg, "Clockify - Info Message"
|
||||||
self.message_widget.closed.connect(self.on_message_widget_close)
|
)
|
||||||
self.message_widget.show()
|
self.message_widget.closed.connect(
|
||||||
|
self.on_message_widget_close
|
||||||
|
)
|
||||||
|
self.message_widget.show()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -227,31 +237,29 @@ class ClockifyModule:
|
||||||
# Definition of Tray menu
|
# Definition of Tray menu
|
||||||
def tray_menu(self, parent_menu):
|
def tray_menu(self, parent_menu):
|
||||||
# Menu for Tray App
|
# Menu for Tray App
|
||||||
self.menu = QtWidgets.QMenu('Clockify', parent_menu)
|
from Qt import QtWidgets
|
||||||
self.menu.setProperty('submenu', 'on')
|
menu = QtWidgets.QMenu("Clockify", parent_menu)
|
||||||
self.menu.setStyleSheet(style.load_stylesheet())
|
menu.setProperty("submenu", "on")
|
||||||
|
|
||||||
# Actions
|
# Actions
|
||||||
self.aShowSettings = QtWidgets.QAction(
|
action_show_settings = QtWidgets.QAction("Settings", menu)
|
||||||
"Settings", self.menu
|
action_stop_timer = QtWidgets.QAction("Stop timer", menu)
|
||||||
)
|
|
||||||
self.aStopTimer = QtWidgets.QAction(
|
|
||||||
"Stop timer", self.menu
|
|
||||||
)
|
|
||||||
|
|
||||||
self.menu.addAction(self.aShowSettings)
|
menu.addAction(action_show_settings)
|
||||||
self.menu.addAction(self.aStopTimer)
|
menu.addAction(action_stop_timer)
|
||||||
|
|
||||||
self.aShowSettings.triggered.connect(self.show_settings)
|
action_show_settings.triggered.connect(self.show_settings)
|
||||||
self.aStopTimer.triggered.connect(self.stop_timer)
|
action_stop_timer.triggered.connect(self.stop_timer)
|
||||||
|
|
||||||
|
self.action_stop_timer = action_stop_timer
|
||||||
|
|
||||||
self.set_menu_visibility()
|
self.set_menu_visibility()
|
||||||
|
|
||||||
parent_menu.addMenu(self.menu)
|
parent_menu.addMenu(menu)
|
||||||
|
|
||||||
def show_settings(self):
|
def show_settings(self):
|
||||||
self.widget_settings.input_api_key.setText(self.clockapi.get_api_key())
|
self.widget_settings.input_api_key.setText(self.clockapi.get_api_key())
|
||||||
self.widget_settings.show()
|
self.widget_settings.show()
|
||||||
|
|
||||||
def set_menu_visibility(self):
|
def set_menu_visibility(self):
|
||||||
self.aStopTimer.setVisible(self.bool_timer_run)
|
self.action_stop_timer.setVisible(self.bool_timer_run)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
from Qt import QtWidgets
|
|
||||||
from pype.api import Logger
|
from pype.api import Logger
|
||||||
from ..gui.app import LogsWindow
|
|
||||||
|
|
||||||
|
|
||||||
class LoggingModule:
|
class LoggingModule:
|
||||||
|
|
@ -8,7 +6,13 @@ class LoggingModule:
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.log = Logger().get_logger(self.__class__.__name__, "logging")
|
self.log = Logger().get_logger(self.__class__.__name__, "logging")
|
||||||
|
|
||||||
|
self.window = None
|
||||||
|
|
||||||
|
self.tray_init(main_parent, parent)
|
||||||
|
|
||||||
|
def tray_init(self, main_parent, parent):
|
||||||
try:
|
try:
|
||||||
|
from .gui.app import LogsWindow
|
||||||
self.window = LogsWindow()
|
self.window = LogsWindow()
|
||||||
self.tray_menu = self._tray_menu
|
self.tray_menu = self._tray_menu
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
@ -18,12 +22,12 @@ class LoggingModule:
|
||||||
|
|
||||||
# Definition of Tray menu
|
# Definition of Tray menu
|
||||||
def _tray_menu(self, parent_menu):
|
def _tray_menu(self, parent_menu):
|
||||||
|
from Qt import QtWidgets
|
||||||
# Menu for Tray App
|
# Menu for Tray App
|
||||||
menu = QtWidgets.QMenu('Logging', parent_menu)
|
menu = QtWidgets.QMenu('Logging', parent_menu)
|
||||||
# menu.setProperty('submenu', 'on')
|
|
||||||
|
|
||||||
show_action = QtWidgets.QAction("Show Logs", menu)
|
show_action = QtWidgets.QAction("Show Logs", menu)
|
||||||
show_action.triggered.connect(self.on_show_logs)
|
show_action.triggered.connect(self._show_logs_gui)
|
||||||
menu.addAction(show_action)
|
menu.addAction(show_action)
|
||||||
|
|
||||||
parent_menu.addMenu(menu)
|
parent_menu.addMenu(menu)
|
||||||
|
|
@ -34,5 +38,6 @@ class LoggingModule:
|
||||||
def process_modules(self, modules):
|
def process_modules(self, modules):
|
||||||
return
|
return
|
||||||
|
|
||||||
def on_show_logs(self):
|
def _show_logs_gui(self):
|
||||||
self.window.show()
|
if self.window:
|
||||||
|
self.window.show()
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,7 @@
|
||||||
import appdirs
|
|
||||||
from avalon import style
|
|
||||||
from Qt import QtWidgets
|
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
from .widget_login import MusterLogin
|
import appdirs
|
||||||
from avalon.vendor import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
class MusterModule:
|
class MusterModule:
|
||||||
|
|
@ -21,6 +18,11 @@ class MusterModule:
|
||||||
self.cred_path = os.path.join(
|
self.cred_path = os.path.join(
|
||||||
self.cred_folder_path, self.cred_filename
|
self.cred_folder_path, self.cred_filename
|
||||||
)
|
)
|
||||||
|
self.tray_init(main_parent, parent)
|
||||||
|
|
||||||
|
def tray_init(self, main_parent, parent):
|
||||||
|
from .widget_login import MusterLogin
|
||||||
|
|
||||||
self.main_parent = main_parent
|
self.main_parent = main_parent
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.widget_login = MusterLogin(main_parent, self)
|
self.widget_login = MusterLogin(main_parent, self)
|
||||||
|
|
@ -38,10 +40,6 @@ class MusterModule:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def process_modules(self, modules):
|
def process_modules(self, modules):
|
||||||
|
|
||||||
def api_callback():
|
|
||||||
self.aShowLogin.trigger()
|
|
||||||
|
|
||||||
if "RestApiServer" in modules:
|
if "RestApiServer" in modules:
|
||||||
def api_show_login():
|
def api_show_login():
|
||||||
self.aShowLogin.trigger()
|
self.aShowLogin.trigger()
|
||||||
|
|
@ -51,13 +49,12 @@ class MusterModule:
|
||||||
|
|
||||||
# Definition of Tray menu
|
# Definition of Tray menu
|
||||||
def tray_menu(self, parent):
|
def tray_menu(self, parent):
|
||||||
"""
|
"""Add **change credentials** option to tray menu."""
|
||||||
Add **change credentials** option to tray menu.
|
from Qt import QtWidgets
|
||||||
"""
|
|
||||||
# Menu for Tray App
|
# Menu for Tray App
|
||||||
self.menu = QtWidgets.QMenu('Muster', parent)
|
self.menu = QtWidgets.QMenu('Muster', parent)
|
||||||
self.menu.setProperty('submenu', 'on')
|
self.menu.setProperty('submenu', 'on')
|
||||||
self.menu.setStyleSheet(style.load_stylesheet())
|
|
||||||
|
|
||||||
# Actions
|
# Actions
|
||||||
self.aShowLogin = QtWidgets.QAction(
|
self.aShowLogin = QtWidgets.QAction(
|
||||||
|
|
@ -91,9 +88,9 @@ class MusterModule:
|
||||||
if not MUSTER_REST_URL:
|
if not MUSTER_REST_URL:
|
||||||
raise AttributeError("Muster REST API url not set")
|
raise AttributeError("Muster REST API url not set")
|
||||||
params = {
|
params = {
|
||||||
'username': username,
|
'username': username,
|
||||||
'password': password
|
'password': password
|
||||||
}
|
}
|
||||||
api_entry = '/api/login'
|
api_entry = '/api/login'
|
||||||
response = self._requests_post(
|
response = self._requests_post(
|
||||||
MUSTER_REST_URL + api_entry, params=params)
|
MUSTER_REST_URL + api_entry, params=params)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import pype
|
import pype
|
||||||
from pype import tools
|
|
||||||
|
|
||||||
|
|
||||||
class StandAlonePublishModule:
|
class StandAlonePublishModule:
|
||||||
|
|
@ -30,6 +29,7 @@ class StandAlonePublishModule:
|
||||||
))
|
))
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
|
from pype import tools
|
||||||
standalone_publisher_tool_path = os.path.join(
|
standalone_publisher_tool_path = os.path.join(
|
||||||
os.path.dirname(tools.__file__),
|
os.path.dirname(tools.__file__),
|
||||||
"standalonepublish"
|
"standalonepublish"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
from .timers_manager import TimersManager
|
from .timers_manager import TimersManager
|
||||||
from .widget_user_idle import WidgetUserIdle
|
|
||||||
|
|
||||||
CLASS_DEFINIION = TimersManager
|
CLASS_DEFINIION = TimersManager
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,7 @@
|
||||||
from .widget_user_idle import WidgetUserIdle, SignalHandler
|
from pype.api import Logger
|
||||||
from pype.api import Logger, config
|
|
||||||
|
|
||||||
|
|
||||||
class Singleton(type):
|
class TimersManager:
|
||||||
""" Signleton implementation
|
|
||||||
"""
|
|
||||||
_instances = {}
|
|
||||||
|
|
||||||
def __call__(cls, *args, **kwargs):
|
|
||||||
if cls not in cls._instances:
|
|
||||||
cls._instances[cls] = super(
|
|
||||||
Singleton, cls
|
|
||||||
).__call__(*args, **kwargs)
|
|
||||||
return cls._instances[cls]
|
|
||||||
|
|
||||||
|
|
||||||
class TimersManager(metaclass=Singleton):
|
|
||||||
""" Handles about Timers.
|
""" Handles about Timers.
|
||||||
|
|
||||||
Should be able to start/stop all timers at once.
|
Should be able to start/stop all timers at once.
|
||||||
|
|
@ -41,7 +27,13 @@ class TimersManager(metaclass=Singleton):
|
||||||
|
|
||||||
self.idle_man = None
|
self.idle_man = None
|
||||||
self.signal_handler = None
|
self.signal_handler = None
|
||||||
|
|
||||||
|
self.trat_init(tray_widget, main_widget)
|
||||||
|
|
||||||
|
def trat_init(self, tray_widget, main_widget):
|
||||||
|
from .widget_user_idle import WidgetUserIdle, SignalHandler
|
||||||
self.widget_user_idle = WidgetUserIdle(self, tray_widget)
|
self.widget_user_idle = WidgetUserIdle(self, tray_widget)
|
||||||
|
self.signal_handler = SignalHandler(self)
|
||||||
|
|
||||||
def set_signal_times(self):
|
def set_signal_times(self):
|
||||||
try:
|
try:
|
||||||
|
|
@ -119,7 +111,6 @@ class TimersManager(metaclass=Singleton):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if 'IdleManager' in modules:
|
if 'IdleManager' in modules:
|
||||||
self.signal_handler = SignalHandler(self)
|
|
||||||
if self.set_signal_times() is True:
|
if self.set_signal_times() is True:
|
||||||
self.register_to_idle_manager(modules['IdleManager'])
|
self.register_to_idle_manager(modules['IdleManager'])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ import json
|
||||||
import getpass
|
import getpass
|
||||||
|
|
||||||
import appdirs
|
import appdirs
|
||||||
from Qt import QtWidgets
|
|
||||||
from .widget_user import UserWidget
|
|
||||||
|
|
||||||
from pype.api import Logger
|
from pype.api import Logger
|
||||||
|
|
||||||
|
|
@ -24,6 +22,12 @@ class UserModule:
|
||||||
self.cred_path = os.path.normpath(os.path.join(
|
self.cred_path = os.path.normpath(os.path.join(
|
||||||
self.cred_folder_path, self.cred_filename
|
self.cred_folder_path, self.cred_filename
|
||||||
))
|
))
|
||||||
|
self.widget_login = None
|
||||||
|
|
||||||
|
self.tray_init(main_parent, parent)
|
||||||
|
|
||||||
|
def tray_init(self, main_parent=None, parent=None):
|
||||||
|
from .widget_user import UserWidget
|
||||||
self.widget_login = UserWidget(self)
|
self.widget_login = UserWidget(self)
|
||||||
|
|
||||||
self.load_credentials()
|
self.load_credentials()
|
||||||
|
|
@ -66,6 +70,7 @@ class UserModule:
|
||||||
|
|
||||||
# Definition of Tray menu
|
# Definition of Tray menu
|
||||||
def tray_menu(self, parent_menu):
|
def tray_menu(self, parent_menu):
|
||||||
|
from Qt import QtWidgets
|
||||||
"""Add menu or action to Tray(or parent)'s menu"""
|
"""Add menu or action to Tray(or parent)'s menu"""
|
||||||
action = QtWidgets.QAction("Username", parent_menu)
|
action = QtWidgets.QAction("Username", parent_menu)
|
||||||
action.triggered.connect(self.show_widget)
|
action.triggered.connect(self.show_widget)
|
||||||
|
|
@ -121,7 +126,8 @@ class UserModule:
|
||||||
|
|
||||||
self.cred = {"username": username}
|
self.cred = {"username": username}
|
||||||
os.environ[self.env_name] = username
|
os.environ[self.env_name] = username
|
||||||
self.widget_login.set_user(username)
|
if self.widget_login:
|
||||||
|
self.widget_login.set_user(username)
|
||||||
try:
|
try:
|
||||||
file = open(self.cred_path, "w")
|
file = open(self.cred_path, "w")
|
||||||
file.write(json.dumps(self.cred))
|
file.write(json.dumps(self.cred))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue