feat(nks): workio integration

This commit is contained in:
Jakub Jezek 2019-08-05 14:10:19 +02:00
parent bfdb1bc379
commit 4da9c04d9e
2 changed files with 82 additions and 0 deletions

View file

@ -4,7 +4,17 @@ from avalon.tools import workfiles
from avalon import api as avalon from avalon import api as avalon
from pyblish import api as pyblish from pyblish import api as pyblish
from .workio import (
open,
save,
current_file,
has_unsaved_changes,
file_extensions,
work_root
)
from .. import api from .. import api
from .menu import ( from .menu import (
install as menu_install, install as menu_install,
_update_menu_task_label _update_menu_task_label
@ -17,6 +27,17 @@ import hiero
log = Logger().get_logger(__name__, "nukestudio") log = Logger().get_logger(__name__, "nukestudio")
__all__ = [
# Workfiles API
"open",
"save",
"current_file",
"has_unsaved_changes",
"file_extensions",
"work_root",
]
AVALON_CONFIG = os.getenv("AVALON_CONFIG", "pype") AVALON_CONFIG = os.getenv("AVALON_CONFIG", "pype")
PARENT_DIR = os.path.dirname(__file__) PARENT_DIR = os.path.dirname(__file__)

61
pype/nukestudio/workio.py Normal file
View file

@ -0,0 +1,61 @@
"""Host API required Work Files tool"""
import os
import hiero
def file_extensions():
return [".hrox"]
def has_unsaved_changes():
return hiero.core.projects()[-1]
def save(filepath):
project = hiero.core.projects()[-1]
if project:
project.saveAs(filepath)
else:
project = hiero.core.newProject()
project.saveAs(filepath)
def open(filepath):
try:
hiero.core.openProject(filepath)
return True
except Exception as e:
try:
from PySide.QtGui import *
from PySide.QtCore import *
except:
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from PySide2.QtCore import *
prompt = "Cannot open the selected file: `{}`".format(e)
hiero.core.log.error(prompt)
dialog = QMessageBox.critical(
hiero.ui.mainWindow(), "Error", unicode(prompt))
def current_file():
import os
import hiero
current_file = hiero.core.projects()[-1].path()
normalised = os.path.normpath(current_file)
# Unsaved current file
if normalised is '':
return "NOT SAVED"
return normalised
def work_root():
from avalon import api
return os.path.normpath(api.Session["AVALON_WORKDIR"]).replace("\\", "/")