forked from mtivadar/qiew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnpackPlugin.py
91 lines (69 loc) · 2.24 KB
/
UnpackPlugin.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
from yapsy.IPlugin import IPlugin
from PyQt4 import QtGui, QtCore
from PyQt4.QtGui import *
import PyQt4
import os, sys
class DecryptPlugin(IPlugin):
ui = None
def init(self, dataModel, viewMode):
self.dataModel = dataModel
self.viewMode = viewMode
return True
def getUI(self):
return self.ui
def proceed(self):
return True
def _convert(s):
try:
x = int(s, 0)
except ValueError:
x = None
if not x:
x = 0
L = s.split(' ')
for i, l in enumerate(L):
if len(l) != 2:
return 0
else:
try:
z = int('0x' + l, 0)
except ValueError:
return 0
z = z << 8*i
x = x | z
return x
class MyValidator(QValidator):
def __init__(self, parent=None):
super(MyValidator, self).__init__(parent)
def validate(self, c, pos):
c = str(c)
k = pos - 1
def _validate(s, k):
color = '#ffffff'
YELLOW = '#fff79a'
# accept empty string
if s == '':
return (QValidator.Acceptable, color)
# must be hex digits, or 'x' on second position
if s[k] not in ' 0123456789abcdefABCDEFx':
return (QValidator.Invalid, color)
else:
if s[k] == 'x' and k != 1:
return (QValidator.Invalid, color)
# if we have spaces, must be of form XX XX XX XX
if ' ' in s:
L = s.split(' ')
for l in L:
if len(l) != 2:
return (QValidator.Acceptable, YELLOW)
return (QValidator.Acceptable, color)
# else, try at least to convert it to a number
try:
x = int(s, 0)
except ValueError:
return (QValidator.Acceptable, YELLOW)
return (QValidator.Acceptable, color)
state, color = _validate(c, k)
if state == QValidator.Acceptable:
self.parent().setStyleSheet('QLineEdit {{ background-color: {} }}'.format(color))
return (state, k + 1)