From 40254625d95aef6ae8bcea45ff08f8f14bbbd3ff Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 27 Aug 2017 20:57:38 +0530 Subject: [PATCH] Fix timers not being replaced --- kitty/boss.py | 19 ++++++++++++++++++- kitty/timers.c | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/kitty/boss.py b/kitty/boss.py index 1a5628463..ba5270b2a 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -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) diff --git a/kitty/timers.c b/kitty/timers.c index 7a54a7e41..9b4369ca4 100644 --- a/kitty/timers.c +++ b/kitty/timers.c @@ -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,