本文整理汇总了Python中dispatcher.Dispatcher.setParent方法的典型用法代码示例。如果您正苦于以下问题:Python Dispatcher.setParent方法的具体用法?Python Dispatcher.setParent怎么用?Python Dispatcher.setParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dispatcher.Dispatcher
的用法示例。
在下文中一共展示了Dispatcher.setParent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Client
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import setParent [as 别名]
class Client(NetStream, QtCore.QObject):
def __init__(self, headMode=8, serverIP="127.0.0.1", serverPort=4829, sleepInterval=0.1, parent=None):
NetStream.__init__(self, headMode)
QtCore.QObject.__init__(self)
print "Client Init ", serverIP, serverPort
self.initData(serverIP, serverPort, sleepInterval, parent)
self.setup()
self.parent.parent.connect(self, QtCore.SIGNAL("serverCrashedAlert()"), self.parent.parent.serverCrashedAlert)
def initData(self, serverIP, serverPort, sleepInterval, parent):
self.serverIP = serverIP
self.serverPort = serverPort
self.sleepInterval = sleepInterval
self.dispatcher = Dispatcher()
self.parent = parent
self.isAlive = True
self.hasBegan = False
def killClient(self):
self.isAlive = False
def setup(self):
self.setupDispatcher()
self.setupClient()
def setupDispatcher(self):
self.dispatcher.setParent(self)
services = {
1001: LoginService(self.dispatcher),
1002: HallService(self.dispatcher),
1003: RoomService(self.dispatcher),
}
self.dispatcher.registers(services)
def setupClient(self):
print self.serverPort, "\n", self.serverIP
self.connect(self.serverIP, self.serverPort)
self.nodelay(0)
self.nodelay(1)
def sendToServer(self, serviceID, commandID, data):
message = {}
message["create_time"] = time.time()
message["service_id"] = serviceID
message["command_id"] = commandID
message["data"] = data
try:
messageString = json.dumps(message)
except TypeError, e:
print "Error while dumping json"
print e
print message
print "Sending Messgae:", message
self.send(messageString)