Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to Nuke #1

Open
beatreichenbach opened this issue Mar 2, 2025 · 0 comments
Open

Add to Nuke #1

beatreichenbach opened this issue Mar 2, 2025 · 0 comments

Comments

@beatreichenbach
Copy link

In your user folder's init.py:

import nuke

nuke.pluginAddPath(r'Z:\ImageClassifier')

# NUKE_PLUGIN_PATH=Z:\ImageClassifier

menu.py:

from image_classifier.menu import create_menu

create_menu()

image_classifier.menu:

from __future__ import annotations

from PySide2 import QtWidgets, QtCore
import nuke
import image_classifier


def create_menu() -> None:
    main_menu = nuke.menu('Nuke')
    if menu := main_menu.menu(image_classifier.__name__):
        menu.clearMenu()
    else:
        menu = main_menu.addMenu(image_classifier.__name__)

    menu.addCommand('Open ...', open_widget)


def open_widget() -> None:
    widget = QtWidgets.QWidget()
    parent = get_main_window()
    widget.setParent(parent, QtCore.Qt.Tool)
    widget.show()


def get_main_window() -> QtWidgets.QWidget | None:
    for widget in QtWidgets.QApplication.topLevelWidgets():
        if widget.metaObject().className() == 'Foundry::UI::DockMainWindow':
            return widget
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant