-
-
Notifications
You must be signed in to change notification settings - Fork 238
/
Copy pathdisplaymod.py
573 lines (475 loc) · 21 KB
/
displaymod.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
# -*- coding: utf-8 -*-
import PyQt4.QtGui as gui
import PyQt4.QtCore as core
import options
from uiutils import *
class labelWidget(gui.QLabel):
def __init__(self, parent, uiscale):
super(labelWidget, self).__init__(parent)
self.jsondata = None
self.ismovable = True
self.uiscale = uiscale
def change_ratio(self, x):
return
def initXML(self, xmldata):
text = xmldata.getAttribute("Text")
color = xmldata.getAttribute("Color")
alignment = xmldata.getAttribute("Alignment")
rect = getRectangleXML(getChildNodesByName(xmldata, "Rectangle")[0], self.uiscale)
qfnt = getXMLFont(xmldata, self.uiscale)
self.setFont(qfnt)
self.setText(text)
self.resize(rect['width'], rect['height'])
self.setStyleSheet("background: %s; color: %s" % (colorConvert(color), getFontColor(xmldata)))
self.move(rect['left'], rect['top'])
if alignment == '2':
self.setAlignment(core.Qt.AlignHCenter)
else:
self.setAlignment(core.Qt.AlignLeft)
def initJson(self, jsdata):
text = jsdata['text']
color = jsdata['color']
alignment = jsdata['alignment']
fontcolor = jsdata['fontcolor']
rect = jsdata['bbox']
qfnt = jsonFont(jsdata['font'], self.uiscale)
self.ismovable = True
self.setFont(qfnt)
self.setText(text)
self.resize(rect['width'] / self.uiscale, rect['height'] / self.uiscale)
self.setStyleSheet("background: %s; color: %s" % (color, fontcolor))
self.move(rect['left'] / self.uiscale, rect['top'] / self.uiscale)
if alignment == '2':
self.setAlignment(core.Qt.AlignHCenter)
else:
self.setAlignment(core.Qt.AlignLeft)
self.jsondata = jsdata
def resize(self, x, y):
super(labelWidget, self).resize(x, y)
self.update_json()
def move(self, x, y):
super(labelWidget, self).move(x, y)
self.update_json()
def update_json(self):
if self.jsondata:
# TODO : Manage colors and presend commands
self.jsondata['bbox']['width'] = self.width() * self.uiscale
self.jsondata['bbox']['height'] = self.height() * self.uiscale
self.jsondata['bbox']['left'] = self.pos().x() * self.uiscale
self.jsondata['bbox']['top'] = self.pos().y() * self.uiscale
class screenWidget(gui.QFrame):
def __init__(self, parent, uiscale):
super(screenWidget, self).__init__(parent)
self.setFrameStyle(gui.QFrame.Panel | gui.QFrame.Sunken)
self.jsondata = None
self.ismovable = True
self.uiscale = uiscale
self.setContentsMargins(0, 0, 0, 0)
self.screen_height = 0
self.screen_width = 0
self.presend = []
def change_ratio(self, x):
return
def initXML(self, xmldata):
screencolorxml = xmldata.getAttribute("Color")
self.screencolor = colorConvert(screencolorxml)
self.screen_width = int(xmldata.getAttribute("Width")) / self.uiscale
self.screen_height = int(xmldata.getAttribute("Height")) / self.uiscale
self.setStyleSheet("background-color: %s" % self.screencolor)
self.resize(self.screen_width, self.screen_height)
for elem in getChildNodesByName(xmldata, u"Send"):
delay = elem.getAttribute('Delay')
req_name = elem.getAttribute('RequestName')
self.presend.append({'Delay': delay, 'RequestName': req_name})
def initJson(self, jsdata):
self.screen_width = int(jsdata['width']) / self.uiscale
self.screen_height = int(jsdata['height']) / self.uiscale
self.setStyleSheet("background-color: %s" % jsdata['color'])
self.resize(self.screen_width, self.screen_height)
self.presend = jsdata['presend']
self.jsondata = jsdata
def resize(self, x, y):
super(screenWidget, self).resize(x, y)
self.update_json()
def lock(self, lock):
pass
def move(self, x, y):
return
def update_json(self):
if self.jsondata:
# TODO : Manage colors and presend commands
self.jsondata['width'] = self.width() * self.uiscale
self.jsondata['height'] = self.height() * self.uiscale
class buttonRequest(gui.QPushButton):
def __init__(self, parent, uiscale, ecureq, count):
super(buttonRequest, self).__init__(parent)
self.jsdata = None
self.ismovable = True
self.uiscale = uiscale
self.ecurequest = ecureq
self.count = count
self.messages = []
self.butname = ""
self.uniquename = ""
self.jsondata = None
def change_ratio(self, x):
pass
def initXML(self, xmldata):
text = xmldata.getAttribute("Text")
rect = getRectangleXML(getChildNodesByName(xmldata, "Rectangle")[0], self.uiscale)
qfnt = getXMLFont(xmldata, self.uiscale)
self.messages = getChildNodesByName(xmldata, "Message")
self.setFont(qfnt)
self.setText(text)
self.resize(rect['width'], rect['height'])
self.setStyleSheet("background: red; color: black")
self.move(rect['left'], rect['top'])
self.butname = text + "_" + str(self.count)
def initJson(self, jsdata):
text = jsdata['text']
rect = jsdata['rect']
qfnt = jsonFont(jsdata['font'], self.uiscale)
self.messages = jsdata['messages']
self.setFont(qfnt)
self.setText(text)
self.resize(rect['width'] / self.uiscale, rect['height'] / self.uiscale)
self.setStyleSheet("background: red; color: black")
self.move(rect['left'] / self.uiscale, rect['top'] / self.uiscale)
self.butname = jsdata['text']
self.uniquename = jsdata['uniquename']
self.jsondata = jsdata
def mousePressEvent(self, event):
if options.simulation_mode:
self.parent().mousePressEvent(event)
return
return super(buttonRequest, self).mousePressEvent(event)
def resize(self, x, y):
super(buttonRequest, self).resize(x, y)
self.update_json()
def move(self, x, y):
super(buttonRequest, self).move(x, y)
self.update_json()
def update_json(self):
if self.jsondata:
self.jsondata['rect']['left'] = self.pos().x() * self.uiscale
self.jsondata['rect']['top'] = self.pos().y() * self.uiscale
self.jsondata['rect']['height'] = self.height() * self.uiscale
self.jsondata['rect']['width'] = self.width() * self.uiscale
class displayWidget(gui.QWidget):
def __init__(self, parent, uiscale, ecureq):
super(displayWidget, self).__init__(parent)
self.uiscale = uiscale
self.ecurequestsparser = ecureq
self.ismovable = True
self.qlabel = None
self.qlabelval = None
self.jsondata = None
def lock(self, lock):
pass
def resize(self,x ,y):
oldwidth = self.width()
super(displayWidget, self).resize(x, y)
newwidth = self.width()
if not self.qlabelval or not self.qlabel:
return
diff = newwidth - oldwidth
self.qlabel.resize(self.qlabel.width() + diff, self.height())
self.qlabelval.resize(self.qlabelval.width(), self.height())
self.qlabelval.move(self.qlabelval.pos().x() + diff, 0)
self.update_json()
def move(self, x, y):
super(displayWidget, self).move(x, y)
self.update_json()
def update_json(self):
if self.jsondata:
self.jsondata['width'] = self.qlabel.width() * self.uiscale
self.jsondata['rect']['left'] = self.pos().x() * self.uiscale
self.jsondata['rect']['top'] = self.pos().y() * self.uiscale
self.jsondata['rect']['height'] = self.height() * self.uiscale
self.jsondata['rect']['width'] = self.width() * self.uiscale
def change_ratio(self, x):
valnewx = self.qlabelval.pos().x() + x
if valnewx < 0:
return
if valnewx > self.width():
return
oldlabelsize = self.qlabel.width()
oldvalsize = self.qlabelval.width()
self.qlabel.resize(oldlabelsize + x, self.height())
self.qlabelval.resize(oldvalsize - x, self.height())
self.qlabelval.move(valnewx, 0)
self.update_json()
def initXML(self, display, displaydict):
text = display.getAttribute("DataName")
req_name = display.getAttribute("RequestName")
color = display.getAttribute("Color")
width = int(display.getAttribute("Width")) / self.uiscale
rect = getRectangleXML(getChildNodesByName(display, "Rectangle")[0], self.uiscale)
qfnt = getXMLFont(display, self.uiscale)
if req_name not in self.ecurequestsparser.requests:
print "No request named ", req_name
return
req = self.ecurequestsparser.requests[req_name]
dataitem = None
if text in req.dataitems:
dataitem = req.dataitems[text]
else:
keys = req.dataitems.keys()
for k in keys:
if k.upper() == text.upper():
dataitem = req.dataitems[k]
print "Found similar", k, " vs ", text
break
if not dataitem:
print "DataItem not found", text
return
try:
data = self.ecurequestsparser.data[text]
except:
print "Cannot find data ", text
return
if not color:
color = 0xAAAAAA
self.move(rect['left'], rect['top'])
self.resize(rect['width'], rect['height'])
self.qlabel = gui.QLabel(self)
self.qlabel.setFont(qfnt)
self.qlabel.setText(text)
self.qlabel.resize(width, rect['height'])
self.qlabel.setStyleSheet("background: %s; color: %s" % (colorConvert(color), getFontColor(display)))
self.qlabel.setFrameStyle(gui.QFrame.Panel | gui.QFrame.Sunken)
self.qlabel.setAlignment(core.Qt.AlignLeft)
self.qlabelval = gui.QLabel(self)
self.qlabelval.setFont(qfnt)
self.qlabelval.setText("")
self.qlabelval.resize(rect['width'] - width, rect['height'])
self.qlabelval.setStyleSheet("background: %s; color: %s" % (colorConvert(color), getFontColor(display)))
self.qlabelval.setFrameStyle(gui.QFrame.Panel | gui.QFrame.Sunken)
self.qlabelval.move(width, 0)
endianess = req.endian
if dataitem.endian != "":
endianess = dataitem.endian
infos = req_name + u'\n'
if data.comment:
infos += data.comment + u'\n'
infos += u"Request=" + unicode(req.sentbytes) + u' ManualRequest=' + unicode(req.manualsend)
infos += u'\nNumBits=' + unicode(data.bitscount)
infos += u' FirstByte=' + unicode(dataitem.firstbyte)
infos += u' BitOffset=' + unicode(dataitem.bitoffset)
infos += u' Endianess=' + unicode(endianess)
self.qlabelval.setToolTip(infos)
ddata = displayData(data, self.qlabelval)
if not req_name in displaydict:
displaydict[req_name] = displayDict(req_name, req)
dd = displaydict[req_name]
dd.addData(ddata)
def initJson(self, display, displaydict):
text = display['text']
req_name = display['request']
color = display['color']
width = display['width'] / self.uiscale
rect = display['rect']
qfnt = jsonFont(display['font'], self.uiscale)
fontcolor = display['fontcolor']
req = self.ecurequestsparser.requests[req_name]
dataitem = None
if text in req.dataitems:
dataitem = req.dataitems[text]
else:
keys = req.dataitems.keys()
for k in keys:
if k.upper() == text.upper():
dataitem = req.dataitems[k]
print "Found similar", k, " vs ", text
break
if not dataitem:
print "DataItem not found", text
return
data = self.ecurequestsparser.data[text]
self.move(rect['left'] / self.uiscale, rect['top'] / self.uiscale)
self.resize(rect['width'] / self.uiscale, rect['height'] / self.uiscale)
self.qlabel = gui.QLabel(self)
self.qlabel.setFont(qfnt)
self.qlabel.setText(text)
self.qlabel.resize(width, rect['height'] / self.uiscale)
self.qlabel.setStyleSheet("background: %s; color: %s" % (color, fontcolor))
self.qlabel.setFrameStyle(gui.QFrame.Panel | gui.QFrame.Sunken);
self.qlabel.setAlignment(core.Qt.AlignLeft)
self.qlabelval = gui.QLabel(self)
self.qlabelval.setFont(qfnt)
self.qlabelval.setText("")
self.qlabelval.resize(rect['width'] / self.uiscale - width, rect['height'] / self.uiscale)
self.qlabelval.setStyleSheet("background: %s; color: %s" % (color, fontcolor))
self.qlabelval.setFrameStyle(gui.QFrame.Panel | gui.QFrame.Sunken);
self.qlabelval.move(width, 0)
infos = req_name + u'\n'
if data.comment:
infos += data.comment + u'\n'
infos += u"Request=" + unicode(req.sentbytes) + u' ManualRequest=' + unicode(req.manualsend)
infos += u'\nNumBits=' + unicode(data.bitscount)
infos += u' FirstByte=' + unicode(dataitem.firstbyte)
infos += u' BitOffset=' + unicode(dataitem.bitoffset)
self.qlabelval.setToolTip(infos)
ddata = displayData(data, self.qlabelval)
if not req_name in displaydict:
displaydict[req_name] = displayDict(req_name, req)
dd = displaydict[req_name]
dd.addData(ddata)
self.jsondata = display
class inputWidget(gui.QWidget):
def __init__(self, parent, uiscale, ecureq):
super(inputWidget, self).__init__(parent)
self.uiscale = uiscale
self.ecurequestsparser = ecureq
self.ismovable = True
self.qlabel = None
self.editwidget = None
self.jsondata = None
self.locked = False
def lock(self, lock):
self.locked = lock
def resize(self, x, y):
oldwidth = self.width()
super(inputWidget, self).resize(x, y)
newwidth = self.width()
if not self.qlabel or not self.editwidget:
return
diff = newwidth - oldwidth
self.qlabel.resize(self.qlabel.width() + diff, self.height())
self.editwidget.resize(self.editwidget.width(), self.height())
self.editwidget.move(self.editwidget.pos().x() + diff, 0)
self.update_json()
def move(self, x, y):
super(inputWidget, self).move(x, y)
self.update_json()
def update_json(self):
if self.jsondata:
scale = float(self.uiscale)
self.jsondata['width'] = int(self.qlabel.width() * scale)
self.jsondata['rect']['left'] = int(self.pos().x() * scale)
self.jsondata['rect']['top'] = int(self.pos().y() * scale)
self.jsondata['rect']['height'] = int(self.height() * scale)
self.jsondata['rect']['width'] = int(self.width() * scale)
def change_ratio(self, x):
valnewx = self.editwidget.pos().x() + x
if valnewx < 0:
return
if valnewx > self.width():
return
oldlabelsize = self.qlabel.width()
oldvalsize = self.editwidget.width()
self.qlabel.resize(oldlabelsize + x, self.height())
self.editwidget.resize(oldvalsize - x, self.height())
self.editwidget.move(valnewx, 0)
self.update_json()
def initXML(self, input, inputdict):
text = input.getAttribute("DataName")
req_name = input.getAttribute("RequestName")
color = input.getAttribute("Color")
width = int(input.getAttribute("Width")) / self.uiscale
rect = getRectangleXML(getChildNodesByName(input, "Rectangle")[0], self.uiscale)
qfnt = getXMLFont(input, self.uiscale)
if not color:
color = 0xAAAAAA
self.resize(rect['width'], rect['height'])
self.qlabel = gui.QLabel(self)
self.qlabel.setFont(qfnt)
self.qlabel.setText(text)
self.qlabel.setStyleSheet("background:%s; color:%s" % (colorConvert(color), getFontColor(input)))
self.qlabel.setFrameStyle(gui.QFrame.Panel | gui.QFrame.Sunken)
self.qlabel.resize(width, rect['height'])
self.move(rect['left'], rect['top'])
try:
data = self.ecurequestsparser.data[text]
except:
print "Cannot draw input ", text
return
if len(self.ecurequestsparser.data[text].items) > 0:
self.editwidget = gui.QComboBox(self)
items_ref = self.ecurequestsparser.data[text].items
for key in items_ref.keys():
self.editwidget.addItem(key)
self.editwidget.resize(rect['width'] - width, rect['height'])
self.editwidget.move(width, 0)
if data.comment:
infos = data.comment + u'\n' + req_name + u' : ' + text + u'\nNumBits=' + unicode(data.bitscount)
else:
infos = req_name + u' : ' + text + u'\nNumBits=' + unicode(data.bitscount)
self.editwidget.setToolTip(infos)
self.editwidget.setStyleSheet("background:%s; color:%s" % (colorConvert(color), getFontColor(input)))
ddata = displayData(data, self.editwidget, True)
else:
self.editwidget = gui.QLineEdit(self)
if options.simulation_mode:
self.editwidget.setEnabled(False)
self.editwidget.setFont(qfnt)
self.editwidget.setText("No Value")
self.editwidget.resize(rect['width'] - width, rect['height'])
self.editwidget.setStyleSheet("background:%s; color:%s" % (colorConvert(color), getFontColor(input)))
self.editwidget.move(width, 0)
if data.comment:
infos = data.comment + u'\n' + req_name + u' : ' + text + u'\nNumBits=' + unicode(data.bitscount)
else:
infos = req_name + u' : ' + text + u'\nNumBits=' + unicode(data.bitscount)
self.editwidget.setToolTip(infos)
ddata = displayData(data, self.editwidget)
if not req_name in inputdict:
req = self.ecurequestsparser.requests[req_name]
inputdict[req_name] = displayDict(req_name, req)
dd = inputdict[req_name]
dd.addData(ddata)
def initJson(self, jsoninput, inputdict):
text = jsoninput['text']
req_name = jsoninput['request']
color = jsoninput['color']
width = jsoninput['width'] / self.uiscale
rect = jsoninput['rect']
qfnt = jsonFont(jsoninput['font'], self.uiscale)
fntcolor = jsoninput['fontcolor']
self.move(rect['left'] / self.uiscale, rect['top'] / self.uiscale)
self.resize(rect['width'] / self.uiscale, rect['height'] / self.uiscale)
self.qlabel = gui.QLabel(self)
self.qlabel.setFont(qfnt)
self.qlabel.setText(text)
self.qlabel.setStyleSheet("background:%s; color:%s" % (color, jsoninput))
self.qlabel.setFrameStyle(gui.QFrame.Panel | gui.QFrame.Sunken)
self.qlabel.resize(width, rect['height'] / self.uiscale)
data = self.ecurequestsparser.data[text]
if len(self.ecurequestsparser.data[text].items) > 0:
self.editwidget = gui.QComboBox(self)
items_ref = self.ecurequestsparser.data[text].items
for key in items_ref.keys():
self.editwidget.addItem(key)
self.editwidget.move(width, 0)
if data.comment:
infos = data.comment + u'\n' + req_name + u' : ' + text + u'\nNumBits=' + unicode(
data.bitscount)
else:
infos = req_name + u' : ' + text + u'\nNumBits=' + unicode(data.bitscount)
self.editwidget.setToolTip(infos)
self.editwidget.setStyleSheet(
"background:%s; color:%s" % (color, fntcolor))
ddata = displayData(data, self.editwidget, True)
else:
self.editwidget = gui.QLineEdit(self)
self.editwidget.setFont(qfnt)
self.editwidget.setText("No Value")
self.editwidget.setStyleSheet(
"background:%s; color:%s" % (color, fntcolor))
if data.comment:
infos = data.comment + u'\n' + req_name + u' : ' + text + u'\nNumBits=' + unicode(
data.bitscount)
else:
infos = req_name + u' : ' + text + u'\nNumBits=' + unicode(data.bitscount)
self.editwidget.setToolTip(infos)
ddata = displayData(data, self.editwidget)
if options.simulation_mode:
self.editwidget.setEnabled(False)
self.editwidget.resize(rect['width'] / self.uiscale - width, rect['height'] / self.uiscale)
self.editwidget.move(width, 0)
if not req_name in inputdict:
req = self.ecurequestsparser.requests[req_name]
inputdict[req_name] = displayDict(req_name, req)
dd = inputdict[req_name]
dd.addData(ddata)
self.jsondata = jsoninput