-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproperty.py
61 lines (46 loc) · 1.42 KB
/
property.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
def step_list(current, list, step, loop=True):
item_idx = list.index(current)
step_idx = item_idx + step
if step_idx >= len(list):
if loop:
step_idx = 0
else:
step_idx = len(list) - 1
elif step_idx < 0:
if loop:
step_idx = len(list) - 1
else:
step_idx = 0
return list[step_idx]
def step_enum(current, items, step, loop=True):
item_list = [item[0] for item in items]
item_idx = item_list.index(current)
step_idx = item_idx + step
if step_idx >= len(item_list):
if loop:
step_idx = 0
else:
step_idx = len(item_list) - 1
elif step_idx < 0:
if loop:
step_idx = len(item_list) - 1
else:
step_idx = 0
return item_list[step_idx]
def step_collection(object, currentitem, itemsname, indexname, step):
item_list = [item for item in getattr(object, itemsname)]
item_idx = item_list.index(currentitem)
step_idx = item_idx + step
if step_idx >= len(item_list):
step_idx = len(item_list) - 1
elif step_idx < 0:
step_idx = 0
setattr(object, indexname, step_idx)
return getattr(object, itemsname)[step_idx]
def rotate_list(list, amount):
for i in range(abs(amount)):
if amount > 0:
list.append(list.pop(0))
else:
list.insert(0, list.pop(-1))
return list