Files
BEdit/src/bedit_gui/application.py

70 lines
2.5 KiB
Python

from __future__ import annotations
import sys
import argparse
from PySide6.QtWidgets import QApplication
from bedit_gui.controllers.clipboard_controller import ClipboardController, DocumentTreeClipboardHandler, TextClipboardHandler
from bedit_gui.controllers.document_controller import DocumentController
from bedit_gui.controllers.log_controller import LogController
from bedit_gui.controllers.settings_controller import SettingsController
from bedit_gui.controllers.simulation_settings_controller import SimulationSettingsController
from bedit_gui.controllers.simulation_controller import SimulationController
from bedit_gui.controllers.undo_controller import UndoController
from bedit_gui.controllers.view_menu_controller import ViewMenuController
from bedit_gui.controllers.window_state_controller import WindowStateController
from bedit_gui.controllers.document_tree_controller import DocumentTreeController
from bedit_gui.documents import Document
from bedit_gui.services.application_settings import ApplicationSettings
from bedit_gui.services.clipboard import ClipboardService
from bedit_gui.views.main_window import MainWindow
def parse_arguments():
parser = argparse.ArgumentParser(exit_on_error=False)
parser.add_argument(
"-f", "--file", type=str, help="Path to a file to open", default=None, required=False
)
return parser.parse_args()
def main() -> int:
try:
args = parse_arguments()
except argparse.ArgumentError as e:
print(e.message)
return 1
app = QApplication(sys.argv)
app.setOrganizationName("BEdit")
app.setApplicationName("BEdit")
settings = ApplicationSettings()
document = Document(app)
window = MainWindow()
LogController(window, settings.log_level)
DocumentController(document, window)
SettingsController(window, settings)
SimulationSettingsController(document, window)
SimulationController(document, window)
UndoController(document, window)
ViewMenuController(window)
document_tree_controller = DocumentTreeController(document, window)
clipboard = ClipboardService(app)
ClipboardController(window, clipboard, [TextClipboardHandler(clipboard), DocumentTreeClipboardHandler(document, window.ui.documentTree, document_tree_controller.model, clipboard)])
window_state_controller = WindowStateController(app, window)
window_state_controller.restore()
if args.file:
document.open(args.file)
else:
document.new()
window.showMaximized()
return app.exec()