diff --git a/finalcif/gui/plaintextedit.py b/finalcif/gui/plaintextedit.py index f854b0b5..9b38a046 100644 --- a/finalcif/gui/plaintextedit.py +++ b/finalcif/gui/plaintextedit.py @@ -1,12 +1,10 @@ -from contextlib import suppress from enum import IntEnum -from functools import cache +from enum import IntEnum from typing import TYPE_CHECKING -from PyQt5 import QtCore from PyQt5.QtCore import pyqtSignal, Qt, QObject, QEvent, QSize from PyQt5.QtGui import QTextOption, QFontMetrics, QContextMenuEvent, QFont, QColor -from PyQt5.QtWidgets import QPlainTextEdit, QFrame, QApplication, QAbstractScrollArea +from PyQt5.QtWidgets import QPlainTextEdit, QFrame, QAbstractScrollArea from numpy import random from finalcif.gui.edit_button import FloatingButtonWidget @@ -55,7 +53,6 @@ def __str__(self): return self.toPlainText() @property - @cache def fontmetric(self): return QFontMetrics(self.document().defaultFont()) @@ -118,7 +115,9 @@ def setText(self, text: str, color: QColor = None, column: int = None): """ if color: self.setBackground(color) - if self.cif_key in self.to_be_shortened and column == Column.CIF: + if not text: + return + if column == Column.CIF and self.cif_key in self.to_be_shortened: self.setPlainText(f'{text[:300]} [...]') else: self.setPlainText(text) @@ -146,7 +145,7 @@ def enterEvent(self, a0): self.edit_button.update_position() self.edit_button.show() - def leaveEvent(self, a0): + def leaveEvent(self, a0: QEvent) -> None: super().leaveEvent(a0) if self.edit_button and self.column == Column.EDIT: self.edit_button.hide() @@ -227,7 +226,7 @@ def sizeHint(self) -> QSize: if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication, QTableWidget, QTableWidgetItem + from PyQt5.QtWidgets import QApplication, QTableWidget app = QApplication(sys.argv) window = QTableWidget() diff --git a/tests/test_loops.py b/tests/test_loops.py index f75d4cc0..ad90600a 100644 --- a/tests/test_loops.py +++ b/tests/test_loops.py @@ -101,7 +101,6 @@ def setUp(self) -> None: # TODO: make tests where changes file is active: (data / 'examples/1979688-finalcif_changes.cif').unlink(missing_ok=True) self.myapp = AppWindow(file=self.testcif) - self.myapp.hide() # For full screen view self.myapp.ui.LoopsPushButton.click() def tearDown(self) -> None: