本文整理汇总了Python中EventDispatcher.EventDispatcher类的典型用法代码示例。如果您正苦于以下问题:Python EventDispatcher类的具体用法?Python EventDispatcher怎么用?Python EventDispatcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EventDispatcher类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
class Device:
def __init__(self):
self.model = loader.loadModel('Ipod.egg')
self.model.reparentTo(render)
self.base = self.model.find("**/Cubierta")
self.base.reparentTo(render)
#self.base.setHpr(0, 0, 0)
#base.camera.setPos(0, -5, 0)
self.events = EventDispatcher(self, "Ipod Shuffle")
alight = AmbientLight('alight')
alight.setColor(VBase4(1, 1, 1, 1))
alnp = render.attachNewNode(alight)
render.setLight(alnp)
self.apps = {}
self.apps["Reproductor de Audio"] = MusicApp(self)
self.launch("Reproductor de Audio")
def run(self):
print "I'm in a race and I'm winning"
run()
def get_model(self):
return self.model
def get_base(self):
return self.base
def launch(self, app_name):
if app_name in self.apps:
self.events.clear()
self.apps[app_name].activate(self.events)
else:
print "unknown command: " + app_name
示例2: __init__
class IRCBot:
def __init__(self, configname):
self.config = ConfigLoader(configname)
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.irc = IRCInterface(self.socket)
self.plugins = {}
self.dispatcher = EventDispatcher(self.irc)
def rise(self):
self.loadAllPlugins()
self.connect()
def loadPlugin(self, pluginName):
plugin = importlib.import_module("plugins." + pluginName)
for name in dir(plugin):
local = getattr(plugin, name)
if hasattr(local, "_ircEvent"):
self.dispatcher.hookEvent(getattr(local, "_ircEvent"), local)
def loadAllPlugins(self):
for m in self.config.get("plugins"):
self.loadPlugin(m)
def connect(self):
self.socket.connect( (self.config.get("server"), int(self.config.get("port"))) )
self.handshake()
self.loop()
def handshake(self):
self.irc.nick(self.config.get("nick"))
self.irc.user(self.config.get("nick"), "...", "...", "...")
for channel in self.config.get("channels"):
self.irc.join(channel)
def loop(self):
buffer = ""
while True:
data = self.irc.read()
for cmd in data:
if cmd["command"] == "PING":
self.irc.pong(cmd["params"][0])
self.dispatcher.dispatch(cmd)
示例3: __init__
def __init__(self, raw_in, outstream):
"""
raw_data is the raw content of a midi file as a string.
"""
# internal values, don't mess with 'em directly
self.raw_in = raw_in
self.dispatch = EventDispatcher(outstream)
# Used to keep track of stuff
self._running_status = None
示例4: __init__
class MidiFileParser:
"""
The MidiFileParser is the lowest level parser that see the data as
midi data. It generates events that gets triggered on the outstream.
"""
def __init__(self, raw_in, outstream):
"""
raw_data is the raw content of a midi file as a string.
"""
# internal values, don't mess with 'em directly
self.raw_in = raw_in
self.dispatch = EventDispatcher(outstream)
# Used to keep track of stuff
self._running_status = None
def parseMThdChunk(self):
"Parses the header chunk"
raw_in = self.raw_in
header_chunk_type = raw_in.nextSlice(4)
header_chunk_zise = raw_in.readBew(4)
# check if it is a proper midi file
if header_chunk_type != 'MThd':
raise TypeError, "It is not a valid midi file!"
# Header values are at fixed locations, so no reason to be clever
self.format = raw_in.readBew(2)
self.nTracks = raw_in.readBew(2)
self.division = raw_in.readBew(2)
# Theoretically a header larger than 6 bytes can exist
# but no one has seen one in the wild
# But correctly ignore unknown data if it is though
if header_chunk_zise > 6:
raw_in.moveCursor(header_chunk_zise-6)
# call the header event handler on the stream
self.dispatch.header(self.format, self.nTracks, self.division)
def parseMTrkChunk(self):
"Parses a track chunk. This is the most important part of the parser."
# set time to 0 at start of a track
self.dispatch.reset_time()
dispatch = self.dispatch
raw_in = self.raw_in
# Trigger event at the start of a track
dispatch.start_of_track(self._current_track)
# position cursor after track header
raw_in.moveCursor(4)
# unsigned long is 4 bytes
tracklength = raw_in.readBew(4)
track_endposition = raw_in.getCursor() + tracklength # absolute position!
while raw_in.getCursor() < track_endposition:
# find relative time of the event
time = raw_in.readVarLen()
dispatch.update_time(time)
# be aware of running status!!!!
peak_ahead = raw_in.readBew(move_cursor=0)
if (peak_ahead & 0x80):
# the status byte has the high bit set, so it
# was not running data but proper status byte
status = self._running_status = raw_in.readBew()
else:
# use that darn running status
status = self._running_status
# could it be illegal data ?? Do we need to test for that?
# I need more example midi files to be shure.
# Also, while I am almost certain that no realtime
# messages will pop up in a midi file, I might need to
# change my mind later.
# we need to look at nibbles here
hi_nible, lo_nible = status & 0xF0, status & 0x0F
# match up with events
# Is it a meta_event ??
#.........这里部分代码省略.........
示例5: Device
class Device():
def __init__(self):
self.base = ShowBase()
self.model = self.base.loader.loadModel('device.egg')
self.model.reparentTo(self.base.render)
self.base.disableMouse()
self.base.camera.setPos(0, -10, 0)
self.model.setHpr(0,90,0)
mat = Mat4(self.base.camera.getMat())
mat.invertInPlace()
self.base.mouseInterfaceNode.setMat(mat)
self.base.enableMouse()
self.screen = self.model.find("**/pantalla")
self.list_app = ListApp(self)
self.music_app = MusicApp(self)
self.dial_app = DialApp(self)
self.apps = {}
self.events = EventDispatcher(self, "Sony Ericsson W200")
self.apps["init"] = InitApp(self)
self.apps["Dial"] = self.display_dial_screen
self.apps["menu"] = MainMenu(self)
self.apps["Reproductor"] = self.play
self.apps["Reproductor de Audio"] = self.display_list
self.apps["Camara"] = CameraApp(self)
self.apps["Album Fotografico"] = PhotoApp(self)
self.apps["Llamadas"] = self.display_list
self.apps["Contactos"] = self.display_list
self.apps["Mensajes"] = self.display_list
self.apps["Juegos"] = self.display_list
self.apps["Utileria"] = self.display_list
self.apps["Reproducir Todas"] = self.play
self.apps["Lista de Albums"] = self.list_albums
self.apps["Lista de Artistas"] = self.list_artists
self.apps["Lista de Contactos"] = self.list_contacts
self.apps["Dial Contact"] = self.dial_contact
self.apps["Llamadas Perdidas"] = self.list_lost_calls
self.apps["Llamadas Contestadas"] = self.list_answered_calls
self.apps["Llamadas Marcadas"] = self.list_done_calls
self.launch("init")
def list_lost_calls(self, arg = None):
manager = GestorRegistros()
self.list_app.set_options(manager.get_logs_by_state("PERDIDA"))
return self.list_app
def list_answered_calls(self, arg = None):
manager = GestorRegistros()
self.list_app.set_options(manager.get_logs_by_state("RECIBIDA"))
return self.list_app
def list_done_calls(self, arg = None):
manager = GestorRegistros()
self.list_app.set_options(manager.get_logs_by_state("REALIZADA"))
return self.list_app
def dial_contact(self, arg = None):
cntct = self.list_app.get_selected_option()[2]
self.dial_app.write_number(cntct[1])
return self.dial_app
def list_contacts(self, arg = None):
manager = GestorContactos()
self.list_app.set_options(manager.get_contactos())
return self.list_app
def display_dial_screen(self, arg = None):
self.dial_app.write_number(self.apps["init"].get_number())
return self.dial_app
def display_list(self, option):
temp_list = OptionManager.get_option_subtree(option)
self.list_app.set_options(temp_list)
return self.list_app
def list_albums(self, arg = None):
manager = GestorMusica()
temp_list = manager.get_albums()
self.list_app.set_options(temp_list)
return self.list_app
def list_artists(self, arg = None):
manager = GestorMusica()
temp_list = manager.get_artists()
self.list_app.set_options(temp_list)
return self.list_app
def play(self, arg = None):
#.........这里部分代码省略.........