diff --git a/pydm/utilities/__init__.py b/pydm/utilities/__init__.py index 21eef755c..30e51d2d1 100644 --- a/pydm/utilities/__init__.py +++ b/pydm/utilities/__init__.py @@ -15,6 +15,7 @@ from .iconfont import IconFont from ..qtdesigner import DesignerHooks +from . import shortcuts logger = logging.getLogger(__name__) diff --git a/pydm/utilities/shortcuts.py b/pydm/utilities/shortcuts.py new file mode 100644 index 000000000..3ed06b2bf --- /dev/null +++ b/pydm/utilities/shortcuts.py @@ -0,0 +1,29 @@ +from qtpy import QtWidgets, QtGui, QtCore + + +def install_connection_inspector(parent, keys=None): + """ + Install a QShortcut at the application which opens the PyDM Connection + Inspector + + Parameters + ---------- + parent : QWidget + A shortcut is "listened for" by Qt's event loop when the shortcut's + parent widget is receiving events. + keys : QKeySequence, optional + Default value is `Alt+C` + """ + from pydm.connection_inspector import ConnectionInspector + + def show_inspector(): + c = ConnectionInspector(parent=parent) + c.show() + + parent = parent or QtWidgets.QApplication.desktop() + + if keys is None: + keys = QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_C) + shortcut = QtWidgets.QShortcut(keys, parent); + shortcut.setContext(QtCore.Qt.ApplicationShortcut) + shortcut.activated.connect(show_inspector) diff --git a/pydm_launcher/main.py b/pydm_launcher/main.py index 96055992c..c72b03e29 100755 --- a/pydm_launcher/main.py +++ b/pydm_launcher/main.py @@ -123,6 +123,9 @@ def main(): stylesheet_path=pydm_args.stylesheet ) + pydm.utilities.shortcuts.install_connection_inspector( + parent=app.main_window) + sys.exit(app.exec_())