-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgestalt.py
More file actions
executable file
·225 lines (160 loc) · 5.5 KB
/
gestalt.py
File metadata and controls
executable file
·225 lines (160 loc) · 5.5 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#! /usr/bin/env python3
import os
import sys
import argparse
import pathlib
import tempfile
import traceback
import cProfile
from layouts import *
from gestalt import Datasheet, Stylesheet, Utils
curr_dir = str(pathlib.Path(__file__).resolve().parent.resolve())
parser = argparse.ArgumentParser(prog='gestalt', usage='%(prog)s [OPTIONS] [LAYOUT]', formatter_class=argparse.RawTextHelpFormatter, exit_on_error=False)
parser.add_argument("layout", nargs="?", metavar="LAYOUT", type=str, help="The layout 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', "pydm", "dm", "auto"]
(Default: 'auto')
""",
type=str,
default="auto",
choices=["qt", "bob", "ui", "css", "pydm", "dm", "auto"])
parser.add_argument("-o", "--output",
metavar="FILE",
dest="out_filename",
action="store",
help="""
Output file name
(Default: Generate from layout file and output format)
""",
type=str)
parser.add_argument('-i', "--input",
metavar="FILE",
dest='in_filename',
action='store',
help="""
Input data to apply to layout 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: Layout 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 layout.
Can be applied multiple times, one folder per argument.
By default, the search path includes the current directory
and gestalt's widgets directory (for colors.yml).
""",
type=str)
parser.add_argument("--profile",
action="store_true",
dest="enable_profile",
help="""
Enable the python profiler and output speed information
""")
parser.add_argument("--depends",
action="store_true",
dest="list_depends",
help="""
List all includes of provided input and layout
""")
def listDepends(args):
include_dirs = [".", curr_dir + "/widgets"]
output_files = []
output_files.append(args.layout)
if args.include_dirs:
include_dirs.extend(args.include_dirs)
if args.in_filename:
output_files.append(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 == "yaml" or parse_format == "yml":
output_files.extend(Utils.get_includes(args.in_filename, include_dirs, []))
output_files.extend(Utils.get_includes(args.layout, include_dirs, []))
print(" ".join(output_files))
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.layout, 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"
elif args.out_format == "pydm":
args.out_format = "dm"
if not args.out_filename:
args.out_filename = pathlib.PurePath(args.layout).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)
elif args.out_format == "dm":
from gestalt.convert.pydm.DMGenerator import generateDMFile
generateDMFile(styles, data, outputfile=args.out_filename)
else:
print("Unknown file extension: ", args.out_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.layout == None:
print("Layout file required for command-line conversion")
elif args.enable_profile:
cProfile.run("doGenerate(args)")
elif args.list_depends:
listDepends(args)
else:
doGenerate(args)