-
-
Notifications
You must be signed in to change notification settings - Fork 236
/
uiutils.py
130 lines (101 loc) · 3.47 KB
/
uiutils.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
import PyQt5.QtGui as gui
import version
def getChildNodesByName(parent, name):
nodes = []
for node in parent.childNodes:
if node.nodeType == node.ELEMENT_NODE and node.localName == name:
nodes.append(node)
return nodes
def colorConvert(color):
hexcolor = hex(int(color) & 0xFFFFFF)[2:].upper().zfill(6)
redcolor = int('0x' + hexcolor[0:2], 16)
greencolor = int('0x' + hexcolor[2:4], 16)
bluecolor = int('0x' + hexcolor[4:6], 16)
return 'rgb(%i,%i,%i)' % (bluecolor, greencolor, redcolor)
def getRectangleXML(xml, scale=1):
rect = {}
rect['left'] = int(float(xml.getAttribute("Left")) / float(scale))
rect['top'] = int(float(xml.getAttribute("Top")) / float(scale))
rect['height'] = int(float(xml.getAttribute("Height")) / float(scale))
rect['width'] = int(float(xml.getAttribute("Width")) / float(scale))
return rect
def getFontColor(xml):
font = getChildNodesByName(xml, "Font")[0]
if font.getAttribute("Color"):
return colorConvert(font.getAttribute("Color"))
else:
return colorConvert(0xAAAAAA)
def getFontXML(xml):
f = {}
font = getChildNodesByName(xml, "Font")[0]
f['name'] = font.getAttribute("Name")
f['size'] = float(font.getAttribute("Size").replace(',', '.'))
f['bold'] = font.getAttribute("Bold")
f['italic'] = font.getAttribute("Italic")
return f
def getXMLFont(xml, scale=1):
font = getChildNodesByName(xml, "Font")[0]
font_name = font.getAttribute("Name")
font_size = float(font.getAttribute("Size").replace(',', '.'))
if sys.platform[:3] == "dar":
font_name = "Arial"
font_size = 11
font_bold = font.getAttribute("Bold")
font_italic = font.getAttribute("Italic")
if font_bold == '1':
fnt_flags = gui.QFont.Bold
else:
fnt_flags = gui.QFont.Normal
if font_italic == '1':
fnt_flags |= gui.QFont.StyleItalic
font_size: float = font_size / float(scale) * 14.
qfnt = gui.QFont(font_name, int(font_size), fnt_flags)
qfnt.setPixelSize(int(font_size))
return qfnt
class displayData:
def __init__(self, data, widget, is_combo=False):
self.data = data
self.widget = widget
self.is_combo = is_combo
class displayDict:
def __init__(self, request_name, request):
self.request = request
self.request_name = request_name
self.data = []
self.datadict = {}
def addData(self, displaydata):
self.data.append(displaydata)
if not displaydata.data.name in self.datadict:
self.datadict[displaydata.data.name] = displaydata
def getDataByName(self, name):
for data in self.data:
if data.data.name == name:
return data
return None
def jsonFont(fnt, scale):
font_name = fnt['name']
font_size = fnt['size']
if sys.platform[:3] == "dar":
font_name = "Arial"
font_size = 11
if 'bold' in fnt:
font_bold = fnt['bold']
else:
font_bold = '0'
if 'italic' in fnt:
font_italic = fnt['italic']
else:
font_italic = '0'
if font_bold == '1':
fnt_flags = gui.QFont.Bold
else:
fnt_flags = gui.QFont.Normal
if font_italic == '1':
fnt_flags |= gui.QFont.StyleItalic
font_size = int(font_size / float(scale) * 14.)
qfnt = gui.QFont(font_name, font_size, fnt_flags)
qfnt.setPixelSize(font_size)
return qfnt