Skip to content
Permalink
Browse files

Convert script to python3 and pep8 it

  • Loading branch information
lbartoletti committed Feb 22, 2018
1 parent b47eb87 commit 002c02085985a2be99477f174d609c279fbb4094
Showing with 16 additions and 8 deletions.
  1. +16 −8 scripts/mkuidefaults.py
24 scripts/mkuidefaults.py 100644 → 100755
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
@@ -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)
@@ -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

0 comments on commit 002c020

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