Commit cc9f853a authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

refactoring: Add PamhyrWidget and continue refacto using PamhyrWindow.

Showing with 62 additions and 78 deletions
+62 -78
...@@ -23,8 +23,6 @@ from datetime import date, time, datetime, timedelta ...@@ -23,8 +23,6 @@ from datetime import date, time, datetime, timedelta
from tools import trace, timer from tools import trace, timer
from View.ASubWindow import ASubMainWindow, AWidget
from View.ListedSubWindow import ListedSubWindow
from View.Tools.PamhyrTable import PamhyrTableModel from View.Tools.PamhyrTable import PamhyrTableModel
from PyQt5.QtCore import ( from PyQt5.QtCore import (
......
...@@ -20,8 +20,8 @@ import logging ...@@ -20,8 +20,8 @@ import logging
from tools import timer, trace from tools import timer, trace
from View.ASubWindow import ASubMainWindow, AWidget from View.Tools.PamhyrWindow import PamhyrWindow
from View.ListedSubWindow import ListedSubWindow from View.Tools.PamhyrWidget import PamhyrWidget
from View.Tools.PamhyrDelegate import PamhyrExTimeDelegate from View.Tools.PamhyrDelegate import PamhyrExTimeDelegate
from PyQt5.QtGui import ( from PyQt5.QtGui import (
...@@ -54,16 +54,16 @@ _translate = QCoreApplication.translate ...@@ -54,16 +54,16 @@ _translate = QCoreApplication.translate
logger = logging.getLogger() logger = logging.getLogger()
class WD50Sigma(AWidget): class WD50Sigma(PamhyrWidget):
_pamhyr_ui = "d50sigma"
d50Changed = pyqtSignal(float) d50Changed = pyqtSignal(float)
sigmaChanged = pyqtSignal(float) sigmaChanged = pyqtSignal(float)
def __init__(self, parent=None): def __init__(self, parent=None):
super(WD50Sigma, self).__init__( super(WD50Sigma, self).__init__(
ui="d50sigma",
parent=parent parent=parent
) )
self.parent = parent
self.spinBox_d50 = self.find(QDoubleSpinBox, "doubleSpinBox_d50") self.spinBox_d50 = self.find(QDoubleSpinBox, "doubleSpinBox_d50")
self.spinBox_sigma = self.find(QDoubleSpinBox, "doubleSpinBox_sigma") self.spinBox_sigma = self.find(QDoubleSpinBox, "doubleSpinBox_sigma")
...@@ -95,46 +95,38 @@ class WD50Sigma(AWidget): ...@@ -95,46 +95,38 @@ class WD50Sigma(AWidget):
def valueChangedSigma(self, value): def valueChangedSigma(self, value):
self.sigmaChanged.emit(value) self.sigmaChanged.emit(value)
class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow): class EditBoundaryConditionWindow(PamhyrWindow):
def __init__(self, title="Edit boundary condition", _pamhyr_ui = "EditBoundaryConditions"
data=None, study=None, parent=None): _pamhyr_name = "Edit Boundary Conditions"
def __init__(self, data=None, study=None, config=None, parent=None):
self._data = data self._data = data
self._study = study
self._title = title
self.compute_title() name = self._pamhyr_name
if self._data is not None:
node_name = (self._data.node.name if self._data.node is not None
else _translate("BoundaryCondition", "Not associate"))
name = (
_translate("Edit boundary condition", self._pamhyr_name) +
f" - {study.name} " +
f" - {self._data.name} ({self._data.id}) " +
f"({long_types[self._data.bctype]} - {node_name})"
)
super(EditBoundaryConditionWindow, self).__init__( super(EditBoundaryConditionWindow, self).__init__(
name=self._title, ui="EditBoundaryConditions", parent=parent title = name,
study = study,
config = config,
parent = parent
) )
self.ui.setWindowTitle(self._title) self.ui.setWindowTitle(self._title)
self.setup_sc()
self.setup_table() self.setup_table()
self.setup_plot() self.setup_plot()
self.setup_data() self.setup_data()
self.setup_connections() self.setup_connections()
def compute_title(self):
if self._data is not None:
node_name = (self._data.node.name if self._data.node is not None
else _translate("BoundaryCondition", "Not associate"))
self._title = (
_translate("Edit boundary condition", self._title) +
f" - {self._study.name} " +
f" - {self._data.name} ({self._data.id}) " +
f"({long_types[self._data.bctype]} - {node_name})"
)
def setup_sc(self):
self._undo_stack = QUndoStack()
self.undo_sc = QShortcut(QKeySequence.Undo, self)
self.redo_sc = QShortcut(QKeySequence.Redo, self)
self.copy_sc = QShortcut(QKeySequence.Copy, self)
self.paste_sc = QShortcut(QKeySequence.Paste, self)
def setup_data(self): def setup_data(self):
self._is_solid = self._data.bctype == "SL" self._is_solid = self._data.bctype == "SL"
...@@ -193,17 +185,11 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow): ...@@ -193,17 +185,11 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
) )
self.plot.draw() self.plot.draw()
def setup_connections(self): def setup_connections(self):
self.find(QAction, "action_add").triggered.connect(self.add) self.find(QAction, "action_add").triggered.connect(self.add)
self.find(QAction, "action_del").triggered.connect(self.delete) self.find(QAction, "action_del").triggered.connect(self.delete)
self.find(QAction, "action_sort").triggered.connect(self.sort) self.find(QAction, "action_sort").triggered.connect(self.sort)
self.undo_sc.activated.connect(self.undo)
self.redo_sc.activated.connect(self.redo)
self.copy_sc.activated.connect(self.copy)
self.paste_sc.activated.connect(self.paste)
self._table.dataChanged.connect(self.update) self._table.dataChanged.connect(self.update)
if self._is_solid: if self._is_solid:
...@@ -252,7 +238,6 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow): ...@@ -252,7 +238,6 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
) )
) )
def add(self): def add(self):
rows = self.index_selected_rows() rows = self.index_selected_rows()
if len(self._data) == 0 or len(rows) == 0: if len(self._data) == 0 or len(rows) == 0:
...@@ -285,7 +270,7 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow): ...@@ -285,7 +270,7 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
self.plot.update() self.plot.update()
def copy(self): def _copy(self):
rows = self.index_selected_rows() rows = self.index_selected_rows()
table = [] table = []
...@@ -297,7 +282,7 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow): ...@@ -297,7 +282,7 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
self.copyTableIntoClipboard(table) self.copyTableIntoClipboard(table)
def paste(self): def _paste(self):
header, data = self.parseClipboardTable() header, data = self.parseClipboardTable()
if len(data) == 0: if len(data) == 0:
...@@ -311,12 +296,12 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow): ...@@ -311,12 +296,12 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
self._table.paste(row, header, data) self._table.paste(row, header, data)
self.plot.update() self.plot.update()
def undo(self): def _undo(self):
self._table.undo() self._table.undo()
self.plot.update() self.plot.update()
self.widget_update() self.widget_update()
def redo(self): def _redo(self):
self._table.redo() self._table.redo()
self.plot.update() self.plot.update()
self.widget_update() self.widget_update()
...@@ -20,8 +20,7 @@ import logging ...@@ -20,8 +20,7 @@ import logging
from tools import trace, timer from tools import trace, timer
from View.ASubWindow import ASubMainWindow from View.Tools.PamhyrWindow import PamhyrWindow
from View.ListedSubWindow import ListedSubWindow
from PyQt5.QtGui import ( from PyQt5.QtGui import (
QKeySequence, QKeySequence,
...@@ -63,32 +62,28 @@ _translate = QCoreApplication.translate ...@@ -63,32 +62,28 @@ _translate = QCoreApplication.translate
logger = logging.getLogger() logger = logging.getLogger()
class BoundaryConditionWindow(ASubMainWindow, ListedSubWindow): class BoundaryConditionWindow(PamhyrWindow):
def __init__(self, title="Boundary conditions", study=None, parent=None): _pamhyr_ui = "BoundaryConditions"
self._title = title + " - " + study.name _pamhyr_name = "Boundary conditions"
def __init__(self, study=None, config=None, parent=None):
name = self._pamhyr_name + " - " + study.name
super(BoundaryConditionWindow, self).__init__( super(BoundaryConditionWindow, self).__init__(
name=title, ui="BoundaryConditions", parent=parent title = name,
study = study,
config = config,
parent=parent
) )
self._study = study
self._bcs = self._study.river.boundary_condition self._bcs = self._study.river.boundary_condition
self.setup_sc()
self.setup_table() self.setup_table()
self.setup_graph() self.setup_graph()
self.setup_connections() self.setup_connections()
self.ui.setWindowTitle(self._title) self.ui.setWindowTitle(self._title)
def setup_sc(self):
self._undo_stack = QUndoStack()
self.undo_sc = QShortcut(QKeySequence.Undo, self)
self.redo_sc = QShortcut(QKeySequence.Redo, self)
self.copy_sc = QShortcut(QKeySequence.Copy, self)
self.paste_sc = QShortcut(QKeySequence.Paste, self)
def setup_table(self): def setup_table(self):
retranslate() retranslate()
self._table = {} self._table = {}
...@@ -141,11 +136,6 @@ class BoundaryConditionWindow(ASubMainWindow, ListedSubWindow): ...@@ -141,11 +136,6 @@ class BoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
self.find(QAction, "action_edit").triggered.connect(self.edit) self.find(QAction, "action_edit").triggered.connect(self.edit)
self.find(QAction, "action_sort").triggered.connect(self.sort) self.find(QAction, "action_sort").triggered.connect(self.sort)
self.undo_sc.activated.connect(self.undo)
self.redo_sc.activated.connect(self.redo)
self.copy_sc.activated.connect(self.copy)
self.paste_sc.activated.connect(self.paste)
def current_tab(self): def current_tab(self):
return self.find(QTabWidget, "tabWidget")\ return self.find(QTabWidget, "tabWidget")\
.currentWidget()\ .currentWidget()\
...@@ -202,17 +192,17 @@ class BoundaryConditionWindow(ASubMainWindow, ListedSubWindow): ...@@ -202,17 +192,17 @@ class BoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
row = self.index_selected_row() row = self.index_selected_row()
self._table[tab].move_down(row) self._table[tab].move_down(row)
def copy(self): def _copy(self):
logger.info("TODO: copy") logger.info("TODO: copy")
def paste(self): def _paste(self):
logger.info("TODO: paste") logger.info("TODO: paste")
def undo(self): def _undo(self):
tab = self.current_tab() tab = self.current_tab()
self._table[tab].undo() self._table[tab].undo()
def redo(self): def _redo(self):
tab = self.current_tab() tab = self.current_tab()
self._table[tab].redo() self._table[tab].redo()
......
...@@ -37,7 +37,8 @@ from PyQt5.QtWidgets import ( ...@@ -37,7 +37,8 @@ from PyQt5.QtWidgets import (
from Model.Geometry.Reach import Reach from Model.Geometry.Reach import Reach
from Model.Geometry.ProfileXYZ import ProfileXYZ from Model.Geometry.ProfileXYZ import ProfileXYZ
from View.ASubWindow import ASubMainWindow from View.Tools.ASubWindow import ASubMainWindow
from View.Geometry.Profile.mainwindow_ui_profile import Ui_MainWindow from View.Geometry.Profile.mainwindow_ui_profile import Ui_MainWindow
from View.Geometry.Profile.Plot import Plot from View.Geometry.Profile.Plot import Plot
from View.Geometry.Profile.Table import * from View.Geometry.Profile.Table import *
......
...@@ -41,8 +41,9 @@ from View.Geometry.PlotXY import PlotXY ...@@ -41,8 +41,9 @@ from View.Geometry.PlotXY import PlotXY
from View.Geometry.PlotKPZ import PlotKPZ from View.Geometry.PlotKPZ import PlotKPZ
from View.Geometry.PlotAC import PlotAC from View.Geometry.PlotAC import PlotAC
from View.ASubWindow import ASubMainWindow, WindowToolKit from View.Tools.ASubWindow import ASubMainWindow, WindowToolKit
from View.ListedSubWindow import ListedSubWindow from View.Tools.ListedSubWindow import ListedSubWindow
from View.Geometry.mainwindow_ui_reach import Ui_MainWindow from View.Geometry.mainwindow_ui_reach import Ui_MainWindow
from View.Geometry.Table import * from View.Geometry.Table import *
from View.Geometry.Profile.Window import ProfileWindow from View.Geometry.Profile.Window import ProfileWindow
......
...@@ -44,8 +44,8 @@ from View.Configure.Window import ConfigureWindow ...@@ -44,8 +44,8 @@ from View.Configure.Window import ConfigureWindow
from View.Study.Window import NewStudyWindow from View.Study.Window import NewStudyWindow
from View.About.Window import AboutWindow from View.About.Window import AboutWindow
from View.Network.Window import NetworkWindow from View.Network.Window import NetworkWindow
# from View.Geometry.Window import GeometryWindow from View.Geometry.Window import GeometryWindow
# from View.BoundaryCondition.Window import BoundaryConditionWindow from View.BoundaryCondition.Window import BoundaryConditionWindow
# from View.LateralContribution.Window import LateralContributionWindow # from View.LateralContribution.Window import LateralContributionWindow
# from View.InitialConditions.Window import InitialConditionsWindow # from View.InitialConditions.Window import InitialConditionsWindow
# from View.Stricklers.Window import StricklersWindow # from View.Stricklers.Window import StricklersWindow
......
...@@ -81,8 +81,6 @@ class PamhyrPlotToolbar(NavigationToolbar2QT): ...@@ -81,8 +81,6 @@ class PamhyrPlotToolbar(NavigationToolbar2QT):
os.path.abspath(f"{file_path}/../ui/ressources/zoom.png") os.path.abspath(f"{file_path}/../ui/ressources/zoom.png")
)) ))
logger.info(os.path.abspath(f"{file_path}/../ui/ressources/zoom.png"))
icons.append(("zoom",icon_zoom)) icons.append(("zoom",icon_zoom))
if "iso" in items: if "iso" in items:
......
...@@ -26,10 +26,21 @@ from PyQt5.QtWidgets import ( ...@@ -26,10 +26,21 @@ from PyQt5.QtWidgets import (
QSpinBox, QTimeEdit, QDateTimeEdit, QItemDelegate, QSpinBox, QTimeEdit, QDateTimeEdit, QItemDelegate,
) )
from View.ASubWindow import AWidget from View.Tools.ASubWindow import AWidget
logger = logging.getLogger() logger = logging.getLogger()
class PamhyrWidget(AWidget):
_pamhyr_ui = ""
_pamhyr_name = "PamhyrWidget"
def __init__(self, parent=None):
super(PamhyrWidget, self).__init__(
ui = self._pamhyr_ui,
parent = parent
)
class PamhyrExtendedTimeEdit(AWidget): class PamhyrExtendedTimeEdit(AWidget):
def __init__(self, parent=None): def __init__(self, parent=None):
super(PamhyrExtendedTimeEdit, self).__init__( super(PamhyrExtendedTimeEdit, self).__init__(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment