From eb5124bd0a7bc37a1031ee3ee52fbedb48fc7cbc Mon Sep 17 00:00:00 2001 From: gabrieljreed Date: Wed, 1 May 2024 22:01:08 -0700 Subject: [PATCH] Update docstrings --- tagstudio/src/qt/helpers/file_opener.py | 36 ++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/tagstudio/src/qt/helpers/file_opener.py b/tagstudio/src/qt/helpers/file_opener.py index e30bedb0..82461242 100644 --- a/tagstudio/src/qt/helpers/file_opener.py +++ b/tagstudio/src/qt/helpers/file_opener.py @@ -20,6 +20,13 @@ logging.basicConfig(format="%(message)s", level=logging.INFO) def open_file(path: str, file_manager: bool = False): + """Open a file in the default application or file explorer. + + Args: + path (str): The path to the file to open. + file_manager (bool, optional): Whether to open the file in the file manager (e.g. Finder on macOS). + Defaults to False. + """ logging.info(f'Opening file: {path}') if not os.path.exists(path): logging.error(f'File not found: {path}') @@ -62,24 +69,47 @@ def open_file(path: str, file_manager: bool = False): class FileOpenerHelper: - def __init__(self, filepath:str): + def __init__(self, filepath: str): + """Initialize the FileOpenerHelper. + + Args: + filepath (str): The path to the file to open. + """ self.filepath = filepath - def set_filepath(self, filepath:str): + def set_filepath(self, filepath: str): + """Set the filepath to open. + + Args: + filepath (str): The path to the file to open. + """ self.filepath = filepath def open_file(self): + """Open the file in the default application.""" open_file(self.filepath) def open_explorer(self): - open_file(self.filepath, True) + """Open the file in the default file explorer.""" + open_file(self.filepath, file_manager=True) class FileOpenerLabel(QLabel): def __init__(self, text, parent=None): + """Initialize the FileOpenerLabel. + + Args: + text (str): The text to display. + parent (QWidget, optional): The parent widget. Defaults to None. + """ super().__init__(text, parent) def setFilePath(self, filepath): + """Set the filepath to open. + + Args: + filepath (str): The path to the file to open. + """ self.filepath = filepath def mousePressEvent(self, event):