mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
flame hook adding docstrings
This commit is contained in:
parent
97a405b5a1
commit
deada2422e
1 changed files with 68 additions and 9 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import print_function
|
||||||
import sys
|
import sys
|
||||||
from Qt import QtWidgets
|
from Qt import QtWidgets
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
|
|
@ -11,23 +12,32 @@ flh._project = None
|
||||||
|
|
||||||
|
|
||||||
def openpype_install():
|
def openpype_install():
|
||||||
|
"""Registering OpenPype in context
|
||||||
|
"""
|
||||||
openpype.install()
|
openpype.install()
|
||||||
avalon.api.install(opflame)
|
avalon.api.install(opflame)
|
||||||
print("<<<<<<<<<<< Avalon registred hosts: {} >>>>>>>>>>>>>>>".format(
|
print("Avalon registred hosts: {}".format(
|
||||||
avalon.api.registered_host()))
|
avalon.api.registered_host()))
|
||||||
|
|
||||||
|
|
||||||
# Exception handler
|
# Exception handler
|
||||||
def exeption_handler(exctype, value, tb):
|
def exeption_handler(exctype, value, _traceback):
|
||||||
|
"""Exception handler for improving UX
|
||||||
|
|
||||||
|
Args:
|
||||||
|
exctype (str): type of exception
|
||||||
|
value (str): exception value
|
||||||
|
tb (str): traceback to show
|
||||||
|
"""
|
||||||
import traceback
|
import traceback
|
||||||
msg = "OpenPype: Python exception {} in {}".format(value, exctype)
|
msg = "OpenPype: Python exception {} in {}".format(value, exctype)
|
||||||
mbox = QtWidgets.QMessageBox()
|
mbox = QtWidgets.QMessageBox()
|
||||||
mbox.setText(msg)
|
mbox.setText(msg)
|
||||||
mbox.setDetailedText(
|
mbox.setDetailedText(
|
||||||
pformat(traceback.format_exception(exctype, value, tb)))
|
pformat(traceback.format_exception(exctype, value, _traceback)))
|
||||||
mbox.setStyleSheet('QLabel{min-width: 800px;}')
|
mbox.setStyleSheet('QLabel{min-width: 800px;}')
|
||||||
mbox.exec_()
|
mbox.exec_()
|
||||||
sys.__excepthook__(exctype, value, tb)
|
sys.__excepthook__(exctype, value, _traceback)
|
||||||
|
|
||||||
|
|
||||||
# add exception handler into sys module
|
# add exception handler into sys module
|
||||||
|
|
@ -36,12 +46,14 @@ sys.excepthook = exeption_handler
|
||||||
|
|
||||||
# register clean up logic to be called at Flame exit
|
# register clean up logic to be called at Flame exit
|
||||||
def cleanup():
|
def cleanup():
|
||||||
|
"""Cleaning up Flame framework context
|
||||||
|
"""
|
||||||
if opflame.apps:
|
if opflame.apps:
|
||||||
print('<<<< `{}` cleaning up apps:\n {}\n'.format(
|
print('`{}` cleaning up apps:\n {}\n'.format(
|
||||||
__file__, pformat(opflame.apps)))
|
__file__, pformat(opflame.apps)))
|
||||||
while len(opflame.apps):
|
while len(opflame.apps):
|
||||||
app = opflame.apps.pop()
|
app = opflame.apps.pop()
|
||||||
print('<<<< `{}` removing : {}'.format(__file__, app.name))
|
print('`{}` removing : {}'.format(__file__, app.name))
|
||||||
del app
|
del app
|
||||||
opflame.apps = []
|
opflame.apps = []
|
||||||
|
|
||||||
|
|
@ -55,24 +67,44 @@ atexit.register(cleanup)
|
||||||
|
|
||||||
|
|
||||||
def load_apps():
|
def load_apps():
|
||||||
|
"""Load available apps into Flame framework
|
||||||
|
"""
|
||||||
opflame.apps.append(opflame.FlameMenuProjectConnect(opflame.app_framework))
|
opflame.apps.append(opflame.FlameMenuProjectConnect(opflame.app_framework))
|
||||||
opflame.apps.append(opflame.FlameMenuTimeline(opflame.app_framework))
|
opflame.apps.append(opflame.FlameMenuTimeline(opflame.app_framework))
|
||||||
opflame.app_framework.log.info("Apps are loaded")
|
opflame.app_framework.log.info("Apps are loaded")
|
||||||
|
|
||||||
|
|
||||||
def project_changed_dict(info):
|
def project_changed_dict(info):
|
||||||
|
"""Hook for project change action
|
||||||
|
|
||||||
|
Args:
|
||||||
|
info (str): info text
|
||||||
|
"""
|
||||||
cleanup()
|
cleanup()
|
||||||
|
|
||||||
|
|
||||||
def app_initialized(parent=None):
|
def app_initialized(parent=None):
|
||||||
|
"""Inicialization of Framework
|
||||||
|
|
||||||
|
Args:
|
||||||
|
parent (obj, optional): Parent object. Defaults to None.
|
||||||
|
"""
|
||||||
opflame.app_framework = opflame.FlameAppFramework()
|
opflame.app_framework = opflame.FlameAppFramework()
|
||||||
|
|
||||||
print(">> flame_hook.py: {} initializing".format(
|
print("{} initializing".format(
|
||||||
opflame.app_framework.bundle_name))
|
opflame.app_framework.bundle_name))
|
||||||
|
|
||||||
load_apps()
|
load_apps()
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Initialisation of the hook is starting from here
|
||||||
|
|
||||||
|
First it needs to test if it can import the flame modul.
|
||||||
|
This will happen only in case a project has been loaded.
|
||||||
|
Then `app_initialized` will load main Framework which will load
|
||||||
|
all menu objects as apps.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
import flame
|
import flame
|
||||||
app_initialized(parent=None)
|
app_initialized(parent=None)
|
||||||
|
|
@ -85,7 +117,17 @@ def rescan_hooks():
|
||||||
|
|
||||||
|
|
||||||
def _build_app_menu(app_name):
|
def _build_app_menu(app_name):
|
||||||
|
"""Flame menu object generator
|
||||||
|
|
||||||
|
Args:
|
||||||
|
app_name (str): name of menu object app
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: menu object
|
||||||
|
"""
|
||||||
menu = []
|
menu = []
|
||||||
|
|
||||||
|
# first find the relative appname
|
||||||
app = None
|
app = None
|
||||||
for _app in opflame.apps:
|
for _app in opflame.apps:
|
||||||
if _app.__class__.__name__ == app_name:
|
if _app.__class__.__name__ == app_name:
|
||||||
|
|
@ -94,8 +136,6 @@ def _build_app_menu(app_name):
|
||||||
if app:
|
if app:
|
||||||
menu.append(app.build_menu())
|
menu.append(app.build_menu())
|
||||||
|
|
||||||
print(">>_> `{}` was build: {}".format(app_name, pformat(menu)))
|
|
||||||
|
|
||||||
if opflame.app_framework:
|
if opflame.app_framework:
|
||||||
menu_auto_refresh = opflame.app_framework.prefs_global.get(
|
menu_auto_refresh = opflame.app_framework.prefs_global.get(
|
||||||
'menu_auto_refresh', {})
|
'menu_auto_refresh', {})
|
||||||
|
|
@ -109,12 +149,26 @@ def _build_app_menu(app_name):
|
||||||
return menu
|
return menu
|
||||||
|
|
||||||
|
|
||||||
|
""" Flame hooks are starting here
|
||||||
|
"""
|
||||||
def project_saved(project_name, save_time, is_auto_save):
|
def project_saved(project_name, save_time, is_auto_save):
|
||||||
|
"""Hook to activate when project is saved
|
||||||
|
|
||||||
|
Args:
|
||||||
|
project_name (str): name of project
|
||||||
|
save_time (str): time when it was saved
|
||||||
|
is_auto_save (bool): autosave is on or off
|
||||||
|
"""
|
||||||
if opflame.app_framework:
|
if opflame.app_framework:
|
||||||
opflame.app_framework.save_prefs()
|
opflame.app_framework.save_prefs()
|
||||||
|
|
||||||
|
|
||||||
def get_main_menu_custom_ui_actions():
|
def get_main_menu_custom_ui_actions():
|
||||||
|
"""Hook to create submenu in start menu
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: menu object
|
||||||
|
"""
|
||||||
# install openpype and the host
|
# install openpype and the host
|
||||||
openpype_install()
|
openpype_install()
|
||||||
|
|
||||||
|
|
@ -122,6 +176,11 @@ def get_main_menu_custom_ui_actions():
|
||||||
|
|
||||||
|
|
||||||
def get_timeline_custom_ui_actions():
|
def get_timeline_custom_ui_actions():
|
||||||
|
"""Hook to create submenu in timeline
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: menu object
|
||||||
|
"""
|
||||||
# install openpype and the host
|
# install openpype and the host
|
||||||
openpype_install()
|
openpype_install()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue