-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkuidefaults.py
executable file
·103 lines (81 loc) · 3.03 KB
/
mkuidefaults.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
"""
***************************************************************************
mkuidefaults.py
---------------------
Date : June 2013
Copyright : (C) 2013 by Juergen E. Fischer
Email : jef at norbit dot de
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
__author__ = "Juergen E. Fischer"
__date__ = "June 2013"
__copyright__ = "(C) 2013, Juergen E. Fischer"
import struct
import sys
from PyQt5.QtCore import QCoreApplication, QSettings
def chunks(l, n):
for i in range(0, len(l), n):
yield l[i : i + n]
QCoreApplication.setOrganizationName("QGIS")
QCoreApplication.setOrganizationDomain("qgis.org")
QCoreApplication.setApplicationName("QGIS3")
if len(sys.argv) == 1:
print('Usage: ./scripts/mkuidefaults.py "location_to_ini"')
sys.exit(1)
s = QSettings(sys.argv[1], QSettings.Format.IniFormat)
ba = bytes(s.value("/UI/geometry"))
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"
)
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")