Skip to content

Commit

Permalink
Convert script to python3 and pep8 it
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti committed Feb 22, 2018
1 parent b47eb87 commit 002c020
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions scripts/mkuidefaults.py 100644 → 100755
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
Expand Down Expand Up @@ -39,7 +40,7 @@ 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)
Expand All @@ -49,33 +50,40 @@ def chunks(l, n):

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

f.write("#ifndef UI_DEFAULTS_H\n#define UI_DEFAULTS_H\n\nstatic const unsigned char defaultUIgeometry[] =\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)))))
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)))))
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("};\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)))))
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 " +
"defaultLayerDesignerUIstate[] =\n{\n")

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

Expand Down

0 comments on commit 002c020

Please sign in to comment.