From 89a29e89478eb0a13230623e6806643f09b715ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Gl=C3=BCpker?= Date: Mon, 6 Jun 2016 13:21:22 +0200 Subject: 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. --- 9kwpyqt.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to '9kwpyqt.py') diff --git a/9kwpyqt.py b/9kwpyqt.py index f6ec392..c2ca068 100755 --- a/9kwpyqt.py +++ b/9kwpyqt.py @@ -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): -- cgit v1.2.3