diff options
author | mkaay <mkaay@mkaay.de> | 2010-01-27 20:05:23 +0100 |
---|---|---|
committer | mkaay <mkaay@mkaay.de> | 2010-01-27 20:05:23 +0100 |
commit | 6d1ec2baa795b0d90d5da33b0447120b50f10c17 (patch) | |
tree | 5fceb5474c83e709fda396f70121a6923b0be106 /module/gui/CaptchaDock.py | |
parent | First Version, works but doesn't reconnect (diff) | |
parent | fix (diff) | |
download | pyload-6d1ec2baa795b0d90d5da33b0447120b50f10c17.tar.xz |
merge
Diffstat (limited to 'module/gui/CaptchaDock.py')
-rw-r--r-- | module/gui/CaptchaDock.py | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/module/gui/CaptchaDock.py b/module/gui/CaptchaDock.py new file mode 100644 index 000000000..8a7e8010e --- /dev/null +++ b/module/gui/CaptchaDock.py @@ -0,0 +1,85 @@ +# -*- 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): + 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): + 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) + + 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 + |