Feat: Add 'Close File' option to menu to unload current file

This commit is contained in:
2025-12-30 21:05:25 +01:00
parent e223917b94
commit 93724da68c

View File

@@ -111,6 +111,12 @@ class MainWindow(QMainWindow):
save_action.triggered.connect(self.save_file) save_action.triggered.connect(self.save_file)
file_menu.addAction(save_action) file_menu.addAction(save_action)
close_action = QAction("Close File", self)
close_action.triggered.connect(self.close_file)
file_menu.addAction(close_action)
file_menu.addSeparator()
exit_action = QAction("Exit", self) exit_action = QAction("Exit", self)
exit_action.triggered.connect(self.close) exit_action.triggered.connect(self.close)
file_menu.addAction(exit_action) file_menu.addAction(exit_action)
@@ -133,6 +139,19 @@ class MainWindow(QMainWindow):
self.canvas.redraw() self.canvas.redraw()
self.canvas.update() self.canvas.update()
def close_file(self):
# Reset everything
self.service = TeletextService()
self.current_page = None
self.populate_list()
self.subpage_combo.clear()
self.page_groups = {}
# Clear canvas
self.canvas.set_page(None)
# Maybe reset text of hex input
self.hex_input.clear()
QMessageBox.information(self, "Closed", "File closed.")
def open_file(self): def open_file(self):
fname, _ = QFileDialog.getOpenFileName(self, "Open T42", "", "Teletext Files (*.t42);;All Files (*)") fname, _ = QFileDialog.getOpenFileName(self, "Open T42", "", "Teletext Files (*.t42);;All Files (*)")
if fname: if fname:
@@ -248,8 +267,8 @@ class MainWindow(QMainWindow):
self.canvas.move_cursor(0, 1) self.canvas.move_cursor(0, 1)
else: else:
# Typing # Typing
# Filter non-printable # Allow wider range of chars for national support
if text and len(text) == 1 and 32 <= ord(text) <= 126: if text and len(text) == 1 and ord(text) >= 32:
self.canvas.handle_input(text) self.canvas.handle_input(text)
elif key == Qt.Key.Key_Backspace: elif key == Qt.Key.Key_Backspace:
# Move back and delete # Move back and delete