diff --git a/bigtext.py b/bigtext.py index fbd434d..3b66eac 100644 --- a/bigtext.py +++ b/bigtext.py @@ -81,15 +81,20 @@ class InnerBigText(QWidget): def keyPressEvent(self, e: QKeyEvent) -> None: - lines_to_scroll = math.floor(self.lines_shown()) -1 - if e.key() == Qt.Key.Key_PageUp: - self.scroll_by_lines(-lines_to_scroll) - if e.key() == Qt.Key.Key_PageDown: - self.scroll_by_lines(lines_to_scroll) - if e.key() == 16777235: - self.scroll_by_lines(-3) - if e.key() == 16777237: - self.scroll_by_lines(3) + + print("%s + %s" % (e.keyCombination().keyboardModifiers(), e.key())) + if e.modifiers() == Qt.KeyboardModifier.NoModifier: + lines_to_scroll = math.floor(self.lines_shown()) - 1 + if e.key() == Qt.Key.Key_PageUp: + self.scroll_by_lines(-lines_to_scroll) + if e.key() == Qt.Key.Key_PageDown: + self.scroll_by_lines(lines_to_scroll) + if e.key() == 16777235: + self.scroll_by_lines(-3) + if e.key() == 16777237: + self.scroll_by_lines(3) + if e.modifiers() == Qt.KeyboardModifier.ControlModifier and e.key() == 67: # 67 == 'c' + self.copy_selection() def wheelEvent(self, event: QWheelEvent): direction = 1 if event.angleDelta().y() < 0 else -1 @@ -174,6 +179,13 @@ class InnerBigText(QWidget): current_byte = self.model.byte_count() return current_byte + def copy_selection(self): + if self.selection_highlight.start_byte != self.selection_highlight.end_byte: + start = min(self.selection_highlight.start_byte, self.selection_highlight.end_byte) + end = max(self.selection_highlight.start_byte, self.selection_highlight.end_byte) + selected_text = self.model.read_range(start, end) + cb = QApplication.clipboard() + cb.setText(selected_text) def paintEvent(self, event: QPaintEvent) -> None: painter = QPainter(self) diff --git a/logFileModel.py b/logFileModel.py index fe7d351..6247f52 100644 --- a/logFileModel.py +++ b/logFileModel.py @@ -12,6 +12,13 @@ class LogFileModel: def __init__(self, file): self._file = file + def read_range(self, start_byte: int, end_byte: int): + with self._lock: + with open(self._file, 'rb') as f: + f.seek(start_byte) + bytes = f.read(end_byte - start_byte) + return bytes.decode("utf8", errors="ignore") + def data(self, byte_offset, scroll_lines, lines) -> List[Line]: #print("data(%s, %s, %s)" % (byte_offset, scroll_lines, lines)) lines_before_offset: List[Line] = []