from typing import Optional from src.pluginbase import PluginBase from src.plugins.domain.raction import RAction from src.plugins.logfile.preprocesslineshook import PreProcessLinesHook from src.plugins.timediff.time_diff_pre_process_lines_hook import TimeDiffPreProcessLinesHook class TimeDiffPlugin(PluginBase): def __init__(self): super(TimeDiffPlugin, self).__init__() self.time_diff_state = False self.time_diff_action = RAction("", lambda: self._toggle_time_diff(), icon_file="icons/myicons/stopwatch.svg", checkable=True) self.time_diff_hook = TimeDiffPreProcessLinesHook() def copy(self): return TimeDiffPlugin() def get_filter_widget_actions(self) -> [RAction]: return [ self.time_diff_action ] def get_pre_process_lines_hook(self) -> Optional[PreProcessLinesHook]: if self.time_diff_state: return self.time_diff_hook return self.time_diff_hook def _toggle_time_diff(self): self.time_diff_state = not self.time_diff_state self.time_diff_action.set_checked(self.time_diff_state) self.time_diff_hook.active = self.time_diff_state