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.
- drawlib/.pylintrc +2 -0
- drawlib/__init__.py +33 -0
- drawlib/__main__.py +21 -0
- drawlib/apis.py +22 -0
- drawlib/assets/__init__.py +8 -0
- drawlib/assets/v0_1/__init__.py +8 -0
- drawlib/assets/v0_1/fonticons/__init__.py +8 -0
- drawlib/assets/v0_1/fonts/__init__.py +8 -0
- drawlib/v0_1/__init__.py +31 -0
- drawlib/v0_1/__main__.py +20 -0
- drawlib/v0_1/apis.py +127 -0
- drawlib/v0_1/private/__init__.py +20 -0
- drawlib/v0_1/private/arg_validator.py +163 -0
- drawlib/v0_1/private/command.py +204 -0
- drawlib/v0_1/private/core/__init__.py +15 -0
- drawlib/v0_1/private/core/colors.py +285 -0
- drawlib/v0_1/private/core/dimage.py +510 -0
- drawlib/v0_1/private/core/fonts.py +324 -0
- drawlib/v0_1/private/core/model.py +1082 -0
- drawlib/v0_1/private/core/model_validator.py +175 -0
- drawlib/v0_1/private/core/theme.py +1042 -0
- drawlib/v0_1/private/core/util.py +809 -0
- drawlib/v0_1/private/core_canvas/__init__.py +15 -0
- drawlib/v0_1/private/core_canvas/base.py +653 -0
- drawlib/v0_1/private/core_canvas/canvas.py +88 -0
- drawlib/v0_1/private/core_canvas/image.py +154 -0
- drawlib/v0_1/private/core_canvas/line.py +263 -0
- drawlib/v0_1/private/core_canvas/original_arrow.py +139 -0
- drawlib/v0_1/private/core_canvas/original_polygon.py +584 -0
- drawlib/v0_1/private/core_canvas/patches.py +547 -0
- drawlib/v0_1/private/core_canvas/text.py +136 -0
- drawlib/v0_1/private/download.py +58 -0
- drawlib/v0_1/private/dutil.py +28 -0
- drawlib/v0_1/private/icons/__init__.py +15 -0
- drawlib/v0_1/private/icons/phosphor.py +35275 -0
- drawlib/v0_1/private/icons/util.py +82 -0
- drawlib/v0_1/private/logging.py +38 -0
- drawlib/v0_1/private/settings.py +233 -0
- drawlib/v0_1/private/smartarts/__init__.py +15 -0
- drawlib/v0_1/private/smartarts/cycle.py +11 -0
- drawlib/v0_1/private/smartarts/dsart.py +17 -0
- drawlib/v0_1/private/smartarts/groups.py +20 -0
- drawlib/v0_1/private/smartarts/pyramid.py +18 -0
- drawlib/v0_1/private/smartarts/sourcecode.py +216 -0
- drawlib/v0_1/private/smartarts/table.py +11 -0
- drawlib/v0_1/private/smartarts/tree.py +18 -0
- drawlib/v0_1/private/tools.py +161 -0
- drawlib/v0_1/private/util.py +353 -0
- drawlib-0.1.1.dist-info/LICENSE.txt +202 -0
- drawlib-0.1.1.dist-info/METADATA +36 -0
- drawlib-0.1.1.dist-info/RECORD +52 -0
- drawlib-0.1.1.dist-info/WHEEL +4 -0
drawlib/.pylintrc
ADDED
drawlib/__init__.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Copyright (c) 2024 Yuichi Ito (yuichi@yuichi.com)
|
|
2
|
+
#
|
|
3
|
+
# This software is licensed under the Apache License, Version 2.0.
|
|
4
|
+
# For more information, please visit: https://github.com/yuichi110/drawlib
|
|
5
|
+
#
|
|
6
|
+
# This software is provided "as is", without warranty of any kind,
|
|
7
|
+
# express or implied, including but not limited to the warranties of
|
|
8
|
+
# merchantability, fitness for a particular purpose and noninfringement.
|
|
9
|
+
|
|
10
|
+
"""drawlib root package
|
|
11
|
+
|
|
12
|
+
this package contains latest modules.
|
|
13
|
+
|
|
14
|
+
- basic: provides single interface of basic classes and functions.
|
|
15
|
+
- advance: provides single interface of basic and advance classes and functions.
|
|
16
|
+
- settings: provides application setting interfaces.
|
|
17
|
+
|
|
18
|
+
subpackages contains latest and old implementations.
|
|
19
|
+
|
|
20
|
+
- drawlib.v0_1: API v0.1 interface (latest)
|
|
21
|
+
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from typing import Final
|
|
25
|
+
|
|
26
|
+
# please update here when you release new version
|
|
27
|
+
VERSION = "0.1.1"
|
|
28
|
+
|
|
29
|
+
# might not be changed
|
|
30
|
+
LIB_NAME: Final[str] = "drawlib"
|
|
31
|
+
AUTHOR: Final[str] = "Yuichi Ito"
|
|
32
|
+
CONTACT: Final[str] = "yuichi@yuichi.com"
|
|
33
|
+
__version__: Final[str] = VERSION
|
drawlib/__main__.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Copyright (c) 2024 Yuichi Ito (yuichi@yuichi.com)
|
|
2
|
+
#
|
|
3
|
+
# This software is licensed under the Apache License, Version 2.0.
|
|
4
|
+
# For more information, please visit: https://github.com/yuichi110/drawlib
|
|
5
|
+
#
|
|
6
|
+
# This software is provided "as is", without warranty of any kind,
|
|
7
|
+
# express or implied, including but not limited to the warranties of
|
|
8
|
+
# merchantability, fitness for a particular purpose and noninfringement.
|
|
9
|
+
|
|
10
|
+
"""Entry point of ``drawlib``
|
|
11
|
+
|
|
12
|
+
When you run ``drawlib <options>`` or ``python -m drawlib <options>``,
|
|
13
|
+
this module will be called.
|
|
14
|
+
And then, latest API's ``command.call()`` will be called.
|
|
15
|
+
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from drawlib.v0_1.private.command import call
|
|
19
|
+
|
|
20
|
+
if __name__ == "__main__":
|
|
21
|
+
call()
|
drawlib/apis.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Copyright (c) 2024 Yuichi Ito (yuichi@yuichi.com)
|
|
2
|
+
#
|
|
3
|
+
# This software is licensed under the Apache License, Version 2.0.
|
|
4
|
+
# For more information, please visit: https://github.com/yuichi110/drawlib
|
|
5
|
+
#
|
|
6
|
+
# This software is provided "as is", without warranty of any kind,
|
|
7
|
+
# express or implied, including but not limited to the warranties of
|
|
8
|
+
# merchantability, fitness for a particular purpose and noninfringement.
|
|
9
|
+
|
|
10
|
+
"""Module for importing functions and classes at latest drawlib API.
|
|
11
|
+
|
|
12
|
+
drawlib posses lots of functions and classes on various modules.
|
|
13
|
+
This module provides single interface for importing public latest API objects.
|
|
14
|
+
|
|
15
|
+
``from drawlib.apis import *``
|
|
16
|
+
|
|
17
|
+
If you want to specify API version,
|
|
18
|
+
please use ``drawlib.<version>.apis`` instead.
|
|
19
|
+
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from drawlib.v0_1.apis import *
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Copyright (c) 2024 Yuichi Ito (yuichi@yuichi.com)
|
|
2
|
+
#
|
|
3
|
+
# This software is licensed under the Apache License, Version 2.0.
|
|
4
|
+
# For more information, please visit: https://github.com/yuichi110/drawlib
|
|
5
|
+
#
|
|
6
|
+
# This software is provided "as is", without warranty of any kind,
|
|
7
|
+
# express or implied, including but not limited to the warranties of
|
|
8
|
+
# merchantability, fitness for a particular purpose and noninfringement.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Copyright (c) 2024 Yuichi Ito (yuichi@yuichi.com)
|
|
2
|
+
#
|
|
3
|
+
# This software is licensed under the Apache License, Version 2.0.
|
|
4
|
+
# For more information, please visit: https://github.com/yuichi110/drawlib
|
|
5
|
+
#
|
|
6
|
+
# This software is provided "as is", without warranty of any kind,
|
|
7
|
+
# express or implied, including but not limited to the warranties of
|
|
8
|
+
# merchantability, fitness for a particular purpose and noninfringement.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Copyright (c) 2024 Yuichi Ito (yuichi@yuichi.com)
|
|
2
|
+
#
|
|
3
|
+
# This software is licensed under the Apache License, Version 2.0.
|
|
4
|
+
# For more information, please visit: https://github.com/yuichi110/drawlib
|
|
5
|
+
#
|
|
6
|
+
# This software is provided "as is", without warranty of any kind,
|
|
7
|
+
# express or implied, including but not limited to the warranties of
|
|
8
|
+
# merchantability, fitness for a particular purpose and noninfringement.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Copyright (c) 2024 Yuichi Ito (yuichi@yuichi.com)
|
|
2
|
+
#
|
|
3
|
+
# This software is licensed under the Apache License, Version 2.0.
|
|
4
|
+
# For more information, please visit: https://github.com/yuichi110/drawlib
|
|
5
|
+
#
|
|
6
|
+
# This software is provided "as is", without warranty of any kind,
|
|
7
|
+
# express or implied, including but not limited to the warranties of
|
|
8
|
+
# merchantability, fitness for a particular purpose and noninfringement.
|
drawlib/v0_1/__init__.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Copyright (c) 2024 Yuichi Ito (yuichi@yuichi.com)
|
|
2
|
+
#
|
|
3
|
+
# This software is licensed under the Apache License, Version 2.0.
|
|
4
|
+
# For more information, please visit: https://github.com/yuichi110/drawlib
|
|
5
|
+
#
|
|
6
|
+
# This software is provided "as is", without warranty of any kind,
|
|
7
|
+
# express or implied, including but not limited to the warranties of
|
|
8
|
+
# merchantability, fitness for a particular purpose and noninfringement.
|
|
9
|
+
|
|
10
|
+
"""drawlib API 0.1 package.
|
|
11
|
+
|
|
12
|
+
this package contains API v0.1 modules.
|
|
13
|
+
|
|
14
|
+
- basic: provides single interface of basic classes and functions.
|
|
15
|
+
- advance: provides single interface of basic and advance classes and functions.
|
|
16
|
+
- settings: provides application setting interfaces.
|
|
17
|
+
|
|
18
|
+
These implementation will not be changed after new API is released.
|
|
19
|
+
We recommend user code change before API deprication.
|
|
20
|
+
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from typing import Final
|
|
24
|
+
import drawlib
|
|
25
|
+
|
|
26
|
+
# this API package is latest now. So, API version is same to software's one.
|
|
27
|
+
# When you create newer API, please set string value instead.
|
|
28
|
+
VERSION: Final[str] = drawlib.VERSION
|
|
29
|
+
|
|
30
|
+
# might not be changed
|
|
31
|
+
__version__: Final[str] = VERSION
|
drawlib/v0_1/__main__.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Copyright (c) 2024 Yuichi Ito (yuichi@yuichi.com)
|
|
2
|
+
#
|
|
3
|
+
# This software is licensed under the Apache License, Version 2.0.
|
|
4
|
+
# For more information, please visit: https://github.com/yuichi110/drawlib
|
|
5
|
+
#
|
|
6
|
+
# This software is provided "as is", without warranty of any kind,
|
|
7
|
+
# express or implied, including but not limited to the warranties of
|
|
8
|
+
# merchantability, fitness for a particular purpose and noninfringement.
|
|
9
|
+
|
|
10
|
+
"""Entry point of ``drawlib.v0_1``
|
|
11
|
+
|
|
12
|
+
When you run ``python -m drawlib.v0_1 <options>``, this module is called.
|
|
13
|
+
And then, drawlib.v0_1.command.call() will be called.
|
|
14
|
+
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from drawlib.v0_1.private.command import call
|
|
18
|
+
|
|
19
|
+
if __name__ == "__main__":
|
|
20
|
+
call()
|
drawlib/v0_1/apis.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Copyright (c) 2024 Yuichi Ito (yuichi@yuichi.com)
|
|
2
|
+
#
|
|
3
|
+
# This software is licensed under the Apache License, Version 2.0.
|
|
4
|
+
# For more information, please visit: https://github.com/yuichi110/drawlib
|
|
5
|
+
#
|
|
6
|
+
# This software is provided "as is", without warranty of any kind,
|
|
7
|
+
# express or implied, including but not limited to the warranties of
|
|
8
|
+
# merchantability, fitness for a particular purpose and noninfringement.
|
|
9
|
+
|
|
10
|
+
"""Module for importing functions and classes at API v0.1.
|
|
11
|
+
|
|
12
|
+
drawlib posses lots of functions and classes on various modules.
|
|
13
|
+
This module provides single interface for importing public API v1.0 objects.
|
|
14
|
+
|
|
15
|
+
``from drawlib.v0_1.apis import *``
|
|
16
|
+
|
|
17
|
+
If you requires latest API, import root module instead.
|
|
18
|
+
|
|
19
|
+
``from drawlib.apis import *``
|
|
20
|
+
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
# pylint: disable=unused-import
|
|
24
|
+
|
|
25
|
+
#############
|
|
26
|
+
### Class ###
|
|
27
|
+
#############
|
|
28
|
+
|
|
29
|
+
from drawlib.v0_1.private.core.colors import (
|
|
30
|
+
Colors,
|
|
31
|
+
Colors140,
|
|
32
|
+
)
|
|
33
|
+
from drawlib.v0_1.private.core.model import (
|
|
34
|
+
IconStyle,
|
|
35
|
+
ImageStyle,
|
|
36
|
+
LineStyle,
|
|
37
|
+
LineArrowStyle,
|
|
38
|
+
ShapeStyle,
|
|
39
|
+
ShapeTextStyle,
|
|
40
|
+
TextStyle,
|
|
41
|
+
)
|
|
42
|
+
from drawlib.v0_1.private.core.fonts import (
|
|
43
|
+
Font,
|
|
44
|
+
FontArabic,
|
|
45
|
+
FontChinese,
|
|
46
|
+
FontJapanese,
|
|
47
|
+
FontKorean,
|
|
48
|
+
FontMonoSpace,
|
|
49
|
+
FontRoboto,
|
|
50
|
+
FontSanSerif,
|
|
51
|
+
FontSerif,
|
|
52
|
+
FontThai,
|
|
53
|
+
FontSourceCode,
|
|
54
|
+
FontFile,
|
|
55
|
+
)
|
|
56
|
+
from drawlib.v0_1.private.core.dimage import (
|
|
57
|
+
Dimage,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
######################
|
|
61
|
+
### Canvas Methods ###
|
|
62
|
+
######################
|
|
63
|
+
|
|
64
|
+
from drawlib.v0_1.private.core_canvas.canvas import (
|
|
65
|
+
# basics
|
|
66
|
+
clear,
|
|
67
|
+
config,
|
|
68
|
+
save,
|
|
69
|
+
shape,
|
|
70
|
+
# image
|
|
71
|
+
image,
|
|
72
|
+
# text
|
|
73
|
+
text,
|
|
74
|
+
text_vertical,
|
|
75
|
+
# line
|
|
76
|
+
line,
|
|
77
|
+
line_curved,
|
|
78
|
+
line_bezier1,
|
|
79
|
+
line_bezier2,
|
|
80
|
+
lines,
|
|
81
|
+
lines_bezier,
|
|
82
|
+
# patches
|
|
83
|
+
arc,
|
|
84
|
+
circle,
|
|
85
|
+
ellipse,
|
|
86
|
+
polygon,
|
|
87
|
+
rectangle,
|
|
88
|
+
regularpolygon,
|
|
89
|
+
wedge,
|
|
90
|
+
donuts,
|
|
91
|
+
fan,
|
|
92
|
+
# original
|
|
93
|
+
arrow,
|
|
94
|
+
rhombus,
|
|
95
|
+
parallelogram,
|
|
96
|
+
trapezoid,
|
|
97
|
+
triangle,
|
|
98
|
+
bubblespeech,
|
|
99
|
+
star,
|
|
100
|
+
chevron,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
#################
|
|
104
|
+
### Utilities ###
|
|
105
|
+
#################
|
|
106
|
+
|
|
107
|
+
from drawlib.v0_1.private.tools import (
|
|
108
|
+
dload,
|
|
109
|
+
)
|
|
110
|
+
from drawlib.v0_1.private import (
|
|
111
|
+
dutil,
|
|
112
|
+
)
|
|
113
|
+
from drawlib.v0_1.private.settings import (
|
|
114
|
+
dsettings,
|
|
115
|
+
)
|
|
116
|
+
from drawlib.v0_1.private.icons.util import (
|
|
117
|
+
dicon,
|
|
118
|
+
)
|
|
119
|
+
from drawlib.v0_1.private.icons import (
|
|
120
|
+
phosphor as dicon_phosphor,
|
|
121
|
+
)
|
|
122
|
+
from drawlib.v0_1.private.smartarts import (
|
|
123
|
+
dsart,
|
|
124
|
+
)
|
|
125
|
+
from drawlib.v0_1.private.core.theme import (
|
|
126
|
+
dtheme,
|
|
127
|
+
)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Copyright (c) 2024 Yuichi Ito (yuichi@yuichi.com)
|
|
2
|
+
#
|
|
3
|
+
# This software is licensed under the Apache License, Version 2.0.
|
|
4
|
+
# For more information, please visit: https://github.com/yuichi110/drawlib
|
|
5
|
+
#
|
|
6
|
+
# This software is provided "as is", without warranty of any kind,
|
|
7
|
+
# express or implied, including but not limited to the warranties of
|
|
8
|
+
# merchantability, fitness for a particular purpose and noninfringement.
|
|
9
|
+
|
|
10
|
+
"""drawlib API 0.1 implementation package.
|
|
11
|
+
|
|
12
|
+
This package contains drawlib's implementations.
|
|
13
|
+
However it is not designed to import directory except tests.
|
|
14
|
+
Please import them through module ``drawlib.v0_1.basic`` or
|
|
15
|
+
``drawlib.v0_1.advance``.
|
|
16
|
+
|
|
17
|
+
Subpackage ``drawlib.v0_1.core`` contains core drawing features.
|
|
18
|
+
Other moduels under this module is helpers.
|
|
19
|
+
|
|
20
|
+
"""
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
from typing import Tuple, Union, List
|
|
2
|
+
from PIL.Image import Image
|
|
3
|
+
|
|
4
|
+
from drawlib.v0_1.private.core.dimage import Dimage
|
|
5
|
+
from drawlib.v0_1.private.core.model_validator import ColorValidator, CoordinateValidator
|
|
6
|
+
from drawlib.v0_1.private.core.model import (
|
|
7
|
+
LineStyle,
|
|
8
|
+
LineArrowStyle,
|
|
9
|
+
ShapeStyle,
|
|
10
|
+
ShapeTextStyle,
|
|
11
|
+
TextStyle,
|
|
12
|
+
ImageStyle,
|
|
13
|
+
IconStyle,
|
|
14
|
+
)
|
|
15
|
+
from drawlib.v0_1.private.core.fonts import FontSourceCode
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ArgValidator:
|
|
19
|
+
|
|
20
|
+
# basic type
|
|
21
|
+
|
|
22
|
+
@staticmethod
|
|
23
|
+
def validate_bool(name: str, value: bool):
|
|
24
|
+
if not isinstance(value, bool):
|
|
25
|
+
raise ValueError(f'Arg "{name}" requires int value. But type {type(value)} "{value}" is given.')
|
|
26
|
+
|
|
27
|
+
@staticmethod
|
|
28
|
+
def validate_int(name: str, value: int):
|
|
29
|
+
if not isinstance(value, int):
|
|
30
|
+
raise ValueError(f'Arg "{name}" requires int value. But "{value}" is given.')
|
|
31
|
+
|
|
32
|
+
@staticmethod
|
|
33
|
+
def validate_float(name: str, value: Union[int, float]):
|
|
34
|
+
if not (isinstance(value, int) or isinstance(value, float)):
|
|
35
|
+
raise ValueError(f'Arg "{name}" requires int/float value. But "{value}" is given.')
|
|
36
|
+
|
|
37
|
+
@staticmethod
|
|
38
|
+
def validate_str(name: str, value: int):
|
|
39
|
+
if not isinstance(value, str):
|
|
40
|
+
raise ValueError(f'Arg "{name}" requires str value. But "{value}" is given.')
|
|
41
|
+
|
|
42
|
+
# drawlib coordinate system
|
|
43
|
+
|
|
44
|
+
@staticmethod
|
|
45
|
+
def validate_xy(name: str, value: Tuple[float, float]):
|
|
46
|
+
try:
|
|
47
|
+
CoordinateValidator.validate_xy(value)
|
|
48
|
+
except ValueError:
|
|
49
|
+
raise ValueError(f'Arg "{name}" requires coordinate (x, y). But "{value}" is given.')
|
|
50
|
+
|
|
51
|
+
@staticmethod
|
|
52
|
+
def validate_xys(name: str, value: List[Tuple[float, float]]):
|
|
53
|
+
try:
|
|
54
|
+
CoordinateValidator.validate_xys(value)
|
|
55
|
+
except ValueError:
|
|
56
|
+
raise ValueError(
|
|
57
|
+
f'Arg "{name}" requires list of coordinates [(x, y), (x, y), ...] '
|
|
58
|
+
f'at least 2 elements. But "{value}" is given.'
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
@staticmethod
|
|
62
|
+
def validate_path_points(
|
|
63
|
+
name: str,
|
|
64
|
+
value: List[
|
|
65
|
+
Union[
|
|
66
|
+
Tuple[float, float],
|
|
67
|
+
Tuple[float, float, float, float],
|
|
68
|
+
Tuple[float, float, float, float, float, float],
|
|
69
|
+
]
|
|
70
|
+
],
|
|
71
|
+
):
|
|
72
|
+
try:
|
|
73
|
+
CoordinateValidator.validate_path_points(value)
|
|
74
|
+
except ValueError:
|
|
75
|
+
raise ValueError(f'Arg "{name}" requires list of path_points. Your input value has problem.')
|
|
76
|
+
|
|
77
|
+
@staticmethod
|
|
78
|
+
def validate_angle(name: str, value: int):
|
|
79
|
+
try:
|
|
80
|
+
CoordinateValidator.validate_angle(value)
|
|
81
|
+
except ValueError:
|
|
82
|
+
raise ValueError(f'Arg "{name}" requires angle 0.0 ~ 360.0. But {value} is given.')
|
|
83
|
+
|
|
84
|
+
# drawlib color
|
|
85
|
+
|
|
86
|
+
@staticmethod
|
|
87
|
+
def validate_color(name: str, value: Union[Tuple[int, int, int], Tuple[int, int, int, float]]):
|
|
88
|
+
try:
|
|
89
|
+
ColorValidator.validate_color(value)
|
|
90
|
+
except ValueError:
|
|
91
|
+
raise ValueError(
|
|
92
|
+
f'Arg "{name}" requires color value(tuple[int, int, int] | '
|
|
93
|
+
f"tuple[int, int, int, float]). But {value} is given."
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
@staticmethod
|
|
97
|
+
def validate_alpha(name: str, value: Union[int, float]):
|
|
98
|
+
try:
|
|
99
|
+
ColorValidator.validate_alpha(value)
|
|
100
|
+
except ValueError:
|
|
101
|
+
raise ValueError(f'Arg "{name}" requires alpha value 0.0 ~ 1.0. But {value} is given.')
|
|
102
|
+
|
|
103
|
+
# drawlib style
|
|
104
|
+
|
|
105
|
+
@staticmethod
|
|
106
|
+
def validate_iconstyle(name: str, value: IconStyle):
|
|
107
|
+
if not isinstance(value, IconStyle):
|
|
108
|
+
raise ValueError(f'Arg "{name}" requires IconStyle. But "{value}" is given.')
|
|
109
|
+
|
|
110
|
+
@staticmethod
|
|
111
|
+
def validate_imagestyle(name: str, value: ImageStyle):
|
|
112
|
+
if not isinstance(value, ImageStyle):
|
|
113
|
+
raise ValueError(f'Arg "{name}" requires ImageStyle. But "{value}" is given.')
|
|
114
|
+
|
|
115
|
+
@staticmethod
|
|
116
|
+
def validate_linestyle(name: str, value: LineStyle):
|
|
117
|
+
if not isinstance(value, LineStyle):
|
|
118
|
+
raise ValueError(f'Arg "{name}" requires LineStyle. But "{value}" is given.')
|
|
119
|
+
|
|
120
|
+
@staticmethod
|
|
121
|
+
def validate_linearrowstyle(name: str, value: LineArrowStyle):
|
|
122
|
+
if not isinstance(value, LineArrowStyle):
|
|
123
|
+
raise ValueError(f'Arg "{name}" requires LineArrowStyle. But "{value}" is given.')
|
|
124
|
+
|
|
125
|
+
@staticmethod
|
|
126
|
+
def validate_linestyle_or_linearrowstyle(name: str, value: Union[LineStyle, LineArrowStyle]):
|
|
127
|
+
if isinstance(value, LineStyle):
|
|
128
|
+
return
|
|
129
|
+
if isinstance(value, LineArrowStyle):
|
|
130
|
+
return
|
|
131
|
+
raise ValueError(f'Arg "{name}" requires LineStyle or LineArrowStyle. But "{value}" is given.')
|
|
132
|
+
|
|
133
|
+
@staticmethod
|
|
134
|
+
def validate_shapestyle(name: str, value: ShapeStyle):
|
|
135
|
+
if not isinstance(value, ShapeStyle):
|
|
136
|
+
raise ValueError(f'Arg "{name}" requires ShapeStyle. But "{value}" is given.')
|
|
137
|
+
|
|
138
|
+
@staticmethod
|
|
139
|
+
def validate_shapetextstyle(name: str, value: ShapeTextStyle):
|
|
140
|
+
if not isinstance(value, ShapeTextStyle):
|
|
141
|
+
raise ValueError(f'Arg "{name}" requires ShapeTextStyle. But "{value}" is given.')
|
|
142
|
+
|
|
143
|
+
@staticmethod
|
|
144
|
+
def validate_textstyle(name: str, value: TextStyle):
|
|
145
|
+
if not isinstance(value, TextStyle):
|
|
146
|
+
raise ValueError(f'Arg "{name}" requires TextStyle. But "{value}" is given.')
|
|
147
|
+
|
|
148
|
+
# others
|
|
149
|
+
@staticmethod
|
|
150
|
+
def validate_image_objects(name: str, value: Union[str, Image, Dimage]):
|
|
151
|
+
if isinstance(value, str):
|
|
152
|
+
return
|
|
153
|
+
if isinstance(value, Image):
|
|
154
|
+
return
|
|
155
|
+
if isinstance(value, Dimage):
|
|
156
|
+
return
|
|
157
|
+
|
|
158
|
+
raise ValueError(f'Arg "{name}" requires str or PIL.Image.Image or ShapeTextStyle. But {value} is given.')
|
|
159
|
+
|
|
160
|
+
@staticmethod
|
|
161
|
+
def validate_fontsourcecode(name, str, value: FontSourceCode):
|
|
162
|
+
if not isinstance(value, FontSourceCode):
|
|
163
|
+
raise ValueError(f'Arg "{name}" requirest FontSourcecode. But {value} is given.')
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# Copyright (c) 2024 Yuichi Ito (yuichi@yuichi.com)
|
|
2
|
+
#
|
|
3
|
+
# This software is licensed under the Apache License, Version 2.0.
|
|
4
|
+
# For more information, please visit: https://github.com/yuichi110/drawlib
|
|
5
|
+
#
|
|
6
|
+
# This software is provided "as is", without warranty of any kind,
|
|
7
|
+
# express or implied, including but not limited to the warranties of
|
|
8
|
+
# merchantability, fitness for a particular purpose and noninfringement.
|
|
9
|
+
|
|
10
|
+
"""Handle drawlib command
|
|
11
|
+
|
|
12
|
+
Entry point ``__main__`` calls this module's function ``call()``.
|
|
13
|
+
After that class ``DrawlibArgParser`` parse options.
|
|
14
|
+
Then operate appropriate actions.
|
|
15
|
+
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
import os
|
|
19
|
+
import sys
|
|
20
|
+
import argparse
|
|
21
|
+
from typing import Optional, List
|
|
22
|
+
import drawlib
|
|
23
|
+
import drawlib.v0_1
|
|
24
|
+
from drawlib.v0_1.private.logging import logger
|
|
25
|
+
from drawlib.v0_1.private.settings import dsettings
|
|
26
|
+
from drawlib.v0_1.private.tools import dload
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def call() -> None:
|
|
30
|
+
"""drawlib command handling function.
|
|
31
|
+
|
|
32
|
+
This method is called from each API's ``__main__`` module.
|
|
33
|
+
If the API is latest, called from root package's ``__main__`` module too.
|
|
34
|
+
|
|
35
|
+
Abstract procedure of this function.
|
|
36
|
+
|
|
37
|
+
1. Crate DrawlibArgParser instance.
|
|
38
|
+
2. Parse command line options
|
|
39
|
+
3. If options requests version info, show it and quit.
|
|
40
|
+
4. Apply options such as logging level
|
|
41
|
+
5. get target files and directories which drawlib run.
|
|
42
|
+
6. call ``tools.run()`` for each files, directories
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
None
|
|
46
|
+
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
argparser = DrawlibArgParser()
|
|
50
|
+
argparser.parse()
|
|
51
|
+
argparser.show_version_then_exit0_if_requested()
|
|
52
|
+
argparser.apply_options()
|
|
53
|
+
paths = argparser.get_positional_args()
|
|
54
|
+
|
|
55
|
+
if len(paths) == 0:
|
|
56
|
+
logger.critical("no input files and directories")
|
|
57
|
+
logger.critical('check options with "drawlib --help"')
|
|
58
|
+
sys.exit(1)
|
|
59
|
+
|
|
60
|
+
for path in paths:
|
|
61
|
+
if not os.path.isfile(path) and not os.path.isdir(path):
|
|
62
|
+
msg = f'ignore arg "{path}" since it is not a file/dir path'
|
|
63
|
+
logger.warning(msg)
|
|
64
|
+
continue
|
|
65
|
+
|
|
66
|
+
abspath = os.path.abspath(path)
|
|
67
|
+
realpath = os.path.realpath(abspath)
|
|
68
|
+
logger.info(realpath)
|
|
69
|
+
dload(realpath)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class DrawlibArgParser:
|
|
73
|
+
"""drawlib ArgParser Class"""
|
|
74
|
+
|
|
75
|
+
def __init__(self) -> None:
|
|
76
|
+
"""Initializa DrawlibArgParser
|
|
77
|
+
|
|
78
|
+
In this method, create ``ArgumentParser`` instance and
|
|
79
|
+
define command line options.
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
None
|
|
83
|
+
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
parser = argparse.ArgumentParser(
|
|
87
|
+
description="Ilustration as code by python",
|
|
88
|
+
)
|
|
89
|
+
parser.add_argument(
|
|
90
|
+
"file_or_directory",
|
|
91
|
+
nargs="...",
|
|
92
|
+
help="Target python file or directory which contains python codes",
|
|
93
|
+
)
|
|
94
|
+
parser.add_argument(
|
|
95
|
+
"-v",
|
|
96
|
+
"--version",
|
|
97
|
+
action="store_true",
|
|
98
|
+
help="Show version",
|
|
99
|
+
)
|
|
100
|
+
parser.add_argument(
|
|
101
|
+
"--quiet",
|
|
102
|
+
action="store_true",
|
|
103
|
+
help="Enable quiet logging. show only error messages",
|
|
104
|
+
)
|
|
105
|
+
parser.add_argument(
|
|
106
|
+
"--verbose",
|
|
107
|
+
action="store_true",
|
|
108
|
+
help="Enable verbose logging.",
|
|
109
|
+
)
|
|
110
|
+
parser.add_argument(
|
|
111
|
+
"--developer",
|
|
112
|
+
action="store_true",
|
|
113
|
+
help=("Enable verbose logging. " "Disable error handling for library users."),
|
|
114
|
+
)
|
|
115
|
+
self._parser = parser
|
|
116
|
+
self._positional_args: Optional[List[str]] = None
|
|
117
|
+
self._name_args: Optional[argparse.Namespace] = None
|
|
118
|
+
|
|
119
|
+
def parse(self) -> None:
|
|
120
|
+
"""Parse command line options.
|
|
121
|
+
|
|
122
|
+
Parse command line options.
|
|
123
|
+
This method must be called before calling get methods.
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
None
|
|
127
|
+
|
|
128
|
+
"""
|
|
129
|
+
|
|
130
|
+
self._name_args, _ = self._parser.parse_known_args()
|
|
131
|
+
args = self._parser.parse_args()
|
|
132
|
+
self._positional_args = args.file_or_directory
|
|
133
|
+
|
|
134
|
+
def get_positional_args(self) -> List[str]:
|
|
135
|
+
"""Get positional args. which are files and directories.
|
|
136
|
+
|
|
137
|
+
drawlib command requires files and directories as positional args.
|
|
138
|
+
They are the target of ``tool.run()`` function.
|
|
139
|
+
It means specified file or files inside directories
|
|
140
|
+
are called from python.
|
|
141
|
+
If those python files are drawlib's one, generate images.
|
|
142
|
+
|
|
143
|
+
This method must be called after ``parse()`` method is called.
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
List[str]: Positional args (files and directories)
|
|
147
|
+
|
|
148
|
+
"""
|
|
149
|
+
|
|
150
|
+
if self._positional_args is None:
|
|
151
|
+
logger.critical("DrawlibArgParser must be parsed before getting optional args")
|
|
152
|
+
sys.exit(1)
|
|
153
|
+
|
|
154
|
+
return self._positional_args
|
|
155
|
+
|
|
156
|
+
def show_version_then_exit0_if_requested(self) -> None:
|
|
157
|
+
"""show version if option ``-v/`` or ``--version`` exists. And then quit.
|
|
158
|
+
|
|
159
|
+
Check whether option has ``-v`` or ``--version``.
|
|
160
|
+
If yes, show version. And then, quit with ``sys.exit(0)``.
|
|
161
|
+
|
|
162
|
+
Returns:
|
|
163
|
+
None
|
|
164
|
+
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
if self._name_args is None:
|
|
168
|
+
logger.critical("DrawlibArgParser must be parsed before apply options")
|
|
169
|
+
sys.exit(1)
|
|
170
|
+
|
|
171
|
+
if self._name_args.version:
|
|
172
|
+
logger.critical(f"software={drawlib.VERSION}")
|
|
173
|
+
logger.critical(f"api={drawlib.v0_1.VERSION}")
|
|
174
|
+
sys.exit(0)
|
|
175
|
+
|
|
176
|
+
def apply_options(self) -> None:
|
|
177
|
+
"""Check named args and apply appropriate configs.
|
|
178
|
+
|
|
179
|
+
Check these named argses. And do appropriate actions.
|
|
180
|
+
|
|
181
|
+
* --quiet: make logging mode quiet
|
|
182
|
+
* --debug: make logging mode verbose
|
|
183
|
+
* --devdebug: make logging mode developer
|
|
184
|
+
|
|
185
|
+
Returns:
|
|
186
|
+
None
|
|
187
|
+
|
|
188
|
+
"""
|
|
189
|
+
|
|
190
|
+
if self._name_args is None:
|
|
191
|
+
logger.critical("DrawlibArgParser must be parsed before apply options")
|
|
192
|
+
sys.exit(1)
|
|
193
|
+
|
|
194
|
+
if self._name_args.quiet and (self._name_args.verbose or self._name_args.developer):
|
|
195
|
+
raise ValueError("option --quiet can't use with option --debug and --devdebug")
|
|
196
|
+
|
|
197
|
+
if self._name_args.quiet:
|
|
198
|
+
dsettings.set_logging_mode("quiet")
|
|
199
|
+
|
|
200
|
+
if self._name_args.verbose:
|
|
201
|
+
dsettings.set_logging_mode("verbose")
|
|
202
|
+
|
|
203
|
+
if self._name_args.developer:
|
|
204
|
+
dsettings.set_logging_mode("developer")
|