forked from pyload/pyload
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaptchaDock.py
More file actions
94 lines (76 loc) · 3 KB
/
CaptchaDock.py
File metadata and controls
94 lines (76 loc) · 3 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
# -*- coding: utf-8 -*-
"""
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License,
or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
@author: mkaay
"""
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class CaptchaDock(QDockWidget):
"""
dock widget for captcha input
"""
def __init__(self):
QDockWidget.__init__(self, _("Captcha"))
self.setObjectName("Captcha Dock")
self.widget = CaptchaDockWidget(self)
self.setWidget(self.widget)
self.setAllowedAreas(Qt.BottomDockWidgetArea)
self.setFeatures(QDockWidget.NoDockWidgetFeatures)
self.hide()
self.processing = False
self.currentID = None
self.connect(self, SIGNAL("setTask"), self.setTask)
def isFree(self):
return not self.processing
def setTask(self, tid, img, imgType):
self.processing = True
data = QByteArray(img)
self.currentID = tid
self.widget.emit(SIGNAL("setImage"), data)
self.widget.input.setText("")
self.show()
class CaptchaDockWidget(QWidget):
"""
widget for the input widgets
"""
def __init__(self, dock):
QWidget.__init__(self)
self.dock = dock
self.setLayout(QHBoxLayout())
layout = self.layout()
imgLabel = QLabel()
captchaInput = QLineEdit()
okayButton = QPushButton(_("OK"))
cancelButton = QPushButton(_("Cancel"))
layout.addStretch()
layout.addWidget(imgLabel)
layout.addWidget(captchaInput)
layout.addWidget(okayButton)
layout.addWidget(cancelButton)
layout.addStretch()
self.input = captchaInput
self.connect(okayButton, SIGNAL("clicked()"), self.slotSubmit)
self.connect(captchaInput, SIGNAL("returnPressed()"), self.slotSubmit)
self.connect(self, SIGNAL("setImage"), self.setImg)
self.connect(self, SIGNAL("setPixmap(const QPixmap &)"), imgLabel, SLOT("setPixmap(const QPixmap &)"))
def setImg(self, data):
pixmap = QPixmap()
pixmap.loadFromData(data)
self.emit(SIGNAL("setPixmap(const QPixmap &)"), pixmap)
self.input.setFocus(Qt.OtherFocusReason)
def slotSubmit(self):
text = self.input.text()
tid = self.dock.currentID
self.dock.currentID = None
self.dock.emit(SIGNAL("done"), tid, str(text))
self.dock.hide()
self.dock.processing = False