Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8fd2c59

Browse filesBrowse files
martinRenoutacaswell
authored andcommitted
Put back TimerTornado class
1 parent b420b3e commit 8fd2c59
Copy full SHA for 8fd2c59

File tree

Expand file treeCollapse file tree

3 files changed

+44
-2
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+44
-2
lines changed

‎lib/matplotlib/backends/backend_nbagg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_nbagg.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
from matplotlib._pylab_helpers import Gcf
2222
from matplotlib.backend_bases import _Backend, NavigationToolbar2
2323
from matplotlib.backends.backend_webagg_core import (
24-
FigureCanvasWebAggCore, FigureManagerWebAgg, NavigationToolbar2WebAgg
24+
FigureCanvasWebAggCore, FigureManagerWebAgg, NavigationToolbar2WebAgg,
25+
TimerTornado, TimerAsyncio
2526
)
2627

2728

‎lib/matplotlib/backends/backend_webagg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_webagg.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from matplotlib.backend_bases import _Backend
3737
from matplotlib._pylab_helpers import Gcf
3838
from . import backend_webagg_core as core
39+
from .backend_webagg_core import TimerAsyncio, TimerTornado
3940

4041

4142
class ServerThread(threading.Thread):

‎lib/matplotlib/backends/backend_webagg_core.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_webagg_core.py
+41-1Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
# - `backend_webagg.py` contains a concrete implementation of a basic
1111
# application, implemented with asyncio.
1212

13+
import asyncio
14+
import datetime
1315
from io import BytesIO, StringIO
1416
import json
1517
import logging
@@ -18,7 +20,6 @@
1820

1921
import numpy as np
2022
from PIL import Image
21-
import asyncio
2223

2324
from matplotlib import _api, backend_bases, backend_tools
2425
from matplotlib.backends import backend_agg
@@ -78,6 +79,45 @@ def _handle_key(key):
7879
return key
7980

8081

82+
class TimerTornado(backend_bases.TimerBase):
83+
def __init__(self, *args, **kwargs):
84+
self._timer = None
85+
super().__init__(*args, **kwargs)
86+
87+
def _timer_start(self):
88+
import tornado
89+
90+
self._timer_stop()
91+
if self._single:
92+
ioloop = tornado.ioloop.IOLoop.instance()
93+
self._timer = ioloop.add_timeout(
94+
datetime.timedelta(milliseconds=self.interval),
95+
self._on_timer)
96+
else:
97+
self._timer = tornado.ioloop.PeriodicCallback(
98+
self._on_timer,
99+
max(self.interval, 1e-6))
100+
self._timer.start()
101+
102+
def _timer_stop(self):
103+
import tornado
104+
105+
if self._timer is None:
106+
return
107+
elif self._single:
108+
ioloop = tornado.ioloop.IOLoop.instance()
109+
ioloop.remove_timeout(self._timer)
110+
else:
111+
self._timer.stop()
112+
self._timer = None
113+
114+
def _timer_set_interval(self):
115+
# Only stop and restart it if the timer has already been started
116+
if self._timer is not None:
117+
self._timer_stop()
118+
self._timer_start()
119+
120+
81121
class TimerAsyncio(backend_bases.TimerBase):
82122
def __init__(self, *args, **kwargs):
83123
self._task = None

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.