Skip to content

Commit 99ae08a

Browse files
committedApr 8, 2018
use with open as block
1 parent 002c020 commit 99ae08a

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed
 

‎scripts/mkuidefaults.py

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,45 +48,43 @@ def chunks(l, n):
4848
ba = bytes(s.value("/UI/geometry"))
4949
print
5050

51-
f = open("src/app/ui_defaults.h", "w")
51+
with open("src/app/ui_defaults.h", "w") as f:
5252

53-
f.write("#ifndef UI_DEFAULTS_H\n#define UI_DEFAULTS_H\n" +
54-
"\nstatic const unsigned char defaultUIgeometry[] =\n{\n")
55-
56-
for chunk in chunks(ba, 16):
57-
f.write(' {},\n'.format(
58-
', '.join(map(hex, struct.unpack('B' * len(chunk), chunk)))))
59-
60-
f.write("};\n\nstatic const unsigned char defaultUIstate[] =\n{\n")
61-
62-
ba = bytes(s.value("/UI/state"))
63-
64-
for chunk in chunks(ba, 16):
65-
f.write(' {},\n'.format(
66-
', '.join(map(hex, struct.unpack('B' * len(chunk), chunk)))))
67-
68-
try:
69-
ba = bytes(s.value("/app/LayoutDesigner/geometry"))
70-
f.write("};\n\nstatic const unsigned char " +
71-
"defaultLayerDesignerUIgeometry[] =\n{\n")
53+
f.write("#ifndef UI_DEFAULTS_H\n#define UI_DEFAULTS_H\n" +
54+
"\nstatic const unsigned char defaultUIgeometry[] =\n{\n")
7255

7356
for chunk in chunks(ba, 16):
7457
f.write(' {},\n'.format(
7558
', '.join(map(hex, struct.unpack('B' * len(chunk), chunk)))))
76-
except TypeError as ex:
77-
pass
7859

79-
try:
80-
ba = bytes(s.value("/app/LayoutDesigner/state"))
81-
f.write("};\n\nstatic const unsigned char " +
82-
"defaultLayerDesignerUIstate[] =\n{\n")
60+
f.write("};\n\nstatic const unsigned char defaultUIstate[] =\n{\n")
61+
62+
ba = bytes(s.value("/UI/state"))
8363

8464
for chunk in chunks(ba, 16):
8565
f.write(' {},\n'.format(
8666
', '.join(map(hex, struct.unpack('B' * len(chunk), chunk)))))
87-
except TypeError as ex:
88-
pass
89-
90-
f.write("};\n\n#endif // UI_DEFAULTS_H\n")
9167

92-
f.close()
68+
try:
69+
ba = bytes(s.value("/app/LayoutDesigner/geometry"))
70+
f.write("};\n\nstatic const unsigned char " +
71+
"defaultLayerDesignerUIgeometry[] =\n{\n")
72+
73+
for chunk in chunks(ba, 16):
74+
f.write(' {},\n'.format(
75+
', '.join(map(hex, struct.unpack('B' * len(chunk), chunk)))))
76+
except TypeError as ex:
77+
pass
78+
79+
try:
80+
ba = bytes(s.value("/app/LayoutDesigner/state"))
81+
f.write("};\n\nstatic const unsigned char " +
82+
"defaultLayerDesignerUIstate[] =\n{\n")
83+
84+
for chunk in chunks(ba, 16):
85+
f.write(' {},\n'.format(
86+
', '.join(map(hex, struct.unpack('B' * len(chunk), chunk)))))
87+
except TypeError as ex:
88+
pass
89+
90+
f.write("};\n\n#endif // UI_DEFAULTS_H\n")

0 commit comments

Comments
 (0)
Please sign in to comment.