2013-04-13 20:33:06 +00:00
|
|
|
"""
|
|
|
|
This plugin adds a message at 00:00 in each of your chat tabs saying that the
|
|
|
|
date has changed.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2011-09-27 17:15:15 +00:00
|
|
|
from gettext import gettext as _
|
2016-06-27 23:10:52 +00:00
|
|
|
from poezio.plugin import BasePlugin
|
2011-09-27 17:15:15 +00:00
|
|
|
import datetime
|
2016-06-27 23:10:52 +00:00
|
|
|
from poezio import tabs
|
|
|
|
from poezio import timed_events
|
2011-09-27 17:15:15 +00:00
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
|
2011-09-27 17:15:15 +00:00
|
|
|
class Plugin(BasePlugin):
|
|
|
|
def init(self):
|
|
|
|
self.schedule_event()
|
|
|
|
|
|
|
|
def cleanup(self):
|
2013-03-08 21:53:35 +00:00
|
|
|
self.api.remove_timed_event(self.next_event)
|
2011-09-27 17:15:15 +00:00
|
|
|
|
|
|
|
def schedule_event(self):
|
2018-08-15 11:13:17 +00:00
|
|
|
day_change = datetime.datetime.combine(datetime.date.today(),
|
|
|
|
datetime.time())
|
2011-09-27 17:15:15 +00:00
|
|
|
day_change += datetime.timedelta(1)
|
|
|
|
self.next_event = timed_events.TimedEvent(day_change, self.day_change)
|
2013-03-08 21:53:35 +00:00
|
|
|
self.api.add_timed_event(self.next_event)
|
2011-09-27 17:15:15 +00:00
|
|
|
|
|
|
|
def day_change(self):
|
2013-04-23 22:15:41 +00:00
|
|
|
msg = _("Day changed to %s") % (datetime.date.today().isoformat())
|
2011-09-27 17:15:15 +00:00
|
|
|
|
|
|
|
for tab in self.core.tabs:
|
2014-07-31 23:26:19 +00:00
|
|
|
if isinstance(tab, tabs.ChatTab):
|
2011-11-07 23:14:44 +00:00
|
|
|
tab.add_message(msg)
|
2011-09-27 17:15:15 +00:00
|
|
|
|
|
|
|
self.core.refresh_window()
|
|
|
|
self.schedule_event()
|