Skip to content
Permalink
Browse files

Merge pull request #6405 from lbartoletti/mkuidefaults_python3

Convert mkuidefaults script to python3 and pep8 it
  • Loading branch information
m-kuhn committed Apr 12, 2018
2 parents 222e45b + 99ae08a commit c3fdef9db127f84de666f651734b1c580d95dcd4
Showing with 36 additions and 30 deletions.
  1. +36 −30 scripts/mkuidefaults.py
66 scripts/mkuidefaults.py 100644 → 100755
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
@@ -39,46 +40,51 @@ def chunks(l, n):
QCoreApplication.setApplicationName("QGIS3")

if len(sys.argv) == 1:
print "Usage: python ./scripts/mkuidefaults.py \"location_to_ini\""
print("Usage: ./scripts/mkuidefaults.py \"location_to_ini\"")
sys.exit(1)

s = QSettings(sys.argv[1], QSettings.IniFormat)

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'.format(
', '.join(map(hex, struct.unpack('B' * len(chunk), chunk)))))

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\nstatic const unsigned char defaultUIstate[] =\n{\n")

f.write("};\n\n#endif // UI_DEFAULTS_H\n")
ba = bytes(s.value("/UI/state"))

f.close()
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")

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 c3fdef9

Please sign in to comment.
You can’t perform that action at this time.