Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit55b7d30

Browse files
committed
Correctly go through property setter when init'ing Timer interval.
The setter casts the interval to an int, which is required at least bythe tk backend.This caught a bug in the wx timer, where just setting the interval wouldstart the timer. Fixed that.
1 parent53faed9 commit55b7d30

File tree

8 files changed

+22
-12
lines changed

8 files changed

+22
-12
lines changed

‎doc/api/api_changes_3.3/behaviour.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,8 @@ explicitly pass a "%1.2f" as the *valfmt* parameter to `.Slider`.
176176
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
177177
All the functionality of ``CustomCell`` has been moved to its base class
178178
`~.table.Cell`.
179+
180+
wx Timer interval
181+
~~~~~~~~~~~~~~~~~
182+
Setting the timer interval on a not-yet-started ``TimerWx`` won't start it
183+
anymore.

‎lib/matplotlib/backend_bases.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,10 +1059,9 @@ def __init__(self, interval=None, callbacks=None):
10591059
`remove_callback` can be used.
10601060
"""
10611061
self.callbacks= []ifcallbacksisNoneelsecallbacks.copy()
1062-
self._interval=1000ifintervalisNoneelseinterval
1063-
self._single=False
1064-
# Default attribute for holding the GUI-specific timer object
1065-
self._timer=None
1062+
# Set .interval and not ._interval to go through the property setter.
1063+
self.interval=1000ifintervalisNoneelseinterval
1064+
self.single_shot=False
10661065

10671066
def__del__(self):
10681067
"""Need to stop timer and possibly disconnect timer."""

‎lib/matplotlib/backends/_backend_tk.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ class TimerTk(TimerBase):
8282
"""Subclass of `backend_bases.TimerBase` using Tk timer events."""
8383

8484
def__init__(self,parent,*args,**kwargs):
85+
self._timer=None
8586
TimerBase.__init__(self,*args,**kwargs)
8687
self.parent=parent
87-
self._timer=None
8888

8989
def_timer_start(self):
9090
self._timer_stop()
@@ -97,7 +97,6 @@ def _timer_stop(self):
9797

9898
def_on_timer(self):
9999
TimerBase._on_timer(self)
100-
101100
# Tk after() is only a single shot, so we need to add code here to
102101
# reset the timer if we're not operating in single shot mode. However,
103102
# if _timer is None, this means that _timer_stop has been called; so

‎lib/matplotlib/backends/backend_gtk3.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
classTimerGTK3(TimerBase):
5353
"""Subclass of `.TimerBase` using GTK3 timer events."""
5454

55+
def__init__(self,*args,**kwargs):
56+
self._timer=None
57+
TimerBase.__init__(self,*args,**kwargs)
58+
5559
def_timer_start(self):
5660
# Need to stop it, otherwise we potentially leak a timer id that will
5761
# never be stopped.

‎lib/matplotlib/backends/backend_qt5.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,11 @@ class TimerQT(TimerBase):
180180
"""Subclass of `.TimerBase` using QTimer events."""
181181

182182
def__init__(self,*args,**kwargs):
183-
TimerBase.__init__(self,*args,**kwargs)
184183
# Create a new timer and connect the timeout() signal to the
185184
# _on_timer method.
186185
self._timer=QtCore.QTimer()
187186
self._timer.timeout.connect(self._on_timer)
188-
self._timer_set_interval()
187+
TimerBase.__init__(self,*args,**kwargs)
189188

190189
def__del__(self):
191190
# The check for deletedness is needed to avoid an error at animation

‎lib/matplotlib/backends/backend_webagg_core.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,10 @@ def _send_event(self, event_type, **kwargs):
489489

490490

491491
classTimerTornado(backend_bases.TimerBase):
492+
def__init__(self,*args,**kwargs):
493+
self._timer=None
494+
TimerBase.__init__(self,*args,**kwargs)
495+
492496
def_timer_start(self):
493497
self._timer_stop()
494498
ifself._single:
@@ -510,7 +514,6 @@ def _timer_stop(self):
510514
ioloop.remove_timeout(self._timer)
511515
else:
512516
self._timer.stop()
513-
514517
self._timer=None
515518

516519
def_timer_set_interval(self):

‎lib/matplotlib/backends/backend_wx.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ class TimerWx(TimerBase):
7070
"""Subclass of `.TimerBase` using wx.Timer events."""
7171

7272
def__init__(self,*args,**kwargs):
73-
TimerBase.__init__(self,*args,**kwargs)
7473
self._timer=wx.Timer()
7574
self._timer.Notify=self._on_timer
75+
TimerBase.__init__(self,*args,**kwargs)
7676

7777
def_timer_start(self):
7878
self._timer.Start(self._interval,self._single)
@@ -81,7 +81,8 @@ def _timer_stop(self):
8181
self._timer.Stop()
8282

8383
def_timer_set_interval(self):
84-
self._timer_start()
84+
ifself._timer.IsRunning():
85+
self._timer_start()# Restart with new interval.
8586

8687
def_timer_set_single_shot(self):
8788
self._timer.Start()

‎lib/matplotlib/tests/test_backends_interactive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def check_alt_backend(alt_backend):
114114
115115
ax.plot([0, 1], [2, 3])
116116
117-
timer = fig.canvas.new_timer(1)
117+
timer = fig.canvas.new_timer(1.) # Test that floats are cast to int as needed.
118118
timer.add_callback(FigureCanvasBase.key_press_event, fig.canvas, "q")
119119
# Trigger quitting upon draw.
120120
fig.canvas.mpl_connect("draw_event", lambda event: timer.start())

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp