drawlib 0.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of drawlib might be problematic. Click here for more details.

Files changed (52) hide show
  1. drawlib/.pylintrc +2 -0
  2. drawlib/__init__.py +33 -0
  3. drawlib/__main__.py +21 -0
  4. drawlib/apis.py +22 -0
  5. drawlib/assets/__init__.py +8 -0
  6. drawlib/assets/v0_1/__init__.py +8 -0
  7. drawlib/assets/v0_1/fonticons/__init__.py +8 -0
  8. drawlib/assets/v0_1/fonts/__init__.py +8 -0
  9. drawlib/v0_1/__init__.py +31 -0
  10. drawlib/v0_1/__main__.py +20 -0
  11. drawlib/v0_1/apis.py +127 -0
  12. drawlib/v0_1/private/__init__.py +20 -0
  13. drawlib/v0_1/private/arg_validator.py +163 -0
  14. drawlib/v0_1/private/command.py +204 -0
  15. drawlib/v0_1/private/core/__init__.py +15 -0
  16. drawlib/v0_1/private/core/colors.py +285 -0
  17. drawlib/v0_1/private/core/dimage.py +510 -0
  18. drawlib/v0_1/private/core/fonts.py +324 -0
  19. drawlib/v0_1/private/core/model.py +1082 -0
  20. drawlib/v0_1/private/core/model_validator.py +175 -0
  21. drawlib/v0_1/private/core/theme.py +1042 -0
  22. drawlib/v0_1/private/core/util.py +809 -0
  23. drawlib/v0_1/private/core_canvas/__init__.py +15 -0
  24. drawlib/v0_1/private/core_canvas/base.py +653 -0
  25. drawlib/v0_1/private/core_canvas/canvas.py +88 -0
  26. drawlib/v0_1/private/core_canvas/image.py +154 -0
  27. drawlib/v0_1/private/core_canvas/line.py +263 -0
  28. drawlib/v0_1/private/core_canvas/original_arrow.py +139 -0
  29. drawlib/v0_1/private/core_canvas/original_polygon.py +584 -0
  30. drawlib/v0_1/private/core_canvas/patches.py +547 -0
  31. drawlib/v0_1/private/core_canvas/text.py +136 -0
  32. drawlib/v0_1/private/download.py +58 -0
  33. drawlib/v0_1/private/dutil.py +28 -0
  34. drawlib/v0_1/private/icons/__init__.py +15 -0
  35. drawlib/v0_1/private/icons/phosphor.py +35275 -0
  36. drawlib/v0_1/private/icons/util.py +82 -0
  37. drawlib/v0_1/private/logging.py +38 -0
  38. drawlib/v0_1/private/settings.py +233 -0
  39. drawlib/v0_1/private/smartarts/__init__.py +15 -0
  40. drawlib/v0_1/private/smartarts/cycle.py +11 -0
  41. drawlib/v0_1/private/smartarts/dsart.py +17 -0
  42. drawlib/v0_1/private/smartarts/groups.py +20 -0
  43. drawlib/v0_1/private/smartarts/pyramid.py +18 -0
  44. drawlib/v0_1/private/smartarts/sourcecode.py +216 -0
  45. drawlib/v0_1/private/smartarts/table.py +11 -0
  46. drawlib/v0_1/private/smartarts/tree.py +18 -0
  47. drawlib/v0_1/private/tools.py +161 -0
  48. drawlib/v0_1/private/util.py +353 -0
  49. drawlib-0.1.1.dist-info/LICENSE.txt +202 -0
  50. drawlib-0.1.1.dist-info/METADATA +36 -0
  51. drawlib-0.1.1.dist-info/RECORD +52 -0
  52. drawlib-0.1.1.dist-info/WHEEL +4 -0
