An error occurred while loading the file. Please try again.
-
Guillaume Blanchy authoredc7c1afb3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Window.py -- Pamhyr
# Copyright (C) 2023 INRAE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# -*- coding: utf-8 -*-
import logging
from tools import trace, timer
from View.ASubWindow import ASubMainWindow
from View.ListedSubWindow import ListedSubWindow
from PyQt5.QtGui import (
QKeySequence,
)
from PyQt5.QtCore import (
Qt, QVariant, QAbstractTableModel,
QCoreApplication, QModelIndex, pyqtSlot,
QRect,
)
from PyQt5.QtWidgets import (
QDialogButtonBox, QPushButton, QLineEdit,
QFileDialog, QTableView, QAbstractItemView,
QUndoStack, QShortcut, QAction, QItemDelegate,
QComboBox, QVBoxLayout, QHeaderView, QTabWidget,
QWidget, QGridLayout,
)
from View.SolverParameters.UndoCommand import *
from View.SolverParameters.Table import TableModel
from View.SolverParameters import translate as tr
from Solver.Solvers import solver_long_name, solver_type_list
_translate = QCoreApplication.translate
logger = logging.getLogger()
class SolverParametersWindow(ASubMainWindow, ListedSubWindow):
def __init__(self, title="Solver parameters", study=None, parent=None):
# Init tanslate dictionary
tr.init()
self._title = title + " - " + study.name
super(SolverParametersWindow, self).__init__(
name=title, ui="SolverParameters", parent=parent
)
self._study = study
self._params = self._study.river.parameters
self.setup_sc()
self.setup_table()
self.setup_connections()
self.ui.setWindowTitle(self._title)
def setup_sc(self):
self._undo_stack = {}
for st in solver_type_list:
self._undo_stack[st] = 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):
self._table = {}
self._tab_widget = self.find(QTabWidget, f"tabWidget")
for st in solver_type_list:
# Create widgets
widget = QWidget()
grid = QGridLayout()
table = QTableView()
widget.setObjectName(f"tab_{st}")
table.setObjectName(f"tableView_{st}")
# Create table model
self._table[st] = TableModel(
data = self._study.river,
undo = self._undo_stack[st],
tab = st,
)
table.setModel(self._table[st])
table.setSelectionBehavior(QAbstractItemView.SelectRows)
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
table.setAlternatingRowColors(True)
# Add table to tab
grid.addWidget(table, 0, 0)
widget.setLayout(grid)
table.setParent(widget)
# Create tab
self._tab_widget.addTab(widget, f"{solver_long_name[st]}")
def setup_connections(self):
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):
return self.find(QTabWidget, "tabWidget")\
.currentWidget()\
.objectName()\
.replace("tab_", "")
def undo(self):
tab = self.current_tab()
self._table[tab].undo()
self._set_current_reach()
def redo(self):
tab = self.current_tab()
self._table[tab].redo()
self._set_current_reach()
def copy(self):
logger.info("TODO: copy")
def paste(self):
logger.info("TODO: paste")