本文整理汇总了Python中pluginmanager.PluginManager.on_event方法的典型用法代码示例。如果您正苦于以下问题:Python PluginManager.on_event方法的具体用法?Python PluginManager.on_event怎么用?Python PluginManager.on_event使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pluginmanager.PluginManager
的用法示例。
在下文中一共展示了PluginManager.on_event方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Gooby
# 需要导入模块: from pluginmanager import PluginManager [as 别名]
# 或者: from pluginmanager.PluginManager import on_event [as 别名]
class Gooby(object):
def __init__(self, options):
self.options = options
self.plugin_manager = None
log.info("Gooby %s", gooby_version)
log.debug("Options: %s", self.options)
skype_options = {}
if any(sys.platform.startswith(p) for p in ("linux", "darwin")):
skype_options.update({"Transport": "x11"})
self.skype = Skype4Py.Skype(**skype_options)
setattr(self.skype, "FriendlyName", "Gooby")
self.skype.Client.Start(Minimized=True, Nosplash=True)
self.skype.Attach(Protocol=8)
for path in (options.cache_dir, options.logs_dir):
if not os.path.exists(path):
os.mkdir(path)
log.info("Cache: %s", os.path.abspath(options.cache_dir))
log.info("Logs: %s", os.path.abspath(options.logs_dir))
def __connect_signals(self):
dispatcher.connect(self._plugins, signals.REQUEST_PLUGINS, False)
dispatcher.connect(self._usage, signals.REQUEST_USAGE, False)
dispatcher.connect(self._chats, signals.REQUEST_CHATS, False)
def _chats(self):
"""Signal receiver."""
for chat in chain(self.skype.RecentChats, self.skype.BookmarkedChats):
yield chat.Name
def _usage(self, target, *args, **kwargs):
"""Signal receiver."""
for plugin in self.plugin_manager.plugins:
usage = plugin.usage
if plugin.__class__.__name__.lower() == target.lower():
return [usage(*args, **kwargs)]
return None
def _plugins(self):
"""Signal receiver."""
plugins = list()
for plugin in self.plugin_manager.plugins:
plugins.append(plugin.__class__.__name__)
return plugins
def _list_chats(self):
log.info("Recent chats:")
for i, chat in enumerate(self.skype.RecentChats):
log.info("%3d) %s", i + 1, chat.Name)
log.info("Bookmarked chats:")
for i, chat in enumerate(self.skype.BookmarkedChats):
log.info("%3d) %s", i + 1, chat.Name)
def _attached_to_skype(self):
return self.skype.AttachmentStatus == Skype4Py.enums.apiAttachSuccess
def run(self):
if self.options.listchats:
self._list_chats()
return
self.__connect_signals()
self.plugin_manager = PluginManager(PLUGINS_CONFIG)
for event in SKYPE_EVENTS:
self.skype.RegisterEventHandler(
event, self.plugin_manager.on_event(event))
log.info("*** Entering main loop. Press CTRL+C to quit ***")
while self._attached_to_skype():
for plugin in self.plugin_manager.plugins:
messages = plugin.flush_output()
for message in messages:
try:
message.send(self.skype)
except PluginOutputError, e:
log.error("Unable to send message %s by plugin %s: %s",
plugin, message.text, e)
time.sleep(self.options.sleep_time)