An error occurred while loading the file. Please try again.
-
Theophile Terraz authored143f468c
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
146
147
148
149
150
151
152
153
154
155
# UndoCommand.py -- Pamhyr
# Copyright (C) 2023-2024 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 copy import deepcopy
from tools import trace, timer
from PyQt5.QtWidgets import (
QMessageBox, QUndoCommand, QUndoStack,
)
logger = logging.getLogger()
class SetTitleCommand(QUndoCommand):
def __init__(self, outputrk_lst, index, new_value):
QUndoCommand.__init__(self)
self._outputrk_lst = outputrk_lst
self._index = index
self._old = self._outputrk_lst.get(self._index).title
self._new = str(new_value)
def undo(self):
self._outputrk_lst.get(self._index).title = self._old
def redo(self):
self._outputrk_lst.get(self._index).title = self._new
class SetReachCommand(QUndoCommand):
def __init__(self, outputrk_lst, index, reach):
QUndoCommand.__init__(self)
self._outputrk_lst = outputrk_lst
self._index = index
self._old = self._outputrk_lst.get(self._index).reach
self._new = reach.id
def undo(self):
i = self._outputrk_lst.get(self._index)
i.reach = self._old
def redo(self):
i = self._outputrk_lst.get(self._index)
i.reach = self._new
class SetRKCommand(QUndoCommand):
def __init__(self, outputrk_lst, index, rk):
QUndoCommand.__init__(self)
self._outputrk_lst = outputrk_lst
self._index = index
self._old = self._outputrk_lst.get(self._index).rk
self._new = rk
def undo(self):
self._outputrk_lst.get(self._index).rk = self._old
def redo(self):
self._outputrk_lst.get(self._index).rk = self._new
class SetEnabledCommand(QUndoCommand):
def __init__(self, outputrk_lst, index, enabled):
QUndoCommand.__init__(self)
self._outputrk_lst = outputrk_lst
self._index = index
self._old = not enabled
self._new = enabled
def undo(self):
self._outputrk_lst.get(self._index).enabled = self._old
def redo(self):
self._outputrk_lst.get(self._index).enabled = self._new
class AddCommand(QUndoCommand):
def __init__(self, outputrk_lst, index):
QUndoCommand.__init__(self)
self._outputrk_lst = outputrk_lst
self._index = index
self._new = None
def undo(self):
self._outputrk_lst.delete_i([self._index])
def redo(self):
if self._new is None:
self._new = self._outputrk_lst.new(self._outputrk_lst, self._index)
else:
self._outputrk_lst.insert(self._index, self._new)
class DelCommand(QUndoCommand):
def __init__(self, outputrk_lst, rows):
QUndoCommand.__init__(self)
self._outputrk_lst = outputrk_lst
self._rows = rows
self._outputrk = []
for row in rows:
self._outputrk.append((row, self._outputrk_lst.get(row)))
self._outputrk.sort()
def undo(self):
for row, el in self._outputrk:
self._outputrk_lst.insert(row, el)
def redo(self):
self._outputrk_lst.delete_i(self._rows)
class PasteCommand(QUndoCommand):
def __init__(self, outputrk_lst, row, outputrk):
QUndoCommand.__init__(self)
self._outputrk_lst = outputrk_lst
self._row = row
self._outputrk = deepcopy(outputrk)
self._outputrk.reverse()
def undo(self):
self._outputrk_lst.delete_i(
self._tab,
range(self._row, self._row + len(self._outputrk))
)
def redo(self):
for r in self._outputrk:
self._outputrk_lst.insert(self._row, r)