Exemplo n.º 1
0
def main():
    app = QtWidgets.QApplication(sys.argv)
    window = QtWidgets.QMainWindow()

    print("Press Ctrl+Shift+A any where. Ctrl+Shift+E exits the app.")

    # Setup a global keyboard shortcut to print "Hello World" on pressing
    # the shortcut
    keybinder.init()

    def callback():
        print("hello world")
    def exit_app():
        window.close()
    keybinder.register_hotkey(window.winId(), "Shift+Ctrl+A", callback)
    keybinder.register_hotkey(window.winId(), "Shift+Ctrl+E", exit_app)

    # Install a native event filter to receive events from the OS
    win_event_filter = WinEventFilter(keybinder)
    event_dispatcher = QAbstractEventDispatcher.instance()
    event_dispatcher.installNativeEventFilter(win_event_filter)

    window.show()
    app.exec_()
    keybinder.unregister_hotkey(window.winId(), "Shift+Ctrl+A")
    keybinder.unregister_hotkey(window.winId(), "Shift+Ctrl+E")
Exemplo n.º 2
0
    def run(self):
        '''运行并显示窗口'''
        self.mainWindow.move(*self._position)
        # 输入结束信号连接run槽
        self.ui.lineEdit.editingFinished.connect(self.call_action)
        # 重写keyPressEvent
        self.ui.lineEdit.keyPressEvent = self.keypressevent(
            self.ui.lineEdit.keyPressEvent)
        # 去除顶栏 和 一直在顶部
        self.mainWindow.setWindowFlags(QtCore.Qt.FramelessWindowHint
                                       | QtCore.Qt.WindowStaysOnTopHint)

        self._getconfig()
        self._loadconfig()
        self._writeconfig()

        pyperclip.determine_clipboard()
        keybinder.init()
        keybinder.register_hotkey(self.mainWindow.winId(), "Shift+Ctrl+A",
                                  self.callback)
        keybinder.register_hotkey(self.mainWindow.winId(), "Shift+Ctrl+E",
                                  self.mainWindow.close)

        win_event_filter = WinEventFilter(keybinder)
        event_dispatcher = QtCore.QAbstractEventDispatcher.instance()
        event_dispatcher.installNativeEventFilter(win_event_filter)

        sys.exit(self.app.exec_())
        keybinder.unregister_hotkey(self.mainWindow.winId(), "Shift+Ctrl+A")
        keybinder.unregister_hotkey(self.mainWindow.winId(), "Shift+Ctrl+F")
Exemplo n.º 3
0
 def enableHotKey(self, enable:bool):
     try:
         if enable:
             keybinder.register_hotkey(self.window_.winId(), self.hotkeyCombo,self.onTriggerHotKey)
         else:
             keybinder.unregister_hotkey(self.window_.winId(), self.hotkeyCombo)
     except Exception as e:
         print(e)
def main():
    global tagselector
    app = QApplication(sys.argv)
    nonShownMainWindow = QMainWindow()
    print('Tag File is at: "%s"' % TAGFILE)
    print('global shortcut to raise the tag selector window is: "%s"' %
          GLOBAL_SHOW_HOTKEY)

    tagselector = FuzzySearchDialog()
    tagselector.show()  #initial loading takes quite long so do it now
    tagselector.hide()

    #when I extracted this to a new class and a different file this didn't work in 2019-05.
    keybinder.init()
    filter = WinEventFilter(keybinder)
    keybinder.register_hotkey(nonShownMainWindow.winId(), GLOBAL_SHOW_HOTKEY,
                              onGlobalShowHotkey)
    event_dispatcher = QAbstractEventDispatcher.instance()
    event_dispatcher.installNativeEventFilter(filter)

    app.exec_()
    keybinder.unregister_hotkey(nonShownMainWindow.winId(),
                                GLOBAL_SHOW_HOTKEY)  #necessary?
Exemplo n.º 5
0
def main():
    import sys

    app = QApplication(sys.argv)

    widget = MyWidget()
    win = MainWindow(widget)

    def callback():
        widget.show()

    if 'Darwin' not in platform.system():
        from pyqtkeybind import keybinder
        keybinder.init()
        keybinder.register_hotkey(win.winId(), "Ctrl+Shift+1", callback)

        # Install a native event filter to receive events from the OS
        win_event_filter = WinEventFilter(keybinder)
        event_dispatcher = QAbstractEventDispatcher.instance()
        event_dispatcher.installNativeEventFilter(win_event_filter)

        keybinder.unregister_hotkey(win.winId(), 0x0, 0x0)
    sys.exit(app.exec())
Exemplo n.º 6
0
def main():
    app = QtWidgets.QApplication(sys.argv)
    window = QtWidgets.QMainWindow()

    print("Sample app for pyqtkeybind:")
    print("\tPress Ctrl+Shift+A any where to trigger a callback.")
    print("\tCtrl+Shift+F unregisters and re-registers previous callback.")
    print("\tCtrl+Shift+E exits the app.")

    # Setup a global keyboard shortcut to print "Hello World" on pressing
    # the shortcut
    keybinder.init()
    unregistered = False

    def callback():
        print("hello world")

    def exit_app():
        window.close()

    def unregister():
        keybinder.unregister_hotkey(window.winId(), "Shift+Ctrl+A")
        print("unregister and register previous binding")
        keybinder.register_hotkey(window.winId(), "Shift+Ctrl+A", callback)

    keybinder.register_hotkey(window.winId(), "Shift+Ctrl+A", callback)
    keybinder.register_hotkey(window.winId(), "Shift+Ctrl+E", exit_app)
    keybinder.register_hotkey(window.winId(), "Shift+Ctrl+F", unregister)

    # Install a native event filter to receive events from the OS
    win_event_filter = WinEventFilter(keybinder)
    event_dispatcher = QAbstractEventDispatcher.instance()
    event_dispatcher.installNativeEventFilter(win_event_filter)

    window.show()
    app.exec_()
    keybinder.unregister_hotkey(window.winId(), "Shift+Ctrl+A")
    keybinder.unregister_hotkey(window.winId(), "Shift+Ctrl+F")
    keybinder.unregister_hotkey(window.winId(), "Shift+Ctrl+E")
