Skip to content

Instantly share code, notes, and snippets.

@promto-c
Created March 15, 2024 10:24
Show Gist options
  • Select an option

  • Save promto-c/8a1ae7110ebbdebe2a3b94fc5d7c1349 to your computer and use it in GitHub Desktop.

Select an option

Save promto-c/8a1ae7110ebbdebe2a3b94fc5d7c1349 to your computer and use it in GitHub Desktop.
PySide2 Script to Find Nuke's Main Window: This script iterates through top-level widgets to locate the main window, enabling further customization or interaction through Python.
from PySide2 import QtWidgets
def GetNukeMainWindow():
"""Finds and returns the main Nuke window.
Iterates through all top-level widgets, checking for the Nuke main window
based on its class name.
Returns:
QtWidgets.QWidget: The found main window of Nuke, or None if not found.
"""
for widget in QtWidgets.QApplication.instance().topLevelWidgets():
if widget.metaObject().classname() != 'Foundry::UI::DockMainWindow':
continue
return widget
if __name__ == '__main__':
nuke_main_window = get_nuke_main_window()
_override_shortkey = QtWidgets.QShortCut(QtGui.QKeySequence('Ctrl+q', nuke_main_window)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment