美文网首页CgTd
Nuke Python 用PySide扩展Nuke

Nuke Python 用PySide扩展Nuke

作者: N景波 | 来源:发表于2016-11-22 11:46 被阅读0次

可以用python和pyside来扩展nuke的UI,6.3v5以上已经自带PySide了。

第一个PySide窗口

启动nuke,在脚本编辑器输入:

from PySide import QtGui
label = QtGui.QLabel("hello world")
label.show()
可停靠的 PySide Widgets

用pyside创建可停靠的widget,nukescripts.panels模块可以帮到忙
定义如下:

registerWidgetAsPanel(widget, name, id, create=False)

    registerWidgetAsPanel(widget, name, id, create) -> PythonPanel

    Wraps and registers a widget to be used in a NUKE panel.

    widget - should be a string of the class for the widget
    name - is is the name as it will appear on the Pane menu
    id - should the the unique ID for this widget panel
    create - if this is set to true a new NukePanel will be returned     that wraps this widget

下面的代码创建了一个可定靠的table widegt:

import nuke
import PySide.QtCore as QtCore
import PySide.QtGui as QtGui
from nukescripts import panels

class NukeTestWindow(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.setLayout(QtGui.QVBoxLayout())
        self.myTable    = QtGui.QTableWidget()
        self.myTable.header = ['Date', 'Files', 'Size', 'Path' ]
        self.myTable.size = [ 75, 375, 85, 600 ]
        self.myTable.setColumnCount(len(self.myTable.header))
        self.myTable.setHorizontalHeaderLabels(self.myTable.header)
        self.myTable.setSelectionMode(QtGui.QTableView.ExtendedSelection)
        self.myTable.setSelectionBehavior(QtGui.QTableView.SelectRows)
        self.myTable.setSortingEnabled(1)
        self.myTable.sortByColumn(1, QtCore.Qt.DescendingOrder)
        self.myTable.setAlternatingRowColors(True)
        self.myTable.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.myTable.setRowCount(50)
        self.layout().addWidget(self.myTable)
        self.myTable.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding))
        self.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding))

panels.registerWidgetAsPanel('NukeTestWindow', 'Test table panel', 'uk.co.thefoundry.NukeTestWindow')

这个例子在pane菜单添加了可停靠的pane. 给pane添加widget,打开pane时挨着Properties的panel.
可以运行下列代码:

pane = nuke.getPaneFor('Properties.1')
panels.registerWidgetAsPanel('NukeTestWindow', 'Test table panel', 'uk.co.thefoundry.NukeTestWindow', True).addToPane(pane)
A Web browser panel example

下面的例子创建了可停靠web browder,同时用了信号槽
要使用,把例子添加到Nuke path或者拷贝粘贴到脚本编辑器里,然后从Pane菜单选择 web browser:

## example PySide panel that implements a simple web browser in Nuke
## JW 12/10/11

import nuke
import nukescripts
from nukescripts import panels

from PySide.QtGui import *
from PySide.QtCore import *
from PySide.QtWebKit import *


class WebBrowserWidget(QWidget):
  def changeLocation(self):
    url = self.locationEdit.text()
    if not url.startswith( 'http://' ):
      url = 'http://' + url
    self.webView.load( QUrl(url) )

  def urlChanged(self, url):
    self.locationEdit.setText( url.toString() )

  def __init__(self):
    QWidget.__init__(self)
    self.webView = QWebView()

    self.setLayout( QVBoxLayout() )

    self.locationEdit = QLineEdit( 'http://www.google.com' )
    self.locationEdit.setSizePolicy( QSizePolicy.Expanding, self.locationEdit.sizePolicy().verticalPolicy() )

    QObject.connect( self.locationEdit, SIGNAL('returnPressed()'),  self.changeLocation )
    QObject.connect( self.webView,   SIGNAL('urlChanged(QUrl)'),     self.urlChanged )

    self.layout().addWidget( self.locationEdit )

    bar = QToolBar()
    bar.addAction( self.webView.pageAction(QWebPage.Back))
    bar.addAction( self.webView.pageAction(QWebPage.Forward))
    bar.addAction( self.webView.pageAction(QWebPage.Stop))
    bar.addAction( self.webView.pageAction(QWebPage.Reload))
    bar.addSeparator()

    self.layout().addWidget( bar )
    self.layout().addWidget( self.webView )

    url = 'http://www.thefoundry.co.uk/'
    self.webView.load( QUrl( url ) )
    self.locationEdit.setText( url )
    self.setSizePolicy( QSizePolicy( QSizePolicy.Expanding,  QSizePolicy.Expanding))

## make this work in a .py file and in 'copy and paste' into the script editor
moduleName = __name__
if moduleName == '__main__':
  moduleName = ''
else:
  moduleName = moduleName + '.'

panels.registerWidgetAsPanel( moduleName + 'WebBrowserWidget', 'Web Browser','uk.co.thefoundry.WebBrowserWidget')
Migrating from PyQt Applications

在普通pyside和pyqt程序是兼容的,仅仅把import从 Pyqt4 改成 PySide。
PyQt的例子:

from PyQt4 import QtGui
label = QtGui.QLabel("Hello World")
label.show()

pyside的例子:

from PySide import QtGui
label = QtGui.QLabel("Hello World")
label.show()

相关文章

  • Nuke Python 用PySide扩展Nuke

    可以用python和pyside来扩展nuke的UI,6.3v5以上已经自带PySide了。 第一个PySide窗...

  • Nuke Python 用PyQt扩展Nuke

    虽然nuke内置了pyside,但是想用pyqt还是可以的。配置pyqt需要几个步骤,当然Python26也要安装...

  • Nuke Python 使用命令行

    nuke的命令行如何执行python脚本,请听详细分解 在python模式下运行nuke 通过 -t 参数,可以在...

  • Nuke Python 安装插件

    有好几种安装插件,gizmos, python脚本的方法。 最简单的就是用home目录的 ~/.nuke目录,其在...

  • Nuke V11.1 For Mac破解版软件免费下载附安装教程

    nuke studio mac全称The Foundry Nuke Studio,是一款视频后期合成编辑软件。nu...

  • Nuke Python 始

    这部分解释Nuke启动后运行的脚本 评估顺序 Nuke 初始化脚本的运行顺序和插件路径的顺序是相反的。插件默认路径...

  • Nuke Python roto

    怎么创建roto 图形和 画笔当获取或者设置roto,rotopaint节点时,需要读取节点的curves kno...

  • Nuke Python 数学

    本章讲解了一些数学模块的特性,详解了矢量和矩阵对象以及它们的成员函数。你可以在Nukepedia上找到一个很棒的教...

  • Nuke Python 格式

    这部分将如何处理格式 读取格式 使用nuke.formats()可会获取nuke支持的格式 各种方法展示如下: 结...

  • Nuke Python Metadata

    这章介绍如何读写Metadata。 读取metadata 函数metadata() 返回一个字典,包含了特点指定节...

网友评论

    本文标题:Nuke Python 用PySide扩展Nuke

    本文链接:https://www.haomeiwen.com/subject/yjmppttx.html