本文整理汇总了Python中Event类的典型用法代码示例。如果您正苦于以下问题:Python Event类的具体用法?Python Event怎么用?Python Event使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Event类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
def start(self):
"""
Start the game engine.
"""
lasttime = time()
curtime = 0
frames = 0
# Start the main event loop
while 1:
# Process the internal event queue
Event.handle_events()
# Process the SDL event queue
for event in SDL.event.get():
if event.type == SDL.QUIT:
self.shutdown()
elif event.type == SDL.VIDEORESIZE:
self.resize(event.w, event.h)
elif event.type == SDL.KEYDOWN:
StateManager.current.key_pressed(event.key)
self.queue_flip()
elif event.type == SDL.KEYUP:
StateManager.current.key_released(event.key)
# Update and draw the current state
StateManager.update()
self.draw()
frames += 1
curtime = time()
if curtime - lasttime >= 1:
Log.info("FPS: " + str(frames / (curtime - lasttime)))
frames = 0
lasttime = curtime
示例2: process
def process(entry, result, mode="Num"):
Event.process(entry, result)
margin = Auction.process(entry, result)
Auction_Site.process(entry, result)
Auction_BidRequests.process(margin, entry, result, mode)
# Response
result.append(entry["response"])
示例3: createSocket
def createSocket(addr, port):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((addr, port))
rudpSocket = RudpSocket(sock)
rudpSocket.addr_src = sock.getsockname()
rudpSockets.append(rudpSocket)
Event.eventFd(sock.fileno(), handleDataAvailable, rudpSocket, "DataReceived")
return rudpSocket
示例4: received_message
def received_message(self, m):
# self.clients is set from within the server
# and holds the list of all connected servers
# we can dispatch to
import json
msg = json.loads(str(m))
Event.broadcast(msg['event'], msg['msg'])
pass
示例5: __handleTimeoutFIN
def __handleTimeoutFIN(self, packetSequenceNumber):
logger.log(Level.DEBUG, "Handling FIN timeout of:" + str(packetSequenceNumber))
if self.__incrementRetries():
Event.eventTimeoutDelete(self.__handleTimeoutFIN, packetSequenceNumber)
packet = RudpPacket()
packet.type = RudpPacket.TYPE_FIN
packet.seqnum = packetSequenceNumber
self.rudpSocket.sendPacketControl(self.addr, packet)
Event.eventTimeout(RudpSocket.PARAM_TIMEOUT, self.__handleTimeoutFIN, packet.seqnum, "DATA Timeout")
示例6: __emptyBuffer
def __emptyBuffer(self):
logger.log(Level.TRACE, "Sending packets, window:" + str(self.window) + " index:" + str(self.nextSendingPacketSeqNumber))
if len(self.dataBuffer) > self.nextSendingPacketSeqNumber:
while self.window > 0 and len(self.dataBuffer) > 0 and len(self.dataBuffer) > self.nextSendingPacketSeqNumber:
packet = self.dataBuffer[self.nextSendingPacketSeqNumber]
self.rudpSocket.sendPacketData(self.addr, packet)
self.nextSendingPacketSeqNumber = self.nextSendingPacketSeqNumber + 1
self.window = self.window - 1
Event.eventTimeout(RudpSocket.PARAM_TIMEOUT, self.__handleTimeoutData, packet.seqnum, "DATA Timeout")
示例7: __handleTimeoutSYN
def __handleTimeoutSYN(self, packetSequenceNumber):
logger.log(Level.DEBUG, "Handling SYN timeout of:" + str(packetSequenceNumber))
Event.eventTimeoutDelete(self.__handleTimeoutSYN, packetSequenceNumber)
if self.__incrementRetries():
packet = self.rudpSocket.generateSynPacket()
self.nextAckSeqNumber = packet.seqnum + 1
logger.log(Level.INFO, "Retransmitting SYN")
self.rudpSocket.sendPacketControl(self.addr, packet)
Event.eventTimeout(RudpSocket.PARAM_TIMEOUT, self.__handleTimeoutSYN, packet.seqnum, "SYN timeout")
示例8: fill_insert
def fill_insert(classe, i):
classe.name = "C"+str(i)
classe.planning = Planning()
# XXX fill planning with normal events ?
#classe.planning.cb_fill(number)
# XXX fill planning with course events
cursus = db.session.query(Cursus).get(i+1)
if cursus:
periods = cursus.periods
import Event
Event.fill_date = cursus.start
else:
periods = []
for period in periods:
for course in period.courses:
from Event import Event
# XXX move fill event in class
event = Event()
event.planning = classe.planning
event.course = course
course.c_elearning_rest = course.c_elearning
course.c_classroom_rest = course.c_classroom
course.c_practice_rest = course.c_practice
course.e_oral_rest = course.e_oral
course.e_practice_rest = course.e_practice
hours = course.c_elearning
hours += course.c_classroom
hours += course.c_practice
hours += course.e_oral
hours += course.e_practice
event.cb_fill(hours / 2)
if len(period.classes) == 0:
for course in period.courses:
event = Event()
event.planning = period.planning
event.course = course
event.cb_fill(event.course.e_exam / 2 + 1)
import Event
Event.fill_date = period.end
classe.periods = periods
user = User()
user.manager_class = [classe]
user.cb_fill(randint(1, number),
classe.campus.name + '_' + classe.name +
'_manager_user' + str(i))
user = User()
user.student_class = classe
user.cb_fill(randint(10, 30), classe.campus.name+'_'+classe.name+'_student_user'+str(i))
db.session.add(classe)
示例9: __handleTimeoutData
def __handleTimeoutData(self, rudpSecNum):
logger.log(Level.DEBUG, "Handling packet timeout DATA packet seq:" + str(rudpSecNum))
''' Here we need to remove all other DATA packet timeouts'''
for seq in range(rudpSecNum, self.nextSendingPacketSeqNumber):
Event.eventTimeoutDelete(self.__handleTimeoutData, seq)
if self.__incrementRetries():
''' Decrease window size, reset packet index to the one we lost'''
self.window = 1 if self.window - 1 < 1 else self.window - 1
self.nextSendingPacketSeqNumber = rudpSecNum
self.__emptyBuffer()
self.retries = self.retries + 1
示例10: createEvents
def createEvents(self):
nextDate = next_weekday(datetime.datetime.now().date(),self.day)
created = []
skipped = []
while(nextDate < self.endDate):
if not Event.getByDate(nextDate):
Event.create(self.name,self.place,datetime.datetime.combine(nextDate, self.time),self.key)
created.append(nextDate)
else:
skipped.append(nextDate)
nextDate += datetime.timedelta(days=7)
return [created,skipped]
示例11: __checkClose
def __checkClose(self):
''' Send FIN if all packet have been sent - last packet in a buffer was sent and all have been ACK'ed'''
if self.closePending is True:
logger.log(Level.DEBUG, str(self.nextBufferPacketSeqNumber) + ">" + str(self.nextSendingPacketSeqNumber) + " >" + str(self.nextAckSeqNumber))
if self.nextBufferPacketSeqNumber == self.nextSendingPacketSeqNumber == (self.nextAckSeqNumber - 1):
logger.log(Level.DEBUG, "Closing peer socket:" + str(self))
packet = RudpPacket()
packet.type = RudpPacket.TYPE_FIN
packet.seqnum = self.dataBuffer[self.nextSendingPacketSeqNumber - 1].seqnum + 1
self.rudpSocket.sendPacketControl(self.addr, packet)
Event.eventTimeout(RudpSocket.PARAM_TIMEOUT, self.__handleTimeoutFIN, packet.seqnum, "DATA Timeout")
self.state = RudpSocket.STATE_CLOSED
else:
logger.log(Level.DEBUG, "Could not close peer socket yet !!!!")
示例12: process
def process(entry, result, mode="Num"):
"""
Given a JSON object formatted by Extractor.py, parse each key-value pair in the object.
:param entry: the JSON object that represents one impression
:param result: the buffer to store the parsed variables
:param mode: "Num" or "Bin"; a flag indicating whether to parse bid bloor into binary variables or just keep the numerical value
:return: a list containing parsed variables of an impression
"""
Event.process(entry, result)
margin = Auction.process(entry, result)
Auction_Site.process(entry, result)
Auction_BidRequests.process(margin, entry, result, mode)
# Response
result.append(entry["response"])
示例13: old_main
def old_main():
for line in sys.stdin:
event = Event.decode_event(line)
# Common handling
Global.UpdateThreadState(event)
# Event-specific handling
event_handler_map[event.event](event)
示例14: main
def main():
print("Handler Chain #1")
pipeline = key_handler(mouse_handler(timer_handler()))
while True:
event = Event.next()
if event.kind == Event.TERMINATE:
break
pipeline.send(event)
print("\nHandler Chain #2 (debugging)")
pipeline = debug_handler(pipeline)
while True:
event = Event.next()
if event.kind == Event.TERMINATE:
break
pipeline.send(event)
示例15: main
def main():
print("Handler Chain #1")
handler1 = TimerHandler(KeyHandler(MouseHandler(NullHandler())))
# Could pass None or nothing instead of the NullHandler
while True:
event = Event.next()
if event.kind == Event.TERMINATE:
break
handler1.handle(event)
print("\nHandler Chain #2 (debugging)")
handler2 = DebugHandler(handler1)
while True:
event = Event.next()
if event.kind == Event.TERMINATE:
break
handler2.handle(event)