Skip to content

Commit

Permalink
use with open as block
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti committed Apr 8, 2018
1 parent 002c020 commit 99ae08a
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions scripts/mkuidefaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,45 +48,43 @@ def chunks(l, n):
ba = bytes(s.value("/UI/geometry"))
print

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

f.write("#ifndef UI_DEFAULTS_H\n#define UI_DEFAULTS_H\n" +
"\nstatic const unsigned char defaultUIgeometry[] =\n{\n")

for chunk in chunks(ba, 16):
f.write(' {},\n'.format(
', '.join(map(hex, struct.unpack('B' * len(chunk), chunk)))))

f.write("};\n\nstatic const unsigned char defaultUIstate[] =\n{\n")

ba = bytes(s.value("/UI/state"))

for chunk in chunks(ba, 16):
f.write(' {},\n'.format(
', '.join(map(hex, struct.unpack('B' * len(chunk), chunk)))))

try:
ba = bytes(s.value("/app/LayoutDesigner/geometry"))
f.write("};\n\nstatic const unsigned char " +
"defaultLayerDesignerUIgeometry[] =\n{\n")
f.write("#ifndef UI_DEFAULTS_H\n#define UI_DEFAULTS_H\n" +
"\nstatic const unsigned char defaultUIgeometry[] =\n{\n")

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

try:
ba = bytes(s.value("/app/LayoutDesigner/state"))
f.write("};\n\nstatic const unsigned char " +
"defaultLayerDesignerUIstate[] =\n{\n")
f.write("};\n\nstatic const unsigned char defaultUIstate[] =\n{\n")

ba = bytes(s.value("/UI/state"))

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

f.write("};\n\n#endif // UI_DEFAULTS_H\n")

f.close()
try:
ba = bytes(s.value("/app/LayoutDesigner/geometry"))
f.write("};\n\nstatic const unsigned char " +
"defaultLayerDesignerUIgeometry[] =\n{\n")

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

try:
ba = bytes(s.value("/app/LayoutDesigner/state"))
f.write("};\n\nstatic const unsigned char " +
"defaultLayerDesignerUIstate[] =\n{\n")

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

f.write("};\n\n#endif // UI_DEFAULTS_H\n")

0 comments on commit 99ae08a

Please sign in to comment.