forked from kz26/PyExcelerate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlignment.py
More file actions
87 lines (68 loc) · 2.71 KB
/
Alignment.py
File metadata and controls
87 lines (68 loc) · 2.71 KB
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
import six
from . import Utility
from . import Color
class Alignment(object):
def __init__(self, horizontal='left', vertical='bottom', rotation=0, wrap_text=False):
self._horizontal = horizontal
self._vertical = vertical
self._rotation = rotation
self._wrap_text = wrap_text
@property
def wrap_text(self):
return self._wrap_text
@wrap_text.setter
def wrap_text(self, value):
if value not in (True, False):
raise TypeError('Invalid wrap text alignment value. Expects either True or False.')
self._wrap_text = value
@property
def horizontal(self):
return self._horizontal
@horizontal.setter
def horizontal(self, value):
if value not in ('left', 'center', 'right'):
raise ValueError('Invalid horizontal alignment value. Expects either \'left\', \'center\', or \'right\'.')
self._horizontal = value
@property
def vertical(self):
return self._vertical
@vertical.setter
def vertical(self, value):
if value not in ('top', 'center', 'bottom'):
raise ValueError('Invalid vertical alignment value. Expects either \'top\', \'center\', or \'bottom\'.')
self._vertical = value
@property
def rotation(self):
return self._rotation
@rotation.setter
def rotation(self, value):
self._rotation = (value % 360)
@property
def is_default(self):
return self._horizontal == 'left' and self._vertical == 'bottom' and self._rotation == 0 and not self._wrap_text
def get_xml_string(self):
return "<alignment horizontal=\"%s\" vertical=\"%s\" textRotation=\"%.15g\" wrapText=\"%d\"/>" % (self._horizontal, self._vertical, self._rotation, 1 if self._wrap_text else 0)
def __or__(self, other):
return self._binary_operation(other, Utility.nonboolean_or)
def __and__(self, other):
return self._binary_operation(other, Utility.nonboolean_and)
def __xor__(self, other):
return self._binary_operation(other, Utility.nonboolean_xor)
def _binary_operation(self, other, operation):
return Alignment( \
horizontal = operation(self._horizontal, other._horizontal, 'left'), \
vertical = operation(self._vertical, other._vertical, 'bottom'), \
rotation = operation(self._rotation, other._rotation, 0), \
wrap_text = operation(self._wrap_text, other._wrap_text, False)
)
def __eq__(self, other):
if other is None:
return self.is_default
elif Utility.YOLO:
return self._vertical == other._vertical and self._rotation == other._rotation
else:
return self._vertical == other._vertical and self._rotation == other._rotation and self._horizontal == other._horizontal and self._wrap_text == other._wrap_text
def __hash__(self):
return hash((self._horizontal, self._wrap_text))
def __str__(self):
return "Align: %s %s %s" % (self._horizontal, self._vertical, self._rotation)