ember/ui/main_window.py

54 lines
1.8 KiB
Python

import traceback
from PyQt5.QtWidgets import QMainWindow, QVBoxLayout, QWidget, QApplication, QMessageBox
from PyQt5.QtCore import QTimer
from model import Project
from business import ProjectManager
from ui.project.project_panel import ProjectPanel
from ui.project.new_project_dialog import NewProjectDialog
from ui.welcome.welcome_dialog import WelcomeDialog
class MainWindow(QMainWindow):
def __init__(self, projectManager : ProjectManager):
super().__init__()
self.__projectManager = projectManager
self.setupUi()
QTimer.singleShot(0, self.showWelcomeDialog)
def setupUi(self):
self.projectPanel = ProjectPanel()
layout = QVBoxLayout()
layout.addWidget(self.projectPanel)
cwidget = QWidget()
cwidget.setLayout(layout)
self.setCentralWidget(cwidget)
def showWelcomeDialog(self):
# Show welcome dialog
welcome = WelcomeDialog(self.__projectManager, self)
if welcome.exec() > 0:
if welcome.resultAction == WelcomeDialog.NEW_PROJECT:
self.newProject()
elif welcome.resultAction == WelcomeDialog.OPEN_PROJECT:
self.openProject(welcome.projectToOpen)
def newProject(self):
dialog = NewProjectDialog(self.__projectManager, self)
if dialog.exec() > 0:
self.loadProject(dialog.project)
def openProject(self, projectPath : str = None):
try:
project = self.__projectManager.openProject(projectPath)
except Exception as ex:
print("Failed to open project: ", traceback.format_exc())
QMessageBox.critical(self,
self.tr('An error occurred'),
self.tr('The project could not be open.'))
def loadProject(self, project : Project):
pass