py-file-dialog 0.0.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.3
2
+ Name: py-file-dialog
3
+ Version: 0.0.5
4
+ Summary: A small collection of quality-of-life methods using Python tkinter to interface with the windows file explorer.
5
+ Author: Bela Vogler
6
+ Author-email: Bela Vogler <bela.vogler@uni-jena.de>
7
+ Requires-Python: >=3.12
8
+ Description-Content-Type: text/markdown
9
+
10
+ # PyFiledialog
11
+ A small collection of quality-of-life methods built ontop Python tkinter to interface with the windows file explorer.
@@ -0,0 +1,2 @@
1
+ # PyFiledialog
2
+ A small collection of quality-of-life methods built ontop Python tkinter to interface with the windows file explorer.
@@ -0,0 +1,18 @@
1
+ [project]
2
+ name = "py-file-dialog"
3
+ version = "0.0.5"
4
+ description = "A small collection of quality-of-life methods using Python tkinter to interface with the windows file explorer."
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ dependencies = []
8
+
9
+ [[project.authors]]
10
+ name = "Bela Vogler"
11
+ email = "bela.vogler@uni-jena.de"
12
+
13
+ [project.scripts]
14
+ py-file-dialog = "py_file_dialog:main"
15
+
16
+ [build-system]
17
+ requires = ["uv_build>=0.13.10,<0.14.0"]
18
+ build-backend = "uv_build"
@@ -0,0 +1,17 @@
1
+ [project]
2
+ name = "py-file-dialog"
3
+ version = "0.0.5"
4
+ description = "A small collection of quality-of-life methods using Python tkinter to interface with the windows file explorer."
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "Bela Vogler", email = "bela.vogler@uni-jena.de" }
8
+ ]
9
+ requires-python = ">=3.12"
10
+ dependencies = []
11
+
12
+ [project.scripts]
13
+ py-file-dialog = "py_file_dialog:main"
14
+
15
+ [build-system]
16
+ requires = ["uv_build>=0.13.10,<0.14.0"]
17
+ build-backend = "uv_build"
@@ -0,0 +1,16 @@
1
+ from py_file_dialog import (
2
+ call_directory as call_directory,
3
+ call_subdirectories as call_subdirectories,
4
+ call_file as call_file,
5
+ call_multiple_files as call_multiple_files,
6
+ call_save_as_file as call_save_as_file,
7
+ )
8
+
9
+
10
+ __all__ = [
11
+ "call_directory",
12
+ "call_subdirectories",
13
+ "call_file",
14
+ "call_multiple_files",
15
+ "call_save_as_file",
16
+ ]
@@ -0,0 +1,131 @@
1
+ ## dependencies
2
+ import os
3
+ import tkinter as tk
4
+ from tkinter import filedialog
5
+ from typing import List, Tuple, Union
6
+
7
+ __all__ = [
8
+ "call_directory",
9
+ "call_subdirectories",
10
+ "call_file",
11
+ "call_multiple_files",
12
+ "call_save_as_file",
13
+ ]
14
+
15
+
16
+ # method implementations
17
+ def call_directory(title: str = "Please select a directory") -> str:
18
+ """Open a file dialog to select a directory.
19
+
20
+ Args:
21
+ title (str, optional): Select a title for the dialog. Defaults to "Please select a directory".
22
+
23
+ Returns:
24
+ str: The path of the selected directory.
25
+ """
26
+ root = tk.Tk()
27
+ root.withdraw()
28
+ root.call("wm", "attributes", ".", "-topmost", True)
29
+ DIR_path = filedialog.askdirectory(title=title)
30
+ return DIR_path
31
+
32
+
33
+ def call_subdirectories(
34
+ title: str = "Please select a directory to scan",
35
+ ) -> List[str]:
36
+ """Open a file dialog to select a directory and return a list of all subdirectories within it.
37
+
38
+ Args:
39
+ title (str, optional): Select a title for the dialog. Defaults to "Please select a directory to scan".
40
+
41
+ Returns:
42
+ List[str]: A list of paths for the selected subdirectories.
43
+ """
44
+ directory = call_directory(title=title)
45
+ return [f.path for f in os.scandir(directory) if f.is_dir()]
46
+
47
+
48
+ def call_file(
49
+ title: str = "Please select a file",
50
+ filetypes: List[Tuple[str, str]] = [("All files", "*")],
51
+ ) -> str:
52
+ """Open a file dialog to select a file.
53
+
54
+ Args:
55
+ title (str, optional): Select a title for the dialog. Defaults to "Please select a file".
56
+ filetypes (List[Tuple[str, str]], optional): A list of tuples specifying the file types to display. Defaults to [("All files", "*")].
57
+
58
+ Returns:
59
+ str: The path of the selected file.
60
+ """
61
+ root = tk.Tk()
62
+ root.withdraw()
63
+ root.call("wm", "attributes", ".", "-topmost", True)
64
+ FILE_path = filedialog.askopenfilename(title=title, filetypes=filetypes)
65
+ return FILE_path
66
+
67
+
68
+ def call_multiple_files(
69
+ title: str = "Please select a number of files",
70
+ filetypes: List[Tuple[str, str]] = [("All files", "*")],
71
+ ) -> Union[Tuple[str, ...], str]:
72
+ """Open a file dialog to select multiple files.
73
+
74
+ Args:
75
+ title (str, optional): Select a title for the dialog. Defaults to "Please select a number of files".
76
+ filetypes (List[Tuple[str, str]], optional): A list of tuples specifying the file types to display. Defaults to [("All files", "*")].
77
+
78
+ Returns:
79
+ Union[Tuple[str, ...], str]: A tuple of paths for the selected files, or a single path if only one file is selected.
80
+ """
81
+ root = tk.Tk()
82
+ root.withdraw()
83
+ root.call("wm", "attributes", ".", "-topmost", True)
84
+ FILE_path = filedialog.askopenfilenames(title=title, filetypes=filetypes)
85
+ return FILE_path
86
+
87
+
88
+ def call_save_as_file(
89
+ defaultextension: str = "*",
90
+ title: str = "Save as...",
91
+ confirmoverwrite: bool = True,
92
+ filetypes: Union[List, None] = None,
93
+ initialfile: Union[str, None] = None,
94
+ ) -> str:
95
+ """Open a file dialog to select a file path for saving.
96
+
97
+ Args:
98
+ defaultextension (str, optional): Select the filetype to default to. Defaults to "*".
99
+ title (str, optional): Select a title for the dialog. Defaults to "Save as...".
100
+ confirmoverwrite (bool, optional): Confirm overwrite if the file already exists. Defaults to True.
101
+ filetypes (Union[List, None], optional): A list of tuples specifying the file types to display. Defaults to None.
102
+ initialfile (Union[str, None], optional): The initial filename to display. Defaults to None.
103
+
104
+ Returns:
105
+ str: The path of the selected file.
106
+ """
107
+ root = tk.Tk()
108
+ root.withdraw()
109
+ root.call("wm", "attributes", ".", "-topmost", True)
110
+ FILE_path = filedialog.asksaveasfilename(
111
+ defaultextension=defaultextension,
112
+ title=title,
113
+ confirmoverwrite=confirmoverwrite,
114
+ initialfile=initialfile if initialfile is not None else "",
115
+ filetypes=filetypes
116
+ if filetypes is not None
117
+ else [
118
+ ("Text files", "*.txt"),
119
+ ("Json files", "*.json"),
120
+ ("CSV files", "*.csv"),
121
+ ("Npy files", "*.npy"),
122
+ ("Pkl files", "*.pkl"),
123
+ ("png files", "*.png"),
124
+ ("jpg files", "*.jpg"),
125
+ ("jpeg files", "*.jpeg"),
126
+ ("svg files", "*.svg"),
127
+ ("pdf files", "*.pdf"),
128
+ ("All files", "*"),
129
+ ],
130
+ )
131
+ return FILE_path