def on_timelog_file_changed(self, monitor, file, other_file, event_type):
# When I edit timelog.txt with vim, I get a series of notifications:
# - Gio.FileMonitorEvent.DELETED
# - Gio.FileMonitorEvent.CREATED
# - Gio.FileMonitorEvent.CHANGED
# - Gio.FileMonitorEvent.CHANGED
# - Gio.FileMonitorEvent.CHANGES_DONE_HINT
# - Gio.FileMonitorEvent.ATTRIBUTE_CHANGED
# So, plan: react to CHANGES_DONE_HINT at once, but in case some
# systems/OSes don't ever send it, react to other events after a
# short delay, so we wouldn't have to reload the file more than
# once.
if event_type == Gio.FileMonitorEvent.CHANGES_DONE_HINT:
self.check_reload()
else:
GLib.timeout_add_seconds(1, self.check_reload)
评论列表
文章目录