refactoring: Continue refacto using PamhyrWindow.

This commit is contained in:
Pierre-Antoine Rouby committed 2023-09-25 15:57:53 +02:00
1 parent cc9f853a34
commit 7c4ba10871
4 files changed
+41 -71

No files matched your search

+25 -41
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()