svg_tetraflexagon_editor: draw also the backface
[flexagon-toolkit.git] / src / gimp_diagram_test.py
1 #!/usr/bin/env python
2
3 '''
4 Gimp plugin "TestGimpDiagram"
5
6 Test the GImpDiagram class
7
8 Copyright (C) 2018  Antonio Ospite <ao2@ao2.it>
9
10 This program is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 '''
23
24 from math import pi
25 import gimpfu
26 from gimpfu import *
27
28 from diagram.gimp_diagram import GimpDiagram
29
30 gettext.install("gimp20-python", gimp.locale_directory, unicode=True)
31
32
33 def test_diagram_main(image):
34     pdb.gimp_image_undo_group_start(image)
35     pdb.gimp_context_push()
36     pdb.gimp_context_set_defaults()
37
38     template_layer_name = "TestGimpDiagram"
39     template_layer = pdb.gimp_image_get_layer_by_name(image,
40                                                       template_layer_name)
41     if not template_layer:
42         template_layer = pdb.gimp_layer_new(image, image.width, image.height,
43                                             gimpfu.RGBA_IMAGE,
44                                             template_layer_name,
45                                             100,
46                                             gimpfu.NORMAL_MODE)
47         pdb.gimp_image_add_layer(image, template_layer, -1)
48
49     diagram = GimpDiagram(image.width, image.height, image, template_layer,
50                           font_size=10, stroke_size=2)
51
52     diagram.draw_regular_polygon(200, 200, 6, 100, 0,
53                                  fill_color=(1, 1, 0))
54
55     diagram.draw_regular_polygon(200, 200, 6, 100, pi / 12.,
56                                  stroke_color=(1, 0, 0, 0.2))
57
58     diagram.draw_centered_text(200, 200, "__30__", pi / 6., (0, 0, 0))
59
60     pdb.gimp_context_pop()
61     pdb.gimp_image_undo_group_end(image)
62
63
64 if __name__ == "__main__":
65     register(
66         "python_fu_test_gimp_diagram",
67         N_("Test GimpDiagram"),
68         "Test GimpDiagram",
69         "Antonio Ospite <ao2@ao2.it>",
70         "Copyright (C) 2018  Antonio Ospite <ao2@ao2.it>",
71         "2017",
72         N_("TestGImpDiagram..."),
73         "RGB*, GRAY*",
74         [
75             (PF_IMAGE, "image", "Input image", None),
76         ],
77         [],
78         test_diagram_main,
79         menu="<Image>/Filters/Render",
80         domain=("gimp20-python", gimp.locale_directory)
81     )
82
83     main()