mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-02 00:44:52 +01:00
first prototype of editor
This commit is contained in:
parent
7948820108
commit
8683ab3c3f
2 changed files with 103 additions and 1 deletions
|
|
@ -1,6 +1,25 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""OpenPype script commands to be used directly in Maya."""
|
||||
import sys
|
||||
|
||||
|
||||
def edit_shader_definitions():
|
||||
from avalon.tools import lib
|
||||
from Qt import QtWidgets, QtCore
|
||||
from openpype.hosts.maya.api.shader_definition_editor import ShaderDefinitionsEditor
|
||||
|
||||
print("Editing shader definitions...")
|
||||
pass
|
||||
|
||||
module = sys.modules[__name__]
|
||||
module.window = None
|
||||
|
||||
top_level_widgets = QtWidgets.QApplication.topLevelWidgets()
|
||||
mainwindow = next(widget for widget in top_level_widgets
|
||||
if widget.objectName() == "MayaWindow")
|
||||
|
||||
with lib.application():
|
||||
window = ShaderDefinitionsEditor(parent=mainwindow)
|
||||
# window.setStyleSheet(style.load_stylesheet())
|
||||
window.show()
|
||||
|
||||
module.window = window
|
||||
|
|
|
|||
83
openpype/hosts/maya/api/shader_definition_editor.py
Normal file
83
openpype/hosts/maya/api/shader_definition_editor.py
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""Editor for shader definitions."""
|
||||
import os
|
||||
import csv
|
||||
from Qt import QtWidgets, QtCore, QtGui
|
||||
from openpype.lib.mongo import OpenPypeMongoConnection
|
||||
from openpype import resources
|
||||
import gridfs
|
||||
|
||||
|
||||
class ShaderDefinitionsEditor(QtWidgets.QWidget):
|
||||
|
||||
DEFINITION_FILENAME = "maya/shader_definition.csv"
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super(ShaderDefinitionsEditor, self).__init__(parent)
|
||||
self._mongo = OpenPypeMongoConnection.get_mongo_client()
|
||||
self._gridfs = gridfs.GridFS( self._mongo[os.getenv("OPENPYPE_DATABASE_NAME")])
|
||||
|
||||
# TODO: handle GridIn and GridOut
|
||||
self._file = self._gridfs.find_one(
|
||||
{"filename": self.DEFINITION_FILENAME})
|
||||
if not self._file:
|
||||
self._file = self._gridfs.new_file(filename=self.DEFINITION_FILENAME)
|
||||
|
||||
self.setObjectName("shaderDefinitionEditor")
|
||||
self.setWindowTitle("OpenPype shader definition editor")
|
||||
icon = QtGui.QIcon(resources.pype_icon_filepath())
|
||||
self.setWindowIcon(icon)
|
||||
self.setWindowFlags(QtCore.Qt.Window)
|
||||
self.setParent(parent)
|
||||
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
|
||||
self.resize(750, 500)
|
||||
|
||||
self.setup_ui()
|
||||
|
||||
def setup_ui(self):
|
||||
layout = QtWidgets.QVBoxLayout(self)
|
||||
self._editor = QtWidgets.QPlainTextEdit()
|
||||
layout.addWidget(self._editor)
|
||||
|
||||
btn_layout = QtWidgets.QHBoxLayout()
|
||||
save_btn = QtWidgets.QPushButton("Save")
|
||||
save_btn.clicked.connect(self._close)
|
||||
|
||||
reload_btn = QtWidgets.QPushButton("Reload")
|
||||
reload_btn.clicked.connect(self._reload)
|
||||
|
||||
exit_btn = QtWidgets.QPushButton("Exit")
|
||||
exit_btn.clicked.connect(self._close)
|
||||
|
||||
btn_layout.addWidget(reload_btn)
|
||||
btn_layout.addWidget(save_btn)
|
||||
btn_layout.addWidget(exit_btn)
|
||||
|
||||
layout.addLayout(btn_layout)
|
||||
|
||||
def _read_definition_file(self):
|
||||
content = []
|
||||
with open(self._file, "r") as f:
|
||||
reader = csv.reader(f)
|
||||
for row in reader:
|
||||
content.append(row)
|
||||
|
||||
return content
|
||||
|
||||
def _write_definition_file(self, content):
|
||||
with open(self._file, "w", newline="") as f:
|
||||
writer = csv.writer(f)
|
||||
writer.writerows(content.splitlines())
|
||||
|
||||
def _close(self):
|
||||
self.close()
|
||||
|
||||
def _reload(self):
|
||||
print("reloading")
|
||||
self._set_content(self._read_definition_file())
|
||||
|
||||
def _save(self):
|
||||
pass
|
||||
|
||||
def _set_content(self, content):
|
||||
self._editor.set_content("\n".join(content))
|
||||
Loading…
Add table
Add a link
Reference in a new issue