-
Notifications
You must be signed in to change notification settings - Fork 0
/
undoCommands.py
117 lines (85 loc) · 3.5 KB
/
undoCommands.py
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
import numpy as np
from PyQt6.QtGui import QUndoCommand
from table.cleanup import remove_mult_spaces
import re
class CommandEditCell(QUndoCommand):
def __init__(self, model, index, value, description):
super(CommandEditCell, self).__init__(description)
self.model = model
self.index = index
self.value = value
self.prev = self.model.items[index.row(), index.column()]
def redo(self):
self.model.edit_item(self.index, self.value)
def undo(self):
self.model.edit_item(self.index, self.prev)
class CommandInsertRow(QUndoCommand):
def __init__(self, model, row_index, items, description):
super(CommandInsertRow, self).__init__(description)
self.model = model
self.row_index = row_index
self.items = items
def redo(self):
self.model.insert_row(self.row_index, self.items)
def undo(self):
self.model.delete_row(self.row_index)
class CommandDeleteRow(QUndoCommand):
def __init__(self, model, row_index, description):
super(CommandDeleteRow, self).__init__(description)
self.model = model
self.row_index = row_index
self.items = self.model.items[row_index, :]
def redo(self):
self.model.delete_row(self.row_index)
def undo(self):
self.model.insert_row(self.row_index, self.items)
class CommandInsertCol(QUndoCommand):
def __init__(self, model, col_index, items, description):
super(CommandInsertCol, self).__init__(description)
self.model = model
self.col_index = col_index
self.items = items
def redo(self):
self.model.insert_column(self.col_index, self.items)
def undo(self):
self.model.delete_column(self.col_index)
class CommandDeleteCol(QUndoCommand):
def __init__(self, model, col_index, description):
super(CommandDeleteCol, self).__init__(description)
self.model = model
self.col_index = col_index
self.items = self.model.items[:, col_index]
def redo(self):
self.model.delete_column(self.col_index)
def undo(self):
self.model.insert_column(self.col_index, self.items)
class CommandReplaceAll(QUndoCommand):
def __init__(self, model, find_text, replace_text, description):
super(CommandReplaceAll, self).__init__(description)
self.model = model
self.findText = find_text
self.replaceText = replace_text
self.prevItems = self.model.items
def redo(self):
self.model.replace(self.findText, self.replaceText)
def undo(self):
self.model.items = self.prevItems
class CommandStandardize(QUndoCommand):
def __init__(self, model, description):
super(CommandStandardize, self).__init__(description)
self.model = model
self.prevItems = self.model.items
def redo(self):
vfunc1 = np.vectorize(remove_mult_spaces)
self.model.items = vfunc1(self.model.items)
vfunc2 = np.vectorize(titlecase)
self.model.items = vfunc2(self.model.items)
def undo(self):
self.model.items = self.prevItems
def titlecase(s):
return re.sub(
r"(?<!\d)\b[A-Za-zΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψωςΆΈΊΪΌΎΫΏάέήϊΐόύϋΰώ]+"
r"('[A-Za-zΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψωςΆΈΊΪΌΎΫΏάέήϊΐόύϋΰώ]+)?",
lambda word: word.group(0).capitalize(),
s
)