refactoring: Continue refacto using PamhyrWindow.

setup.py
Pierre-Antoine Rouby 2023-09-25 15:57:28 +02:00
parent cc9f853a34
commit 7c4ba10871
4 changed files with 41 additions and 71 deletions

View File

@ -22,8 +22,6 @@ from datetime import date, time, datetime, timedelta
from tools import trace, timer
from View.ASubWindow import ASubMainWindow, AWidget
from View.ListedSubWindow import ListedSubWindow
from View.Tools.PamhyrTable import PamhyrTableModel
from PyQt5.QtCore import (

View File

@ -18,8 +18,7 @@
from tools import timer, trace
from View.ASubWindow import ASubMainWindow
from View.ListedSubWindow import ListedSubWindow
from View.Tools.PamhyrWindow import PamhyrWindow
from View.Tools.PamhyrDelegate import PamhyrExTimeDelegate
from PyQt5.QtGui import (
@ -47,44 +46,36 @@ from View.LateralContribution.Edit.Plot import Plot
_translate = QCoreApplication.translate
class EditLateralContributionWindow(ASubMainWindow, ListedSubWindow):
def __init__(self, title="Edit lateral contribution",
data=None, study=None, parent=None):
class EditLateralContributionWindow(PamhyrWindow):
_pamhyr_ui = "EditLateralContribution"
_pamhyr_name = "Edit lateral contribution"
def __init__(self, data=None,
study=None, config=None,
parent=None):
self._data = data
self._study = study
self._title = title
self.compute_title()
super(EditLateralContributionWindow, self).__init__(
name=title, ui="EditLateralContribution", parent=parent
)
self.ui.setWindowTitle(self._title)
self.setup_sc()
self.setup_table()
self.setup_plot()
self.setup_connections()
def compute_title(self):
name = self._pamhyr_name
if self._data is not None:
edge_name = (self._data.edge.name if self._data.edge is not None
else _translate("LateralContribution", "Not associate"))
self._title = (
_translate("Edit lateral contribution", self._title) +
f" - {self._study.name} " +
name = (
_translate("Edit lateral contribution", self._pamhyr_name) +
f" - {study.name} " +
f" - {self._data.name} ({self._data.id}) " +
f"({long_types[self._data.lctype]} - {edge_name})"
)
def setup_sc(self):
self._undo_stack = QUndoStack()
super(EditLateralContributionWindow, self).__init__(
title = name,
study = study,
config = config,
parent = parent
)
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)
self.setup_table()
self.setup_plot()
self.setup_connections()
def setup_table(self):
retranslate()
@ -133,17 +124,11 @@ class EditLateralContributionWindow(ASubMainWindow, ListedSubWindow):
)
self.plot.draw()
def setup_connections(self):
self.find(QAction, "action_add").triggered.connect(self.add)
self.find(QAction, "action_del").triggered.connect(self.delete)
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)
def update(self):
@ -199,8 +184,7 @@ class EditLateralContributionWindow(ASubMainWindow, ListedSubWindow):
self._table.move_down(row)
self.plot.update()
def copy(self):
def _copy(self):
rows = self.index_selected_rows()
table = []
@ -212,7 +196,7 @@ class EditLateralContributionWindow(ASubMainWindow, ListedSubWindow):
self.copyTableIntoClipboard(table)
def paste(self):
def _paste(self):
header, data = self.parseClipboardTable()
if len(data) == 0:
@ -226,10 +210,10 @@ class EditLateralContributionWindow(ASubMainWindow, ListedSubWindow):
self._table.paste(row, header, data)
self.plot.update()
def undo(self):
def _undo(self):
self._table.undo()
self.plot.update()
def redo(self):
def _redo(self):
self._table.redo()
self.plot.update()

View File

@ -20,8 +20,7 @@ import logging
from tools import trace, timer
from View.ASubWindow import ASubMainWindow
from View.ListedSubWindow import ListedSubWindow
from View.Tools.PamhyrWindow import PamhyrWindow
from PyQt5.QtGui import (
QKeySequence,
@ -66,32 +65,26 @@ _translate = QCoreApplication.translate
logger = logging.getLogger()
class LateralContributionWindow(ASubMainWindow, ListedSubWindow):
def __init__(self, title="Lateral contribution", study=None, parent=None):
self._title = title + " - " + study.name
class LateralContributionWindow(PamhyrWindow):
_pamhyr_ui = "LateralContributions"
_pamhyr_name = "Lateral contribution"
def __init__(self, study=None, config=None, parent=None):
name = self._pamhyr_name + " - " + study.name
super(LateralContributionWindow, self).__init__(
name=title, ui="LateralContributions", parent=parent
title = name,
study = study,
config = config,
parent=parent
)
self._study = study
self._lcs = self._study.river.lateral_contribution
self.setup_sc()
self.setup_table()
self.setup_graph()
self.setup_connections()
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):
retranslate()
self._table = {}
@ -146,11 +139,6 @@ class LateralContributionWindow(ASubMainWindow, ListedSubWindow):
self.find(QAction, "action_edit").triggered.connect(self.edit)
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)
for t in ["liquid", "solid", "suspenssion"]:
table = self.find(QTableView, f"tableView_{t}")
table.selectionModel()\
@ -247,20 +235,20 @@ class LateralContributionWindow(ASubMainWindow, ListedSubWindow):
self._table[tab].move_down(row)
self._set_current_reach()
def copy(self):
def _copy(self):
logger.info("TODO: copy")
self._set_current_reach()
def paste(self):
def _paste(self):
logger.info("TODO: paste")
self._set_current_reach()
def undo(self):
def _undo(self):
tab = self.current_tab()
self._table[tab].undo()
self._set_current_reach()
def redo(self):
def _redo(self):
tab = self.current_tab()
self._table[tab].redo()
self._set_current_reach()

View File

@ -46,7 +46,7 @@ from View.About.Window import AboutWindow
from View.Network.Window import NetworkWindow
from View.Geometry.Window import GeometryWindow
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.Stricklers.Window import StricklersWindow
# from View.Frictions.Window import FrictionsWindow