这是我的密码。代码没有给出任何错误,但问题是时间没有更新,我的CPU有50%被玛雅占用,就像玛雅的“scriptjob -idle flag
”,我希望我能在这里得到答案,而我是新来这个网站提问。在
from PyQt4 import QtGui, QtCore
import maya.OpenMayaUI as mui
import sip
def maya_main_window():
ptr = mui.MQtUtil.mainWindow()
return sip.wrapinstance(long(ptr), QtCore.QObject)
class RenamingDialog(QtGui.QDialog):
def __init__(self, parent= maya_main_window()):
QtGui.QDialog.__init__(self,parent)
self.setWindowTitle("Clock")
self.setFixedSize(250, 200)
self.createLayout()
self.button_update()
self.run_time()
def run_time(self):
self.timer = QtCore.QTimer(self)
self.connect(self.timer, QtCore.SIGNAL("timeout()"), self, QtCore.SLOT("update_time()"))
self.timer.start()
def createLayout(self):
self.button1 = QtGui.QPushButton("Ok")
self.label = QtGui.QLabel("time")
buttonLayout = QtGui.QHBoxLayout()
buttonLayout.addWidget(self.button1)
buttonLayout.addWidget(self.label)
mainLayout = QtGui.QVBoxLayout()
mainLayout.addLayout(buttonLayout)
self.setLayout(mainLayout)
def update_time(self):
self.time = QtCore.QTime.currentTime()
self.updater = QtCore.QString(self.time.toString("hh:mm:ss"))
self.label.setText(self.updater)
def button_update(self):
self.connect(self.button1, QtCore.SIGNAL("clicked()"), self.printer)
def printer(self):
print "hai",
if __name__ == "__main__":
dialog = RenamingDialog()
dialog.show()
谢谢。在
如果您有一个python槽,您可以通过以下方法指定它:自我更新时间. 这适用于Python可访问的所有方法。在
应该是
^{pr2}$无论如何,您可以使用更新的连接方式:
如果您想使用原始语法,您必须用decorator@pyqtSlot
根据您的建议添加这一行代码
self.timer.setInterval(1000)
,那么它就完美地工作了,现在我的maya
应用程序不再占用我一半的cpu。非常感谢。在相关问题 更多 >
编程相关推荐