diff options
author | André Glüpker <git@wgmd.de> | 2016-06-06 13:21:22 +0200 |
---|---|---|
committer | André Glüpker <git@wgmd.de> | 2016-06-06 13:21:22 +0200 |
commit | 89a29e89478eb0a13230623e6806643f09b715ea (patch) | |
tree | a7bfe762f44579c247bb68630f6df4e6fe6866bd /9kwpyqt.py | |
parent | d09a7fa0ccb9afd314c17c708481752e91b825e5 (diff) | |
download | 9kwpyqt-89a29e89478eb0a13230623e6806643f09b715ea.tar.gz 9kwpyqt-89a29e89478eb0a13230623e6806643f09b715ea.tar.bz2 9kwpyqt-89a29e89478eb0a13230623e6806643f09b715ea.zip |
Use paths relative to the executeable.
The default soundfile and config are stored next to the executeable.
This is not an optimal solution, but for a small script like this it
is good enough. This should work on windows and linux.
Diffstat (limited to '9kwpyqt.py')
-rwxr-xr-x | 9kwpyqt.py | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -1,6 +1,7 @@ #!/usr/bin/env python3 import configparser +import os import sys import time from PyQt5.QtCore import Qt, QTimer, QUrl, pyqtSignal @@ -11,6 +12,8 @@ from PyQt5.QtGui import QPixmap, QImage from PyQt5.QtMultimedia import QSound from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest, QNetworkReply +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + class ExtendedQLabel(QLabel): clicked = pyqtSignal(int, str) image = False # QPixmap() @@ -338,7 +341,7 @@ class CaptchaGUI(QWidget): defaultconfig['Autostart'] = 'no' self.config = configparser.ConfigParser(defaultconfig) try: - with open('9kwpyqt.ini') as configfile: + with open(os.path.join(THIS_DIR, '9kwpyqt.ini')) as configfile: self.config.read_file(configfile) except FileNotFoundError: self.writeConfig() @@ -349,14 +352,14 @@ class CaptchaGUI(QWidget): # 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.sound = QSound(os.path.join(THIS_DIR, 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): - with open('9kwpyqt.ini', 'w') as configfile: + with open(os.path.join(THIS_DIR, '9kwpyqt.ini'), 'w') as configfile: self.config.write(configfile) def skipCaptcha(self): |