|
12 | 12 | default
|
13 | 13 | )
|
14 | 14 |
|
| 15 | +import matplotlib |
15 | 16 | from matplotlib import rcParams
|
16 | 17 | from matplotlib.figure import Figure
|
17 | 18 | from matplotlib import is_interactive
|
@@ -241,6 +242,69 @@ def send_binary(self, data):
|
241 | 242 | def new_timer(self, *args, **kwargs):
|
242 | 243 | return TimerTornado(*args, **kwargs)
|
243 | 244 |
|
| 245 | + if matplotlib.__version__ < '3.4': |
| 246 | + # backport the Python side changes to match the js changes |
| 247 | + def _handle_key(self, event): |
| 248 | + _SPECIAL_KEYS_LUT = {'Alt': 'alt', |
| 249 | + 'AltGraph': 'alt', |
| 250 | + 'CapsLock': 'caps_lock', |
| 251 | + 'Control': 'control', |
| 252 | + 'Meta': 'meta', |
| 253 | + 'NumLock': 'num_lock', |
| 254 | + 'ScrollLock': 'scroll_lock', |
| 255 | + 'Shift': 'shift', |
| 256 | + 'Super': 'super', |
| 257 | + 'Enter': 'enter', |
| 258 | + 'Tab': 'tab', |
| 259 | + 'ArrowDown': 'down', |
| 260 | + 'ArrowLeft': 'left', |
| 261 | + 'ArrowRight': 'right', |
| 262 | + 'ArrowUp': 'up', |
| 263 | + 'End': 'end', |
| 264 | + 'Home': 'home', |
| 265 | + 'PageDown': 'pagedown', |
| 266 | + 'PageUp': 'pageup', |
| 267 | + 'Backspace': 'backspace', |
| 268 | + 'Delete': 'delete', |
| 269 | + 'Insert': 'insert', |
| 270 | + 'Escape': 'escape', |
| 271 | + 'Pause': 'pause', |
| 272 | + 'Select': 'select', |
| 273 | + 'Dead': 'dead', |
| 274 | + 'F1': 'f1', |
| 275 | + 'F2': 'f2', |
| 276 | + 'F3': 'f3', |
| 277 | + 'F4': 'f4', |
| 278 | + 'F5': 'f5', |
| 279 | + 'F6': 'f6', |
| 280 | + 'F7': 'f7', |
| 281 | + 'F8': 'f8', |
| 282 | + 'F9': 'f9', |
| 283 | + 'F10': 'f10', |
| 284 | + 'F11': 'f11', |
| 285 | + 'F12': 'f12'} |
| 286 | + |
| 287 | + |
| 288 | + def handle_key(key): |
| 289 | + """Handle key values""" |
| 290 | + value = key[key.index('k') + 1:] |
| 291 | + if 'shift+' in key: |
| 292 | + if len(value) == 1: |
| 293 | + key = key.replace('shift+', '') |
| 294 | + if value in _SPECIAL_KEYS_LUT: |
| 295 | + value = _SPECIAL_KEYS_LUT[value] |
| 296 | + key = key[:key.index('k')] + value |
| 297 | + return key |
| 298 | + |
| 299 | + key = handle_key(event['key']) |
| 300 | + e_type = event['type'] |
| 301 | + guiEvent = event.get('guiEvent', None) |
| 302 | + if e_type == 'key_press': |
| 303 | + self.key_press_event(key, guiEvent=guiEvent) |
| 304 | + elif e_type == 'key_release': |
| 305 | + self.key_release_event(key, guiEvent=guiEvent) |
| 306 | + handle_key_press = handle_key_release = _handle_key |
| 307 | + |
244 | 308 |
|
245 | 309 | class FigureManager(FigureManagerWebAgg):
|
246 | 310 | ToolbarCls = Toolbar
|
|
0 commit comments