Source code for taurus.qt.qtgui.util.diagnostics

#!/usr/bin/env python

# ###########################################################################
#
# This file is part of Taurus
#
# http://taurus-scada.org
#
# Copyright 2011 CELLS / ALBA Synchrotron, Bellaterra, Spain
#
# Taurus is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ###########################################################################

"""Application-wide access to Taurus diagnostics."""

from taurus.external.qt import Qt

__all__ = ["install_diagnostics_shortcut", "show_diagnostics"]


class _DiagnosticsShortcutFilter(Qt.QObject):
    """Application-wide Ctrl+Shift+D handler shared by all Taurus widgets."""

    def __init__(self, application):
        Qt.QObject.__init__(self, application)
        self._dialog = None

    def eventFilter(self, watched, event):
        if (
            event.type() == Qt.QEvent.KeyPress
            and event.key() == Qt.Qt.Key_D
            and event.modifiers() == (Qt.Qt.ControlModifier | Qt.Qt.ShiftModifier)
        ):
            if not event.isAutoRepeat():
                self.showDiagnostics()
            return True
        return Qt.QObject.eventFilter(self, watched, event)

    def showDiagnostics(self):
        from taurus.qt.qtgui.panel.taurusdiagnostics import TaurusDiagnosticsDialog

        if self._dialog is None:
            self._dialog = TaurusDiagnosticsDialog()
        self._dialog.show()
        self._dialog.raise_()
        self._dialog.activateWindow()
        return self._dialog


[docs] def install_diagnostics_shortcut(): """Install and return the process-wide diagnostics shortcut handler. The handler is stored on ``QApplication`` so repeated calls from Taurus widgets remain inexpensive and create neither duplicate event filters nor duplicate dialogs. """ application = Qt.QApplication.instance() if application is None: return None handler = getattr(application, "_taurus_diagnostics_shortcut", None) if handler is None: handler = _DiagnosticsShortcutFilter(application) application.installEventFilter(handler) application._taurus_diagnostics_shortcut = handler return handler
[docs] def show_diagnostics(): """Show the process-wide Taurus diagnostics dialog.""" handler = install_diagnostics_shortcut() if handler is None: return None return handler.showDiagnostics()