connect toggle for time diff plugin

This commit is contained in:
2022-04-24 09:25:20 +02:00
parent 297f67b9b5
commit 4fbb7ac712
4 changed files with 16 additions and 4 deletions

View File

@@ -9,6 +9,7 @@ class RAction():
def __init__(self,
label: str,
action: Callable[[], None] = None,
after_action: Callable[[], None] = None,
shortcut: str = None,
icon_from_theme: str = None,
icon_file: str = None,
@@ -28,6 +29,7 @@ class RAction():
super(RAction, self).__init__()
self.label = label
self.action = action
self.after_action = after_action
self.shortcut = shortcut
self.icon_from_theme = icon_from_theme
self.icon_file = icon_file
@@ -82,6 +84,7 @@ class RAction():
action.setShortcut(self.shortcut)
if self.action:
action.triggered.connect(self.action)
action.triggered.connect(self.after_action)
if self.checkable:
self._update_check_state()
@@ -99,6 +102,7 @@ class RAction():
button.setShortcut(self.shortcut)
if self.action:
button.pressed.connect(self.action)
button.pressed.connect(self.after_action)
if self.checkable:
button.setChecked(self.checked)
button.setCheckable(self.checkable)

View File

@@ -182,7 +182,8 @@ class FilterWidget(QWidget):
actions = self._zoned_plugin_registry.execute_flat_map("get_filter_widget_actions")
for action in actions:
raction: RAction = action;
raction: RAction = action
raction.after_action = self.filter_changed
button = raction.to_qpushbutton(menu)
menu.addWidget(button)
return menu

View File

@@ -11,8 +11,12 @@ class TimeDiffPreProcessLinesHook(PreProcessLinesHook):
super(TimeDiffPreProcessLinesHook, self).__init__()
self.date_pattern = compile(r"\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}([,.]\d{3})")
self.prev_time: Optional[datetime] = None
self.active = False
def pre_process_line(self, line: str, file_io: BinaryIO) -> str:
if not self.active:
return line
time = self._parse_time(line)
if time:
if self.prev_time:
@@ -21,7 +25,7 @@ class TimeDiffPreProcessLinesHook(PreProcessLinesHook):
line_ending = self.parse_line_ending(line)
time_diff_str = self.time_diff_to_str(time_diff)
time_diff_line = f" {time_diff_str}{line_ending}"
time_diff_line = f" {time_diff_str}{line_ending}"
file_io.write(time_diff_line.encode("utf8"))
self.prev_time = time
return line

View File

@@ -4,6 +4,7 @@ from PySide6.QtGui import QIcon
from src.pluginbase import PluginBase
from src.plugins.domain.raction import RAction
from src.plugins.logfile.filterwidget import FilterWidget
from src.plugins.logfile.preprocesslineshook import PreProcessLinesHook
from src.plugins.timediff.time_diff_pre_process_lines_hook import TimeDiffPreProcessLinesHook
from src.i18n import _
@@ -15,6 +16,7 @@ class TimeDiffPlugin(PluginBase):
self.time_diff_state = False
self.time_diff_action = RAction(_(""), lambda: self._toggle_time_diff(),
icon_file="icons/ionicons/stopwatch-outline.svg", checkable=True)
self.time_diff_hook = TimeDiffPreProcessLinesHook()
def copy(self):
return TimeDiffPlugin()
@@ -26,9 +28,10 @@ class TimeDiffPlugin(PluginBase):
def get_pre_process_lines_hook(self) -> Optional[PreProcessLinesHook]:
if self.time_diff_state:
return TimeDiffPreProcessLinesHook()
return None
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