Skip to content

Commit

Permalink
Merge pull request #633 from hhslepicka/install_inspector
Browse files Browse the repository at this point in the history
ENH: Add utilities.shortcuts and initial shortcut ConnectionInspector
  • Loading branch information
hhslepicka authored Apr 29, 2020
2 parents e7d7f4b + 8e38735 commit 5ed07aa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions pydm/utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .iconfont import IconFont
from ..qtdesigner import DesignerHooks

from . import shortcuts

logger = logging.getLogger(__name__)

Expand Down
29 changes: 29 additions & 0 deletions pydm/utilities/shortcuts.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions pydm_launcher/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_())


Expand Down

0 comments on commit 5ed07aa

Please sign in to comment.