@@ -117,8 +117,43 @@ def _handle_key(key):
117117 return key
118118
119119
120+ class TimerTornado (backend_bases .TimerBase ):
121+ def __init__ (self , * args , ** kwargs ):
122+ self ._timer = None
123+ super ().__init__ (* args , ** kwargs )
124+
125+ def _timer_start (self ):
126+ self ._timer_stop ()
127+ if self ._single :
128+ ioloop = tornado .ioloop .IOLoop .instance ()
129+ self ._timer = ioloop .add_timeout (
130+ datetime .timedelta (milliseconds = self .interval ),
131+ self ._on_timer )
132+ else :
133+ self ._timer = tornado .ioloop .PeriodicCallback (
134+ self ._on_timer ,
135+ max (self .interval , 1e-6 ))
136+ self ._timer .start ()
137+
138+ def _timer_stop (self ):
139+ if self ._timer is None :
140+ return
141+ elif self ._single :
142+ ioloop = tornado .ioloop .IOLoop .instance ()
143+ ioloop .remove_timeout (self ._timer )
144+ else :
145+ self ._timer .stop ()
146+ self ._timer = None
147+
148+ def _timer_set_interval (self ):
149+ # Only stop and restart it if the timer has already been started
150+ if self ._timer is not None :
151+ self ._timer_stop ()
152+ self ._timer_start ()
153+
154+
120155class FigureCanvasWebAggCore (backend_agg .FigureCanvasAgg ):
121- supports_blit = True
156+ _timer_cls = TimerTornado
122157
123158 def __init__ (self , * args , ** kwargs ):
124159 super ().__init__ (* args , ** kwargs )
@@ -478,8 +513,7 @@ def get_javascript(cls, stream=None):
478513 for filetype , ext in sorted (FigureCanvasWebAggCore .
479514 get_supported_filetypes_grouped ().
480515 items ()):
481- if ext [0 ] != 'pgf' : # pgf does not support BytesIO
482- extensions .append (ext [0 ])
516+ extensions .append (ext [0 ])
483517 output .write ("mpl.extensions = {0};\n \n " .format (
484518 json .dumps (extensions )))
485519
@@ -499,41 +533,6 @@ def _send_event(self, event_type, **kwargs):
499533 s .send_json (payload )
500534
501535
502- class TimerTornado (backend_bases .TimerBase ):
503- def __init__ (self , * args , ** kwargs ):
504- self ._timer = None
505- super ().__init__ (* args , ** kwargs )
506-
507- def _timer_start (self ):
508- self ._timer_stop ()
509- if self ._single :
510- ioloop = tornado .ioloop .IOLoop .instance ()
511- self ._timer = ioloop .add_timeout (
512- datetime .timedelta (milliseconds = self .interval ),
513- self ._on_timer )
514- else :
515- self ._timer = tornado .ioloop .PeriodicCallback (
516- self ._on_timer ,
517- max (self .interval , 1e-6 ))
518- self ._timer .start ()
519-
520- def _timer_stop (self ):
521- if self ._timer is None :
522- return
523- elif self ._single :
524- ioloop = tornado .ioloop .IOLoop .instance ()
525- ioloop .remove_timeout (self ._timer )
526- else :
527- self ._timer .stop ()
528- self ._timer = None
529-
530- def _timer_set_interval (self ):
531- # Only stop and restart it if the timer has already been started
532- if self ._timer is not None :
533- self ._timer_stop ()
534- self ._timer_start ()
535-
536-
537536@_Backend .export
538537class _BackendWebAggCoreAgg (_Backend ):
539538 FigureCanvas = FigureCanvasWebAggCore
0 commit comments