mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
various fixes
This commit is contained in:
parent
e66432d7ed
commit
228829e81a
5 changed files with 62 additions and 32 deletions
|
|
@ -3,6 +3,28 @@
|
|||
import sys
|
||||
|
||||
|
||||
class ToolWindows:
|
||||
|
||||
_windows = {}
|
||||
|
||||
@classmethod
|
||||
def get_window(cls, tool, window=None):
|
||||
# type: (str, QtWidgets.QWidget) -> QtWidgets.QWidget
|
||||
try:
|
||||
return cls._windows[tool]
|
||||
except KeyError:
|
||||
if window:
|
||||
cls.set_window(tool, window)
|
||||
return window
|
||||
else:
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def set_window(cls, tool, window):
|
||||
# type: (str, QtWidget.QWidget) -> None
|
||||
cls._windows[tool] = window
|
||||
|
||||
|
||||
def edit_shader_definitions():
|
||||
from avalon.tools import lib
|
||||
from Qt import QtWidgets
|
||||
|
|
@ -10,15 +32,13 @@ def edit_shader_definitions():
|
|||
ShaderDefinitionsEditor
|
||||
)
|
||||
|
||||
module = sys.modules[__name__]
|
||||
module.window = None
|
||||
|
||||
top_level_widgets = QtWidgets.QApplication.topLevelWidgets()
|
||||
main_window = next(widget for widget in top_level_widgets
|
||||
if widget.objectName() == "MayaWindow")
|
||||
|
||||
with lib.application():
|
||||
window = ShaderDefinitionsEditor(parent=main_window)
|
||||
window = ToolWindows.get_window("shader_definition_editor")
|
||||
if not window:
|
||||
window = ShaderDefinitionsEditor(parent=main_window)
|
||||
ToolWindows.set_window("shader_definition_editor", window)
|
||||
window.show()
|
||||
|
||||
module.window = window
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@ import maya.cmds as cmds
|
|||
from openpype.settings import get_project_settings
|
||||
|
||||
self = sys.modules[__name__]
|
||||
project_settings = get_project_settings(os.getenv("AVALON_PROJECT"))
|
||||
self._menu = project_settings["maya"]["scriptsmenu"]["name"]
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
|
@ -19,8 +17,11 @@ log = logging.getLogger(__name__)
|
|||
def _get_menu(menu_name=None):
|
||||
"""Return the menu instance if it currently exists in Maya"""
|
||||
|
||||
project_settings = get_project_settings(os.getenv("AVALON_PROJECT"))
|
||||
_menu = project_settings["maya"]["scriptsmenu"]["name"]
|
||||
|
||||
if menu_name is None:
|
||||
menu_name = self._menu
|
||||
menu_name = _menu
|
||||
widgets = dict((
|
||||
w.objectName(), w) for w in QtWidgets.QApplication.allWidgets())
|
||||
menu = widgets.get(menu_name)
|
||||
|
|
@ -74,12 +75,18 @@ def deferred():
|
|||
return
|
||||
|
||||
# load configuration of custom menu
|
||||
project_settings = get_project_settings(os.getenv("AVALON_PROJECT"))
|
||||
config = project_settings["maya"]["scriptsmenu"]["definition"]
|
||||
_menu = project_settings["maya"]["scriptsmenu"]["name"]
|
||||
|
||||
if not config:
|
||||
log.warning("Skipping studio menu, no definition found.")
|
||||
return
|
||||
|
||||
# run the launcher for Maya menu
|
||||
studio_menu = launchformaya.main(
|
||||
title=self._menu.title(),
|
||||
objectName=self._menu
|
||||
title=_menu.title(),
|
||||
objectName=_menu.title().lower().replace(" ", "_")
|
||||
)
|
||||
|
||||
# apply configuration
|
||||
|
|
@ -109,9 +116,8 @@ def install():
|
|||
|
||||
|
||||
def popup():
|
||||
"""Pop-up the existing menu near the mouse cursor"""
|
||||
"""Pop-up the existing menu near the mouse cursor."""
|
||||
menu = _get_menu()
|
||||
|
||||
cursor = QtGui.QCursor()
|
||||
point = cursor.pos()
|
||||
menu.exec_(point)
|
||||
|
|
|
|||
|
|
@ -11,11 +11,14 @@ from openpype import resources
|
|||
import gridfs
|
||||
|
||||
|
||||
DEFINITION_FILENAME = "{}/maya/shader_definition.txt".format(
|
||||
os.getenv("AVALON_PROJECT"))
|
||||
|
||||
|
||||
class ShaderDefinitionsEditor(QtWidgets.QWidget):
|
||||
"""Widget serving as simple editor for shader name definitions."""
|
||||
|
||||
# name of the file used to store definitions
|
||||
DEFINITION_FILENAME = "maya/shader_definition.txt"
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super(ShaderDefinitionsEditor, self).__init__(parent)
|
||||
|
|
@ -78,7 +81,7 @@ class ShaderDefinitionsEditor(QtWidgets.QWidget):
|
|||
content = ""
|
||||
if not file:
|
||||
file = self._gridfs.find_one(
|
||||
{"filename": self.DEFINITION_FILENAME})
|
||||
{"filename": DEFINITION_FILENAME})
|
||||
if not file:
|
||||
print(">>> [SNDE]: nothing in database yet")
|
||||
return content
|
||||
|
|
@ -102,7 +105,7 @@ class ShaderDefinitionsEditor(QtWidgets.QWidget):
|
|||
editor is running.
|
||||
"""
|
||||
file = self._gridfs.find_one(
|
||||
{"filename": self.DEFINITION_FILENAME})
|
||||
{"filename": DEFINITION_FILENAME})
|
||||
if file:
|
||||
content_check = self._read_definition_file(file)
|
||||
if content == content_check:
|
||||
|
|
@ -116,7 +119,7 @@ class ShaderDefinitionsEditor(QtWidgets.QWidget):
|
|||
self._gridfs.delete(file._id)
|
||||
|
||||
file = self._gridfs.new_file(
|
||||
filename=self.DEFINITION_FILENAME,
|
||||
filename=DEFINITION_FILENAME,
|
||||
content_type='text/plain',
|
||||
encoding='utf-8')
|
||||
file.write(content)
|
||||
|
|
@ -134,7 +137,11 @@ class ShaderDefinitionsEditor(QtWidgets.QWidget):
|
|||
self._editor.setStyleSheet("border: none;")
|
||||
|
||||
def _close(self):
|
||||
self.close()
|
||||
self.hide()
|
||||
|
||||
def closeEvent(self, event):
|
||||
event.ignore()
|
||||
self.hide()
|
||||
|
||||
def _reload(self):
|
||||
print(">>> [SNDE]: reloading")
|
||||
|
|
@ -156,16 +163,10 @@ class ShaderDefinitionsEditor(QtWidgets.QWidget):
|
|||
self,
|
||||
"Warning",
|
||||
("Content you are editing was changed meanwhile in database.\n"
|
||||
"Do you want to overwrite it?"),
|
||||
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
|
||||
"Please, reload and solve the conflict."),
|
||||
QtWidgets.QMessageBox.OK)
|
||||
|
||||
if reply == QtWidgets.QMessageBox.Yes:
|
||||
self._write_definition_file(
|
||||
content=self._editor.toPlainText(),
|
||||
force=True
|
||||
)
|
||||
|
||||
elif reply == QtWidgets.QMessageBox.No:
|
||||
if reply == QtWidgets.QMessageBox.OK:
|
||||
# do nothing
|
||||
pass
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ from maya import cmds
|
|||
import pyblish.api
|
||||
import openpype.api
|
||||
import openpype.hosts.maya.api.action
|
||||
from openpype.hosts.maya.api.shader_definition_editor import (
|
||||
DEFINITION_FILENAME)
|
||||
from openpype.lib.mongo import OpenPypeMongoConnection
|
||||
import gridfs
|
||||
import re
|
||||
|
|
@ -25,12 +27,13 @@ class ValidateModelName(pyblish.api.InstancePlugin):
|
|||
label = "Model Name"
|
||||
actions = [openpype.hosts.maya.api.action.SelectInvalidAction]
|
||||
material_file = None
|
||||
database_file = "maya/shader_definition.txt"
|
||||
database_file = DEFINITION_FILENAME
|
||||
|
||||
@classmethod
|
||||
def get_invalid(cls, instance):
|
||||
"""Get invalid nodes."""
|
||||
use_db = instance.context.data["project_settings"]["maya"]["publish"]["ValidateModelName"]["database"] # noqa: E501
|
||||
# use_db = instance.context.data["project_settings"]["maya"]["publish"]["ValidateModelName"]["database"] # noqa: E501
|
||||
use_db = cls.database
|
||||
|
||||
def is_group(group_name):
|
||||
"""Find out if supplied transform is group or not."""
|
||||
|
|
@ -84,7 +87,8 @@ class ValidateModelName(pyblish.api.InstancePlugin):
|
|||
shaders = map(lambda s: s.rstrip(), shaders)
|
||||
|
||||
# compile regex for testing names
|
||||
regex = instance.context.data["project_settings"]["maya"]["publish"]["ValidateModelName"]["regex"] # noqa: E501
|
||||
# regex = instance.context.data["project_settings"]["maya"]["publish"]["ValidateModelName"]["regex"] # noqa: E501
|
||||
regex = cls.regex
|
||||
r = re.compile(regex)
|
||||
|
||||
for obj in filtered:
|
||||
|
|
|
|||
|
|
@ -119,8 +119,7 @@ module.{module_name}()"""
|
|||
"""
|
||||
|
||||
# get the current application and its linked keyboard modifiers
|
||||
app = QtWidgets.QApplication.instance()
|
||||
modifiers = app.keyboardModifiers()
|
||||
modifiers = QtWidgets.QApplication.keyboardModifiers()
|
||||
|
||||
# If the menu has a callback registered for the current modifier
|
||||
# we run the callback instead of the action itself.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue