-
Notifications
You must be signed in to change notification settings - Fork 0
/
recordwindow.py
49 lines (32 loc) · 1.24 KB
/
recordwindow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from PySide6.QtCore import QEvent
from PySide6.QtWidgets import QListWidgetItem, QMessageBox, QWidget, QApplication
from core import TesseractEngine
from recordsui import Ui_recordForm
class RecordWindow(QWidget, Ui_recordForm):
def __init__(self, engine: TesseractEngine):
super().__init__()
self._engine = engine
self.setupUi(self)
self.copy.clicked.connect(self.copyClipboard)
self._buf = []
self.update_records()
def changeEvent(self, event: QEvent):
if event.type() == QEvent.ActivationChange and self.isActiveWindow():
self.updateRecordsIfRequired()
def show(self) -> None:
self.update_records()
super().show()
def update_records(self):
self.records.clear()
self._buf = list(self._engine.records)
for record in self._engine.records:
self.records.addItem(record)
def updateRecordsIfRequired(self):
if self._buf != self._engine.records:
self.update_records()
def copyClipboard(self):
self.updateRecordsIfRequired()
selected = self.records.selectedItems()
if len(selected):
text = selected[0].text()
QApplication.clipboard().setText(text)