diff options
-rwxr-xr-x | 9kwpyqt.py | 41 |
1 files changed, 28 insertions, 13 deletions
@@ -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() |