@@ -44,11 +44,11 @@ def draw_if_interactive():
44
44
class Show (backend_bases .ShowBase ):
45
45
def mainloop (self ):
46
46
WebAggApplication .initialize ()
47
-
47
+
48
48
url = "http://127.0.0.1:{port}{prefix}" .format (
49
49
port = WebAggApplication .port ,
50
50
prefix = WebAggApplication .url_prefix )
51
-
51
+
52
52
if rcParams ['webagg.open_in_browser' ]:
53
53
import webbrowser
54
54
webbrowser .open (url )
@@ -199,7 +199,7 @@ def get_diff_image(self):
199
199
self ._png_is_old = False
200
200
return self ._png_buffer .getvalue ()
201
201
202
- def get_renderer (self ):
202
+ def get_renderer (self , cleared = False ):
203
203
# Mirrors super.get_renderer, but caches the old one
204
204
# so that we can do things such as prodce a diff image
205
205
# in get_diff_image
@@ -211,14 +211,14 @@ def get_renderer(self):
211
211
need_new_renderer = True
212
212
else :
213
213
need_new_renderer = (self ._lastKey != key )
214
-
214
+
215
215
if need_new_renderer :
216
216
self ._renderer = backend_agg .RendererAgg (
217
217
w , h , self .figure .dpi )
218
218
self ._last_renderer = backend_agg .RendererAgg (
219
219
w , h , self .figure .dpi )
220
220
self ._lastKey = key
221
-
221
+
222
222
return self ._renderer
223
223
224
224
def handle_event (self , event ):
@@ -323,16 +323,16 @@ class NavigationToolbar2WebAgg(backend_bases.NavigationToolbar2):
323
323
324
324
def _init_toolbar (self ):
325
325
# Use the standard toolbar items + download button
326
- toolitems = (backend_bases .NavigationToolbar2 .toolitems +
326
+ toolitems = (backend_bases .NavigationToolbar2 .toolitems +
327
327
(('Download' , 'Download plot' , 'download' , 'download' ),))
328
-
328
+
329
329
NavigationToolbar2WebAgg .toolitems = \
330
330
tuple (
331
331
(text , tooltip_text , self ._jquery_icon_classes [image_file ],
332
332
name_of_method )
333
333
for text , tooltip_text , image_file , name_of_method
334
334
in toolitems if image_file in self ._jquery_icon_classes )
335
-
335
+
336
336
self .message = ''
337
337
self .cursor = 0
338
338
@@ -365,7 +365,7 @@ def release_zoom(self, event):
365
365
class WebAggApplication (tornado .web .Application ):
366
366
initialized = False
367
367
started = False
368
-
368
+
369
369
_mpl_data_path = os .path .join (os .path .dirname (os .path .dirname (__file__ )),
370
370
'mpl-data' )
371
371
_mpl_dirs = {'mpl-data' : _mpl_data_path ,
@@ -385,15 +385,15 @@ def __init__(self, application, request, **kwargs):
385
385
self .url_prefix = kwargs .pop ('url_prefix' , '' )
386
386
return tornado .web .RequestHandler .__init__ (self , application ,
387
387
request , ** kwargs )
388
-
388
+
389
389
def get (self , fignum ):
390
390
with open (os .path .join (WebAggApplication ._mpl_dirs ['web_backend' ],
391
391
'single_figure.html' )) as fd :
392
392
tpl = fd .read ()
393
393
394
394
fignum = int (fignum )
395
395
manager = Gcf .get_fig_manager (fignum )
396
-
396
+
397
397
ws_uri = 'ws://{req.host}{prefix}/' .format (req = self .request ,
398
398
prefix = self .url_prefix )
399
399
t = tornado .template .Template (tpl )
@@ -409,23 +409,23 @@ def __init__(self, application, request, **kwargs):
409
409
self .url_prefix = kwargs .pop ('url_prefix' , '' )
410
410
return tornado .web .RequestHandler .__init__ (self , application ,
411
411
request , ** kwargs )
412
-
412
+
413
413
def get (self ):
414
414
with open (os .path .join (WebAggApplication ._mpl_dirs ['web_backend' ],
415
415
'all_figures.html' )) as fd :
416
416
tpl = fd .read ()
417
-
417
+
418
418
ws_uri = 'ws://{req.host}{prefix}/' .format (req = self .request ,
419
419
prefix = self .url_prefix )
420
420
t = tornado .template .Template (tpl )
421
-
421
+
422
422
self .write (t .generate (
423
423
prefix = self .url_prefix ,
424
424
ws_uri = ws_uri ,
425
425
figures = sorted (list (Gcf .figs .items ()), key = lambda item : item [0 ]),
426
- toolitems = NavigationToolbar2WebAgg .toolitems ))
427
-
428
-
426
+ toolitems = NavigationToolbar2WebAgg .toolitems ))
427
+
428
+
429
429
class MPLInterfaceJS (tornado .web .RequestHandler ):
430
430
def get (self , fignum ):
431
431
with open (os .path .join (WebAggApplication ._mpl_dirs ['web_backend' ],
@@ -507,7 +507,7 @@ def __init__(self, url_prefix=''):
507
507
if url_prefix :
508
508
assert url_prefix [0 ] == '/' and url_prefix [- 1 ] != '/' , \
509
509
'url_prefix must start with a "/" and not end with one.'
510
-
510
+
511
511
super (WebAggApplication , self ).__init__ ([
512
512
# Static files for the CSS and JS
513
513
(url_prefix + r'/_static/(.*)' ,
@@ -518,40 +518,40 @@ def __init__(self, url_prefix=''):
518
518
(url_prefix + r'/_static/images/(.*)' ,
519
519
tornado .web .StaticFileHandler ,
520
520
{'path' : self ._mpl_dirs ['images' ]}),
521
-
521
+
522
522
(url_prefix + r'/_static/jquery/css/themes/base/(.*)' ,
523
523
tornado .web .StaticFileHandler ,
524
524
{'path' : os .path .join (self ._mpl_dirs ['web_backend' ], 'jquery' ,
525
525
'css' , 'themes' , 'base' )}),
526
-
526
+
527
527
(url_prefix + r'/_static/jquery/css/themes/base/images/(.*)' ,
528
528
tornado .web .StaticFileHandler ,
529
529
{'path' : os .path .join (self ._mpl_dirs ['web_backend' ], 'jquery' ,
530
530
'css' , 'themes' , 'base' , 'images' )}),
531
-
531
+
532
532
(url_prefix + r'/_static/jquery/js/(.*)' , tornado .web .StaticFileHandler ,
533
533
{'path' : os .path .join (self ._mpl_dirs ['web_backend' ],
534
534
'jquery' , 'js' )}),
535
-
535
+
536
536
(url_prefix + r'/_static/css/(.*)' , tornado .web .StaticFileHandler ,
537
537
{'path' : os .path .join (self ._mpl_dirs ['web_backend' ], 'css' )}),
538
-
538
+
539
539
# An MPL favicon
540
540
(url_prefix + r'/favicon.ico' , self .FavIcon ),
541
-
541
+
542
542
# The page that contains all of the pieces
543
543
(url_prefix + r'/([0-9]+)' , self .SingleFigurePage ,
544
544
{'url_prefix' : url_prefix }),
545
-
545
+
546
546
(url_prefix + r'/([0-9]+)/mpl_interface.js' , self .MPLInterfaceJS ),
547
-
547
+
548
548
# Sends images and events to the browser, and receives
549
549
# events from the browser
550
550
(url_prefix + r'/([0-9]+)/ws' , self .WebSocket ),
551
-
551
+
552
552
# Handles the downloading (i.e., saving) of static images
553
553
(url_prefix + r'/([0-9]+)/download.([a-z]+)' , self .Download ),
554
-
554
+
555
555
# The page that contains all of the figures
556
556
(url_prefix + r'/?' , self .AllFiguresPage ,
557
557
{'url_prefix' : url_prefix }),
0 commit comments