summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Glüpker <git@wgmd.de>2016-04-07 17:34:46 +0200
committerAndré Glüpker <git@wgmd.de>2016-04-07 17:34:46 +0200
commit27339dbc98d9f9bdbc919ce87e8d95659334e1ce (patch)
tree9e25b1aa516e4acc889eb84cef1b8c75e175f564
parenta9bbed05ba2d6a72bada8ecc350b5cb1512ddb4a (diff)
download9kwpyqt-27339dbc98d9f9bdbc919ce87e8d95659334e1ce.tar.gz
9kwpyqt-27339dbc98d9f9bdbc919ce87e8d95659334e1ce.tar.bz2
9kwpyqt-27339dbc98d9f9bdbc919ce87e8d95659334e1ce.zip
Add timer to count down 30 seconds
-rwxr-xr-x9kwpyqt.py41
1 files changed, 28 insertions, 13 deletions
diff --git a/9kwpyqt.py b/9kwpyqt.py
index 0f0a191..a4d7be8 100755
--- a/9kwpyqt.py
+++ b/9kwpyqt.py
@@ -51,6 +51,7 @@ class CaptchaGUI(QWidget):
currentQueued = 0
currentWorker = 0
offlinemessage = "Click \"Start\" to fetch next captcha."
+ timeleft = None
waitingoncaptcha = 0
@@ -84,6 +85,7 @@ class CaptchaGUI(QWidget):
# Bottom: StartStop/Sound-Button
self.captchaInputLine = QLineEdit()
+ self.captchaTimer = QLabel("---")
self.startstopButton = QPushButton("Start")
self.startstopButton.setCheckable(True)
self.soundCheckbox = QCheckBox("Sound")
@@ -99,8 +101,12 @@ class CaptchaGUI(QWidget):
self.LayoutSettings.addWidget(self.soundCheckbox)
self.LayoutSettings.addWidget(self.startstopButton)
+ self.LayoutInputTimer = QHBoxLayout()
+ self.LayoutInputTimer.addWidget(self.captchaInputLine)
+ self.LayoutInputTimer.addWidget(self.captchaTimer)
+
self.LayoutSubmit = QVBoxLayout()
- self.LayoutSubmit.addWidget(self.captchaInputLine)
+ self.LayoutSubmit.addLayout(self.LayoutInputTimer)
self.LayoutSubmit.addLayout(self.LayoutSettings)
# Compile layout
@@ -127,8 +133,9 @@ class CaptchaGUI(QWidget):
QTimer.singleShot(500, self.getCaptchaID)
self.timer = QTimer()
- self.timer.timeout.connect(self.onTimeout)
- self.timer.setSingleShot(True)
+ self.timer.setInterval(100)
+ self.timer.timeout.connect(self.onTimerTick)
+ self.timer.start()
self.startstopButton.setFocus()
@@ -162,7 +169,8 @@ class CaptchaGUI(QWidget):
self.captchaInputLine.setFocus()
if self.soundCheckbox.isChecked():
self.sound.play()
- self.timer.start(30000)
+ self.timeleft = time.time() + 30
+ self.timer.start()
self.captchaImage.setText("")
else:
self.captchaImage.setText("Could not display image. Skip!")
@@ -330,6 +338,7 @@ class CaptchaGUI(QWidget):
# Overwrite file to add potential new options
self.writeConfig()
+ # Use config settings
self.apiurl = self.config['DEFAULT']['API_URL']+"?source=pythonapi&apikey="+self.config['DEFAULT']['API_KEY']+"&"
self.sound = QSound(self.config['DEFAULT']['Soundfile'])
self.soundCheckbox.setChecked( self.config.getboolean('DEFAULT', 'Sound') )
@@ -346,18 +355,26 @@ class CaptchaGUI(QWidget):
answer = self.captchaInputLine.text()
if not answer:
skip = True
- self.timer.stop()
+ self.timeleft = None
self.captchaInputLine.setText("")
self.removeCaptchaImage()
if self.currentCaptchaID:
self.setCaptchaAnswer(answer, skip)
- def onTimeout(self):
- self.running = False
- self.offlinemessage = "30 seconds passed without input."
- self.startstopButton.setText(self.running and "Stop" or "Start")
- self.startstopButton.setChecked(self.running)
- self.skipCaptcha()
+ def onTimerTick(self):
+ if not self.timeleft:
+ self.captchaTimer.setText("...")
+ self.timer.stop()
+ else:
+ timing = self.timeleft - time.time()
+ self.captchaTimer.setText(str(round(timing, 1))+"s")
+ if timing <= 0:
+ self.timeleft = None
+ self.running = False
+ self.offlinemessage = "30 seconds passed without input."
+ self.startstopButton.setText(self.running and "Stop" or "Start")
+ self.startstopButton.setChecked(self.running)
+ self.skipCaptcha()
def onQuit(self):
if self.currentCaptchaID:
@@ -365,8 +382,6 @@ class CaptchaGUI(QWidget):
self.setCaptchaAnswer("", skip=True, queue=False)
def main():
- # import pudb; pudb.set_trace()
-
app = QApplication(sys.argv)
screen = CaptchaGUI()
screen.show()