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


Python PluginManager.get_compiled_hotkeys方法代碼示例

本文整理匯總了Python中pluginmanager.PluginManager.get_compiled_hotkeys方法的典型用法代碼示例。如果您正苦於以下問題:Python PluginManager.get_compiled_hotkeys方法的具體用法?Python PluginManager.get_compiled_hotkeys怎麽用?Python PluginManager.get_compiled_hotkeys使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pluginmanager.PluginManager的用法示例。


在下文中一共展示了PluginManager.get_compiled_hotkeys方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Kalpana

# 需要導入模塊: from pluginmanager import PluginManager [as 別名]
# 或者: from pluginmanager.PluginManager import get_compiled_hotkeys [as 別名]
class Kalpana(QtGui.QApplication):
    read_plugin_config = pyqtSignal()
    write_plugin_config = pyqtSignal()
    print_ = pyqtSignal(str)
    error = pyqtSignal(str)

    def __init__(self, configdir, file_to_open=None):
        super().__init__(['kalpana'])
        self.objects = create_objects(configdir)
        self.objects['mainwindow'].create_ui(self.objects['chaptersidebar'],
                                             self.objects['textarea'],
                                             self.objects['terminal'])
        # Plugins
        self.pluginmanager = PluginManager(self.objects.copy())
        self.objects['terminal'].update_commands(self.pluginmanager.plugin_commands)
        # Signals
        connect_others_signals(*self.objects.values())
        self.connect_own_signals()
        # Hotkeys
        set_key_shortcuts(self.objects['mainwindow'], self.objects['textarea'],
                          self.objects['terminal'],
                          self.pluginmanager.get_compiled_hotkeys())
        self.init_hotkeys()
        # Load settings and get it oooon
        self.objects['settingsmanager'].load_settings()
        self.install_event_filter()
        # Try to open a file and die if it doesn't work, or make a new file
        if file_to_open:
            if not self.objects['textarea'].open_file(file_to_open):
                self.close()
        else:
            self.objects['textarea'].set_filename(new=True)
        # FIN
        self.objects['mainwindow'].show()

    def install_event_filter(self):
        # Event filter
        class AppEventFilter(QtCore.QObject):
            activation_event = pyqtSignal()
            def eventFilter(self, object, event):
                if event.type() == QtCore.QEvent.ApplicationActivate:
                    self.activation_event.emit()
                return False
        self.event_filter = AppEventFilter()
        def refresh_config():
            self.objects['settingsmanager'].load_settings(refresh_only=True)
        self.event_filter.activation_event.connect(refresh_config)
        self.installEventFilter(self.event_filter)

    def connect_own_signals(self):
        self.objects['settingsmanager'].set_stylesheet.connect(self.setStyleSheet)
        self.objects['terminal'].list_plugins.connect(self.list_plugins)

    def list_plugins(self, _):
        plugins = self.pluginmanager.plugins
        self.objects['terminal'].print_(', '.join(name for name, p in plugins))

    # === Configurable hotkeys =========================================

    def init_hotkeys(self):
        l = (('terminal', self.objects['terminal'].toggle, self.set_terminal_hotkey),
             ('chapter sidebar', self.objects['chaptersidebar'].toggle, self.set_chaptersidebar_hotkey))
        self.hotkeys = {name: QtGui.QShortcut(QtGui.QKeySequence(''),
                                              self.objects['mainwindow'],
                                              callback)
                        for name, callback, _ in l}
        for n, _, callback in l:
            self.objects['settingsmanager'].register_setting(n + ' hotkey', callback)

    def set_terminal_hotkey(self, newkey):
        self.set_hotkey('terminal', newkey)

    def set_chaptersidebar_hotkey(self, newkey):
        self.set_hotkey('chapter sidebar', newkey)

    def set_hotkey(self, hotkey, newkey):
        self.hotkeys[hotkey].setKey(QtGui.QKeySequence(newkey))
開發者ID:nycz,項目名稱:lcars-tem,代碼行數:79,代碼來源:kalpana.py


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