|
12 | 12 | default
|
13 | 13 | )
|
14 | 14 |
|
| 15 | +import matplotlib |
15 | 16 | from matplotlib import rcParams
|
16 | 17 | from matplotlib import is_interactive
|
17 | 18 | from matplotlib.backends.backend_webagg_core import (FigureManagerWebAgg,
|
@@ -204,6 +205,68 @@ def send_binary(self, data):
|
204 | 205 | def new_timer(self, *args, **kwargs):
|
205 | 206 | return TimerTornado(*args, **kwargs)
|
206 | 207 |
|
| 208 | + if matplotlib.__version__ < '3.4': |
| 209 | + # backport the Python side changes to match the js changes |
| 210 | + def _handle_key(self, event): |
| 211 | + _SPECIAL_KEYS_LUT = {'Alt': 'alt', |
| 212 | + 'AltGraph': 'alt', |
| 213 | + 'CapsLock': 'caps_lock', |
| 214 | + 'Control': 'control', |
| 215 | + 'Meta': 'meta', |
| 216 | + 'NumLock': 'num_lock', |
| 217 | + 'ScrollLock': 'scroll_lock', |
| 218 | + 'Shift': 'shift', |
| 219 | + 'Super': 'super', |
| 220 | + 'Enter': 'enter', |
| 221 | + 'Tab': 'tab', |
| 222 | + 'ArrowDown': 'down', |
| 223 | + 'ArrowLeft': 'left', |
| 224 | + 'ArrowRight': 'right', |
| 225 | + 'ArrowUp': 'up', |
| 226 | + 'End': 'end', |
| 227 | + 'Home': 'home', |
| 228 | + 'PageDown': 'pagedown', |
| 229 | + 'PageUp': 'pageup', |
| 230 | + 'Backspace': 'backspace', |
| 231 | + 'Delete': 'delete', |
| 232 | + 'Insert': 'insert', |
| 233 | + 'Escape': 'escape', |
| 234 | + 'Pause': 'pause', |
| 235 | + 'Select': 'select', |
| 236 | + 'Dead': 'dead', |
| 237 | + 'F1': 'f1', |
| 238 | + 'F2': 'f2', |
| 239 | + 'F3': 'f3', |
| 240 | + 'F4': 'f4', |
| 241 | + 'F5': 'f5', |
| 242 | + 'F6': 'f6', |
| 243 | + 'F7': 'f7', |
| 244 | + 'F8': 'f8', |
| 245 | + 'F9': 'f9', |
| 246 | + 'F10': 'f10', |
| 247 | + 'F11': 'f11', |
| 248 | + 'F12': 'f12'} |
| 249 | + |
| 250 | + def handle_key(key): |
| 251 | + """Handle key values""" |
| 252 | + value = key[key.index('k') + 1:] |
| 253 | + if 'shift+' in key: |
| 254 | + if len(value) == 1: |
| 255 | + key = key.replace('shift+', '') |
| 256 | + if value in _SPECIAL_KEYS_LUT: |
| 257 | + value = _SPECIAL_KEYS_LUT[value] |
| 258 | + key = key[:key.index('k')] + value |
| 259 | + return key |
| 260 | + |
| 261 | + key = handle_key(event['key']) |
| 262 | + e_type = event['type'] |
| 263 | + guiEvent = event.get('guiEvent', None) |
| 264 | + if e_type == 'key_press': |
| 265 | + self.key_press_event(key, guiEvent=guiEvent) |
| 266 | + elif e_type == 'key_release': |
| 267 | + self.key_release_event(key, guiEvent=guiEvent) |
| 268 | + handle_key_press = handle_key_release = _handle_key |
| 269 | + |
207 | 270 |
|
208 | 271 | class FigureManager(FigureManagerWebAgg):
|
209 | 272 | ToolbarCls = Toolbar
|
|
0 commit comments