@@ -0,0 +1,175 @@
1
+ from typing import Tuple, Union, List
2
+ from drawlib.v0_1.private.core.fonts import FontBase, FontFile
3
+
4
+
5
+ class ColorValidator:
6
+ ERROR_MESSAGE_ALPHA = 'Alpha must be float/int between 0.0~1.0. But "{value}" is given.'
7
+ ERROR_MESSAGE_COLOR_FORMAT = 'Color format must be (R,G,B) or (R,G,B,A). But "{value}" is given.'
8
+ ERROR_MESSAGE_RGB_VALUE = 'Each RGB color must be int between 0~255. But "{value}" is given.'
9
+
10
+ @staticmethod
11
+ def validate_alpha(value: float):
12
+ if not (isinstance(value, float) or isinstance(value, int)):
13
+ raise ValueError(ColorValidator.ERROR_MESSAGE_ALPHA.format(value=value))
14
+ if not 0.0 <= value <= 1.0:
15
+ raise ValueError(ColorValidator.ERROR_MESSAGE_ALPHA.format(value=value))
16
+
17
+ @staticmethod
18
+ def validate_color(value: Union[Tuple[int, int, int], Tuple[int, int, int, float]]):
19
+ if not isinstance(value, tuple):
20
+ raise ValueError(ColorValidator.ERROR_MESSAGE_COLOR_FORMAT.format(value=value))
21
+ if len(value) not in [3, 4]:
22
+ raise ValueError(ColorValidator.ERROR_MESSAGE_COLOR_FORMAT.format(value=value))
23
+
24
+ r = value[0]
25
+ g = value[1]
26
+ b = value[2]
27
+ a = 1.0 if len(value) == 3 else value[3]
28
+
29
+ for c in [r, g, b]:
30
+ if not isinstance(c, int):
31
+ raise ValueError(ColorValidator.ERROR_MESSAGE_RGB_VALUE.format(value=c))
32
+ if not 0 <= c <= 255:
33
+ raise ValueError(ColorValidator.ERROR_MESSAGE_RGB_VALUE.format(value=c))
34
+
35
+ if not (isinstance(a, float) or isinstance(a, int)):
36
+ raise ValueError(ColorValidator.ERROR_MESSAGE_ALPHA.format(value=a))
37
+ if not 0.0 <= a <= 1.0:
38
+ raise ValueError(ColorValidator.ERROR_MESSAGE_ALPHA.format(value=a))
39
+
40
+
41
+ class AlignValidator:
42
+
43
+ @staticmethod
44
+ def validate_halign(value: str):
45
+ supported = ["left", "center", "right"]
46
+ if value not in supported:
47
+ raise ValueError(f'Supported horizontal aligns are {supported}. But "{value}" is given.')
48
+
49
+ @staticmethod
50
+ def validate_valign(value: str):
51
+ supported = ["bottom", "center", "top"]
52
+ if value not in supported:
53
+ raise ValueError(f'Supported vertical aligns are {supported}. But "{value}" is given.')
54
+
55
+
56
+ class LineValidator:
57
+ ERROR_MESSAGE_WIDTH = 'Line width must be between 0.0 ~ 100.0. But "{value}" is given.'
58
+ ERROR_MESSAGE_SCALE = 'Line arrow head scale must be between 0.0 ~ 100.0. But "{value}" is given.'
59
+
60
+ @staticmethod
61
+ def validate_width(value: float):
62
+ if not (isinstance(value, float) or isinstance(value, int)):
63
+ raise ValueError(LineValidator.ERROR_MESSAGE_WIDTH.format(value=value))
64
+ if not 0.0 <= value <= 100.0:
65
+ raise ValueError(LineValidator.ERROR_MESSAGE_WIDTH.format(value=value))
66
+
67
+ @staticmethod
68
+ def validate_style(value: str):
69
+ supported = ["solid", "dashed", "dotted", "dashdot"]
70
+ if value not in supported:
71
+ raise ValueError(f'Supported line styles are {supported}. But "{value}" is given.')
72
+
73
+ @staticmethod
74
+ def validate_arrowhead_style(value: str):
75
+ supported = ["->", "<-", "<->", "-|>", "<|-", "<|-|>"]
76
+ if value not in supported:
77
+ raise ValueError(f'Supported arrow head styles are {supported}. But "{value}" is given.')
78
+
79
+ @staticmethod
80
+ def validate_arrowhead_scale(value: float):
81
+ if not (isinstance(value, float) or isinstance(value, int)):
82
+ raise ValueError(LineValidator.ERROR_MESSAGE_SCALE.format(value=value))
83
+ if not 0.0 <= value <= 100.0:
84
+ raise ValueError(LineValidator.ERROR_MESSAGE_SCALE.format(value=value))
85
+
86
+
87
+ class TextValidator:
88
+ ERROR_MESSAGE_SIZE = 'Text size must be between 0.0 ~ 1000.0. But "{value}" is given.'
89
+ ERROR_MESSAGE_FLIP = 'Text flip must be False/True. But "{value}" is given.'
90
+
91
+ @staticmethod
92
+ def validate_size(value: float):
93
+ if not (isinstance(value, float) or isinstance(value, int)):
94
+ raise ValueError(TextValidator.ERROR_MESSAGE_SIZE.format(value=value))
95
+ if not 0.0 <= value <= 1000.0:
96
+ raise ValueError(TextValidator.ERROR_MESSAGE_SIZE.format(value=value))
97
+
98
+ @staticmethod
99
+ def validate_font(value: Union[FontBase, FontFile]):
100
+ if isinstance(value, FontBase):
101
+ return
102
+ if isinstance(value, FontFile):
103
+ return
104
+
105
+ raise ValueError(f'Font must be "instance of FontFile" or "member of Font classes". But "{value}" is given.')
106
+
107
+ @staticmethod
108
+ def validate_flip(value: bool):
109
+ if not isinstance(value, bool):
110
+ raise ValueError(TextValidator.ERROR_MESSAGE_FLIP.format(value=value))
111
+
112
+
113
+ class CoordinateValidator:
114
+ ERROR_MESSAGE_XY = 'xy must be (int/float, int/float) format. But "{value}" is given.'
115
+ ERROR_MESSAGE_XYS = "xys must be list of coordinate."
116
+ ERROR_MESSAGE_PATH_POINTS = "path_points must be list of path_point. (x,y) or (x1,y1,x2,y2) or (x1,y1,x2,y2,x3,y3)."
117
+ ERROR_MESSAGE_ANGLE = 'Angle must be between 0.0 ~ 360.0. But "{value}" is given.'
118
+
119
+ @staticmethod
120
+ def validate_xy(value: Tuple[float, float]):
121
+ if not isinstance(value, tuple):
122
+ raise ValueError(CoordinateValidator.ERROR_MESSAGE_XY.format(value=value))
123
+ if len(value) != 2:
124
+ raise ValueError(CoordinateValidator.ERROR_MESSAGE_XY.format(value=value))
125
+
126
+ x, y = value
127
+ for c in [x, y]:
128
+ if not (isinstance(c, float) or isinstance(c, int)):
129
+ raise ValueError(CoordinateValidator.ERROR_MESSAGE_XY.format(value=value))
130
+
131
+ @staticmethod
132
+ def validate_xys(value: List[Tuple[float, float]]):
133
+ if not isinstance(value, list):
134
+ raise ValueError()
135
+
136
+ for e in value:
137
+ if not isinstance(e, tuple):
138
+ raise ValueError()
139
+ if len(e) != 2:
140
+ raise ValueError()
141
+
142
+ x, y = e
143
+ for c in [x, y]:
144
+ if not (isinstance(c, float) or isinstance(c, int)):
145
+ raise ValueError()
146
+
147
+ @staticmethod
148
+ def validate_path_points(
149
+ value: List[
150
+ Union[
151
+ Tuple[float, float],
152
+ Tuple[float, float, float, float],
153
+ Tuple[float, float, float, float, float, float],
154
+ ]
155
+ ],
156
+ ):
157
+ if not isinstance(value, list):
158
+ raise ValueError()
159
+
160
+ for e in value:
161
+ if not isinstance(e, tuple):
162
+ raise ValueError()
163
+ if len(e) not in [2, 4, 6]:
164
+ raise ValueError()
165
+
166
+ for c in e:
167
+ if not (isinstance(c, float) or isinstance(c, int)):
168
+ raise ValueError()
169
+
170
+ @staticmethod
171
+ def validate_angle(value: float):
172
+ if not (isinstance(value, float) or isinstance(value, int)):
173
+ raise ValueError(CoordinateValidator.ERROR_MESSAGE_ANGLE.format(value=value))
174
+ if not 0.0 <= value <= 360.0:
175
+ raise ValueError(CoordinateValidator.ERROR_MESSAGE_ANGLE.format(value=value))