[英]Only create a Pane if it doesn't already exist
I found the code below from https://community.foundry.com/discuss/topic/140355/only-create-a-pane-if-it-doesn-t-already-exist but I am struggling to make this work in Nuke 12我从https://community.foundry.com/discuss/topic/140355/only-create-a-pane-if-it-doesn-t-already-exist中找到了以下代码,但我正在努力使这项工作核子12
from Qt import QtCore, QtGui, QtWidgets
def get_nuke_main_window():
"""Returns Nuke's main window"""
app = QtWidgets.QApplication.instance()
for obj in app.topLevelWidgets():
if obj.inherits('QMainWindow') and obj.metaObject().className() == 'Foundry::UI::DockMainWindow':
return obj
else:
raise RuntimeError('Could not find DockMainWindow instance')
def show_qt_pane(widget_class, title, id):
""" Either shows an existing QT pane, or make a new one.
:param widget_class:
:param title:
:param id:
:return:
"""
# Check if pane already exists.
qwindow = get_nuke_main_window()
widgets = qwindow.findChildren(QtWidgets.QWidget, id)
if widgets:
# We found at least one instance, show the first one.
widget = widgets[0]
parent_widget = widgets[0].parentWidget()
parent_widget.setCurrentWidget(widget)
parent_widget.activateWindow()
parent_widget.setFocus()
else:
# No instances were found, let's initialize a new one in a new Panel.
panel = nukescripts.PythonPanel(title, id)
widget = nuke.PyCustom_Knob(title, "", "__import__('nukescripts').panels.WidgetKnob({})".format(widget_class))
panel.addKnob(widget)
panel.show()
Can someone please translate this to Pyside2.QtCore - I am very inexperienced with QT and I can't make it work.有人可以把它翻译成 Pyside2.QtCore - 我对 QT 非常缺乏经验,我无法让它工作。 I changed QtWidgets to QtGui and imported QtGui as import PySide2.QtWidgets as QtGui (I think I also had to remove the id variable from "widgets" but I am stuck on parent_widget.setCurrentWidget (widget) - I get我将 QtWidgets 更改为 QtGui 并将 QtGui 作为 import PySide2.QtWidgets 作为 QtGui 导入(我想我还必须从“widgets”中删除 id 变量,但我被困在 parent_widget.setCurrentWidget (widget)上 - 我明白了
AttributeError: 'PySide2.QtWidgets.QMainWindow' object has no attribute 'setCurrentWidget'
You might have better luck thinking outside the box - why not add a variable to the nuke library and use that variable to store the status of your panel?跳出框框思考可能会更好 - 为什么不向 nuke 库添加一个变量并使用该变量来存储面板的状态?
import nuke
nuke.panelExists=False
You could set it to True/False in your create panel logic and check for it during creation.您可以在创建面板逻辑中将其设置为 True/False,并在创建过程中检查它。 That variable will now be accessible anywhere you import the module.该变量现在可以在您导入模块的任何地方访问。
Check out this article from my blog - I did a lot of digging around panels in nuke and built out something that could wrap any widget.从我的博客中查看这篇文章——我在 nuke 的面板上做了很多挖掘工作,并构建了一些可以包装任何小部件的东西。 It doesn't do exactly what you're looking for;它并不能完全满足您的要求; however it's got details about the signals the panels emit when they move around (or are closed):但是它有关于面板移动(或关闭)时发出的信号的详细信息:
https://www.tks-designs.com/blog/?p=350 https://www.tks-designs.com/blog/?p=350
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.