diff options
author | mkaay <mkaay@mkaay.de> | 2009-12-30 12:35:03 +0100 |
---|---|---|
committer | mkaay <mkaay@mkaay.de> | 2009-12-30 12:35:03 +0100 |
commit | c1516088e4e7f76dddd68ef71f58c6413862e31c (patch) | |
tree | 9e392f79fc225934b8a0a99cc4a119332b6685e0 /module/gui | |
parent | messed up last commit message; added new icons, default connection in gui, pu... (diff) | |
download | pyload-c1516088e4e7f76dddd68ef71f58c6413862e31c.tar.xz |
show captchas in gui, SerienjunkiesOrg plugin
Diffstat (limited to 'module/gui')
-rw-r--r-- | module/gui/CaptchaDock.py | 82 | ||||
-rw-r--r-- | module/gui/MainWindow.py | 5 | ||||
-rw-r--r-- | module/gui/connector.py | 40 |
3 files changed, 124 insertions, 3 deletions
diff --git a/module/gui/CaptchaDock.py b/module/gui/CaptchaDock.py new file mode 100644 index 000000000..193bac6fa --- /dev/null +++ b/module/gui/CaptchaDock.py @@ -0,0 +1,82 @@ +# -*- 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 + + 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.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.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 + diff --git a/module/gui/MainWindow.py b/module/gui/MainWindow.py index 6daa0aa55..94ff63dda 100644 --- a/module/gui/MainWindow.py +++ b/module/gui/MainWindow.py @@ -21,6 +21,7 @@ from PyQt4.QtGui import * from module.gui.PackageDock import * from module.gui.LinkDock import * +from module.gui.CaptchaDock import CaptchaDock class MainWindow(QMainWindow): def __init__(self): @@ -34,7 +35,7 @@ class MainWindow(QMainWindow): self.resize(850,500) #layout version - self.version = 1 + self.version = 2 #init docks self.newPackDock = NewPackageDock() @@ -43,6 +44,8 @@ class MainWindow(QMainWindow): self.addDockWidget(Qt.RightDockWidgetArea, self.newLinkDock) self.connect(self.newLinkDock, SIGNAL("done"), self.slotAddLinks) self.connect(self.newPackDock, SIGNAL("done"), self.slotAddPackage) + self.captchaDock = CaptchaDock() + self.addDockWidget(Qt.BottomDockWidgetArea, self.captchaDock) #central widget, layout self.masterlayout = QVBoxLayout() diff --git a/module/gui/connector.py b/module/gui/connector.py index 2915cf568..432999161 100644 --- a/module/gui/connector.py +++ b/module/gui/connector.py @@ -374,7 +374,7 @@ class connector(QThread): finally: self.mutex.unlock() - def slotPullOutPackage(self, pid): + def pullOutPackage(self, pid): """ pull out package """ @@ -382,7 +382,43 @@ class connector(QThread): try: return self.proxy.pull_out_package(pid) except Exception, e: - self.emit(SIGNAL("proxy_error"), "slotPullOutPackage", e) + self.emit(SIGNAL("proxy_error"), "pullOutPackage", e) + finally: + self.mutex.unlock() + + def captchaWaiting(self): + """ + is the a captcha waiting? + """ + self.mutex.lock() + try: + return self.proxy.is_captcha_waiting() + except Exception, e: + self.emit(SIGNAL("proxy_error"), "captchaWaiting", e) + finally: + self.mutex.unlock() + + def getCaptcha(self): + """ + get captcha + """ + self.mutex.lock() + try: + return self.proxy.get_captcha_task() + except Exception, e: + self.emit(SIGNAL("proxy_error"), "getCaptcha", e) + finally: + self.mutex.unlock() + + def setCaptchaResult(self, cid, result): + """ + get captcha + """ + self.mutex.lock() + try: + return self.proxy.set_captcha_result(cid, result) + except Exception, e: + self.emit(SIGNAL("proxy_error"), "setCaptchaResult", e) finally: self.mutex.unlock() |