-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
section.py
executable file
·75 lines (59 loc) · 1.86 KB
/
section.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
from style import Style
class Section:
"""
Holds logical and graphical information for a given section, as well as other properties such as
style, visibility, type, etc...
"""
size: int
address: int
id: str
size_x: int
size_y: int
pos_x: int
pos_y: int
label_offset: int = 10
style: Style
def __init__(self, size, address, id, _type, parent, flags=[], name=None):
self.type = _type
self.parent = parent
self.size = size
self.address = address
self.id = id
self.name = name
self.size_y = 0
self.size_x = 0
self.style = Style()
self.flags = flags
def is_grow_up(self):
return 'grows-up' in self.flags
def is_grow_down(self):
return 'grows-down' in self.flags
def is_break(self):
return 'break' in self.flags
def is_hidden(self):
return 'hidden' in self.flags
def _should_element_be_hidden(self, attribute):
return True if str(attribute) in ['True', 'yes'] \
else False if str(attribute) in ['False', 'no'] \
else self.size_y < 20
def is_address_hidden(self):
return self._should_element_be_hidden(self.style.hide_address)
def is_name_hidden(self):
return self._should_element_be_hidden(self.style.hide_name)
def is_size_hidden(self):
return self._should_element_be_hidden(self.style.hide_size)
@property
def addr_label_pos_x(self):
return self.size_x + self.label_offset
@property
def addr_label_pos_y(self):
return self.pos_y + self.size_y
@property
def name_label_pos_x(self):
return self.size_x / 2
@property
def size_label_pos(self):
return self.pos_x + 2, self.pos_y + 2
@property
def name_label_pos_y(self):
return self.pos_y + (self.size_y / 2)