add follow tail feature
This commit is contained in:
@@ -18,6 +18,9 @@ class ScaledScrollBar(QScrollBar):
|
||||
code involved. We work around this by converting the python int
|
||||
into a string."""
|
||||
|
||||
scrolled_to_end = Signal(bool)
|
||||
"""Signal emitted when the scroll bar value is set."""
|
||||
|
||||
def __init__(self):
|
||||
super(ScaledScrollBar, self).__init__()
|
||||
self.real_maximum = self.maximum()
|
||||
@@ -46,6 +49,7 @@ class ScaledScrollBar(QScrollBar):
|
||||
super().setMaximum(maximum)
|
||||
|
||||
def _valueChanged(self, value: int):
|
||||
self.scrolled_to_end.emit(value == self.maximum() and value > 0)
|
||||
if self.is_huge:
|
||||
real_value = (value / self.maximum()) * self.real_maximum
|
||||
# print("scaled value changed: %d -> %d (%f)" % (value, real_value, value / self.maximum()))
|
||||
|
||||
@@ -66,10 +66,6 @@ class BigText(QWidget):
|
||||
|
||||
self.model = model
|
||||
|
||||
self.watchdog = FileWatchdogThread(self, model.get_file())
|
||||
QThreadPool.globalInstance().start(self.watchdog)
|
||||
self.trigger_update.connect(self.update)
|
||||
|
||||
self.grid = QGridLayout()
|
||||
self.grid.setContentsMargins(0, 0, 0, 0)
|
||||
self.grid.setHorizontalSpacing(0)
|
||||
@@ -87,11 +83,16 @@ class BigText(QWidget):
|
||||
self.v_scroll_bar = ScaledScrollBar()
|
||||
# self.v_scroll_bar.setPageStep(1)
|
||||
self.v_scroll_bar.scaledValueChanged.connect(self.big_text.v_scroll_event)
|
||||
self.v_scroll_bar.scrolled_to_end.connect(self.big_text.v_scroll_update_follow_tail)
|
||||
|
||||
self.grid.addWidget(self.big_text, 0, 0)
|
||||
self.grid.addWidget(self.h_scroll_bar, 1, 0)
|
||||
self.grid.addWidget(self.v_scroll_bar, 0, 1)
|
||||
|
||||
self.watchdog = FileWatchdogThread(self, model.get_file())
|
||||
QThreadPool.globalInstance().start(self.watchdog)
|
||||
self.trigger_update.connect(self.big_text._file_changed)
|
||||
|
||||
def get_file(self):
|
||||
return self.model.get_file()
|
||||
|
||||
@@ -137,6 +138,8 @@ class InnerBigText(QWidget):
|
||||
self._last_double_click_time = 0
|
||||
self._last_double_click_line_number = -1
|
||||
|
||||
self._follow_tail = False
|
||||
|
||||
self.highlight_selected_text = HighlightRegex(
|
||||
"",
|
||||
is_regex=False,
|
||||
@@ -306,6 +309,10 @@ class InnerBigText(QWidget):
|
||||
self._byte_offset = int(byte_offset)
|
||||
self.update()
|
||||
|
||||
@Slot()
|
||||
def v_scroll_update_follow_tail(self, scrolled_to_end: bool):
|
||||
self._follow_tail = scrolled_to_end
|
||||
|
||||
def update_longest_line(self, length: int):
|
||||
width_in_chars = self.width() / self.char_width
|
||||
# print("width_in_chars: %d" % width_in_chars)
|
||||
@@ -369,7 +376,6 @@ class InnerBigText(QWidget):
|
||||
|
||||
if you_sure.clickedButton() != copy_btn:
|
||||
# abort
|
||||
print("abort")
|
||||
return
|
||||
|
||||
selected_text = self.model.read_range(start, end)
|
||||
@@ -409,7 +415,14 @@ class InnerBigText(QWidget):
|
||||
|
||||
self.highlight_selected_text.set_query("")
|
||||
|
||||
def _file_changed(self):
|
||||
if self._follow_tail:
|
||||
self.scroll_to_byte(self.model.byte_count())
|
||||
self.update()
|
||||
|
||||
def paintEvent(self, event: QPaintEvent) -> None:
|
||||
start_ns = time.process_time_ns()
|
||||
print(f"paint {self.model.get_file()} at {self._byte_offset} with follow_tail={self._follow_tail}")
|
||||
painter = QPainter(self)
|
||||
# font = "Courier New" if sys.platform == 'win32' or sys.platform == 'cygwin' else "Monospace"
|
||||
painter.setFont(QFont("Courier New", self.model.settings.getint_session('general', "font_size")))
|
||||
@@ -458,6 +471,8 @@ class InnerBigText(QWidget):
|
||||
y_line_offset = y_line_offset + self.char_height
|
||||
|
||||
painter.end()
|
||||
end_ns = time.process_time_ns()
|
||||
print(f"paint took {(end_ns - start_ns) / 1000000.0}")
|
||||
|
||||
def draw_highlights(self, highlights: [HighlightedRange], painter: QPainter, y_line_offset: int):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user