copy to clipboard for ascii text
Non ascii does not work yet. Code does not handle multi-byte characters.
This commit is contained in:
12
bigtext.py
12
bigtext.py
@@ -81,6 +81,9 @@ class InnerBigText(QWidget):
|
||||
|
||||
|
||||
def keyPressEvent(self, e: QKeyEvent) -> None:
|
||||
|
||||
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)
|
||||
@@ -90,6 +93,8 @@ class InnerBigText(QWidget):
|
||||
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)
|
||||
|
||||
@@ -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] = []
|
||||
|
||||
Reference in New Issue
Block a user