bouquin/bouquin/save_dialog.py
Miguel Jacq 3e91f158c3
All checks were successful
CI / test (push) Successful in 4m31s
Lint / test (push) Successful in 1m2s
Trivy / test (push) Successful in 23s
Make Tags and TimeLog optional features that can be switched on/off in Settings (enabled by default)
2025-11-21 08:50:06 +11:00

50 lines
1.3 KiB
Python

from __future__ import annotations
import datetime
from PySide6.QtGui import QFontMetrics
from PySide6.QtWidgets import (
QDialog,
QVBoxLayout,
QLabel,
QLineEdit,
QDialogButtonBox,
)
from . import strings
class SaveDialog(QDialog):
def __init__(
self,
parent=None,
):
"""
Used for explicitly saving a new version of a page.
"""
super().__init__(parent)
self.setWindowTitle(strings._("enter_a_name_for_this_version"))
v = QVBoxLayout(self)
v.addWidget(QLabel(strings._("enter_a_name_for_this_version")))
self.note = QLineEdit()
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
text = strings._("new_version_i_saved_at") + f" {now}"
self.note.setText(text)
v.addWidget(self.note)
# make dialog wide enough for the line edit text
fm = QFontMetrics(self.note.font())
text_width = fm.horizontalAdvance(text) + 20
self.note.setMinimumWidth(text_width)
self.adjustSize()
bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
bb.accepted.connect(self.accept)
bb.rejected.connect(self.reject)
v.addWidget(bb)
def note_text(self) -> str:
return self.note.text()