-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMegaUIClasses.py
More file actions
116 lines (88 loc) · 3.5 KB
/
MegaUIClasses.py
File metadata and controls
116 lines (88 loc) · 3.5 KB
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
# -*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui
class QHexSpinBox(QtGui.QDoubleSpinBox):
class HexValidator(QtGui.QValidator):
def __init__(self, min, max, parent=None):
QtGui.QValidator.__init__(self, parent)
self.valid = set('0123456789abcdef')
self.min = min
self.max = max
def validate(self, input, pos):
try:
input = str(input).lower()
except:
return (self.Invalid, pos)
valid = self.valid
for char in input:
if char not in valid:
return (self.Invalid, pos)
value = int(input, 16)
if value < self.min or value > self.max:
return (self.Intermediate, pos)
return (self.Acceptable, pos)
class DecValidator(QtGui.QValidator):
def __init__(self, min, max, parent=None):
QtGui.QValidator.__init__(self, parent)
self.valid = set('0123456789')
self.min = min
self.max = max
def validate(self, input, pos):
try:
input = str(input).lower()
except:
return (self.Invalid, pos)
valid = self.valid
for char in input:
if char not in valid:
return (self.Invalid, pos)
value = int(input, 10)
if value < self.min or value > self.max:
return (self.Intermediate, pos)
return (self.Acceptable, pos)
def __init__(self, padding = 8, format='X', *args):
self.format = format
self.padding = padding
self.mode = 'Hex'
QtGui.QSpinBox.__init__(self, *args)
self.validator = self.HexValidator(self.minimum(), self.maximum())
self.setRange(2147483648, 3556769791)
self.setDecimals(0)
def setMinimum(self, value):
self.validator.min = value
QtGui.QDoubleSpinBox.setMinimum(self, value)
def setMaximum(self, value):
self.validator.max = value
QtGui.QDoubleSpinBox.setMaximum(self, value)
def setRange(self, min, max):
self.validator.min = min
self.validator.max = max
QtGui.QDoubleSpinBox.setMinimum(self, min)
QtGui.QDoubleSpinBox.setMaximum(self, max)
def validate(self, text, pos):
return self.validator.validate(text, pos)
def textFromValue(self, value):
if self.mode == 'Hex':
string = '%0' + str(self.padding) + self.format
return string % value
elif self.mode == 'Dec':
string = '%' + self.format
return string % value
def valueFromText(self, value):
if self.mode == 'Hex':
return int(str(value), 16)
elif self.mode == 'Dec':
return int(str(value), 10)
def setPad(self, padvalue):
self.padding = padvalue
self.setValue(self.value())
def setMode(self, string):
self.mode = string
if string == 'Hex':
self.validator = self.HexValidator(self.minimum(), self.maximum())
self.format = 'X'
elif string == 'Dec':
self.validator = self.DecValidator(self.minimum(), self.maximum())
self.format = 'u'
#class QHexTableView(QtGui.QTableView):
#
# Stuff goes here with lots of stuff going here.