MainWindow: Add enable and disable feature mechanism.

mesh
Pierre-Antoine Rouby 2023-03-09 17:35:29 +01:00
parent 01fcc36a67
commit 8f87bd7339
3 changed files with 123 additions and 44 deletions

View File

@ -9,12 +9,6 @@ from PyQt5.QtWidgets import (
)
from PyQt5.uic import loadUi
# class ASubWindow(QMdiSubWindow):
# def __init__(self, ui="error"):
# super(ASubWindow, self).__init__()
# loadUi(f"ui/{ui}.ui", self)
class ASubWindow(QDialog):
def __init__(self, name="", ui="dummy", parent=None):
super(ASubWindow, self).__init__(parent=parent)
@ -24,6 +18,7 @@ class ASubWindow(QDialog):
)
self.name = name
self.parent = parent
self.parent.sub_win_add(name, self)
def closeEvent(self, event):
if not self.parent is None:

View File

@ -4,5 +4,5 @@ from view.ASubWindow import ASubWindow
class AboutWindow(ASubWindow):
def __init__(self, title="About", parent=None):
super(AboutWindow, self).__init__(ui="about", parent=parent)
super(AboutWindow, self).__init__(name=title, ui="about", parent=parent)
self.ui.setWindowTitle(title)

View File

@ -7,36 +7,60 @@ 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.showMaximized()
self.basic_callback()
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.sub_win_add(title, self.dummy)
self.dummy.show()
self.init_callback()
self.default_style()
def open_about(self):
self.about = AboutWindow(parent=self)
self.about.show()
def enable_actions(self, action:str, enable:bool):
self.ui.findChild(QAction, action).setEnabled(enable)
def basic_callback(self):
def init_callback(self):
"""
Connect action to callback function.
"""
@ -44,10 +68,10 @@ class ApplicationWindow(QMainWindow, ListedSubWindow):
# Menu action
"actionA_propos": self.open_about,
# ToolBar action
"actionOuvrir_une_tude": self.open_dummy,
"actionquitter_application": self.close,
"actionOuvrir_une_tude": self.dummy_model,
"actionenregistrer_etude_en_cours": self.open_dummy,
"actionfermer_etude_en_cours": self.open_dummy,
"actionquitter_application": 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,
@ -67,3 +91,63 @@ class ApplicationWindow(QMainWindow, ListedSubWindow):
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])