summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Glüpker <git@wgmd.de>2016-03-22 16:37:29 +0100
committerAndré Glüpker <git@wgmd.de>2016-03-22 16:37:29 +0100
commit8851f7f2f20e53515908370ce03ed5dc7b117ff9 (patch)
treec868b7aa4808590e11d995b07b0c42fd94b09511
parentc1108bfad7919d2cd0df1cfeef0ef720110210db (diff)
download9kwpyqt-8851f7f2f20e53515908370ce03ed5dc7b117ff9.tar.gz
9kwpyqt-8851f7f2f20e53515908370ce03ed5dc7b117ff9.tar.bz2
9kwpyqt-8851f7f2f20e53515908370ce03ed5dc7b117ff9.zip
First prototype of clickable images (find all trees)
Only works on one of those. (The one with the black borders)
-rwxr-xr-x9kwpyqt.py40
1 files changed, 38 insertions, 2 deletions
diff --git a/9kwpyqt.py b/9kwpyqt.py
index d92398d..d676013 100755
--- a/9kwpyqt.py
+++ b/9kwpyqt.py
@@ -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))