summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Glüpker <git@wgmd.de>2016-06-06 13:21:22 +0200
committerAndré Glüpker <git@wgmd.de>2016-06-06 13:21:22 +0200
commit89a29e89478eb0a13230623e6806643f09b715ea (patch)
treea7bfe762f44579c247bb68630f6df4e6fe6866bd
parentd09a7fa0ccb9afd314c17c708481752e91b825e5 (diff)
download9kwpyqt-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.
-rwxr-xr-x9kwpyqt.py9
1 files changed, 6 insertions, 3 deletions
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):