Fix timers not being replaced

This commit is contained in:
Kovid Goyal 2017-08-27 20:57:38 +05:30
parent 29b16d0856
commit 40254625d9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 19 additions and 2 deletions

View File

@ -24,7 +24,7 @@ from .constants import (
from .fast_data_types import (
GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GLFW_CURSOR, GLFW_CURSOR_HIDDEN,
GLFW_CURSOR_NORMAL, GLFW_MOUSE_BUTTON_1, GLFW_PRESS, GLFW_REPEAT,
drain_read, glBlendFunc, glfw_post_empty_event, glViewport, Timers
drain_read, glBlendFunc, glfw_post_empty_event, glViewport, Timers as _Timers
)
from .fonts.render import set_font_family
from .keys import (
@ -39,6 +39,23 @@ if isosx:
from .fast_data_types import cocoa_update_title
class Timers(_Timers):
def __init__(self):
_Timers.__init__(self)
self.timer_hash = {}
def add(self, delay, timer, *args):
# Needed because bound methods are recreated on every access
timer = self.timer_hash.setdefault(timer, timer)
return _Timers.add(self, delay, timer) if args else _Timers.add(self, delay, timer, args)
def remove(self, timer):
# Needed because bound methods are recreated on every access
timer = self.timer_hash.setdefault(timer, timer)
return _Timers.remove_event(self, timer)
def conditional_run(w, i):
if w is None or not w.destroyed:
next(i, None)

View File

@ -201,7 +201,7 @@ PyTypeObject Timers_Type = {
.tp_name = "fast_data_types.Timers",
.tp_basicsize = sizeof(Timers),
.tp_dealloc = (destructor)dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_doc = "Timers",
.tp_methods = methods,
.tp_new = new,