# -*- coding: utf-8 -*- import os from PyQt5 import QtGui from PyQt5.QtWidgets import ( QMainWindow, QApplication, QAction, ) from PyQt5.uic import loadUi from view.ListedSubWindow import ListedSubWindow from view.DummyWindow import DummyWindow from view.AboutWindow import AboutWindow from model.Study import Study no_model_action = [ "actionOuvrir_une_tude", "actionR_seau", "actionNouvelle_tude_RubarBE", "actionOuvrir_une_tude_2", "actionImporter_un_jeu_de_donn_es_MAGE", "actionImporter_un_jeu_de_donn_es_RubarBE" ] model_action = [ "actionenregistrer_etude_en_cours", "actionfermer_etude_en_cours", "actionFermer", "actionEnregistrer", "actionEnregistrer_2", "actionEnregistrer_sous", "actionArchiver", ] other_model_action = [ "actionlancer_solveur", ] define_model_action = [ "actionReseau", "actionGeometrie", "actionMaillage", "actionlancer_mailleur_externe", "actionCond_Limites", "actionApp_Lat_raux", "actionDeversements", "actionTroncons", "actionFrottements", "actionOuvrages", ] action = ( no_model_action + model_action + define_model_action ) class ApplicationWindow(QMainWindow, ListedSubWindow): def __init__(self): super(ApplicationWindow, self).__init__() # Model self.model = None # UI self.ui = loadUi( os.path.join(os.path.dirname(__file__), "ui", "MainWindow.ui"), self ) self.init_callback() self.default_style() def enable_actions(self, action:str, enable:bool): self.ui.findChild(QAction, action).setEnabled(enable) def init_callback(self): """ Connect action to callback function. """ actions = { # Menu action "actionA_propos": self.open_about, # ToolBar action "actionquitter_application": self.close, "actionOuvrir_une_tude": self.dummy_model, "actionenregistrer_etude_en_cours": self.open_dummy, "actionfermer_etude_en_cours": self.close_model, "actionlancer_solveur": self.open_dummy, "actioninterrompt_simulation_en_cours": self.open_dummy, "actionafficher_listings_simulation": self.open_dummy, "actionlancer_solveur": self.open_dummy, "actionReseau": lambda: self.open_dummy("Networks"), "actionGeometrie": lambda: self.open_dummy("Geomerty"), "actionMaillage": lambda: self.open_dummy("Maillage"), "actionlancer_mailleur_externe": lambda: self.open_dummy("Lancement mailleur externe"), "actionCond_Limites": lambda: self.open_dummy("Condition Limites"), "actionApp_Lat_raux": lambda: self.open_dummy("Apport Lateraux"), "actionDeversements": lambda: self.open_dummy("Deversement"), "actionTroncons": lambda: self.open_dummy("Tronçons"), "actionFrottements": lambda: self.open_dummy("Frottements"), "actionOuvrages": lambda: self.open_dummy("Ouvrages"), } for action in actions: self.ui.findChild(QAction, action)\ .triggered.connect(actions[action]) def default_style(self): self.update_enable_action() # Maximise window self.showMaximized() ######### # MODEL # ######### def get_model(self): return self.model def set_model(self, model): self.model = model self.update_enable_action() def close_model(self): self.model = None self.update_enable_action() def update_enable_action(self): no_model = self.model is None if no_model: for action in define_model_action + other_model_action: self.enable_actions(action, False) for action in no_model_action: self.enable_actions(action, no_model) for action in model_action: self.enable_actions(action, not no_model) ############# # SUBWINDOW # ############# def open_about(self): self.about = AboutWindow(parent=self) self.about.show() # TODO: Delete me ! ############### # DUMMY STUFF # ############### def open_dummy(self, title="Dummy"): """ Open a dummy dialog window. """ self.dummy = DummyWindow( title=title if type(title) is str else "Dummy", parent=self ) self.dummy.show() self.set_model([1,2,3]) def dummy_model(self): self.set_model([1,2,3])