Exemplo n.º 7
0
def deactiveHotkeys(h1, h2, h3, h4):
    keybinder.unregister_hotkey(window.winId(), h1)
    keybinder.unregister_hotkey(window.winId(), h2)
    keybinder.unregister_hotkey(window.winId(), h3)
    keybinder.unregister_hotkey(window.winId(), h4)
Exemplo n.º 8
0
 def unregister():
     keybinder.unregister_hotkey(window.winId(), "Shift+Ctrl+F10")
     print("unregister and register previous binding")
     keybinder.register_hotkey(window.winId(), "Shift+Ctrl+F10", on_toggle)
Exemplo n.º 9
0
def main():
    # sys._excepthook = sys.excepthook
    #
    # def exception_hook(exctype, value, traceback):
    #     print(exctype, value, traceback)
    #     sys._excepthook(exctype, value, traceback)
    #     sys.exit(1)
    #
    # sys.excepthook = exception_hook

    app = QtWidgets.QApplication(sys.argv)
    window = MainWindow()

    print(
        "This will show a quick view of your keybindings (corsair only currently)."
    )
    print("Until I can figure out how to hide this window, just minimize it.")
    print("\tPress Ctrl+Shift+F10 any where to trigger a callback.")
    # print("\tCtrl+Shift+F unregisters and re-registers previous callback.")
    print("\tCtrl+Shift+E exits the app.")

    # Setup a global keyboard shortcut to print "Hello World" on pressing
    # the shortcut
    keybinder.init()
    unregistered = False

    def on_toggle():

        global latch
        nonlocal window

        if latch:
            window.show()
            latch = False
            print("worked On")
        else:
            window.hide()
            latch = True
            print("worked Off")

    def exit_app():
        window.close()

    def unregister():
        keybinder.unregister_hotkey(window.winId(), "Shift+Ctrl+F10")
        print("unregister and register previous binding")
        keybinder.register_hotkey(window.winId(), "Shift+Ctrl+F10", on_toggle)

    keybinder.register_hotkey(window.winId(), "Shift+Ctrl+F10", on_toggle)
    keybinder.register_hotkey(window.winId(), "Shift+Ctrl+E", exit_app)
    keybinder.register_hotkey(window.winId(), "Shift+Ctrl+F", unregister)

    # Install a native event filter to receive events from the OS
    win_event_filter = WinEventFilter(keybinder)
    event_dispatcher = QAbstractEventDispatcher.instance()
    event_dispatcher.installNativeEventFilter(win_event_filter)

    window.show()
    app.exec_()
    keybinder.unregister_hotkey(window.winId(), "Shift+Ctrl+F10")
    # keybinder.unregister_hotkey(window.winId(), "Shift+Ctrl+F")
    keybinder.unregister_hotkey(window.winId(), "Shift+Ctrl+E")
Exemplo n.º 10
0
 def unregister():
     keybinder.unregister_hotkey(window.winId(), "Shift+Ctrl+A")
     print("unregister and register previous binding")
     keybinder.register_hotkey(window.winId(), "Shift+Ctrl+A", callback)
Exemplo n.º 11
0
class WinEventFilter(QAbstractNativeEventFilter):
    def __init__(self, keybinder):
        self.keybinder = keybinder
        super().__init__()

    def nativeEventFilter(self, eventType, message):
        ret = self.keybinder.handler(eventType, message)
        return ret, 0


if __name__ == '__main__':

    def callback():
        w.on_pushButton_clicked()

    app = QApplication(sys.argv)
    w = MyWindow()

    keybinder.init()
    keybinder.register_hotkey(w.winId(), "Ctrl+Shift+M", callback)
    # Install a native event filter to receive events from the OS
    win_event_filter = WinEventFilter(keybinder)
    event_dispatcher = QAbstractEventDispatcher.instance()
    event_dispatcher.installNativeEventFilter(win_event_filter)

    w.show()
    sys.exit(app.exec_())

    keybinder.unregister_hotkey(w.winId(), "Ctrl+Shift+M")
Exemplo n.º 12
0
if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = EasyTranslator()

    def callback():
        window.setWindowState(window.windowState() & ~QtCore.Qt.WindowMinimized
                              | QtCore.Qt.WindowActive)
        window.activateWindow()
        text = QApplication.clipboard().text()
        text = text.strip().replace('\r\n', ' ').replace('\n', ' ')
        window.textEdit_in.setText(text)
        window.on_button_trans()

    def exit_app():
        window.close()

    keybinder.init()
    keybinder.register_hotkey(window.winId(), "Ctrl+Q", callback)
    keybinder.register_hotkey(window.winId(), "Ctrl+E", exit_app)

    # Install a native event filter to receive events from the OS
    win_event_filter = WinEventFilter(keybinder)
    event_dispatcher = QAbstractEventDispatcher.instance()
    event_dispatcher.installNativeEventFilter(win_event_filter)

    window.show()
    sys.exit(app.exec_())
    keybinder.unregister_hotkey(window.winId(), "Ctrl+Q")
    keybinder.unregister_hotkey(window.winId(), "Ctrl+E")