forked from kz26/PyExcelerate
/
Border.py
63 lines (53 loc) · 1.53 KB
/
Border.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
from . import Utility
from . import Color
#
# An object representing a single border
#
class Border(object):
STYLE_MAPPING = { \
'dashDot': ('.-', '-.', 'dash dot'), \
'dashDotDot': ('..-', '-..', 'dash dot dot'), \
'dashed': ('--'), \
'dotted': ('..', ':'), \
'double': ('='), \
'hair': ('hairline', '.'), \
'medium': (), \
'mediumDashDot': ('medium dash dot', 'medium -.', 'medium .-'), \
'mediumDashDotDot': ('medium dash dot dot', 'medium -..', 'medium ..-'), \
'mediumDashed': ('medium dashed', 'medium --'), \
'slantDashDot': ('/-.', 'slant dash dot'), \
'thick': (), \
'thin': ('_') \
}
def __init__(self, color=None, style='thin'):
self._color = color
self._style = Border.get_style_name(style)
@property
def color(self):
return Utility.lazy_get(self, '_color', Color.Color(0, 0, 0))
@color.setter
def color(self, value):
Utility.lazy_set(self, '_color', None, value)
@property
def style(self):
return self._style
@style.setter
def style(self, value):
self._style = Border.get_style_name(value)
@staticmethod
def get_style_name(style):
for key, values in Border.STYLE_MAPPING.items():
if style == key or style in values:
return key
# TODO: warn the user?
return 'thin'
@property
def is_default(self):
return self._color is None and self._style == 'thin'
def __eq__(self, other):
if other is None:
return self.is_default
else:
return self._color == other._color and self._style == other._style
def __hash__(self):
return hash((self._color, self._style))