summaryrefslogtreecommitdiff
path: root/lib/inx/extensions.py
blob: cab1ece6705adaec8df3d883752ab4ced6cd2585 (plain)
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
# Authors: see git history
#
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later.  See the file LICENSE for details.

import os

import pystitch

from ..commands import (COMMANDS, GLOBAL_COMMANDS, LAYER_COMMANDS,
                        OBJECT_COMMANDS)
from ..extensions import Input, Output, extensions
from ..lettering.categories import FONT_CATEGORIES
from ..threads import ThreadCatalog
from .outputs import pystitch_output_formats
from .utils import build_environment, write_inx_file


def layer_commands():
    # We purposefully avoid using commands.get_command_description() here.  We
    # want to call _() on the description inside the actual template so that
    # we use the translation language selected in build_environment().
    return [(command, COMMANDS[command]) for command in LAYER_COMMANDS]


def global_commands():
    return [(command, COMMANDS[command]) for command in GLOBAL_COMMANDS]


def object_commands():
    return [(command, COMMANDS[command]) for command in OBJECT_COMMANDS]


def pystitch_debug_formats():
    for format in pystitch.supported_formats():
        if 'writer' in format and format['category'] not in ['embroidery', 'image', 'color', 'stitch']:
            yield format['extension'], format['description']


def threadcatalog():
    threadcatalog = ThreadCatalog().palette_names()
    return threadcatalog


def generate_extension_inx_files(alter_data):
    env = build_environment()

    for extension in extensions:
        if extension is Input or extension is Output:
            continue

        if extension.DEVELOPMENT_ONLY and 'BUILD' in os.environ:
            continue

        name = extension.name()
        template = env.get_template(f'{name}.xml')
        write_inx_file(name, template.render(alter_data,
                                             formats=pystitch_output_formats(),
                                             debug_formats=pystitch_debug_formats(),
                                             threadcatalog=threadcatalog(),
                                             font_categories=FONT_CATEGORIES,
                                             layer_commands=layer_commands(),
                                             object_commands=object_commands(),
                                             global_commands=global_commands()))