Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions doc/api/api_changes_3.3/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,20 @@ APIs which support the values True, False, and "TeX" for ``ismath``.
~~~~~~~~~~~~~~~~~~~~~
This module is deprecated.


Stricter PDF metadata keys in PGF
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Saving metadata in PDF with the PGF backend currently normalizes all keys to
lowercase, unlike the PDF backend, which only accepts the canonical case. This
is deprecated; in a future version, only the canonically cased keys listed in
the PDF specification (and the `~.backend_pgf.PdfPages` documentation) will be
accepted.


Qt modifier keys
~~~~~~~~~~~~~~~~
The ``MODIFIER_KEYS``, ``SUPER``, ``ALT``, ``CTRL``, and ``SHIFT``
global variables of the :mod:`matplotlib.backends.backend_qt4agg`,
:mod:`matplotlib.backends.backend_qt4cairo`,
:mod:`matplotlib.backends.backend_qt5agg` and
:mod:`matplotlib.backends.backend_qt5cairo` modules are deprecated.
3 changes: 2 additions & 1 deletion lib/matplotlib/backends/backend_qt4.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .. import cbook
from .backend_qt5 import (
backend_version, SPECIAL_KEYS, SUPER, ALT, CTRL, SHIFT, MODIFIER_KEYS,
backend_version, SPECIAL_KEYS,
SUPER, ALT, CTRL, SHIFT, MODIFIER_KEYS, # These are deprecated.
cursord, _create_qApp, _BackendQT5, TimerQT, MainWindow, FigureCanvasQT,
FigureManagerQT, NavigationToolbar2QT, SubplotToolQt, exception_handler)

Expand Down
47 changes: 22 additions & 25 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,38 +57,34 @@
QtCore.Qt.Key_Pause: 'pause',
QtCore.Qt.Key_SysReq: 'sysreq',
QtCore.Qt.Key_Clear: 'clear', }

# define which modifier keys are collected on keyboard events.
# elements are (Matplotlib modifier names, Modifier Flag, Qt Key) tuples
SUPER = 0
ALT = 1
CTRL = 2
SHIFT = 3
MODIFIER_KEYS = [('super', QtCore.Qt.MetaModifier, QtCore.Qt.Key_Meta),
('alt', QtCore.Qt.AltModifier, QtCore.Qt.Key_Alt),
('ctrl', QtCore.Qt.ControlModifier, QtCore.Qt.Key_Control),
Comment thread
QuLogic marked this conversation as resolved.
('shift', QtCore.Qt.ShiftModifier, QtCore.Qt.Key_Shift),
]

if sys.platform == 'darwin':
# in OSX, the control and super (aka cmd/apple) keys are switched, so
# switch them back.
SPECIAL_KEYS.update({QtCore.Qt.Key_Control: 'cmd', # cmd/apple key
QtCore.Qt.Key_Meta: 'control',
})
MODIFIER_KEYS[0] = ('cmd', QtCore.Qt.ControlModifier,
QtCore.Qt.Key_Control)
MODIFIER_KEYS[2] = ('ctrl', QtCore.Qt.MetaModifier,
QtCore.Qt.Key_Meta)


# Define which modifier keys are collected on keyboard events.
# Elements are (Modifier Flag, Qt Key) tuples.
# Order determines the modifier order (ctrl+alt+...) reported by Matplotlib.
_MODIFIER_KEYS = [
(QtCore.Qt.ShiftModifier, QtCore.Qt.Key_Shift),
(QtCore.Qt.ControlModifier, QtCore.Qt.Key_Control),
(QtCore.Qt.AltModifier, QtCore.Qt.Key_Alt),
(QtCore.Qt.MetaModifier, QtCore.Qt.Key_Meta),
]
cursord = {
cursors.MOVE: QtCore.Qt.SizeAllCursor,
cursors.HAND: QtCore.Qt.PointingHandCursor,
cursors.POINTER: QtCore.Qt.ArrowCursor,
cursors.SELECT_REGION: QtCore.Qt.CrossCursor,
cursors.WAIT: QtCore.Qt.WaitCursor,
}
SUPER = 0 # Deprecated.
ALT = 1 # Deprecated.
CTRL = 2 # Deprecated.
SHIFT = 3 # Deprecated.
MODIFIER_KEYS = [ # Deprecated.
(SPECIAL_KEYS[key], mod, key) for mod, key in _MODIFIER_KEYS]


# make place holder
Expand Down Expand Up @@ -391,22 +387,24 @@ def _get_key(self, event):
event_mods = int(event.modifiers()) # actually a bitmask

# get names of the pressed modifier keys
# 'control' is named 'control' when a standalone key, but 'ctrl' when a
# modifier
# bit twiddling to pick out modifier keys from event_mods bitmask,
# if event_key is a MODIFIER, it should not be duplicated in mods
mods = [name for name, mod_key, qt_key in MODIFIER_KEYS
if event_key != qt_key and (event_mods & mod_key) == mod_key]
mods = [SPECIAL_KEYS[key].replace('control', 'ctrl')
for mod, key in _MODIFIER_KEYS
if event_key != key and event_mods & mod]
try:
# for certain keys (enter, left, backspace, etc) use a word for the
# key, rather than unicode
key = SPECIAL_KEYS[event_key]
except KeyError:
# unicode defines code points up to 0x0010ffff
# unicode defines code points up to 0x10ffff (sys.maxunicode)
# QT will use Key_Codes larger than that for keyboard keys that are
# are not unicode characters (like multimedia keys)
# skip these
# if you really want them, you should add them to SPECIAL_KEYS
MAX_UNICODE = 0x10ffff
if event_key > MAX_UNICODE:
if event_key > sys.maxunicode:
return None

key = chr(event_key)
Expand All @@ -417,7 +415,6 @@ def _get_key(self, event):
else:
key = key.lower()

mods.reverse()
return '+'.join(mods + [key])

def flush_events(self):
Expand Down