-
Notifications
You must be signed in to change notification settings - Fork 1
/
gestalt.py
executable file
·174 lines (125 loc) · 4.36 KB
/
gestalt.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#! /usr/bin/env python3
import os
import sys
import argparse
import pathlib
import tempfile
import traceback
#import cProfile
from templates import *
from gestalt import Datasheet, Stylesheet
curr_dir = str(pathlib.Path(__file__).resolve().parent.resolve())
parser = argparse.ArgumentParser(prog='gestalt', usage='%(prog)s [OPTIONS] [TEMPLATE]', formatter_class=argparse.RawTextHelpFormatter, exit_on_error=False)
parser.add_argument("template", nargs="?", metavar="TEMPLATE", type=str, help="The template file used in constructing the output")
parser.add_argument("-f", "-r", "--from", "--read",
metavar="FORMAT",
dest="in_format",
action="store",
help="""
File parser that should be used for the input data file.
Recognized values are ['yml', 'yaml', 'string', 'str',
"json", "JSON", "substitutions", "msi", "ini", "cfg", "auto"]
(Default: 'auto')
""",
type=str,
default="auto",
choices=["yml", "yaml", "string", "str", "JSON", "json", "substitutions", "msi", "auto"])
parser.add_argument("-t", "-w", "--to", "--write",
metavar="FORMAT",
dest="out_format",
action="store",
help="""
File type conversion that should be used for the output
UI file.
Recognized values are ['qt', 'css', 'ui', 'bob', "auto"]
(Default: 'auto')
""",
type=str,
default="auto",
choices=["qt", "bob", "ui", "css", "auto"])
parser.add_argument("-o", "--output",
metavar="FILE",
dest="out_filename",
action="store",
help="""
Output file name
(Default: Generate from template file and output format)
""",
type=str)
parser.add_argument('-i', "--input",
metavar="FILE",
dest='in_filename',
action='store',
help="""
Input data to apply to template file. Either a string
containing data in a yaml format, or the path to a
file to be parsed according to the input format.
(Default: Template will be applied with no macros)
""",
type=str)
parser.add_argument("--include",
metavar="FOLDER",
dest="include_dirs",
action="append",
help="""
Folders to search for any files included by the template.
Can be applied multiple times, one folder per argument.
By default, the search path includes the current directory
and gestalt's template directory (for colors.yml).
""",
type=str)
def doGenerate(args):
include_dirs = [".", curr_dir + "/widgets"]
if args.include_dirs:
include_dirs.extend(args.include_dirs)
data = {}
if args.in_filename:
parse_format = args.in_format
if args.in_format == "auto":
parse_format = pathlib.PurePath(args.in_filename).suffix.lstrip('.')
if parse_format == "string" or parse_format == "str" or parse_format=="":
data = Datasheet.parseYAMLString(args.in_filename)
elif parse_format == "yaml" or parse_format == "yml":
data = Datasheet.parseYAMLFile(args.in_filename)
elif parse_format == "json" or parse_format == "JSON":
data = Datasheet.parseJSONFile(args.in_filename)
elif parse_format == "msi" or parse_format == "substitutions":
data = Datasheet.parseSubstitutionFile(args.in_filename)
elif parse_format == "ini" or parse_format == "cfg":
data = Datasheet.parseINIFile(args.in_filename)
else:
print("Unknown file extension: ", parse_format)
return
styles = Stylesheet.parse(args.template, include_dirs)
if args.out_format == "auto":
if not args.out_filename:
print("Must specify either output file type or output file name")
return
args.out_format = pathlib.PurePath(args.out_filename).suffix.lstrip('.')
if args.out_format == "qt":
args.out_format = "ui"
elif args.out_format == "css":
args.out_format = "bob"
if not args.out_filename:
args.out_filename = pathlib.PurePath(args.template).stem + "." + args.out_format
if args.out_format == "ui":
from gestalt.convert.qt.QtGenerator import generateQtFile
generateQtFile(styles, data, outputfile=args.out_filename)
elif args.out_format == "bob":
from gestalt.convert.phoebus.CSSGenerator import generateCSSFile
generateCSSFile(styles, data, outputfile=args.out_filename)
else:
print("Unknown file extension: ", write_format)
if __name__ == "__main__":
args = parser.parse_args()
if (len(sys.argv) == 1):
from gestalt.Gui import UI
from PyQt5.QtWidgets import *
app = QApplication([])
window = UI(curr_dir, doGenerate, registry, parser)
app.exec_()
elif args.template == None:
print("Template file required for command-line conversion")
else:
#cProfile.run("doGenerate(args)")
doGenerate(args)