这是我的代码。代码没有给出任何错误,但问题是时间没有更新,我的CPU的50%是玛雅人喜欢maya的“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()
谢谢。
答案 0 :(得分:0)
如果你有一个python插槽,你可以通过小费方法指定它:self.update_time。这适用于Python可访问的所有方法。
self.connect(self.timer, QtCore.SIGNAL("timeout()"), self, QtCore.SLOT("update_time()"))
应该是
self.connect(self.timer, QtCore.SIGNAL("timeout()"), self.update_time)
无论如何,你可以使用更新的连接方式:
self.timer.timeout.connect(self.update_time)
如果您想使用原始语法,则必须使用装饰器 @pyqtSlot
装饰您的方法 update_time答案 1 :(得分:0)
根据你的建议添加这行代码self.timer.setInterval(1000)
然后它完美无缺现在我的maya
应用程序不再占用我的cpu的一半。谢谢。