From 0fe22d25beaa91aeb714934506e175e5e35b7315 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Mon, 17 Jul 2023 22:57:26 +0200 Subject: use os.startfile to shwo questions on windows --- quiz.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/quiz.py b/quiz.py index d6c6a21..0571a5d 100755 --- a/quiz.py +++ b/quiz.py @@ -17,6 +17,7 @@ import csv from pathlib import Path import random import platform +import os import tomllib import subprocess import sys @@ -28,12 +29,12 @@ WRONG_SOUND = Path(__file__).parent / 'Wrong.mp3' CORRECT_SOUND = Path(__file__).parent / 'Correct.mp3' if platform.system() != 'Windows': - SHOW_QUESTION_CMD = 'xdg-open' PLAY_SOUND_CMD = 'mpv' else: - SHOW_QUESTION_CMD = 'start' PLAY_SOUND_CMD = 'vlc.exe --intf=dummy --dummy-quiet' +SHOW_QUESTION_CMD = 'xdg-open' + def err(msg: str, status=1): """Print the error message to stderr and exit with status""" @@ -146,10 +147,14 @@ def load_solutions(question_dirs: list[Path], return solutions -def show_question(question: Path) -> subprocess.Popen: +def show_question(question: Path): """show the question in an external programm and return the process""" + if platform.system() != 'Windows': + os.startfile(question) # type: ignore # pylint: disable=no-member + return + cmd = SHOW_QUESTION_CMD.split() + [str(question)] - return subprocess.Popen(cmd, shell=True) + subprocess.Popen(cmd) def color_button(layout, text: str, color: str): -- cgit v1.2.3