简体   繁体   English

仅在窗格不存在时才创建它

[英]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.

相关问题 如果文件夹不存在,则创建文件夹的工作流程 - Workflow to create a folder if it doesn't exist already 在python中创建进程,仅当它不存在时 - Create process in python, only if it doesn't exist 仅当Python中的模块尚不存在时才导入该模块 - Import a module in Python only if it doesn't already exist 仅在尚不存在时才打开Tkniter顶层 - Open Tkniter Toplevel only if it doesn't already exist 仅当 Prometheus 指标不存在时才在 Python 中注册它 - Registering a Prometheus metric in Python ONLY if it doesn't already exist 立即创建目录和文件名(如果尚不存在) - Create directories and filename all at once if it doesn't already exist 仅当具有所有属性值的完整实例不存在时才尝试将_item() 放入 DynamoDB - Trying to put_item() to DynamoDB only if the complete instance with all attribute values doesn't exist already 如果 csv 文件不存在,但如果它已经存在然后写入数据,我该如何创建和写入头文件? - How do I create and write headers to a csv file if it doesn't exist, but if it already exists then write data? 如果文件不存在则创建 - Create a file if it doesn't exist 如何使用 Consul Agent CLI 创建新的 KV 条目,但前提是它们尚不存在? - How do I use the Consul Agent CLI to create new KV entries but only if they don't already exist?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM