eric6/Utilities/MouseUtilities.py

Sun, 21 Jun 2020 18:26:12 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 21 Jun 2020 18:26:12 +0200
changeset 7635
0cdead130a81
parent 7360
9190402e4505
child 7781
607a6098cb44
permissions
-rw-r--r--

Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).

# -*- coding: utf-8 -*-

# Copyright (c) 2015 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing utility functions related to Mouse stuff.
"""


from PyQt5.QtCore import Qt, QCoreApplication

import Globals

if Globals.isMacPlatform():
    __modifier2String = {
        Qt.ShiftModifier: QCoreApplication.translate(
            "MouseUtilities", "Shift"),
        Qt.AltModifier: QCoreApplication.translate(
            "MouseUtilities", "Alt"),
        Qt.ControlModifier: QCoreApplication.translate(
            "MouseUtilities", "Cmd"),
        Qt.MetaModifier: QCoreApplication.translate(
            "MouseUtilities", "Ctrl"),
    }
    __modifierOrder = [Qt.MetaModifier, Qt.AltModifier, Qt.ShiftModifier,
                       Qt.ControlModifier]
else:
    __modifier2String = {
        Qt.ShiftModifier: QCoreApplication.translate(
            "MouseUtilities", "Shift"),
        Qt.AltModifier: QCoreApplication.translate(
            "MouseUtilities", "Alt"),
        Qt.ControlModifier: QCoreApplication.translate(
            "MouseUtilities", "Ctrl"),
        Qt.MetaModifier: QCoreApplication.translate(
            "MouseUtilities", "Meta"),
    }
    __modifierOrder = [Qt.MetaModifier, Qt.ControlModifier, Qt.AltModifier,
                       Qt.ShiftModifier]


__button2String = {
    Qt.LeftButton: QCoreApplication.translate(
        "MouseUtilities", "Left Button"),
    Qt.RightButton: QCoreApplication.translate(
        "MouseUtilities", "Right Button"),
    Qt.MidButton: QCoreApplication.translate(
        "MouseUtilities", "Middle Button"),
    Qt.XButton1: QCoreApplication.translate(
        "MouseUtilities", "Extra Button 1"),
    Qt.XButton2: QCoreApplication.translate(
        "MouseUtilities", "Extra Button 2"),
}


def MouseButtonModifier2String(modifiers, button):
    """
    Function to convert a modifier and mouse button combination to a
    displayable string.
    
    @param modifiers keyboard modifiers of the handler
    @type Qt.KeyboardModifiers
    @param button mouse button of the handler
    @type Qt.MouseButton
    @return display string of the modifier and mouse button combination
    @rtype str
    """
    if button not in __button2String:
        return ""
    
    parts = []
    for mod in __modifierOrder:
        if modifiers & mod:
            parts.append(__modifier2String[mod])
    parts.append(__button2String[button])
    return "+".join(parts)

eric ide

mercurial