dcs_liberation/qt_ui/windows/notes/QNotesWindow.py
Dan Albert 2a75d14e0e Revert upgrade to pyside6.
This appears to be incompatible with pyinstaller. I get the following
when trying to run the executable generated with pyside6:

```
Traceback (most recent call last):
  File "qt_ui\main.py", line 29, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
  File "qt_ui\windows\QLiberationWindow.py", line 28, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
  File "qt_ui\widgets\map\QLiberationMap.py", line 11, in <module>
ImportError: could not import module 'PySide6.QtPrintSupport'
```
2021-11-21 17:39:43 -08:00

68 lines
2.0 KiB
Python

from PySide2.QtWidgets import (
QDialog,
QPlainTextEdit,
QVBoxLayout,
QHBoxLayout,
QPushButton,
QLabel,
)
from PySide2.QtGui import QTextCursor
from PySide2.QtCore import QTimer
import qt_ui.uiconstants as CONST
from game.game import Game
from time import sleep
class QNotesWindow(QDialog):
def __init__(self, game: Game):
super(QNotesWindow, self).__init__()
self.game = game
self.setWindowTitle("Notes")
self.setWindowIcon(CONST.ICONS["Notes"])
self.setMinimumSize(400, 100)
self.resize(600, 450)
self.vbox = QVBoxLayout()
self.setLayout(self.vbox)
self.vbox.addWidget(
QLabel("Saved notes are available as a page in your kneeboard.")
)
self.textbox = QPlainTextEdit(self)
try:
self.textbox.setPlainText(self.game.notes)
self.textbox.moveCursor(QTextCursor.End)
except AttributeError: # old save may not have game.notes
pass
self.textbox.move(10, 10)
self.textbox.resize(600, 450)
self.textbox.setStyleSheet("background: #1D2731;")
self.vbox.addWidget(self.textbox)
self.button_row = QHBoxLayout()
self.vbox.addLayout(self.button_row)
self.clear_button = QPushButton(self)
self.clear_button.setText("CLEAR")
self.clear_button.setProperty("style", "btn-primary")
self.clear_button.clicked.connect(self.clearNotes)
self.button_row.addWidget(self.clear_button)
self.save_button = QPushButton(self)
self.save_button.setText("SAVE")
self.save_button.setProperty("style", "btn-success")
self.save_button.clicked.connect(self.saveNotes)
self.button_row.addWidget(self.save_button)
def clearNotes(self) -> None:
self.textbox.setPlainText("")
def saveNotes(self) -> None:
self.game.notes = self.textbox.toPlainText()
self.save_button.setText("SAVED")
QTimer.singleShot(5000, lambda: self.save_button.setText("SAVE"))