mirror of https://gitlab.com/pamhyr/pamhyr2
MainWindow: Add enable and disable feature mechanism.
parent
01fcc36a67
commit
8f87bd7339
|
|
@ -9,12 +9,6 @@ from PyQt5.QtWidgets import (
|
||||||
)
|
)
|
||||||
from PyQt5.uic import loadUi
|
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):
|
class ASubWindow(QDialog):
|
||||||
def __init__(self, name="", ui="dummy", parent=None):
|
def __init__(self, name="", ui="dummy", parent=None):
|
||||||
super(ASubWindow, self).__init__(parent=parent)
|
super(ASubWindow, self).__init__(parent=parent)
|
||||||
|
|
@ -24,6 +18,7 @@ class ASubWindow(QDialog):
|
||||||
)
|
)
|
||||||
self.name = name
|
self.name = name
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
self.parent.sub_win_add(name, self)
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
if not self.parent is None:
|
if not self.parent is None:
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,5 @@ from view.ASubWindow import ASubWindow
|
||||||
|
|
||||||
class AboutWindow(ASubWindow):
|
class AboutWindow(ASubWindow):
|
||||||
def __init__(self, title="About", parent=None):
|
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)
|
self.ui.setWindowTitle(title)
|
||||||
|
|
|
||||||
|
|
@ -7,36 +7,60 @@ from PyQt5.QtWidgets import (
|
||||||
QMainWindow, QApplication, QAction,
|
QMainWindow, QApplication, QAction,
|
||||||
)
|
)
|
||||||
from PyQt5.uic import loadUi
|
from PyQt5.uic import loadUi
|
||||||
|
|
||||||
from view.ListedSubWindow import ListedSubWindow
|
from view.ListedSubWindow import ListedSubWindow
|
||||||
from view.DummyWindow import DummyWindow
|
from view.DummyWindow import DummyWindow
|
||||||
from view.AboutWindow import AboutWindow
|
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):
|
class ApplicationWindow(QMainWindow, ListedSubWindow):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(ApplicationWindow, self).__init__()
|
super(ApplicationWindow, self).__init__()
|
||||||
|
|
||||||
|
# Model
|
||||||
|
self.model = None
|
||||||
|
# UI
|
||||||
self.ui = loadUi(
|
self.ui = loadUi(
|
||||||
os.path.join(os.path.dirname(__file__), "ui", "MainWindow.ui"),
|
os.path.join(os.path.dirname(__file__), "ui", "MainWindow.ui"),
|
||||||
self
|
self
|
||||||
)
|
)
|
||||||
self.showMaximized()
|
|
||||||
self.basic_callback()
|
|
||||||
|
|
||||||
def open_dummy(self, title="Dummy"):
|
self.init_callback()
|
||||||
"""
|
self.default_style()
|
||||||
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()
|
|
||||||
|
|
||||||
def open_about(self):
|
def enable_actions(self, action:str, enable:bool):
|
||||||
self.about = AboutWindow(parent=self)
|
self.ui.findChild(QAction, action).setEnabled(enable)
|
||||||
self.about.show()
|
|
||||||
|
|
||||||
def basic_callback(self):
|
def init_callback(self):
|
||||||
"""
|
"""
|
||||||
Connect action to callback function.
|
Connect action to callback function.
|
||||||
"""
|
"""
|
||||||
|
|
@ -44,10 +68,10 @@ class ApplicationWindow(QMainWindow, ListedSubWindow):
|
||||||
# Menu action
|
# Menu action
|
||||||
"actionA_propos": self.open_about,
|
"actionA_propos": self.open_about,
|
||||||
# ToolBar action
|
# 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,
|
"actionenregistrer_etude_en_cours": self.open_dummy,
|
||||||
"actionfermer_etude_en_cours": self.open_dummy,
|
"actionfermer_etude_en_cours": self.close_model,
|
||||||
"actionquitter_application": self.open_dummy,
|
|
||||||
"actionlancer_solveur": self.open_dummy,
|
"actionlancer_solveur": self.open_dummy,
|
||||||
"actioninterrompt_simulation_en_cours": self.open_dummy,
|
"actioninterrompt_simulation_en_cours": self.open_dummy,
|
||||||
"actionafficher_listings_simulation": self.open_dummy,
|
"actionafficher_listings_simulation": self.open_dummy,
|
||||||
|
|
@ -67,3 +91,63 @@ class ApplicationWindow(QMainWindow, ListedSubWindow):
|
||||||
for action in actions:
|
for action in actions:
|
||||||
self.ui.findChild(QAction, action)\
|
self.ui.findChild(QAction, action)\
|
||||||
.triggered.connect(actions[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])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue