11
11
import random
12
12
import socket
13
13
import threading
14
- import types
15
14
16
15
import numpy as np
17
16
22
21
import tornado .web
23
22
import tornado .ioloop
24
23
import tornado .websocket
25
- import tornado .template
26
24
27
25
import matplotlib
28
26
from matplotlib import rcParams
@@ -57,8 +55,8 @@ def mainloop(self):
57
55
WebAggApplication .initialize ()
58
56
59
57
url = "http://127.0.0.1:{port}{prefix}" .format (
60
- port = WebAggApplication .port ,
61
- prefix = WebAggApplication .url_prefix )
58
+ port = WebAggApplication .port ,
59
+ prefix = WebAggApplication .url_prefix )
62
60
63
61
if rcParams ['webagg.open_in_browser' ]:
64
62
import webbrowser
@@ -308,12 +306,12 @@ def start_event_loop(self, timeout):
308
306
backend_bases .FigureCanvasBase .start_event_loop_default (
309
307
self , timeout )
310
308
start_event_loop .__doc__ = \
311
- backend_bases .FigureCanvasBase .start_event_loop_default .__doc__
309
+ backend_bases .FigureCanvasBase .start_event_loop_default .__doc__
312
310
313
311
def stop_event_loop (self ):
314
312
backend_bases .FigureCanvasBase .stop_event_loop_default (self )
315
313
stop_event_loop .__doc__ = \
316
- backend_bases .FigureCanvasBase .stop_event_loop_default .__doc__
314
+ backend_bases .FigureCanvasBase .stop_event_loop_default .__doc__
317
315
318
316
319
317
class FigureManagerWebAgg (backend_bases .FigureManagerBase ):
@@ -352,26 +350,29 @@ def resize(self, w, h):
352
350
353
351
354
352
class NavigationToolbar2WebAgg (backend_bases .NavigationToolbar2 ):
355
- _jquery_icon_classes = {'home' : 'ui-icon ui-icon-home' ,
356
- 'back' : 'ui-icon ui-icon-circle-arrow-w' ,
357
- 'forward' : 'ui-icon ui-icon-circle-arrow-e' ,
358
- 'zoom_to_rect' : 'ui-icon ui-icon-search' ,
359
- 'move' : 'ui-icon ui-icon-arrow-4' ,
360
- 'download' : 'ui-icon ui-icon-disk' ,
361
- None : None
362
- }
353
+ _jquery_icon_classes = {
354
+ 'home' : 'ui-icon ui-icon-home' ,
355
+ 'back' : 'ui-icon ui-icon-circle-arrow-w' ,
356
+ 'forward' : 'ui-icon ui-icon-circle-arrow-e' ,
357
+ 'zoom_to_rect' : 'ui-icon ui-icon-search' ,
358
+ 'move' : 'ui-icon ui-icon-arrow-4' ,
359
+ 'download' : 'ui-icon ui-icon-disk' ,
360
+ None : None
361
+ }
363
362
364
363
def _init_toolbar (self ):
365
364
# Use the standard toolbar items + download button
366
- toolitems = (backend_bases .NavigationToolbar2 .toolitems +
367
- (('Download' , 'Download plot' , 'download' , 'download' ),))
365
+ toolitems = (
366
+ backend_bases .NavigationToolbar2 .toolitems +
367
+ (('Download' , 'Download plot' , 'download' , 'download' ),)
368
+ )
368
369
369
370
NavigationToolbar2WebAgg .toolitems = \
370
371
tuple (
371
- (text , tooltip_text , self ._jquery_icon_classes [image_file ],
372
- name_of_method )
373
- for text , tooltip_text , image_file , name_of_method
374
- in toolitems if image_file in self ._jquery_icon_classes )
372
+ (text , tooltip_text , self ._jquery_icon_classes [image_file ],
373
+ name_of_method )
374
+ for text , tooltip_text , image_file , name_of_method
375
+ in toolitems if image_file in self ._jquery_icon_classes )
375
376
376
377
self .message = ''
377
378
self .cursor = 0
@@ -432,7 +433,8 @@ def get(self, fignum):
432
433
433
434
ws_uri = 'ws://{req.host}{prefix}/' .format (req = self .request ,
434
435
prefix = self .url_prefix )
435
- self .render ('single_figure.html' ,
436
+ self .render (
437
+ "single_figure.html" ,
436
438
prefix = self .url_prefix ,
437
439
ws_uri = ws_uri ,
438
440
fig_id = fignum ,
@@ -452,22 +454,22 @@ def get(self):
452
454
"all_figures.html" ,
453
455
prefix = self .url_prefix ,
454
456
ws_uri = ws_uri ,
455
- figures = sorted (list (Gcf .figs .items ()), key = lambda item : item [0 ]),
457
+ figures = sorted (
458
+ list (Gcf .figs .items ()), key = lambda item : item [0 ]),
456
459
toolitems = NavigationToolbar2WebAgg .toolitems )
457
460
458
-
459
461
class MPLInterfaceJS (tornado .web .RequestHandler ):
460
462
def get (self ):
461
463
manager = Gcf .get_fig_manager (1 )
462
464
canvas = manager .canvas
463
465
464
466
self .set_header ('Content-Type' , 'application/javascript' )
465
467
466
- self .render ("mpl_interface.js" ,
468
+ self .render (
469
+ "mpl_interface.js" ,
467
470
toolitems = NavigationToolbar2WebAgg .toolitems ,
468
471
canvas = canvas )
469
472
470
-
471
473
class Download (tornado .web .RequestHandler ):
472
474
def get (self , fignum , fmt ):
473
475
self .fignum = int (fignum )
@@ -543,7 +545,7 @@ def send_diff_image(self, diff):
543
545
def __init__ (self , url_prefix = '' ):
544
546
if url_prefix :
545
547
assert url_prefix [0 ] == '/' and url_prefix [- 1 ] != '/' , \
546
- 'url_prefix must start with a "/" and not end with one.'
548
+ 'url_prefix must start with a "/" and not end with one.'
547
549
548
550
super (WebAggApplication , self ).__init__ ([
549
551
# Static files for the CSS and JS
@@ -566,11 +568,13 @@ def __init__(self, url_prefix=''):
566
568
{'path' : os .path .join (self ._mpl_dirs ['web_backend' ], 'jquery' ,
567
569
'css' , 'themes' , 'base' , 'images' )}),
568
570
569
- (url_prefix + r'/_static/jquery/js/(.*)' , tornado .web .StaticFileHandler ,
571
+ (url_prefix + r'/_static/jquery/js/(.*)' ,
572
+ tornado .web .StaticFileHandler ,
570
573
{'path' : os .path .join (self ._mpl_dirs ['web_backend' ],
571
574
'jquery' , 'js' )}),
572
575
573
- (url_prefix + r'/_static/css/(.*)' , tornado .web .StaticFileHandler ,
576
+ (url_prefix + r'/_static/css/(.*)' ,
577
+ tornado .web .StaticFileHandler ,
574
578
{'path' : os .path .join (self ._mpl_dirs ['web_backend' ], 'css' )}),
575
579
576
580
# An MPL favicon
@@ -655,6 +659,7 @@ def start(cls):
655
659
656
660
def ipython_inline_display (figure ):
657
661
import matplotlib ._pylab_helpers as pylab_helpers
662
+ import tornado .template
658
663
659
664
WebAggApplication .initialize ()
660
665
if not server_thread .is_alive ():
@@ -666,7 +671,6 @@ def ipython_inline_display(figure):
666
671
tpl = fd .read ()
667
672
668
673
fignum = figure .number
669
- manager = pylab_helpers .Gcf .get_fig_manager (fignum )
670
674
671
675
t = tornado .template .Template (tpl )
672
676
return t .generate (
0 commit comments