Esempio n. 1
0
    def __init__(self, icon, settings, parent=None):
        self.settings = settings
        QSystemTrayIcon.__init__(self, icon, parent)
        self.mainMenu = QMenu()
        self.actCapture = QAction(QIcon(":/config.png"),
                                  "Capture",
                                  self,
                                  triggered=self.onCapture)

        self.actCapture.setShortcut(
            QKeySequence.fromString(settings.value('SnapShotKey')))
        self.mainMenu.addAction(self.actCapture)

        self.mainMenu.addAction(
            QAction("Set save directory...",
                    self,
                    triggered=self.onSetSavePath))
        self.mainMenu.addAction(
            QAction("Set shortcut...",
                    self,
                    triggered=self.onConfigureShortCut))

        self.mainMenu.addAction(QAction("Exit", self, triggered=self.onExit))
        self.setContextMenu(self.mainMenu)
        self.activated.connect(self.onActived)

        self.gsKey = QxtGlobalShortcut()
        self.gsKey.setShortcut(
            QKeySequence.fromString(settings.value('SnapShotKey')))
        self.gsKey.activated.connect(self.onCapture)
Esempio n. 2
0
 def test_functional():
     app = QApplication(sys.argv)
     shortcut = QxtGlobalShortcut()
     shortcut.setShortcut(QKeySequence('Ctrl+Alt+E'))
     shortcut.activated.connect(app.exit)
     QTimer.singleShot(100, shortcut.activated.emit)
     app.exec_()
Esempio n. 3
0
def CreateGlobalHotkey(keyCombo, func):
    """Create a global hotkey, connecting a callback function to a key or key combination (example: "Ctrl+Z"). A global hotkey can be created after an application has started running, but it must be created after the application has been created. Returns whether a global hotkey was set up or not."""
    if QtLib() == PYQT4:
        shortcut = QxtGlobalShortcut()
        shortcut.setShortcut(QKeySequence(keyCombo))
        shortcut.activated.connect(func)
        _shortcuts.append(shortcut)
        return True
    return False
Esempio n. 4
0
 def onConfigureShortCut(self):
     c = QXShortCutKeyConfigureDialog(self.settings.value('SnapShotKey'),
                                      ":/help.png")
     c.windowTitle = 'QuickCapture'
     c.exec_()
     if not c.key is None:
         self.settings.setValue('SnapShotKey', c.key)
         del self.gsKey
         self.gsKey = QxtGlobalShortcut()
         self.gsKey.setShortcut(
             QKeySequence.fromString(self.settings.value('SnapShotKey')))
         self.gsKey.activated.connect(self.onCapture)
         self.actCapture.setShortcut(
             QKeySequence.fromString(self.settings.value('SnapShotKey')))
Esempio n. 5
0
if os.environ['QT_SELECT'] == '4':
    from PyQt4.QtGui import QApplication, QKeySequence
else:
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtGui import QKeySequence
from pygs import QxtGlobalShortcut

SHORTCUT_SHOW = "Ctrl+Alt+S"  # Ctrl maps to Command on Mac OS X
SHORTCUT_EXIT = "Ctrl+Alt+F"  # again, Ctrl maps to Command on Mac OS X


def show_activated():
    print("Shortcut Activated!")


app = QApplication([])

shortcut_show = QxtGlobalShortcut()
shortcut_show.setShortcut(QKeySequence(SHORTCUT_SHOW))
shortcut_show.activated.connect(show_activated)

shortcut_exit = QxtGlobalShortcut()
shortcut_exit.setShortcut(QKeySequence(SHORTCUT_EXIT))
shortcut_exit.activated.connect(app.exit)

return_code = app.exec_()

del shortcut_show
del shortcut_exit
sys.exit(return_code)
Esempio n. 6
0
 def setGlobalHotkeys(self):
     self.sysTrayMenuRegionGlobalHotkey = QxtGlobalShortcut()
     self.sysTrayMenuRegionGlobalHotkey.setShortcut(QKeySequence(self.hotkey))
     self.sysTrayMenuRegionGlobalHotkey.activated.connect(self.createDrawSurface)