I am in the process of learning how to create GUI’s using PyQt.
I decided to try and create a GUI for a simple tool I made, it works great until I try to close it, it closes but then maya freezes and I have no idea why, it runs fine when I run it outside of maya.
I am using maya 2011.
Here is the code I am executing in maya:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
import Steps.ui_stepsdlg
class StepsDlg(QDialog, Steps.ui_stepsdlg.Ui_TileWalk):
def __init__(self,parent=None):
super(StepsDlg, self).__init__(parent)
self.setupUi(self)
@pyqtSignature("")
def on_createButton_clicked(self):
print "It Works"
app = QApplication(sys.argv)
form = StepsDlg()
form.show()
app.exec_()
And here is the UI file:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'D:\Maya\scripts\Steps\stepsdlg.ui'
#
# Created: Tue Jun 08 15:35:06 2010
# by: PyQt4 UI code generator 4.5.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_TileWalk(object):
def setupUi(self, TileWalk):
TileWalk.setObjectName("TileWalk")
TileWalk.resize(302, 210)
self.gridLayout_3 = QtGui.QGridLayout(TileWalk)
self.gridLayout_3.setObjectName("gridLayout_3")
self.gridLayout = QtGui.QGridLayout()
self.gridLayout.setObjectName("gridLayout")
self.label = QtGui.QLabel(TileWalk)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 0, 0, 1, 2)
self.label_2 = QtGui.QLabel(TileWalk)
self.label_2.setObjectName("label_2")
self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1)
self.stepWSpinBox = QtGui.QDoubleSpinBox(TileWalk)
self.stepWSpinBox.setMinimum(0.01)
self.stepWSpinBox.setProperty("value", QtCore.QVariant(1.0))
self.stepWSpinBox.setObjectName("stepWSpinBox")
self.gridLayout.addWidget(self.stepWSpinBox, 1, 1, 1, 1)
self.label_3 = QtGui.QLabel(TileWalk)
self.label_3.setObjectName("label_3")
self.gridLayout.addWidget(self.label_3, 1, 2, 1, 1)
self.stepDSpinBox = QtGui.QDoubleSpinBox(TileWalk)
self.stepDSpinBox.setMinimum(0.01)
self.stepDSpinBox.setProperty("value", QtCore.QVariant(2.0))
self.stepDSpinBox.setObjectName("stepDSpinBox")
self.gridLayout.addWidget(self.stepDSpinBox, 1, 3, 1, 1)
self.label_4 = QtGui.QLabel(TileWalk)
self.label_4.setObjectName("label_4")
self.gridLayout.addWidget(self.label_4, 1, 4, 1, 1)
self.stepHSpinBox = QtGui.QDoubleSpinBox(TileWalk)
self.stepHSpinBox.setMinimum(0.1)
self.stepHSpinBox.setProperty("value", QtCore.QVariant(0.2))
self.stepHSpinBox.setObjectName("stepHSpinBox")
self.gridLayout.addWidget(self.stepHSpinBox, 1, 5, 1, 1)
self.gridLayout_3.addLayout(self.gridLayout, 0, 0, 1, 2)
self.gridLayout_2 = QtGui.QGridLayout()
self.gridLayout_2.setObjectName("gridLayout_2")
self.label_5 = QtGui.QLabel(TileWalk)
self.label_5.setObjectName("label_5")
self.gridLayout_2.addWidget(self.label_5, 0, 0, 1, 1)
spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_2.addItem(spacerItem, 0, 1, 1, 1)
self.numStepsSpinBox = QtGui.QSpinBox(TileWalk)
self.numStepsSpinBox.setMinimum(1)
self.numStepsSpinBox.setObjectName("numStepsSpinBox")
self.gridLayout_2.addWidget(self.numStepsSpinBox, 0, 2, 1, 1)
spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_2.addItem(spacerItem1, 0, 4, 1, 1)
self.label_6 = QtGui.QLabel(TileWalk)
self.label_6.setObjectName("label_6")
self.gridLayout_2.addWidget(self.label_6, 1, 0, 1, 1)
spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_2.addItem(spacerItem2, 1, 1, 1, 1)
self.gapSpinBox = QtGui.QDoubleSpinBox(TileWalk)
self.gapSpinBox.setObjectName("gapSpinBox")
self.gridLayout_2.addWidget(self.gapSpinBox, 1, 2, 1, 1)
self.label_7 = QtGui.QLabel(TileWalk)
self.label_7.setObjectName("label_7")
self.gridLayout_2.addWidget(self.label_7, 2, 0, 1, 1)
self.durationSpinBox = QtGui.QSpinBox(TileWalk)
self.durationSpinBox.setMinimum(1)
self.durationSpinBox.setMaximum(1000)
self.durationSpinBox.setProperty("value", QtCore.QVariant(10))
self.durationSpinBox.setObjectName("durationSpinBox")
self.gridLayout_2.addWidget(self.durationSpinBox, 2, 2, 1, 2)
self.gridLayout_3.addLayout(self.gridLayout_2, 1, 0, 1, 2)
spacerItem3 = QtGui.QSpacerItem(20, 28, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.gridLayout_3.addItem(spacerItem3, 2, 1, 1, 1)
spacerItem4 = QtGui.QSpacerItem(113, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_3.addItem(spacerItem4, 3, 0, 1, 1)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.createButton = QtGui.QPushButton(TileWalk)
self.createButton.setObjectName("createButton")
self.horizontalLayout.addWidget(self.createButton)
self.cancelButton = QtGui.QPushButton(TileWalk)
self.cancelButton.setObjectName("cancelButton")
self.horizontalLayout.addWidget(self.cancelButton)
self.gridLayout_3.addLayout(self.horizontalLayout, 3, 1, 1, 1)
self.retranslateUi(TileWalk)
QtCore.QObject.connect(self.cancelButton, QtCore.SIGNAL("clicked()"), TileWalk.reject)
QtCore.QMetaObject.connectSlotsByName(TileWalk)
def retranslateUi(self, TileWalk):
TileWalk.setWindowTitle(QtGui.QApplication.translate("TileWalk", "Steps/Tile Walk", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("TileWalk", "Step Dimensions:", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("TileWalk", "Width:", None, QtGui.QApplication.UnicodeUTF8))
self.label_3.setText(QtGui.QApplication.translate("TileWalk", "Depth:", None, QtGui.QApplication.UnicodeUTF8))
self.label_4.setText(QtGui.QApplication.translate("TileWalk", "Height:", None, QtGui.QApplication.UnicodeUTF8))
self.label_5.setText(QtGui.QApplication.translate("TileWalk", "Number of Steps:", None, QtGui.QApplication.UnicodeUTF8))
self.label_6.setText(QtGui.QApplication.translate("TileWalk", "Gap Between Steps:", None, QtGui.QApplication.UnicodeUTF8))
self.label_7.setText(QtGui.QApplication.translate("TileWalk", "Duration of Each Flip:", None, QtGui.QApplication.UnicodeUTF8))
self.durationSpinBox.setSuffix(QtGui.QApplication.translate("TileWalk", " Frames", None, QtGui.QApplication.UnicodeUTF8))
self.createButton.setText(QtGui.QApplication.translate("TileWalk", "Create", None, QtGui.QApplication.UnicodeUTF8))
self.cancelButton.setText(QtGui.QApplication.translate("TileWalk", "Cancel", None, QtGui.QApplication.UnicodeUTF8))
Any ideas why its killing maya.
Also another quick question, how would I get it to close the dialog once I click create?
Cheers.