Skip to content
Permalink
Browse files

[ui] update mkuidefaults.py script

  • Loading branch information
nirvn committed Feb 18, 2018
1 parent 323e75c commit 65f6a909b1895ac0e04fa8d0bed6e894f0c5d1ad
Showing with 18 additions and 11 deletions.
  1. +18 −11 scripts/mkuidefaults.py
@@ -23,7 +23,10 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from qgis.PyQt.QtCore import QCoreApplication, QSettings
import sys
import struct

from PyQt5.QtCore import QCoreApplication, QSettings


def chunks(l, n):
@@ -35,40 +38,44 @@ def chunks(l, n):
QCoreApplication.setOrganizationDomain("qgis.org")
QCoreApplication.setApplicationName("QGIS3")

s = QSettings()
if len(sys.argv) == 1:
print "Usage: python ./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")

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(" %s,\n" % ", ".join(map(lambda x: "0x%02x" % x, 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(" %s,\n" % ", ".join(map(lambda x: "0x%02x" % x, chunk)))
f.write(' {},\n'.format(', '.join(map(hex, struct.unpack('B' * len(chunk), chunk)))))

try:
ba = bytes(s.value("/Composer/geometry"))

f.write("};\n\nstatic const unsigned char defaultComposerUIgeometry[] =\n{\n")
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(" %s,\n" % ", ".join(map(lambda x: "0x%02x" % x, chunk)))
f.write(' {},\n'.format(', '.join(map(hex, struct.unpack('B' * len(chunk), chunk)))))
except TypeError as ex:
pass

try:
ba = bytes(s.value("/ComposerUI/state"))
f.write("};\n\nstatic const unsigned char defaultComposerUIstate[] =\n{\n")
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(" %s,\n" % ", ".join(map(lambda x: "0x%02x" % x, chunk)))
f.write(' {},\n'.format(', '.join(map(hex, struct.unpack('B' * len(chunk), chunk)))))
except TypeError as ex:
pass

0 comments on commit 65f6a90

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