time delta for time diff view is changeable
This commit is contained in:
@@ -93,7 +93,7 @@ class RAction():
|
||||
|
||||
return action
|
||||
|
||||
def to_qpushbutton(self, parent: QWidget) -> QPushButton:
|
||||
def to_widget(self, parent: QWidget) -> QPushButton:
|
||||
button = QPushButton(parent)
|
||||
if self.label:
|
||||
button.setText(self.label)
|
||||
|
||||
@@ -204,8 +204,8 @@ class FilterWidget(QWidget):
|
||||
for action in actions:
|
||||
raction: RAction = action
|
||||
raction.after_action = self.filter_changed
|
||||
button = raction.to_qpushbutton(menu)
|
||||
menu.addWidget(button)
|
||||
widget = raction.to_widget(menu)
|
||||
menu.addWidget(widget)
|
||||
return menu
|
||||
|
||||
def _reload_save_queries(self):
|
||||
|
||||
27
src/plugins/timediff/time_diff_menu_action.py
Normal file
27
src/plugins/timediff/time_diff_menu_action.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from PySide6.QtWidgets import QWidget, QPushButton, QLabel, QComboBox, QLineEdit, QSizePolicy
|
||||
from typing import Callable
|
||||
from src.plugins.domain.raction import RAction
|
||||
from src.plugins.timediff.time_diff_menu_widget import TimeDiffMenuWidget
|
||||
from src.plugins.timediff.time_diff_pre_process_lines_hook import TimeDiffPreProcessLinesHook
|
||||
from src.ui.hbox import HBox
|
||||
from src.ui.icon import Icon
|
||||
|
||||
from src.i18n import _
|
||||
|
||||
|
||||
class TimeDiffMenuAction(RAction):
|
||||
|
||||
def __init__(self, action: Callable[[int], None] = None):
|
||||
super(TimeDiffMenuAction, self).__init__("")
|
||||
self.action = action
|
||||
self.time_diff_hook = TimeDiffPreProcessLinesHook()
|
||||
self._widget = TimeDiffMenuWidget(self._triggered)
|
||||
|
||||
def to_widget(self, parent: QWidget) -> QPushButton:
|
||||
return self._widget
|
||||
|
||||
def _triggered(self, active: bool, delta: float):
|
||||
self.time_diff_hook.active = active
|
||||
self.time_diff_hook.delta = delta
|
||||
print(f"time_diff_hook updated: {active} -- {delta}")
|
||||
self.after_action()
|
||||
66
src/plugins/timediff/time_diff_menu_widget.py
Normal file
66
src/plugins/timediff/time_diff_menu_widget.py
Normal file
@@ -0,0 +1,66 @@
|
||||
from PySide6.QtWidgets import QWidget, QPushButton, QLabel, QComboBox, QLineEdit, QSizePolicy, QHBoxLayout
|
||||
from typing import Callable
|
||||
from src.plugins.domain.raction import RAction
|
||||
from src.ui.hbox import HBox
|
||||
from src.ui.icon import Icon
|
||||
|
||||
from src.i18n import _
|
||||
|
||||
|
||||
# noinspection PyBroadException
|
||||
class TimeDiffMenuWidget(QWidget):
|
||||
|
||||
def __init__(self, action: Callable[[bool, float], None] = None):
|
||||
super(TimeDiffMenuWidget, self).__init__()
|
||||
self.action = action
|
||||
self.active = False
|
||||
self.time_value = 1
|
||||
self.time_unit = 0.001
|
||||
|
||||
self.btn = QPushButton(Icon("icons/myicons/stopwatch.svg"), "")
|
||||
self.btn.setSizePolicy(QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Minimum)
|
||||
self.btn.setCheckable(True)
|
||||
|
||||
self.input = QLineEdit("1")
|
||||
self.input.textChanged.connect(self._input_changed)
|
||||
self.input.setSizePolicy(QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Minimum)
|
||||
self.input.setFixedWidth(40)
|
||||
|
||||
self.time_unit_box = QComboBox()
|
||||
self.time_unit_box.setSizePolicy(QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Minimum)
|
||||
self.time_unit_box.currentIndexChanged.connect(self._time_unit_changed)
|
||||
self.time_unit_box.addItem(_("ms"), 0.001)
|
||||
self.time_unit_box.addItem(_("s"), 1)
|
||||
self.time_unit_box.addItem(_("m"), 60)
|
||||
self.time_unit_box.addItem(_("h"), 60 * 60)
|
||||
|
||||
self.btn.pressed.connect(self._toggle)
|
||||
|
||||
self.layout = QHBoxLayout(self)
|
||||
self.layout.setContentsMargins(0, 0, 0, 0)
|
||||
|
||||
self.layout.addWidget(self.btn)
|
||||
self.layout.addWidget(self.input)
|
||||
self.layout.addWidget(self.time_unit_box)
|
||||
|
||||
def _toggle(self):
|
||||
self.active = not self.active
|
||||
self.btn.setChecked(not self.active)
|
||||
# print(f"toggle -> {self.active}")
|
||||
self._trigger_action()
|
||||
|
||||
def _input_changed(self):
|
||||
try:
|
||||
self.time_value = int(self.input.text())
|
||||
# print(f"update time_value {self.time_value}")
|
||||
self._trigger_action()
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
def _time_unit_changed(self, x):
|
||||
self.time_unit = self.time_unit_box.currentData()
|
||||
# print(f"update time_unit {self.time_unit}")
|
||||
self._trigger_action()
|
||||
|
||||
def _trigger_action(self):
|
||||
self.action(self.active, self.time_value * self.time_unit)
|
||||
@@ -12,6 +12,7 @@ class TimeDiffPreProcessLinesHook(PreProcessLinesHook):
|
||||
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
|
||||
self.delta = 1
|
||||
|
||||
def pre_process_line(self, line: str, file_io: BinaryIO) -> str:
|
||||
if not self.active:
|
||||
@@ -21,7 +22,8 @@ class TimeDiffPreProcessLinesHook(PreProcessLinesHook):
|
||||
if time:
|
||||
if self.prev_time:
|
||||
time_diff = time - self.prev_time
|
||||
if time_diff.total_seconds() > 0:
|
||||
# print(f"pre_process_line {self.delta}")
|
||||
if time_diff.total_seconds() > self.delta:
|
||||
line_ending = self.parse_line_ending(line)
|
||||
time_diff_str = self.time_diff_to_str(time_diff)
|
||||
|
||||
|
||||
@@ -2,15 +2,12 @@ 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
|
||||
from src.plugins.timediff.time_diff_menu_action import TimeDiffMenuAction
|
||||
|
||||
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()
|
||||
self.time_diff_action = TimeDiffMenuAction()
|
||||
|
||||
def copy(self):
|
||||
return TimeDiffPlugin()
|
||||
@@ -21,11 +18,4 @@ class TimeDiffPlugin(PluginBase):
|
||||
]
|
||||
|
||||
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
|
||||
return self.time_diff_action.time_diff_hook
|
||||
|
||||
Reference in New Issue
Block a user