[Pyobjc-dev] pb and pyobjc ...
Brought to you by:
ronaldoussoren
|
From: Antonio <str...@ti...> - 2007-11-12 16:18:20
|
hi all,
I've read the example in twisted documentation ,but I don't understand HOW
make the pb client work ... this is the code:
[CODE]
import objc
from Foundation import *
from AppKit import *
from PyObjCTools import NibClassBuilder, AppHelper
from twisted.internet import _threadedselect
_threadedselect.install()
from twisted.spread import pb
from twisted.internet import reactor, protocol, defer
from twisted.python import util, log
from twisted.protocols import basic
import sys
NibClassBuilder.extractClasses("MainMenu")
class Client(object):
def __init__(self, parent):
super(Client, self).__init__()
print 'init'
self.parent = parent
self.factory = pb.PBClientFactory()
self.root = self.factory.getRootObject()
self.root.debug = True
print self.root
self.root.addCallback(self.getEcho)
#_d.addCallback(self.printRes)
#_d.addCallback(self.parent._fillNome)
self.root.addErrback(self.errore)
def errore(self, msg):
print 'errore:', msg
def printRes(self, data):
print 'res', data
def getEcho(self, obj):
print
print '-'*20
print 'chiamo', obj
print '-'*20
print
_val = obj.callRemote("echo", "sasso")
return _val
def __call__(self):
print
print 'CCCALLL'
print
# class defined in MainMenu.nib
class MyObject(NibClassBuilder.AutoBaseClass):
# the actual base class is NSObject
# The following outlets are added to the class:
# ind
# nome
# piva
def init(self):
self = super(MyObject, self).init()
return self
def salva_(self, sender):
self.piva.setStringValue_('vaffanculo')
def trova_(self, sender):
protocol.ClientCreator(reactor, Client, self).connectTCP(
"a.s.h", 8789)
def _fillNome(self, strng):
print 'ricevo', strng
self.nome.setStringValue_(strng)
def _errore(self, err):
self.ind.setStringValue_('ERRORE: %s' % err)
def applicationDidFinishLaunching_(self, aNotification):
print
print 'finish launching'
print
reactor.interleave(AppHelper.callAfter, self._fillNome)
def applicationShouldTerminate_(self, sender):
if reactor.running:
reactor.stop()
return False
return True
if __name__ == "__main__":
log.startLogging(sys.stdout)
AppHelper.runEventLoop()
tanks in advance ...
--
#include <stdio.h>
int main(void){char c[]={10,65,110,116,111,110,105,111,32,98,97,114,98,111,110,
101,32,60,104,105,110,100,101,109,105,116,64,116,105,115,99,97,108,105,110,101,
116,46,105,116,62,10,10,0};printf("%s",c);return 0;}
|