connect toggle for time diff plugin
This commit is contained in:
@@ -9,6 +9,7 @@ class RAction():
|
|||||||
def __init__(self,
|
def __init__(self,
|
||||||
label: str,
|
label: str,
|
||||||
action: Callable[[], None] = None,
|
action: Callable[[], None] = None,
|
||||||
|
after_action: Callable[[], None] = None,
|
||||||
shortcut: str = None,
|
shortcut: str = None,
|
||||||
icon_from_theme: str = None,
|
icon_from_theme: str = None,
|
||||||
icon_file: str = None,
|
icon_file: str = None,
|
||||||
@@ -28,6 +29,7 @@ class RAction():
|
|||||||
super(RAction, self).__init__()
|
super(RAction, self).__init__()
|
||||||
self.label = label
|
self.label = label
|
||||||
self.action = action
|
self.action = action
|
||||||
|
self.after_action = after_action
|
||||||
self.shortcut = shortcut
|
self.shortcut = shortcut
|
||||||
self.icon_from_theme = icon_from_theme
|
self.icon_from_theme = icon_from_theme
|
||||||
self.icon_file = icon_file
|
self.icon_file = icon_file
|
||||||
@@ -82,6 +84,7 @@ class RAction():
|
|||||||
action.setShortcut(self.shortcut)
|
action.setShortcut(self.shortcut)
|
||||||
if self.action:
|
if self.action:
|
||||||
action.triggered.connect(self.action)
|
action.triggered.connect(self.action)
|
||||||
|
action.triggered.connect(self.after_action)
|
||||||
if self.checkable:
|
if self.checkable:
|
||||||
self._update_check_state()
|
self._update_check_state()
|
||||||
|
|
||||||
@@ -99,6 +102,7 @@ class RAction():
|
|||||||
button.setShortcut(self.shortcut)
|
button.setShortcut(self.shortcut)
|
||||||
if self.action:
|
if self.action:
|
||||||
button.pressed.connect(self.action)
|
button.pressed.connect(self.action)
|
||||||
|
button.pressed.connect(self.after_action)
|
||||||
if self.checkable:
|
if self.checkable:
|
||||||
button.setChecked(self.checked)
|
button.setChecked(self.checked)
|
||||||
button.setCheckable(self.checkable)
|
button.setCheckable(self.checkable)
|
||||||
|
|||||||
@@ -182,7 +182,8 @@ class FilterWidget(QWidget):
|
|||||||
actions = self._zoned_plugin_registry.execute_flat_map("get_filter_widget_actions")
|
actions = self._zoned_plugin_registry.execute_flat_map("get_filter_widget_actions")
|
||||||
|
|
||||||
for action in actions:
|
for action in actions:
|
||||||
raction: RAction = action;
|
raction: RAction = action
|
||||||
|
raction.after_action = self.filter_changed
|
||||||
button = raction.to_qpushbutton(menu)
|
button = raction.to_qpushbutton(menu)
|
||||||
menu.addWidget(button)
|
menu.addWidget(button)
|
||||||
return menu
|
return menu
|
||||||
|
|||||||
@@ -11,8 +11,12 @@ class TimeDiffPreProcessLinesHook(PreProcessLinesHook):
|
|||||||
super(TimeDiffPreProcessLinesHook, self).__init__()
|
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.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.prev_time: Optional[datetime] = None
|
||||||
|
self.active = False
|
||||||
|
|
||||||
def pre_process_line(self, line: str, file_io: BinaryIO) -> str:
|
def pre_process_line(self, line: str, file_io: BinaryIO) -> str:
|
||||||
|
if not self.active:
|
||||||
|
return line
|
||||||
|
|
||||||
time = self._parse_time(line)
|
time = self._parse_time(line)
|
||||||
if time:
|
if time:
|
||||||
if self.prev_time:
|
if self.prev_time:
|
||||||
@@ -21,7 +25,7 @@ class TimeDiffPreProcessLinesHook(PreProcessLinesHook):
|
|||||||
line_ending = self.parse_line_ending(line)
|
line_ending = self.parse_line_ending(line)
|
||||||
time_diff_str = self.time_diff_to_str(time_diff)
|
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"))
|
file_io.write(time_diff_line.encode("utf8"))
|
||||||
self.prev_time = time
|
self.prev_time = time
|
||||||
return line
|
return line
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from PySide6.QtGui import QIcon
|
|||||||
|
|
||||||
from src.pluginbase import PluginBase
|
from src.pluginbase import PluginBase
|
||||||
from src.plugins.domain.raction import RAction
|
from src.plugins.domain.raction import RAction
|
||||||
|
from src.plugins.logfile.filterwidget import FilterWidget
|
||||||
from src.plugins.logfile.preprocesslineshook import PreProcessLinesHook
|
from src.plugins.logfile.preprocesslineshook import PreProcessLinesHook
|
||||||
from src.plugins.timediff.time_diff_pre_process_lines_hook import TimeDiffPreProcessLinesHook
|
from src.plugins.timediff.time_diff_pre_process_lines_hook import TimeDiffPreProcessLinesHook
|
||||||
from src.i18n import _
|
from src.i18n import _
|
||||||
@@ -15,6 +16,7 @@ class TimeDiffPlugin(PluginBase):
|
|||||||
self.time_diff_state = False
|
self.time_diff_state = False
|
||||||
self.time_diff_action = RAction(_(""), lambda: self._toggle_time_diff(),
|
self.time_diff_action = RAction(_(""), lambda: self._toggle_time_diff(),
|
||||||
icon_file="icons/ionicons/stopwatch-outline.svg", checkable=True)
|
icon_file="icons/ionicons/stopwatch-outline.svg", checkable=True)
|
||||||
|
self.time_diff_hook = TimeDiffPreProcessLinesHook()
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
return TimeDiffPlugin()
|
return TimeDiffPlugin()
|
||||||
@@ -26,9 +28,10 @@ class TimeDiffPlugin(PluginBase):
|
|||||||
|
|
||||||
def get_pre_process_lines_hook(self) -> Optional[PreProcessLinesHook]:
|
def get_pre_process_lines_hook(self) -> Optional[PreProcessLinesHook]:
|
||||||
if self.time_diff_state:
|
if self.time_diff_state:
|
||||||
return TimeDiffPreProcessLinesHook()
|
return self.time_diff_hook
|
||||||
return None
|
return self.time_diff_hook
|
||||||
|
|
||||||
def _toggle_time_diff(self):
|
def _toggle_time_diff(self):
|
||||||
self.time_diff_state = not self.time_diff_state
|
self.time_diff_state = not self.time_diff_state
|
||||||
self.time_diff_action.set_checked(self.time_diff_state)
|
self.time_diff_action.set_checked(self.time_diff_state)
|
||||||
|
self.time_diff_hook.active = self.time_diff_state
|
||||||
|
|||||||
Reference in New Issue
Block a user