cellphone.py
上传用户:ghyvgy
上传日期:2009-05-26
资源大小:547k
文件大小:1k
源码类别:

其他游戏

开发平台:

Python

  1. # cell phone service
  2. from twisted.spread.pb import Service, Perspective
  3. class Cellphone(Perspective):
  4.     def attached(self, remoteEar, identity):
  5.         self.remoteEar = remoteEar
  6.         self.caller = None
  7.         self.talkingTo = None
  8.         return Perspective.attached(self, remoteEar, identity)
  9.     def detached(self, remoteEar, identity):
  10.         del self.remoteEar
  11.         self.caller = None
  12.         self.talkingTo = None
  13.         return Perspective.detached(self, remoteEar, identity)
  14.     def hear(self, text):
  15.         self.remoteEar.callRemote('hear', text)
  16.     def perspective_dial(self, phoneNumber):
  17.         otherPhone = self.service.getPerspectiveNamed(phoneNumber)
  18.         otherPhone.ring(self)
  19.     callerID = True
  20.     def ring(self, otherPhone):
  21.         self.caller = otherPhone
  22.         if self.callerID:
  23.             displayNumber = otherPhone.perspectiveName
  24.         else:
  25.             displayNumber = "000-555-1212"
  26.         self.remoteEar.callRemote('ring', displayNumber)
  27.     def perspective_pickup(self):
  28.         if self.caller:
  29.             self.caller.phoneConnected(self)
  30.             self.phoneConnected(self.caller)
  31.             self.caller = None
  32.     def phoneConnected(self, otherPhone):
  33.         self.talkingTo = otherPhone
  34.         self.remoteEar.callRemote('connected')
  35.     def perspective_talk(self, message):
  36.         if self.talkingTo:
  37.             self.talkingTo.hear(message)
  38. class PhoneCompany(Service):
  39.     perspectiveClass = Cellphone