copy to clipboard for ascii text
Non ascii does not work yet. Code does not handle multi-byte characters.
This commit is contained in:
14
bigtext.py
14
bigtext.py
@@ -81,7 +81,10 @@ class InnerBigText(QWidget):
|
|||||||
|
|
||||||
|
|
||||||
def keyPressEvent(self, e: QKeyEvent) -> None:
|
def keyPressEvent(self, e: QKeyEvent) -> None:
|
||||||
lines_to_scroll = math.floor(self.lines_shown()) -1
|
|
||||||
|
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:
|
if e.key() == Qt.Key.Key_PageUp:
|
||||||
self.scroll_by_lines(-lines_to_scroll)
|
self.scroll_by_lines(-lines_to_scroll)
|
||||||
if e.key() == Qt.Key.Key_PageDown:
|
if e.key() == Qt.Key.Key_PageDown:
|
||||||
@@ -90,6 +93,8 @@ class InnerBigText(QWidget):
|
|||||||
self.scroll_by_lines(-3)
|
self.scroll_by_lines(-3)
|
||||||
if e.key() == 16777237:
|
if e.key() == 16777237:
|
||||||
self.scroll_by_lines(3)
|
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):
|
def wheelEvent(self, event: QWheelEvent):
|
||||||
direction = 1 if event.angleDelta().y() < 0 else -1
|
direction = 1 if event.angleDelta().y() < 0 else -1
|
||||||
@@ -174,6 +179,13 @@ class InnerBigText(QWidget):
|
|||||||
current_byte = self.model.byte_count()
|
current_byte = self.model.byte_count()
|
||||||
return current_byte
|
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:
|
def paintEvent(self, event: QPaintEvent) -> None:
|
||||||
painter = QPainter(self)
|
painter = QPainter(self)
|
||||||
|
|||||||
@@ -12,6 +12,13 @@ class LogFileModel:
|
|||||||
def __init__(self, file):
|
def __init__(self, file):
|
||||||
self._file = 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]:
|
def data(self, byte_offset, scroll_lines, lines) -> List[Line]:
|
||||||
#print("data(%s, %s, %s)" % (byte_offset, scroll_lines, lines))
|
#print("data(%s, %s, %s)" % (byte_offset, scroll_lines, lines))
|
||||||
lines_before_offset: List[Line] = []
|
lines_before_offset: List[Line] = []
|
||||||
|
|||||||
Reference in New Issue
Block a user