Created
January 12, 2023 15:57
-
-
Save BigRoy/f77b371d679bc71b184792f0c5332e6f to your computer and use it in GitHub Desktop.
Simple quick and dirty Substance Painter Plug-in which adds a Python Script Editor using OpenPype's scripting console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PySide2 import QtCore, QtWidgets | |
import substance_painter.ui | |
try: | |
from openpype_modules.python_console_interpreter.window import PythonInterpreterWidget # noqa | |
except ModuleNotFoundError: | |
from openpype.modules.python_console_interpreter.window import PythonInterpreterWidget # noqa | |
WIDGET = None | |
ACTION = None | |
class PythonConsole(PythonInterpreterWidget): | |
def __init__(self, parent=None): | |
super(PythonConsole, self).__init__(parent=parent) | |
self.setWindowFlags(QtCore.Qt.Dialog) | |
def _cleanup(): | |
global WIDGET | |
WIDGET = None | |
def show(): | |
"""Show the console - create if not exists""" | |
global WIDGET | |
if WIDGET is not None: | |
WIDGET.show() | |
WIDGET.raise_() | |
return | |
parent = substance_painter.ui.get_main_window() | |
WIDGET = PythonConsole(parent=parent) | |
WIDGET.destroyed.connect(_cleanup) | |
WIDGET.show() | |
WIDGET.raise_() | |
def start_plugin(): | |
global ACTION | |
# Add to menu entry | |
ACTION = QtWidgets.QAction("Python Script Editor") | |
ACTION.triggered.connect(show) | |
top_menu = substance_painter.ui.ApplicationMenu.Window | |
substance_painter.ui.add_action(top_menu, ACTION) | |
# Show on Substance launch | |
show() | |
def close_plugin(): | |
global WIDGET | |
global ACTION | |
if ACTION is not None: | |
ACTION = None | |
if WIDGET is not None: | |
WIDGET.close() | |
substance_painter.ui.delete_ui_element(WIDGET) | |
WIDGET = None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment