diff --git a/speedwagon/frontend/qtwidgets/dialog/dialogs.py b/speedwagon/frontend/qtwidgets/dialog/dialogs.py index 52f298edb..3ebef0075 100644 --- a/speedwagon/frontend/qtwidgets/dialog/dialogs.py +++ b/speedwagon/frontend/qtwidgets/dialog/dialogs.py @@ -3,6 +3,8 @@ import abc import logging import logging.handlers +import os +import pathlib import sys import typing import warnings @@ -25,6 +27,7 @@ import speedwagon from speedwagon.reports import ExceptionReport +from speedwagon.utils import get_desktop_path from speedwagon.frontend.qtwidgets import logging_helpers, ui_loader import speedwagon.frontend.qtwidgets.ui from speedwagon.info import convert_package_metadata_to_string @@ -163,19 +166,31 @@ def __init__( def request_export_system_information( self, - save_dialog_box=QtWidgets.QFileDialog.getSaveFileName + *_, + save_dialog_box=QtWidgets.QFileDialog.getSaveFileName, + **__, ) -> None: """Request system information be saved to a file.""" file, file_format = save_dialog_box( self, "Save File", - "speedwagon-info.txt", + os.path.join( + get_default_export_system_info_path(), + "speedwagon-info.txt" + ), "Text (*.txt)" ) if file: self.export_to_file.emit(file, file_format) +def get_default_export_system_info_path() -> str: + try: + return get_desktop_path() + except FileNotFoundError: + return str(pathlib.Path.home()) + + class AbsWorkflowProgressState(abc.ABC): def __init_subclass__(cls) -> None: if not hasattr(cls, "state_name") or cls.state_name is None: diff --git a/speedwagon/frontend/qtwidgets/gui_startup.py b/speedwagon/frontend/qtwidgets/gui_startup.py index a5a105a5b..b03caa7c9 100644 --- a/speedwagon/frontend/qtwidgets/gui_startup.py +++ b/speedwagon/frontend/qtwidgets/gui_startup.py @@ -29,6 +29,7 @@ import speedwagon from speedwagon.workflow import initialize_workflows from speedwagon import config +from speedwagon.utils import get_desktop_path from speedwagon.tasks import system as system_tasks from speedwagon import plugins, info from . import user_interaction @@ -943,11 +944,10 @@ def export_system_info_to_file( def get_default_log_path() -> str: - home = pathlib.Path.home() - desktop_path = home / "Desktop" - if os.path.exists(desktop_path): - return str(desktop_path) - return str(pathlib.Path.home()) + try: + return get_desktop_path() + except FileNotFoundError: + return str(pathlib.Path.home()) def export_logs_action( diff --git a/speedwagon/utils.py b/speedwagon/utils.py index 64ffc0f0c..b21fab12a 100644 --- a/speedwagon/utils.py +++ b/speedwagon/utils.py @@ -1,5 +1,6 @@ """General module for things that don't fit anywhere else.""" - +import os +import pathlib from typing import Iterator, Callable import logging @@ -45,3 +46,11 @@ def __init__( def emit(self, record: logging.LogRecord) -> None: """Emit logged message to callback function.""" self.callback(logging.Formatter().format(record)) + + +def get_desktop_path() -> str: + home = pathlib.Path.home() + desktop_path = home / "Desktop" + if os.path.exists(desktop_path): + return str(desktop_path) + raise FileNotFoundError("No Desktop folder located")