@@ -427,22 +427,17 @@ def __init__(self, application, request, **kwargs):
427
427
request , ** kwargs )
428
428
429
429
def get (self , fignum ):
430
- with open (os .path .join (WebAggApplication ._mpl_dirs ['web_backend' ],
431
- 'single_figure.html' )) as fd :
432
- tpl = fd .read ()
433
-
434
430
fignum = int (fignum )
435
431
manager = Gcf .get_fig_manager (fignum )
436
432
437
433
ws_uri = 'ws://{req.host}{prefix}/' .format (req = self .request ,
438
434
prefix = self .url_prefix )
439
- t = tornado .template .Template (tpl )
440
- self .write (t .generate (
435
+ self .render ('single_figure.html' ,
441
436
prefix = self .url_prefix ,
442
437
ws_uri = ws_uri ,
443
438
fig_id = fignum ,
444
439
toolitems = NavigationToolbar2WebAgg .toolitems ,
445
- canvas = manager .canvas ))
440
+ canvas = manager .canvas )
446
441
447
442
class AllFiguresPage (tornado .web .RequestHandler ):
448
443
def __init__ (self , application , request , ** kwargs ):
@@ -451,36 +446,26 @@ def __init__(self, application, request, **kwargs):
451
446
request , ** kwargs )
452
447
453
448
def get (self ):
454
- with open (os .path .join (WebAggApplication ._mpl_dirs ['web_backend' ],
455
- 'all_figures.html' )) as fd :
456
- tpl = fd .read ()
457
-
458
449
ws_uri = 'ws://{req.host}{prefix}/' .format (req = self .request ,
459
450
prefix = self .url_prefix )
460
- t = tornado .template .Template (tpl )
461
-
462
- self .write (t .generate (
451
+ self .render (
452
+ "all_figures.html" ,
463
453
prefix = self .url_prefix ,
464
454
ws_uri = ws_uri ,
465
- figures = sorted (list (Gcf .figs .items ()), key = lambda item : item [0 ]),
466
- toolitems = NavigationToolbar2WebAgg .toolitems ))
455
+ figures = sorted (list (Gcf .figs .items ()), key = lambda item : item [0 ]),
456
+ toolitems = NavigationToolbar2WebAgg .toolitems )
467
457
468
458
469
459
class MPLInterfaceJS (tornado .web .RequestHandler ):
470
460
def get (self ):
471
- with open (os .path .join (WebAggApplication ._mpl_dirs ['web_backend' ],
472
- 'mpl_interface.js' )) as fd :
473
- tpl = fd .read ()
474
-
475
461
manager = Gcf .get_fig_manager (1 )
476
462
canvas = manager .canvas
477
463
478
464
self .set_header ('Content-Type' , 'application/javascript' )
479
465
480
- t = tornado .template .Template (tpl )
481
- self .write (t .generate (
466
+ self .render ("mpl_interface.js" ,
482
467
toolitems = NavigationToolbar2WebAgg .toolitems ,
483
- canvas = canvas ))
468
+ canvas = canvas )
484
469
485
470
486
471
class Download (tornado .web .RequestHandler ):
@@ -602,12 +587,13 @@ def __init__(self, url_prefix=''):
602
587
(url_prefix + r'/([0-9]+)/ws' , self .WebSocket ),
603
588
604
589
# Handles the downloading (i.e., saving) of static images
605
- (url_prefix + r'/([0-9]+)/download.([a-z ]+)' , self .Download ),
590
+ (url_prefix + r'/([0-9]+)/download.([a-z0-9. ]+)' , self .Download ),
606
591
607
592
# The page that contains all of the figures
608
593
(url_prefix + r'/?' , self .AllFiguresPage ,
609
594
{'url_prefix' : url_prefix }),
610
- ])
595
+ ],
596
+ template_path = self ._mpl_dirs ['web_backend' ])
611
597
612
598
@classmethod
613
599
def initialize (cls , url_prefix = '' ):
0 commit comments