Commit ed719b62 authored by Bram Schoenmakers's avatar Bram Schoenmakers Committed by Jacek Sowiński

Pass a callback function to the alarm instead of PendingAction object

parent 02529bdf
...@@ -324,19 +324,12 @@ class UIApplication(CLIApplicationBase): ...@@ -324,19 +324,12 @@ class UIApplication(CLIApplicationBase):
self.columns.focus_position = p_pos self.columns.focus_position = p_pos
self._blur_commandline() self._blur_commandline()
def _set_alarm(self, p_action): def _set_alarm(self, p_callback):
""" """ Sets alarm to execute p_action specified in 0.5 sec. """
Sets alarm to execute p_action specified in 0.5 sec. self._alarm = self.mainloop.set_alarm_in(0.5, p_callback)
Handle for this alarm is stored as _alarm attribute.
p_action must be an object with 'execute' method.
"""
self._alarm = self.mainloop.set_alarm_in(0.5, p_action.execute)
def _remove_alarm(self): def _remove_alarm(self):
""" """ Removes pending action alarm stored in _alarm attribute. """
Removes pending action alarm stored in _alarm attribute.
"""
self.mainloop.remove_alarm(self._alarm) self.mainloop.remove_alarm(self._alarm)
self._alarm = None self._alarm = None
......
...@@ -29,27 +29,6 @@ def get_execute_signal(p_prefix): ...@@ -29,27 +29,6 @@ def get_execute_signal(p_prefix):
return signal return signal
class PendingAction(object):
"""
Object class for storing TodoListWidget action waiting for execution.
"""
def __init__(self, p_tlw, p_action_str, p_size):
self.todolist = p_tlw
self.action_str = p_action_str
self.size = p_size
def execute(self, p_loop, p_user_data=None):
"""
Executes action stored in action_str attribute from within p_loop
(typically urwid.MainLoop).
Since this method is primarily used as callback for
urwid.MainLoop.set_alarm_in it has to accept 3rd parameter: p_user_data.
"""
self.todolist.resolve_action(self.action_str, self.size)
self.todolist.keystate = None
class TodoListWidget(urwid.LineBox): class TodoListWidget(urwid.LineBox):
def __init__(self, p_view, p_title, p_keymap): def __init__(self, p_view, p_title, p_keymap):
self._view = None self._view = None
...@@ -288,9 +267,14 @@ class TodoListWidget(urwid.LineBox): ...@@ -288,9 +267,14 @@ class TodoListWidget(urwid.LineBox):
""" """
Creates action waiting for execution and forwards it to the mainloop. Creates action waiting for execution and forwards it to the mainloop.
""" """
urwid.emit_signal(self, 'add_pending_action', PendingAction(self, def generate_callback():
p_action, def callback(*args):
p_size)) self.resolve_action(p_action, p_size)
self.keystate = None
return callback
urwid.emit_signal(self, 'add_pending_action', generate_callback())
def _postpone_selected(self, p_pattern, p_mode): def _postpone_selected(self, p_pattern, p_mode):
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment