Maya QT interfaces in a class
Most tutorials online have suggested the way to fire commands inside QT interfaces launched n Maya (via cmds.loadUi – not involving pyQT) is to add a string property like:
+command="myPythonInstance.pythonCommand()"
Pretty craptastical – it can only fire commands inside a specific python module, the name of which has to be known when you’re laying out your interface.
Ideally, we’d like to have our interface instanced from a python class. This would allow us, amongst other things, so have multiple, independant instances. However it seems that a “self” reference can’t get passed to an interface, which is what you’d reallly like to do.
+command=self.pythonCommand
A (reasonably hacky) solution is to create the widget callbacks from inside our python class, after we’ve loaded the interface via cmds.loadUi().
import maya.cmds as cmds class myUi(object):
def __init__(self, *args):
uiFile = '/path/to/uiFile.ui'
rlDialog = cmds.loadUI(f=uiFile)
cmds.showWindow(rlDialog)
cmds.button( "ovrAdd_btn", edit=True, command=self.overrideAdd ) def overrideAdd(self, *args):
print 'do something!'
Which is slightly better, but we’re still referring to our widget by a string name. This is problematic if you have multiple instances of this class – targeting “ovrAdd_btn” is going to get confusing. We need to find out exactly which control, in amongst the whole widget mess, is the one that we’ve spawned when we’re called cmds.loadUI().
Sadly, loadUI() doesn’t give us any help in this department. So, and here’s the hacky bit, we can trawl through the widgets to find those belonging to our class instance, store them in a dict and then we can refer back to them by a simplified name. Easy!
import maya.cmds as cmds def widgetPath(windowName, widgetNames):
""" @param windowName: Window instance name to search
@param widgetNames: list of names to search for
""" returnDict = {}
mayaWidgetList = cmds.lsUI(dumpWidgets=True) for widget in widgetNames:
for mayaWidge in mayaWidgetList:
if windowName in mayaWidge:
if mayaWidge.endswith(widget):
returnDict[widget] = mayaWidge return returnDict class myUi(object):
def __init__(self, *args):
uiWidgetList = ['ovrAdd_btn'] uiFile = '/path/to/uiFile.ui'
rlDialog = cmds.loadUI(f=uiFile)
self.uiObjects = widgetPath(rlDialog, uiWidgetList) cmds.showWindow(rlDialog) cmds.button( self.uiObjects["ovrAdd_btn"], edit=True, command=self.overrideAdd ) def overrideAdd(self, *args):
print 'do something!'
Trawling through Maya’s widget list isn’t particularly elegant, but you only have to do it once per class initialisation, so there isn’t too much of a cost. The advantage is that you can now have per-instance widget names.
Why not just use pyQT proper, you ask? Installing external dependencies isn’t always an option for our less techy brethren, or easily done in a studio-wide fashion. Using pyQT would be far better (and give all sorts of other benefits), but if you’re constrained to using vanilla maya / python, this seems to do the trick.
Maya QT interfaces in a class的更多相关文章
- 使用 PySide2 开发 Maya 插件系列三:qt语言国际化(internationalization)
使用 PySide2 开发 Maya 插件系列三:qt语言国际化(internationalization) 前言: 这是 qt for python 的语言国际化,基于 UI 的,python 也有 ...
- 使用 PySide2 开发 Maya 插件系列一:QT Designer 设计GUI, pyside-uic 把 .ui 文件转为 .py 文件
使用 PySide2 开发 Maya 插件系列一:QT Designer 设计GUI, pyside-uic 把 .ui 文件转为 .py 文件 前期准备: 安装 python:https://www ...
- 无法启动 Maya 集成的 qt designer 的解决方法和原因 以及 中英文切换
无法启动 Maya 集成的 qt designer 的解决方法和原因 以及 中英文切换 前言: Maya 集成了 PySide,同时集成了qt designer,在 Maya 的安装目录下的 bin ...
- Qt Roadmap for 2018(对3D有很多改进)
When it comes to new features, we have many things ongoing related to graphics, so I’ll start with t ...
- A Simple OpenCASCADE Qt Demo-occQt
A Simple OpenCASCADE Qt Demo-occQt eryar@163.com Abstract. OpenCASCADE have provided the Qt samples ...
- Qt 设计师手册
Qt设计师(Qt Designer)是使用Qt部件(Widgets)设计和使用图形用户界面(GUI)的工具.它允许我们以所见即所得的方式构建和定制自己的窗口(Windows)或对话框(Dialogs) ...
- CG资源网 - Maya教程
Maya中mentalray灯光渲染终极训练视频教程 http://www.cgtsj.com/cg/f/vx3627/index.html Maya无人机建模制作训练视频教程第一季 http://w ...
- 使用Qt 开发图形界面的软件
3DSlicer, a free open source software for visualization and medical image computing AcetoneISO:镜像文件挂 ...
- Qt Examples Qt实例汇总
ActiveQt Examples Using ActiveX from Qt applications. Animation Framework Examples Doing animations ...
随机推荐
- 同时使用ADO与Excel类库冲突的问题
客户需要一个Demo程序实现Access数据库表导出到Excel表格,并将表中存储的照片(OLE对象)以其中一个字段(编号)命名存储到本地.程序中引入了ADO操作Access数据库("C:\ ...
- 功能丰富的 Perl:轻松调试 Perl
http://www.ibm.com/developerworks/cn/linux/sdk/perl/culture-4/index.html
- 信号之sigsetjmp和siglongjmp函数
在信号处理程序中经常调用longjmp函数以返回到程序的主循环中,而不是从该处理程序返回. 但是,调用longjmp有一个问题.当捕捉到一个信号时,进入信号捕捉函数,此时当前信号被自动地加到进程的信号 ...
- select option jquery javascript
jQuery获取Select选择的Text和Value: $('#myselect').find('option:selected').attr('ent_id'); $('#ent_id' ...
- How to Analyze Java Thread Dumps--reference
原文地址:http://architects.dzone.com/articles/how-analyze-java-thread-dumps The Performance Zone is pres ...
- vb.net写的odbc连接dsn数据源和ole链接oracle的小例子
最近由于工作需要开始接触vb2010,也叫vb.net.相比vb6.0有面向对象编程的优势.同时接触一门新语言,要更快的实际应用起来,链接数据库是必不可少的.之前用vba写过一个售书工具,正好可以拿来 ...
- ArcGIS Desktop 与 Excel(转)
来自:http://blog.csdn.net/kikitamoon/article/details/19043161 微软 OFFICE 产品中,Excel是很强大,并且平民化的表格制作工具.Arc ...
- Windows系统下用命令行编译C/C++程序过程总结
转自:http://www.cnblogs.com/caikehe/archive/2013/01/12/2858017.html (1)先用记事本编写如下所示的代码,并另存为hello.cpp,假设 ...
- windows下mysql初始密码设置
转载自:http://blog.csdn.net/ofreelander/article/details/50802780 1.my-default.ini 改名my.ini 在解压的目录下面复制my ...
- Unicode 编码解码
1. Regex.Unescape(str);返回Unicode解码,非Unicode直接返回 /// <summary> /// 2.转为Unicode编码 /// ...