1111import random
1212import socket
1313import threading
14- import types
1514
1615import numpy as np
1716
2221import tornado .web
2322import tornado .ioloop
2423import tornado .websocket
25- import tornado .template
2624
2725import matplotlib
2826from matplotlib import rcParams
@@ -57,8 +55,8 @@ def mainloop(self):
5755 WebAggApplication .initialize ()
5856
5957 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 )
6260
6361 if rcParams ['webagg.open_in_browser' ]:
6462 import webbrowser
@@ -308,12 +306,12 @@ def start_event_loop(self, timeout):
308306 backend_bases .FigureCanvasBase .start_event_loop_default (
309307 self , timeout )
310308 start_event_loop .__doc__ = \
311- backend_bases .FigureCanvasBase .start_event_loop_default .__doc__
309+ backend_bases .FigureCanvasBase .start_event_loop_default .__doc__
312310
313311 def stop_event_loop (self ):
314312 backend_bases .FigureCanvasBase .stop_event_loop_default (self )
315313 stop_event_loop .__doc__ = \
316- backend_bases .FigureCanvasBase .stop_event_loop_default .__doc__
314+ backend_bases .FigureCanvasBase .stop_event_loop_default .__doc__
317315
318316
319317class FigureManagerWebAgg (backend_bases .FigureManagerBase ):
@@ -352,26 +350,29 @@ def resize(self, w, h):
352350
353351
354352class 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+ }
363362
364363 def _init_toolbar (self ):
365364 # 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+ )
368369
369370 NavigationToolbar2WebAgg .toolitems = \
370371 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 )
375376
376377 self .message = ''
377378 self .cursor = 0
@@ -432,7 +433,8 @@ def get(self, fignum):
432433
433434 ws_uri = 'ws://{req.host}{prefix}/' .format (req = self .request ,
434435 prefix = self .url_prefix )
435- self .render ('single_figure.html' ,
436+ self .render (
437+ "single_figure.html" ,
436438 prefix = self .url_prefix ,
437439 ws_uri = ws_uri ,
438440 fig_id = fignum ,
@@ -452,22 +454,22 @@ def get(self):
452454 "all_figures.html" ,
453455 prefix = self .url_prefix ,
454456 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 ]),
456459 toolitems = NavigationToolbar2WebAgg .toolitems )
457460
458-
459461 class MPLInterfaceJS (tornado .web .RequestHandler ):
460462 def get (self ):
461463 manager = Gcf .get_fig_manager (1 )
462464 canvas = manager .canvas
463465
464466 self .set_header ('Content-Type' , 'application/javascript' )
465467
466- self .render ("mpl_interface.js" ,
468+ self .render (
469+ "mpl_interface.js" ,
467470 toolitems = NavigationToolbar2WebAgg .toolitems ,
468471 canvas = canvas )
469472
470-
471473 class Download (tornado .web .RequestHandler ):
472474 def get (self , fignum , fmt ):
473475 self .fignum = int (fignum )
@@ -543,7 +545,7 @@ def send_diff_image(self, diff):
543545 def __init__ (self , url_prefix = '' ):
544546 if url_prefix :
545547 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.'
547549
548550 super (WebAggApplication , self ).__init__ ([
549551 # Static files for the CSS and JS
@@ -566,11 +568,13 @@ def __init__(self, url_prefix=''):
566568 {'path' : os .path .join (self ._mpl_dirs ['web_backend' ], 'jquery' ,
567569 'css' , 'themes' , 'base' , 'images' )}),
568570
569- (url_prefix + r'/_static/jquery/js/(.*)' , tornado .web .StaticFileHandler ,
571+ (url_prefix + r'/_static/jquery/js/(.*)' ,
572+ tornado .web .StaticFileHandler ,
570573 {'path' : os .path .join (self ._mpl_dirs ['web_backend' ],
571574 'jquery' , 'js' )}),
572575
573- (url_prefix + r'/_static/css/(.*)' , tornado .web .StaticFileHandler ,
576+ (url_prefix + r'/_static/css/(.*)' ,
577+ tornado .web .StaticFileHandler ,
574578 {'path' : os .path .join (self ._mpl_dirs ['web_backend' ], 'css' )}),
575579
576580 # An MPL favicon
@@ -655,6 +659,7 @@ def start(cls):
655659
656660def ipython_inline_display (figure ):
657661 import matplotlib ._pylab_helpers as pylab_helpers
662+ import tornado .template
658663
659664 WebAggApplication .initialize ()
660665 if not server_thread .is_alive ():
@@ -666,7 +671,6 @@ def ipython_inline_display(figure):
666671 tpl = fd .read ()
667672
668673 fignum = figure .number
669- manager = pylab_helpers .Gcf .get_fig_manager (fignum )
670674
671675 t = tornado .template .Template (tpl )
672676 return t .generate (
0 commit comments