mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
Merge pull request #321 from pypeclub/feature/module_attributes_in_tray_menu
Feature/module attributes in tray menu
This commit is contained in:
commit
51bb034fb7
6 changed files with 69 additions and 39 deletions
|
|
@ -2,6 +2,8 @@ from .rest_api import RestApiServer
|
||||||
from .base_class import RestApi, abort, route, register_statics
|
from .base_class import RestApi, abort, route, register_statics
|
||||||
from .lib import RestMethods, CallbackResult
|
from .lib import RestMethods, CallbackResult
|
||||||
|
|
||||||
|
CLASS_DEFINIION = RestApiServer
|
||||||
|
|
||||||
|
|
||||||
def tray_init(tray_widget, main_widget):
|
def tray_init(tray_widget, main_widget):
|
||||||
return RestApiServer()
|
return RestApiServer()
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ from socketserver import ThreadingMixIn
|
||||||
from http.server import HTTPServer
|
from http.server import HTTPServer
|
||||||
from .lib import RestApiFactory, Handler
|
from .lib import RestApiFactory, Handler
|
||||||
from .base_class import route, register_statics
|
from .base_class import route, register_statics
|
||||||
from pype.api import config, Logger
|
from pype.api import Logger
|
||||||
|
|
||||||
log = Logger().get_logger("RestApiServer")
|
log = Logger().get_logger("RestApiServer")
|
||||||
|
|
||||||
|
|
@ -85,20 +85,14 @@ class RestApiServer:
|
||||||
Callback may return many types. For more information read docstring of
|
Callback may return many types. For more information read docstring of
|
||||||
`_handle_callback_result` defined in handler.
|
`_handle_callback_result` defined in handler.
|
||||||
"""
|
"""
|
||||||
|
default_port = 8011
|
||||||
|
exclude_ports = []
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.qaction = None
|
self.qaction = None
|
||||||
self.failed_icon = None
|
self.failed_icon = None
|
||||||
self._is_running = False
|
self._is_running = False
|
||||||
|
|
||||||
try:
|
|
||||||
self.presets = config.get_presets()["services"]["rest_api"]
|
|
||||||
except Exception:
|
|
||||||
self.presets = {"default_port": 8011, "exclude_ports": []}
|
|
||||||
log.debug((
|
|
||||||
"There are not set presets for RestApiModule."
|
|
||||||
" Using defaults \"{}\""
|
|
||||||
).format(str(self.presets)))
|
|
||||||
|
|
||||||
port = self.find_port()
|
port = self.find_port()
|
||||||
self.rest_api_thread = RestApiThread(self, port)
|
self.rest_api_thread = RestApiThread(self, port)
|
||||||
|
|
||||||
|
|
@ -130,8 +124,8 @@ class RestApiServer:
|
||||||
RestApiFactory.register_obj(obj)
|
RestApiFactory.register_obj(obj)
|
||||||
|
|
||||||
def find_port(self):
|
def find_port(self):
|
||||||
start_port = self.presets["default_port"]
|
start_port = self.default_port
|
||||||
exclude_ports = self.presets["exclude_ports"]
|
exclude_ports = self.exclude_ports
|
||||||
found_port = None
|
found_port = None
|
||||||
# port check takes time so it's lowered to 100 ports
|
# port check takes time so it's lowered to 100 ports
|
||||||
for port in range(start_port, start_port+100):
|
for port in range(start_port, start_port+100):
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
from .timers_manager import TimersManager
|
from .timers_manager import TimersManager
|
||||||
from .widget_user_idle import WidgetUserIdle
|
from .widget_user_idle import WidgetUserIdle
|
||||||
|
|
||||||
|
CLASS_DEFINIION = TimersManager
|
||||||
|
|
||||||
|
|
||||||
def tray_init(tray_widget, main_widget):
|
def tray_init(tray_widget, main_widget):
|
||||||
return TimersManager(tray_widget, main_widget)
|
return TimersManager(tray_widget, main_widget)
|
||||||
|
|
|
||||||
|
|
@ -23,32 +23,33 @@ class TimersManager(metaclass=Singleton):
|
||||||
If IdleManager is imported then is able to handle about stop timers
|
If IdleManager is imported then is able to handle about stop timers
|
||||||
when user idles for a long time (set in presets).
|
when user idles for a long time (set in presets).
|
||||||
"""
|
"""
|
||||||
modules = []
|
|
||||||
is_running = False
|
# Presetable attributes
|
||||||
last_task = None
|
# - when timer will stop if idle manager is running (minutes)
|
||||||
|
full_time = 15
|
||||||
|
# - how many minutes before the timer is stopped will popup the message
|
||||||
|
message_time = 0.5
|
||||||
|
|
||||||
def __init__(self, tray_widget, main_widget):
|
def __init__(self, tray_widget, main_widget):
|
||||||
self.log = Logger().get_logger(self.__class__.__name__)
|
self.log = Logger().get_logger(self.__class__.__name__)
|
||||||
|
|
||||||
|
self.modules = []
|
||||||
|
self.is_running = False
|
||||||
|
self.last_task = None
|
||||||
|
|
||||||
self.tray_widget = tray_widget
|
self.tray_widget = tray_widget
|
||||||
self.main_widget = main_widget
|
self.main_widget = main_widget
|
||||||
self.widget_user_idle = WidgetUserIdle(self)
|
self.widget_user_idle = WidgetUserIdle(self)
|
||||||
|
|
||||||
def set_signal_times(self):
|
def set_signal_times(self):
|
||||||
try:
|
try:
|
||||||
timer_info = (
|
full_time = int(self.full_time * 60)
|
||||||
config.get_presets()
|
message_time = int(self.message_time * 60)
|
||||||
.get('services')
|
|
||||||
.get('timers_manager')
|
|
||||||
.get('timer')
|
|
||||||
)
|
|
||||||
full_time = int(float(timer_info['full_time'])*60)
|
|
||||||
message_time = int(float(timer_info['message_time'])*60)
|
|
||||||
self.time_show_message = full_time - message_time
|
self.time_show_message = full_time - message_time
|
||||||
self.time_stop_timer = full_time
|
self.time_stop_timer = full_time
|
||||||
return True
|
return True
|
||||||
except Exception:
|
except Exception:
|
||||||
self.log.warning('Was not able to load presets for TimersManager')
|
self.log.error("Couldn't set timer signals.", exc_info=True)
|
||||||
return False
|
|
||||||
|
|
||||||
def add_module(self, module):
|
def add_module(self, module):
|
||||||
""" Adds module to context
|
""" Adds module to context
|
||||||
|
|
@ -180,6 +181,7 @@ class SignalHandler(QtCore.QObject):
|
||||||
signal_show_message = QtCore.Signal()
|
signal_show_message = QtCore.Signal()
|
||||||
signal_change_label = QtCore.Signal()
|
signal_change_label = QtCore.Signal()
|
||||||
signal_stop_timers = QtCore.Signal()
|
signal_stop_timers = QtCore.Signal()
|
||||||
|
|
||||||
def __init__(self, cls):
|
def __init__(self, cls):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.signal_show_message.connect(cls.show_message)
|
self.signal_show_message.connect(cls.show_message)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
from pype.api import Logger
|
|
||||||
from avalon import style
|
from avalon import style
|
||||||
from Qt import QtCore, QtGui, QtWidgets
|
from Qt import QtCore, QtGui, QtWidgets
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,22 +56,35 @@ class TrayManager:
|
||||||
In this case `Statics Server` won't be used.
|
In this case `Statics Server` won't be used.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Backwards compatible presets loading
|
||||||
|
if isinstance(self.items, list):
|
||||||
|
items = self.items
|
||||||
|
else:
|
||||||
items = []
|
items = []
|
||||||
# Get booleans is module should be used
|
# Get booleans is module should be used
|
||||||
for item in self.modules_imports:
|
usages = self.items.get("item_usage") or {}
|
||||||
|
attributes = self.items.get("attributes") or {}
|
||||||
|
for item in self.items.get("item_import", []):
|
||||||
import_path = item.get("import_path")
|
import_path = item.get("import_path")
|
||||||
title = item.get("title")
|
title = item.get("title")
|
||||||
|
|
||||||
item_usage = self.modules_usage.get(title)
|
item_usage = usages.get(title)
|
||||||
if item_usage is None:
|
if item_usage is None:
|
||||||
item_usage = self.modules_usage.get(import_path, True)
|
item_usage = usages.get(import_path, True)
|
||||||
|
|
||||||
if item_usage:
|
if not item_usage:
|
||||||
items.append(item)
|
|
||||||
else:
|
|
||||||
if not title:
|
if not title:
|
||||||
title = import_path
|
title = import_path
|
||||||
self.log.info("{} - Module ignored".format(title))
|
self.log.debug("{} - Module ignored".format(title))
|
||||||
|
continue
|
||||||
|
|
||||||
|
_attributes = attributes.get(title)
|
||||||
|
if _attributes is None:
|
||||||
|
_attributes = attributes.get(import_path)
|
||||||
|
|
||||||
|
if _attributes:
|
||||||
|
item["attributes"] = _attributes
|
||||||
|
items.append(item)
|
||||||
|
|
||||||
if items:
|
if items:
|
||||||
self.process_items(items, self.tray_widget.menu)
|
self.process_items(items, self.tray_widget.menu)
|
||||||
|
|
@ -148,11 +161,29 @@ class TrayManager:
|
||||||
import_path = item.get('import_path', None)
|
import_path = item.get('import_path', None)
|
||||||
title = item.get('title', import_path)
|
title = item.get('title', import_path)
|
||||||
fromlist = item.get('fromlist', [])
|
fromlist = item.get('fromlist', [])
|
||||||
|
attributes = item.get("attributes", {})
|
||||||
try:
|
try:
|
||||||
module = __import__(
|
module = __import__(
|
||||||
"{}".format(import_path),
|
"{}".format(import_path),
|
||||||
fromlist=fromlist
|
fromlist=fromlist
|
||||||
)
|
)
|
||||||
|
klass = getattr(module, "CLASS_DEFINIION", None)
|
||||||
|
if not klass and attributes:
|
||||||
|
self.log.error((
|
||||||
|
"There are defined attributes for module \"{}\" but"
|
||||||
|
"module does not have defined \"CLASS_DEFINIION\"."
|
||||||
|
).format(import_path))
|
||||||
|
|
||||||
|
elif klass and attributes:
|
||||||
|
for key, value in attributes.items():
|
||||||
|
if hasattr(klass, key):
|
||||||
|
setattr(klass, key, value)
|
||||||
|
else:
|
||||||
|
self.log.error((
|
||||||
|
"Module \"{}\" does not have attribute \"{}\"."
|
||||||
|
" Check your settings please."
|
||||||
|
).format(import_path, key))
|
||||||
|
|
||||||
obj = module.tray_init(self.tray_widget, self.main_window)
|
obj = module.tray_init(self.tray_widget, self.main_window)
|
||||||
name = obj.__class__.__name__
|
name = obj.__class__.__name__
|
||||||
if hasattr(obj, 'tray_menu'):
|
if hasattr(obj, 'tray_menu'):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue