diff options
author | André Glüpker <git@wgmd.de> | 2016-04-08 10:17:10 +0200 |
---|---|---|
committer | André Glüpker <git@wgmd.de> | 2016-04-08 10:17:10 +0200 |
commit | 280d5a4222de687374486bf122e51c3bf9318f81 (patch) | |
tree | d2f76863e6e74f95d96726d595ec1d42389400fd | |
parent | 448016ddd7b450ee6b0a5f28798d076c16d540c0 (diff) | |
download | 9kwpyqt-280d5a4222de687374486bf122e51c3bf9318f81.tar.gz 9kwpyqt-280d5a4222de687374486bf122e51c3bf9318f81.tar.bz2 9kwpyqt-280d5a4222de687374486bf122e51c3bf9318f81.zip |
New config option: Autostart
-rwxr-xr-x | 9kwpyqt.py | 17 |
1 files changed, 11 insertions, 6 deletions
@@ -180,8 +180,10 @@ class CaptchaGUI(QWidget): def removeCaptchaImage(self): self.captchaImage.removeImage() - def toggleRunning(self): - self.running = not self.running + def toggleRunning(self, force_start=False, force_stop=False): + if force_start: self.running = True + elif force_stop: self.running = False + else: self.running = not self.running self.captchaImage.setText("") self.offlinemessage = "Click \"Start\" to fetch next captcha." self.startstopButton.setText(self.running and "Stop" or "Start") @@ -325,11 +327,14 @@ class CaptchaGUI(QWidget): # Handle logic ################################################## def readConfig(self): + if self.config is not None: + return False defaultconfig = {} defaultconfig['API_URL'] = 'http://www.9kw.eu/index.cgi' defaultconfig['API_KEY'] = '' defaultconfig['Sound'] = 'yes' defaultconfig['Soundfile'] = 'notify.wav' + defaultconfig['Autostart'] = 'no' self.config = configparser.ConfigParser(defaultconfig) try: self.config.read_file(open('9kwpyqt.ini')) @@ -344,6 +349,8 @@ class CaptchaGUI(QWidget): 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') ) + if self.config.getboolean('DEFAULT', 'Autostart'): + self.toggleRunning(force_start=True) return True def writeConfig(self): @@ -371,11 +378,9 @@ class CaptchaGUI(QWidget): timing = self.timeleft - time.time() self.captchaTimer.setText(str(round(timing, 1))+"s") if timing <= 0: - self.timeleft = None - self.running = False + self.toggleRunning(force_stop=True) self.offlinemessage = "30 seconds passed without input." - self.startstopButton.setText(self.running and "Stop" or "Start") - self.startstopButton.setChecked(self.running) + self.timeleft = None self.skipCaptcha() def onQuit(self): |