Fix timers not being replaced
This commit is contained in:
parent
29b16d0856
commit
40254625d9
@ -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)
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user