Newer
Older
# -*- coding: utf-8 -*-
import os
from PyQt5 import QtGui
from PyQt5.QtWidgets import (
QMainWindow, QApplication, QAction,
from view.ListedSubWindow import ListedSubWindow
from view.DummyWindow import DummyWindow
from view.ConfigureWindow import ConfigureWindow
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, conf=None):
super(ApplicationWindow, self).__init__()
# App Configuration
self.conf = conf
# Model
self.model = None
# UI
self.ui = loadUi(
os.path.join(os.path.dirname(__file__), "ui", "MainWindow_old.ui"),
self.init_callback()
self.default_style()
def enable_actions(self, action:str, enable:bool):
"""Enable of disable an action componant
Args:
action: Action to enable/disable
enable: True to Enable, or False to disable
Returns:
Nothing
"""
self.ui.findChild(QAction, action).setEnabled(enable)
def init_callback(self):
"""Connect action to callback function
Returns:
Nothing
"""
actions = {
# Menu action
"actionA_propos": self.open_about,
"actionConfiguration_de_Pamhyr": self.open_configure,
"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):
"""Set default window style
Returns:
Nothing
"""
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):
"""Update status of action componante
Update status of action componant, enable or disable in
function of model state
Returns:
Nothing
"""
no_model = self.model is None
for action in no_model_action:
self.enable_actions(action, no_model)
for action in define_model_action + other_model_action:
self.enable_actions(action, not no_model)
for action in model_action:
self.enable_actions(action, not no_model)
#############
# SUBWINDOW #
#############
def open_configure(self):
"""Open configure window
Open PamHyr configure window
Returns:
Nothing
"""
self.config = ConfigureWindow(conf=self.conf, parent=self)
self.config.show()
def open_about(self):
"""Open about window
Open a new window with information about PamHyr
Returns:
Nothing
"""
self.about = AboutWindow(parent=self)
self.about.show()
# TODO: Delete me !
###############
# DUMMY STUFF #
###############
def open_dummy(self, title="Dummy"):
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])