diff options
-rwxr-xr-x | 9kwpyqt.py | 40 |
1 files changed, 38 insertions, 2 deletions
@@ -2,7 +2,7 @@ import sys import time -from PyQt5.QtCore import Qt, QTimer, QUrl +from PyQt5.QtCore import Qt, QTimer, QUrl, pyqtSignal from PyQt5.QtWidgets import QApplication, QWidget from PyQt5.QtWidgets import QLayout, QHBoxLayout, QVBoxLayout, QSizePolicy from PyQt5.QtWidgets import QLabel, QLineEdit, QPushButton, QProgressBar @@ -14,6 +14,35 @@ API_URL = "http://www.9kw.eu/index.cgi" API_KEY = "" soundfile = "notify.wav" +class ExtendedQLabel(QLabel): + + clicked = pyqtSignal(int) + + def __init(self, parent): + QLabel.__init(self, parent) + + def mouseReleaseEvent(self, ev): + if not self.pixmap(): + return + + # get size of pixmap + imgx = self.pixmap().size().width() + imgy = self.pixmap().size().height() + + # get cursor size relative to pixmap + x = ev.pos().x() - self.size().width() / 2 + imgx/2 + y = ev.pos().y() - self.size().height() / 2 + imgy/2 + + # check if on pixmap (upper 19% = info) + if x > imgx or y > imgy or x < 0 or y < 0.19*imgy: + print("Not on image") + return + + # which piece is below the mouse? + xpiece = x // (imgx / 3) + 1 + ypiece = (y-0.19*imgy) // (imgy*0.81 / 3) + + self.clicked.emit(3*ypiece+xpiece) class CaptchaGUI(QWidget): sound = False # QSound() @@ -56,13 +85,14 @@ class CaptchaGUI(QWidget): self.LayoutStats.sizeConstraint = QLayout.SetMinimumSize # Middle: Captchaimage - self.captchaImage = QLabel("") + self.captchaImage = ExtendedQLabel("") self.captchaImage.setAlignment(Qt.AlignCenter) self.captchaImage.setMinimumHeight(400) self.captchaImage.setSizePolicy( QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding ) + self.captchaImage.clicked.connect(self.captchaClicked) self.captchaBox = QHBoxLayout() self.captchaBox.addWidget(self.captchaImage) @@ -129,6 +159,12 @@ class CaptchaGUI(QWidget): Qt.KeepAspectRatio) self.captchaImage.setPixmap(self.imageR) + def captchaClicked(self, clickedpiece): + if self.image: + text = self.captchaInputLine.text() + text += str(clickedpiece) + self.captchaInputLine.setText(text) + def updateStats(self): if self.startCredits: credittext = "%d ¥ (%s%d)" % (self.currentCredits, (self.currentCredits - self.startCredits > 0) and '+' or '', (self.currentCredits - self.startCredits)) |