當前位置: 首頁>>代碼示例>>Python>>正文


Python PluginManager.on_event方法代碼示例

本文整理匯總了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)
開發者ID:tetra5,項目名稱:gooby,代碼行數:87,代碼來源:gooby.py


注:本文中的pluginmanager.PluginManager.on_event方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。