Skip to content

Commit

Permalink
Minor improvements (#27)
Browse files Browse the repository at this point in the history
* Get rid of 'QFileSystemWatcher::removePaths: list is empty' warning.

* Change saving log level from info to debug.

* Enable word wrap to avoid expansion of the editor.

* Use SVG logo.

* Update ruff rules.
  • Loading branch information
Bzero authored Aug 16, 2024
1 parent c3207f6 commit 8409217
Show file tree
Hide file tree
Showing 5 changed files with 454 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ indent-width = 4

[tool.ruff.lint]
select = ["E", "F", "W", "N", "D", "Q", "PL", "R", "C", "B", "C4", "G", "PT", "RET", "RUF", "SIM", "UP"]
ignore = ["D212", "D203", "D400", "RET505", "D100", "PLR0915", "RET504", "PLE1205", "UP015", "PLC2401", "PLR0913"]
ignore = ["D212", "D203", "D400", "RET505", "D100", "PLR0915", "RET504", "PLE1205", "UP015", "PLC2401", "PLR0913", "PT001"]

[tool.ruff.format]
quote-style = "double"
Expand Down
28 changes: 16 additions & 12 deletions typstwriter/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ def load(self, path):
self.isloaded = True
self.changed_on_disk = False

self.filesystemwatcher.removePaths(self.filesystemwatcher.files())
if self.filesystemwatcher.files():
self.filesystemwatcher.removePaths(self.filesystemwatcher.files())
self.filesystemwatcher.addPath(path)

self.savestatechanged.emit(self.issaved)
Expand All @@ -407,7 +408,7 @@ def load(self, path):

def write(self):
"""Write file to disk."""
logger.info("Saving to: {!r}.", self.path)
logger.debug("Saving to: {!r}.", self.path)

try:
with open(self.path, "w") as f:
Expand Down Expand Up @@ -514,24 +515,26 @@ def show_error(self, msg):
"""Show an error page."""
self.edit.deleteLater()

self.gridLayout = QtWidgets.QGridLayout()
self.HLayout = QtWidgets.QHBoxLayout()
self.verticalLayout.addLayout(self.HLayout)

self.label_w = QtWidgets.QLabel()
if QtGui.QIcon.hasThemeIcon("data-warning"):
self.label_w.setPixmap(QtGui.QIcon.fromTheme("data-warning").pixmap(64))
else:
self.label_w.setPixmap(QtGui.QPixmap(util.icon_path("warning.svg")))
self.label_t = QtWidgets.QLabel("<h1>" + msg + "</h1>")

self.gridLayout.addWidget(self.label_w, 0, 1)
self.gridLayout.addWidget(self.label_t, 0, 2)

self.gridLayout.setColumnStretch(0, 1)
self.gridLayout.setColumnStretch(1, 0)
self.gridLayout.setColumnStretch(2, 0)
self.gridLayout.setColumnStretch(3, 1)
self.label_t = QtWidgets.QLabel(msg)
font = self.label_t.font()
font.setPointSize(font.pointSize() * 2)
font.setBold(True)
self.label_t.setFont(font)
self.label_t.setWordWrap(True)

self.verticalLayout.addLayout(self.gridLayout)
self.HLayout.addStretch()
self.HLayout.addWidget(self.label_w, alignment=QtCore.Qt.AlignmentFlag.AlignRight)
self.HLayout.addWidget(self.label_t, alignment=QtCore.Qt.AlignmentFlag.AlignLeft)
self.HLayout.addStretch()


class FileChangedWarning(QtWidgets.QFrame):
Expand All @@ -555,6 +558,7 @@ def __init__(self, path):

self.label_text = QtWidgets.QLabel()
self.label_text.setText(f"The file '{path!r}' has been changed on disk.")
self.label_text.setWordWrap(True)
self.horizontalLayout.addWidget(self.label_text)

icon = QtGui.QIcon.fromTheme(QtGui.QIcon.ViewRefresh, QtGui.QIcon(util.icon_path("reload.svg")))
Expand Down
Binary file removed typstwriter/icons/typstwriter.png
Binary file not shown.
Loading

0 comments on commit 8409217

Please sign in to comment.