I'm not sure what you're attempting here... are you trying to set a
200ms timeout for your request to self.getP ?
D
On 17/08/12 17:54, seeks wrote:
hi,Cuchullain,Thank you for your quick reply, I modified a version is
now able to work, I would like to get the latest news from the
server.I do not know this good
self.timer = QTimer()
QObject.connect(self.timer,SIGNAL("timeout()"),self.getP)
self.timer.start(200)
I reactor is used QtReator, and because I use is PyQt.
reactor.callLater (time, function) I also tried, but failed.
在 2012年8月17日星期五UTC+8下午12时37分08秒,seeks写道:
Hello, everyone, I have a twisted use in python. The red part of
the problem in the following code.
I want a process a call to the remote server command, but I
failed, I can not find the reason, can help?
import sys,time
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from net.client import FilmStudioClient
from twisted.python import log
def DefaultErrorHandler(exc):
msg = '%s\n\n%s' % (exc.getErrorMessage(), str(exc))
log.msg(msg)
class Window(QWidget):
a = 0
def __init__(self,reactor, parent = None):
QWidget.__init__(self, parent)
self.projects = []
self.reactor = reactor
button = QPushButton(self.tr <http://self.tr>("Click me"))
self.resultLabel = QLabel(self.tr <http://self.tr>("..."))
self.client = FilmStudioClient(reactor,self.onDisconnected)
# New style: uses the connect method of a pyqtSignal object.
self.connect(button, SIGNAL("clicked()"), self.handleClick)
# Old style: uses the SIGNAL function to describe the signal.
self.connect(self, SIGNAL("sendValue(PyQt_PyObject)"),
self.handleValue)
layout = QVBoxLayout(self)
layout.addWidget(button)
layout.addWidget(self.resultLabel)
self.threadPool = []
def connectAnonymous(self):
self.client.connectAnonymous("192.168.0.108",7777).addCallback(self.onConnected).addErrback(
DefaultErrorHandler )
def handleClick(self):
#self.connectAnonymous()
self.threadPool.append( GenericThread(self.getP) )
self.disconnect( self, SIGNAL("sendValue(PyQt_PyObject)"),
self.handleValue )
self.connect( self, SIGNAL("sendValue(PyQt_PyObject)"),
self.handleValue )
self.threadPool[len(self.threadPool)-1].start()
def getP(self):
while True:
time.sleep(1)
#self.connectAnonymous()
# i can not get projects from QThread because
getProjects_OK was not run.
self.client.perspective.callRemote(
'getProjects').addCallback(self.getProjects_OK)
#self.client.getProjects().addCallback(self.getProjects_OK).addErrback(self.getProjects_Failed)
self.emit(SIGNAL("sendValue(PyQt_PyObject)"),
self.projects)
def handleValue(self, value):
self.resultLabel.setText(repr(value))
def onConnected(self, perspective):
self.connected = True
def onDisconnected(self):
self.connected = False
def getProjects_OK(self,info):
print "get-ok",info,"done"
self.projects = []
for i in info:
print "project:",i
self.projects.append(i.name <http://i.name>)
def getProjects_Failed(self,exc):
print "getProjects_Failed",exc
class GenericThread(QThread):
def __init__(self, function, *args, **kwargs):
QThread.__init__(self)
self.function = function
self.args = args
self.kwargs = kwargs
def __del__(self):
self.wait()
def run(self):
self.function(*self.args,**self.kwargs)
return
def main():
import sys
try:
import qt4reactor
except ImportError:
# Maybe qt4reactor is placed inside twisted.internet in
site-packages?
from twisted.internet import qt4reactor
qt4reactor.install()
from twisted.internet import reactor
app = QApplication(sys.argv)
app.setStyle(QStyleFactory.create("Plastique"))
win = Window(reactor)
win.connectAnonymous()
win.show()
reactor.run()
--
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings:
http://groups.google.com/group/python_inside_maya/subscribe
--
Donal McMullan
Production Engineer
--
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings:
http://groups.google.com/group/python_inside_maya/subscribe