summaryrefslogtreecommitdiffstats
path: root/awlsim/gui/icons/pic2py
blob: b068f203f6d1390266e5e4b55497aef63baa23fc (plain)
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
#!/usr/bin/env python3

import sys
import base64
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtSvg import *

qapp = QApplication(sys.argv)

inFile = sys.argv[1]
outFile = sys.argv[2]

if inFile.lower().endswith(".svg"):
	render = QSvgRenderer(inFile)
	img = QImage(48, 48, QImage.Format_ARGB32)
	img.fill(QColor(0, 0, 0, 0))
	painter = QPainter()
	painter.begin(img)
	render.render(painter)
	painter.end()
else:
	img = QImage(inFile)

ba = QByteArray()
buf = QBuffer(ba)
buf.open(QIODevice.WriteOnly)
img.save(buf, "PNG")
imgB64 = base64.b64encode(ba.data())
fd = open(outFile, "wb")
baseName = outFile.split("/")[-1]
baseName = baseName[ : baseName.rfind(".")]
varName = baseName.replace("-", "_")
varDef = "icon_%s = b'" % varName
fd.write(b"# AUTOMATICALLY GENERATED FILE\n")
fd.write(b"# DO NOT EDIT\n")
fd.write(b"\n")
fd.write(("# Generated from %s\n" % inFile.split("/")[-1]).encode())
fd.write(b"\n")
fd.write(varDef.encode())
while imgB64:
	fd.write(imgB64[:48])
	imgB64 = imgB64[48:]
	if imgB64:
		fd.write(b"'\\\n" + b" " * (len(varDef) - 2) + b"b'")
fd.write(b"'\n")

qapp.exit(0)
bues.ch cgit interface