Allow edit of flight's custom name

This commit is contained in:
Raffson 2023-01-02 01:48:07 +01:00
parent e36d51a7c2
commit f4d75a2c6f
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
2 changed files with 23 additions and 7 deletions

View File

@ -336,7 +336,7 @@ class BriefingPage(KneeboardPage):
def write(self, path: Path) -> None: def write(self, path: Path) -> None:
writer = KneeboardPageWriter(dark_theme=self.dark_kneeboard) writer = KneeboardPageWriter(dark_theme=self.dark_kneeboard)
if self.flight.custom_name is not None: if self.flight.custom_name:
custom_name_title = ' ("{}")'.format(self.flight.custom_name) custom_name_title = ' ("{}")'.format(self.flight.custom_name)
else: else:
custom_name_title = "" custom_name_title = ""
@ -500,7 +500,7 @@ class SupportPage(KneeboardPage):
def write(self, path: Path) -> None: def write(self, path: Path) -> None:
writer = KneeboardPageWriter(dark_theme=self.dark_kneeboard) writer = KneeboardPageWriter(dark_theme=self.dark_kneeboard)
if self.flight.custom_name is not None: if self.flight.custom_name:
custom_name_title = ' ("{}")'.format(self.flight.custom_name) custom_name_title = ' ("{}")'.format(self.flight.custom_name)
else: else:
custom_name_title = "" custom_name_title = ""
@ -611,7 +611,7 @@ class SeadTaskPage(KneeboardPage):
def write(self, path: Path) -> None: def write(self, path: Path) -> None:
writer = KneeboardPageWriter(dark_theme=self.dark_kneeboard) writer = KneeboardPageWriter(dark_theme=self.dark_kneeboard)
if self.flight.custom_name is not None: if self.flight.custom_name:
custom_name_title = ' ("{}")'.format(self.flight.custom_name) custom_name_title = ' ("{}")'.format(self.flight.custom_name)
else: else:
custom_name_title = "" custom_name_title = ""
@ -653,7 +653,7 @@ class StrikeTaskPage(KneeboardPage):
def write(self, path: Path) -> None: def write(self, path: Path) -> None:
writer = KneeboardPageWriter(dark_theme=self.dark_kneeboard) writer = KneeboardPageWriter(dark_theme=self.dark_kneeboard)
if self.flight.custom_name is not None: if self.flight.custom_name:
custom_name_title = ' ("{}")'.format(self.flight.custom_name) custom_name_title = ' ("{}")'.format(self.flight.custom_name)
else: else:
custom_name_title = "" custom_name_title = ""

View File

@ -1,5 +1,6 @@
from PySide2.QtWidgets import QGroupBox, QHBoxLayout, QLabel from typing import Optional
from PySide2.QtWidgets import QGroupBox, QVBoxLayout, QLineEdit, QLabel, QMessageBox
from game.ato.flight import Flight from game.ato.flight import Flight
@ -9,7 +10,22 @@ class QFlightCustomName(QGroupBox):
self.flight = flight self.flight = flight
self.layout = QHBoxLayout() self.layout = QVBoxLayout()
self.custom_name_label = QLabel(f"Custom Name: {flight.custom_name}") self.custom_name_label = QLabel(f"Custom Name:")
self.custom_name_input = QLineEdit(flight.custom_name)
self.custom_name_input.textChanged.connect(self.on_change)
self.layout.addWidget(self.custom_name_label) self.layout.addWidget(self.custom_name_label)
self.layout.addWidget(self.custom_name_input)
self.setLayout(self.layout) self.setLayout(self.layout)
def on_change(self) -> None:
error = self.verify_form()
if error is not None:
QMessageBox.critical(self, "Could not edit flight", error)
return
self.flight.custom_name = self.custom_name_input.text()
def verify_form(self) -> Optional[str]:
if "|" in self.custom_name_input.text():
return f"Cannot include | in flight name"
return None