An error occurred while loading the file. Please try again.
-
Pierre-Antoine Rouby authored956a0714
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
# -*- coding: utf-8 -*-
import logging
from copy import copy
from tools import trace, timer
from Model.DB import SQLSubModel
from Model.Friction.Friction import Friction
logger = logging.getLogger()
class FrictionList(SQLSubModel):
_sub_classes = [
Friction
]
def __init__(self, status = None):
super(FrictionList, self).__init__()
self._status = status
self._frictions = []
@classmethod
def _sql_create(cls, execute):
return cls._create_submodel(execute)
@classmethod
def _sql_update_0_0_1(cls, execute, version):
execute("ALTER TABLE `section` RENAME TO `friction`")
@classmethod
def _sql_update(cls, execute, version):
if version == "0.0.0":
logger.info(f"Update friction TABLE from {version}")
cls._sql_update_0_0_1(execute, version)
return True
@classmethod
def _sql_load(cls, execute, data = None):
new = cls(status = data['status'])
new._frictions = Friction._sql_load(
execute, data
)
return new
def _sql_save(self, execute, data = None):
reach = data["reach"]
execute(f"DELETE FROM friction WHERE reach = {reach.id}")
ok = True
ind = 0
for friction in self._frictions:
data["ind"] = ind
ok &= friction._sql_save(execute, data = data)
ind += 1
return ok
def __len__(self):
return len(self._frictions)
@property
def frictions(self):
return self._frictions.copy()
def get(self, row):
return self._frictions[row]
def set(self, row, new):
self._frictions[row] = new
self._status.modified()
def new(self, index):
n = Friction(status = self._status)
self._frictions.insert(index, n)
self._status.modified()
return n
def insert(self, index, new):
self._frictions.insert(index, new)
self._status.modified()
def delete(self, frictions):
for friction in frictions:
self._frictions.remove(friction)
self._status.modified()
def delete_i(self, indexes):
frictions = list(
map(
lambda x: x[1],
filter(
lambda x: x[0] in indexes,
enumerate(self._frictions)
)
)
)
self.delete(frictions)
def sort(self, reverse=False, key=None):
self._frictions.sort(reverse=reverse, key=key)
self._status.modified()
def move_up(self, index):
if index < len(self._frictions):
next = index - 1
l = self._frictions
l[index], l[next] = l[next], l[index]
self._status.modified()
def move_down(self, index):
if index >= 0:
prev = index + 1
l = self._frictions
l[index], l[prev] = l[prev], l[index]
self._status.modified()