CTKFileDialog-plus 1.0.0__tar.gz → 2.1.1__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.
- ctkfiledialog_plus-2.1.1/CTkFileDialog/Dialog.py +25 -0
- ctkfiledialog_plus-2.1.1/CTkFileDialog/_functions.py +521 -0
- ctkfiledialog_plus-2.1.1/CTkFileDialog/_system.py +5 -0
- ctkfiledialog_plus-2.1.1/CTkFileDialog/core/__init__.py +13 -0
- ctkfiledialog_plus-2.1.1/CTkFileDialog/core/filesystem.py +97 -0
- ctkfiledialog_plus-2.1.1/CTkFileDialog/core/search.py +13 -0
- ctkfiledialog_plus-2.1.1/CTkFileDialog/core/sorting.py +41 -0
- ctkfiledialog_plus-2.1.1/CTkFileDialog/preview/__init__.py +4 -0
- ctkfiledialog_plus-2.1.1/CTkFileDialog/preview/media.py +126 -0
- ctkfiledialog_plus-2.1.1/CTkFileDialog/resources/__init__.py +14 -0
- ctkfiledialog_plus-2.1.1/CTkFileDialog/resources/icons.py +89 -0
- ctkfiledialog_plus-2.1.1/CTkFileDialog/system/__init__.py +4 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/_system.py → ctkfiledialog_plus-2.1.1/CTkFileDialog/system/platform.py +26 -8
- ctkfiledialog_plus-2.1.1/CTkFileDialog/ui/__init__.py +5 -0
- ctkfiledialog_plus-2.1.1/CTkFileDialog/ui/default_dialog.py +1013 -0
- ctkfiledialog_plus-2.1.1/CTkFileDialog/ui/mini_dialog.py +454 -0
- ctkfiledialog_plus-2.1.1/CTkFileDialog/ui/tooltip.py +25 -0
- ctkfiledialog_plus-2.1.1/CTkFileDialog/utils/__init__.py +9 -0
- ctkfiledialog_plus-2.1.1/CTkFileDialog/utils/helpers.py +61 -0
- {ctkfiledialog_plus-1.0.0 → ctkfiledialog_plus-2.1.1/CTkFileDialog_plus.egg-info}/PKG-INFO +99 -37
- ctkfiledialog_plus-2.1.1/CTkFileDialog_plus.egg-info/SOURCES.txt +30 -0
- ctkfiledialog_plus-1.0.0/README.md → ctkfiledialog_plus-2.1.1/PKG-INFO +116 -35
- ctkfiledialog_plus-1.0.0/CTKFileDialog_plus.egg-info/PKG-INFO → ctkfiledialog_plus-2.1.1/README.md +88 -54
- {ctkfiledialog_plus-1.0.0 → ctkfiledialog_plus-2.1.1}/setup.py +1 -1
- ctkfiledialog_plus-1.0.0/CTKFileDialog_plus.egg-info/SOURCES.txt +0 -37
- ctkfiledialog_plus-1.0.0/CTkFileDialog/Dialog.py +0 -1535
- ctkfiledialog_plus-1.0.0/CTkFileDialog/_functions.py +0 -634
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/_IconsMini/file.png +0 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/_IconsMini/folder.png +0 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/bash.png +0 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/conf.png +0 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/css.png +0 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/exe.png +0 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/folder.png +0 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/gz.png +0 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/html.png +0 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/image.png +0 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/ini.png +0 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/javascript.png +0 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/js.png +0 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/json.png +0 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/markdown.png +0 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/odt.png +0 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/pdf.png +0 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/php.png +0 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/python.png +0 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/text.png +0 -0
- ctkfiledialog_plus-1.0.0/CTkFileDialog/icons/video.png +0 -0
- ctkfiledialog_plus-1.0.0/MANIFEST.in +0 -3
- ctkfiledialog_plus-1.0.0/pyproject.toml +0 -22
- {ctkfiledialog_plus-1.0.0 → ctkfiledialog_plus-2.1.1}/CTkFileDialog/Constants/__init__.py +0 -0
- {ctkfiledialog_plus-1.0.0 → ctkfiledialog_plus-2.1.1}/CTkFileDialog/Constants/constants.py +0 -0
- {ctkfiledialog_plus-1.0.0 → ctkfiledialog_plus-2.1.1}/CTkFileDialog/__init__.py +0 -0
- {ctkfiledialog_plus-1.0.0/CTKFileDialog_plus.egg-info → ctkfiledialog_plus-2.1.1/CTkFileDialog_plus.egg-info}/dependency_links.txt +0 -0
- {ctkfiledialog_plus-1.0.0/CTKFileDialog_plus.egg-info → ctkfiledialog_plus-2.1.1/CTkFileDialog_plus.egg-info}/requires.txt +0 -0
- {ctkfiledialog_plus-1.0.0/CTKFileDialog_plus.egg-info → ctkfiledialog_plus-2.1.1/CTkFileDialog_plus.egg-info}/top_level.txt +0 -0
- {ctkfiledialog_plus-1.0.0 → ctkfiledialog_plus-2.1.1}/LICENSE +0 -0
- {ctkfiledialog_plus-1.0.0 → ctkfiledialog_plus-2.1.1}/setup.cfg +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
"""Backward-compatibility shim.
|
|
3
|
+
|
|
4
|
+
Historically all dialog classes lived in this module. They have been
|
|
5
|
+
moved to ``CTkFileDialog.ui``. This file re-exports the public names so
|
|
6
|
+
any external ``from CTkFileDialog.Dialog import _DrawApp`` continues to
|
|
7
|
+
work.
|
|
8
|
+
"""
|
|
9
|
+
from .ui.default_dialog import DrawApp, _DrawApp
|
|
10
|
+
from .ui.mini_dialog import MiniDialog, _MiniDialog
|
|
11
|
+
from .ui.tooltip import CustomToolTip
|
|
12
|
+
from .system.platform import System as _System
|
|
13
|
+
|
|
14
|
+
# Historical private name
|
|
15
|
+
_CustomToolTip = CustomToolTip
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"DrawApp",
|
|
19
|
+
"_DrawApp",
|
|
20
|
+
"MiniDialog",
|
|
21
|
+
"_MiniDialog",
|
|
22
|
+
"CustomToolTip",
|
|
23
|
+
"_CustomToolTip",
|
|
24
|
+
"_System",
|
|
25
|
+
]
|
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
"""Public dialog functions — API surface is unchanged."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import List, Literal, Optional, TextIO, Tuple, Union
|
|
6
|
+
|
|
7
|
+
from typeguard import typechecked
|
|
8
|
+
|
|
9
|
+
from .ui.default_dialog import _DrawApp
|
|
10
|
+
from .ui.mini_dialog import _MiniDialog
|
|
11
|
+
from .utils.helpers import apply_defaultext, normalize_filetypes
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# Re-export helpers under historical private names for any external use
|
|
15
|
+
_normalize_filetypes = normalize_filetypes
|
|
16
|
+
_apply_defaultext = apply_defaultext
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@typechecked
|
|
20
|
+
def askopenfilename(
|
|
21
|
+
style: Literal["Mini", "Default"] = "Default",
|
|
22
|
+
filetypes: Optional[List[Union[str, Tuple[str, str]]]] = None,
|
|
23
|
+
hidden: bool = False,
|
|
24
|
+
preview_img: bool = False,
|
|
25
|
+
autocomplete: bool = False,
|
|
26
|
+
video_preview: bool = False,
|
|
27
|
+
initial_dir: str = ".",
|
|
28
|
+
tool_tip: bool = False,
|
|
29
|
+
foldercreation: bool = True,
|
|
30
|
+
geometry: Tuple[str, str] = ("1320x720", "500x400"),
|
|
31
|
+
title: str = "CTkFileDialog",
|
|
32
|
+
) -> str | None:
|
|
33
|
+
"""
|
|
34
|
+
Displays a file dialog for selecting a single file and returns the file path.
|
|
35
|
+
"""
|
|
36
|
+
normalized = normalize_filetypes(filetypes)
|
|
37
|
+
if style == "Default":
|
|
38
|
+
app = _DrawApp(
|
|
39
|
+
filetypes=normalized,
|
|
40
|
+
current_path=initial_dir,
|
|
41
|
+
hidden=hidden,
|
|
42
|
+
preview_img=preview_img,
|
|
43
|
+
method="askopenfilename",
|
|
44
|
+
autocomplete=autocomplete,
|
|
45
|
+
video_preview=video_preview,
|
|
46
|
+
tool_tip=tool_tip,
|
|
47
|
+
foldercreation=foldercreation,
|
|
48
|
+
geometry=geometry[0],
|
|
49
|
+
title=title,
|
|
50
|
+
)
|
|
51
|
+
app.app.wait_window()
|
|
52
|
+
return app.selected_file if app.selected_file else None
|
|
53
|
+
elif style == "Mini":
|
|
54
|
+
app = _MiniDialog(
|
|
55
|
+
method="askopenfilename",
|
|
56
|
+
filetypes=normalized,
|
|
57
|
+
initial_dir=initial_dir,
|
|
58
|
+
autocomplete=autocomplete,
|
|
59
|
+
hidden=hidden,
|
|
60
|
+
foldercreation=foldercreation,
|
|
61
|
+
geometry=geometry[1],
|
|
62
|
+
title=title,
|
|
63
|
+
)
|
|
64
|
+
return app.selected_path
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@typechecked
|
|
68
|
+
def askdirectory(
|
|
69
|
+
style: Literal["Default", "Mini"] = "Default",
|
|
70
|
+
filetypes: Optional[List[Union[str, Tuple[str, str]]]] = None,
|
|
71
|
+
hidden: bool = False,
|
|
72
|
+
autocomplete: bool = False,
|
|
73
|
+
initial_dir: str = ".",
|
|
74
|
+
tool_tip: bool = False,
|
|
75
|
+
foldercreation: bool = True,
|
|
76
|
+
geometry: Tuple[str, str] = ("1320x720", "500x400"),
|
|
77
|
+
title: str = "CTkFileDialog",
|
|
78
|
+
) -> str | None:
|
|
79
|
+
"""Displays a directory selection dialog and returns the selected path."""
|
|
80
|
+
normalized = normalize_filetypes(filetypes)
|
|
81
|
+
if style == "Default":
|
|
82
|
+
app = _DrawApp(
|
|
83
|
+
filetypes=normalized,
|
|
84
|
+
current_path=initial_dir,
|
|
85
|
+
hidden=hidden,
|
|
86
|
+
method="askdirectory",
|
|
87
|
+
autocomplete=autocomplete,
|
|
88
|
+
tool_tip=tool_tip,
|
|
89
|
+
foldercreation=foldercreation,
|
|
90
|
+
geometry=geometry[0],
|
|
91
|
+
title=title,
|
|
92
|
+
)
|
|
93
|
+
app.app.wait_window()
|
|
94
|
+
return app.selected_file if app.selected_file else None
|
|
95
|
+
elif style == "Mini":
|
|
96
|
+
app = _MiniDialog(
|
|
97
|
+
filetypes=normalized,
|
|
98
|
+
initial_dir=initial_dir,
|
|
99
|
+
hidden=hidden,
|
|
100
|
+
method="askdirectory",
|
|
101
|
+
autocomplete=autocomplete,
|
|
102
|
+
foldercreation=foldercreation,
|
|
103
|
+
title=title,
|
|
104
|
+
geometry=geometry[1],
|
|
105
|
+
)
|
|
106
|
+
return app.selected_path if app.selected_path else None
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@typechecked
|
|
110
|
+
def askopendirname(
|
|
111
|
+
style: Literal["Default", "Mini"] = "Default",
|
|
112
|
+
hidden: bool = False,
|
|
113
|
+
autocomplete: bool = False,
|
|
114
|
+
initial_dir: str = ".",
|
|
115
|
+
tool_tip: bool = False,
|
|
116
|
+
foldercreation: bool = True,
|
|
117
|
+
geometry: Tuple[str, str] = ("1320x720", "500x400"),
|
|
118
|
+
title: str = "CTkFileDialog",
|
|
119
|
+
) -> str:
|
|
120
|
+
"""Allow the user to choose a single directory."""
|
|
121
|
+
if style == "Default":
|
|
122
|
+
app = _DrawApp(
|
|
123
|
+
current_path=initial_dir,
|
|
124
|
+
hidden=hidden,
|
|
125
|
+
method="askdirectory",
|
|
126
|
+
autocomplete=autocomplete,
|
|
127
|
+
tool_tip=tool_tip,
|
|
128
|
+
foldercreation=foldercreation,
|
|
129
|
+
geometry=geometry[0],
|
|
130
|
+
title=title,
|
|
131
|
+
)
|
|
132
|
+
app.app.wait_window()
|
|
133
|
+
return app.selected_file if app.selected_file else ""
|
|
134
|
+
elif style == "Mini":
|
|
135
|
+
app = _MiniDialog(
|
|
136
|
+
initial_dir=initial_dir,
|
|
137
|
+
hidden=hidden,
|
|
138
|
+
method="askdirectory",
|
|
139
|
+
autocomplete=autocomplete,
|
|
140
|
+
foldercreation=foldercreation,
|
|
141
|
+
title=title,
|
|
142
|
+
geometry=geometry[1],
|
|
143
|
+
)
|
|
144
|
+
return app.selected_path if app.selected_path else ""
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
@typechecked
|
|
148
|
+
def askopendirnames(
|
|
149
|
+
style: Literal["Default", "Mini"] = "Default",
|
|
150
|
+
hidden: bool = False,
|
|
151
|
+
autocomplete: bool = False,
|
|
152
|
+
initial_dir: str = ".",
|
|
153
|
+
tool_tip: bool = False,
|
|
154
|
+
foldercreation: bool = True,
|
|
155
|
+
geometry: Tuple[str, str] = ("1320x720", "500x400"),
|
|
156
|
+
title: str = "CTkFileDialog",
|
|
157
|
+
) -> tuple[str, ...]:
|
|
158
|
+
"""Allow the user to choose multiple directories (Ctrl/Shift + click)."""
|
|
159
|
+
if style == "Default":
|
|
160
|
+
app = _DrawApp(
|
|
161
|
+
current_path=initial_dir,
|
|
162
|
+
hidden=hidden,
|
|
163
|
+
method="askdirectories",
|
|
164
|
+
autocomplete=autocomplete,
|
|
165
|
+
tool_tip=tool_tip,
|
|
166
|
+
foldercreation=foldercreation,
|
|
167
|
+
geometry=geometry[0],
|
|
168
|
+
title=title,
|
|
169
|
+
)
|
|
170
|
+
app.app.wait_window()
|
|
171
|
+
return tuple(app.selected_objects) if app.selected_objects else tuple()
|
|
172
|
+
elif style == "Mini":
|
|
173
|
+
app = _MiniDialog(
|
|
174
|
+
initial_dir=initial_dir,
|
|
175
|
+
hidden=hidden,
|
|
176
|
+
method="askdirectories",
|
|
177
|
+
autocomplete=autocomplete,
|
|
178
|
+
foldercreation=foldercreation,
|
|
179
|
+
title=title,
|
|
180
|
+
geometry=geometry[1],
|
|
181
|
+
)
|
|
182
|
+
return tuple(app.selected_paths) if app.selected_paths else tuple()
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
@typechecked
|
|
186
|
+
def askopenpathname(
|
|
187
|
+
style: Literal["Default", "Mini"] = "Default",
|
|
188
|
+
filetypes: Optional[List[Union[str, Tuple[str, str]]]] = None,
|
|
189
|
+
hidden: bool = False,
|
|
190
|
+
preview_img: bool = False,
|
|
191
|
+
autocomplete: bool = False,
|
|
192
|
+
video_preview: bool = False,
|
|
193
|
+
initial_dir: str = ".",
|
|
194
|
+
tool_tip: bool = False,
|
|
195
|
+
foldercreation: bool = True,
|
|
196
|
+
geometry: Tuple[str, str] = ("1320x720", "500x400"),
|
|
197
|
+
title: str = "CTkFileDialog",
|
|
198
|
+
) -> str:
|
|
199
|
+
"""Allow the user to choose a single file or folder."""
|
|
200
|
+
normalized = normalize_filetypes(filetypes)
|
|
201
|
+
if style == "Default":
|
|
202
|
+
app = _DrawApp(
|
|
203
|
+
filetypes=normalized,
|
|
204
|
+
current_path=initial_dir,
|
|
205
|
+
hidden=hidden,
|
|
206
|
+
preview_img=preview_img,
|
|
207
|
+
method="askopenpathname",
|
|
208
|
+
autocomplete=autocomplete,
|
|
209
|
+
video_preview=video_preview,
|
|
210
|
+
tool_tip=tool_tip,
|
|
211
|
+
foldercreation=foldercreation,
|
|
212
|
+
geometry=geometry[0],
|
|
213
|
+
title=title,
|
|
214
|
+
)
|
|
215
|
+
app.app.wait_window()
|
|
216
|
+
return app.selected_file if app.selected_file else ""
|
|
217
|
+
elif style == "Mini":
|
|
218
|
+
app = _MiniDialog(
|
|
219
|
+
method="askopenpathname",
|
|
220
|
+
filetypes=normalized,
|
|
221
|
+
initial_dir=initial_dir,
|
|
222
|
+
autocomplete=autocomplete,
|
|
223
|
+
hidden=hidden,
|
|
224
|
+
foldercreation=foldercreation,
|
|
225
|
+
geometry=geometry[1],
|
|
226
|
+
title=title,
|
|
227
|
+
)
|
|
228
|
+
return app.selected_path if app.selected_path else ""
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
@typechecked
|
|
232
|
+
def askopenpathnames(
|
|
233
|
+
style: Literal["Default", "Mini"] = "Default",
|
|
234
|
+
filetypes: Optional[List[Union[str, Tuple[str, str]]]] = None,
|
|
235
|
+
hidden: bool = False,
|
|
236
|
+
preview_img: bool = False,
|
|
237
|
+
autocomplete: bool = False,
|
|
238
|
+
video_preview: bool = False,
|
|
239
|
+
initial_dir: str = ".",
|
|
240
|
+
tool_tip: bool = False,
|
|
241
|
+
foldercreation: bool = True,
|
|
242
|
+
geometry: Tuple[str, str] = ("1320x720", "500x400"),
|
|
243
|
+
title: str = "CTkFileDialog",
|
|
244
|
+
) -> tuple[str, ...]:
|
|
245
|
+
"""Allow the user to choose multiple files and folders (Ctrl/Shift + click)."""
|
|
246
|
+
normalized = normalize_filetypes(filetypes)
|
|
247
|
+
if style == "Default":
|
|
248
|
+
app = _DrawApp(
|
|
249
|
+
filetypes=normalized,
|
|
250
|
+
current_path=initial_dir,
|
|
251
|
+
hidden=hidden,
|
|
252
|
+
preview_img=preview_img,
|
|
253
|
+
method="askopenpathnames",
|
|
254
|
+
autocomplete=autocomplete,
|
|
255
|
+
video_preview=video_preview,
|
|
256
|
+
tool_tip=tool_tip,
|
|
257
|
+
foldercreation=foldercreation,
|
|
258
|
+
geometry=geometry[0],
|
|
259
|
+
title=title,
|
|
260
|
+
)
|
|
261
|
+
app.app.wait_window()
|
|
262
|
+
return tuple(app.selected_objects) if app.selected_objects else tuple()
|
|
263
|
+
elif style == "Mini":
|
|
264
|
+
app = _MiniDialog(
|
|
265
|
+
filetypes=normalized,
|
|
266
|
+
initial_dir=initial_dir,
|
|
267
|
+
hidden=hidden,
|
|
268
|
+
autocomplete=autocomplete,
|
|
269
|
+
method="askopenpathnames",
|
|
270
|
+
foldercreation=foldercreation,
|
|
271
|
+
geometry=geometry[1],
|
|
272
|
+
title=title,
|
|
273
|
+
)
|
|
274
|
+
return tuple(app.selected_paths) if app.selected_paths else tuple()
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
@typechecked
|
|
278
|
+
def askopenfilenames(
|
|
279
|
+
style: Literal["Default", "Mini"] = "Default",
|
|
280
|
+
filetypes: Optional[List[Union[str, Tuple[str, str]]]] = None,
|
|
281
|
+
hidden: bool = False,
|
|
282
|
+
preview_img: bool = False,
|
|
283
|
+
autocomplete: bool = False,
|
|
284
|
+
video_preview: bool = False,
|
|
285
|
+
initial_dir: str = ".",
|
|
286
|
+
tool_tip: bool = False,
|
|
287
|
+
foldercreation: bool = True,
|
|
288
|
+
geometry: Tuple[str, str] = ("1320x720", "500x400"),
|
|
289
|
+
title: str = "CTkFileDialog",
|
|
290
|
+
) -> tuple[str, ...] | None:
|
|
291
|
+
"""Displays a file dialog for multiple file selection."""
|
|
292
|
+
normalized = normalize_filetypes(filetypes)
|
|
293
|
+
if style == "Default":
|
|
294
|
+
app = _DrawApp(
|
|
295
|
+
filetypes=normalized,
|
|
296
|
+
current_path=initial_dir,
|
|
297
|
+
hidden=hidden,
|
|
298
|
+
preview_img=preview_img,
|
|
299
|
+
method="askopenfilenames",
|
|
300
|
+
autocomplete=autocomplete,
|
|
301
|
+
video_preview=video_preview,
|
|
302
|
+
tool_tip=tool_tip,
|
|
303
|
+
foldercreation=foldercreation,
|
|
304
|
+
geometry=geometry[0],
|
|
305
|
+
title=title,
|
|
306
|
+
)
|
|
307
|
+
app.app.wait_window()
|
|
308
|
+
return tuple(app.selected_objects) if app.selected_objects else None
|
|
309
|
+
elif style == "Mini":
|
|
310
|
+
app = _MiniDialog(
|
|
311
|
+
filetypes=normalized,
|
|
312
|
+
initial_dir=initial_dir,
|
|
313
|
+
hidden=hidden,
|
|
314
|
+
method="askopenfilenames",
|
|
315
|
+
autocomplete=autocomplete,
|
|
316
|
+
foldercreation=foldercreation,
|
|
317
|
+
geometry=geometry[1],
|
|
318
|
+
title=title,
|
|
319
|
+
)
|
|
320
|
+
return tuple(app.selected_paths) if app.selected_paths else None
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
@typechecked
|
|
324
|
+
def asksaveasfilename(
|
|
325
|
+
style: Literal["Default", "Mini"] = "Default",
|
|
326
|
+
filetypes: Optional[List[Union[str, Tuple[str, str]]]] = None,
|
|
327
|
+
hidden: bool = False,
|
|
328
|
+
preview_img: bool = False,
|
|
329
|
+
autocomplete: bool = False,
|
|
330
|
+
video_preview: bool = False,
|
|
331
|
+
initial_dir: str = ".",
|
|
332
|
+
tool_tip: bool = False,
|
|
333
|
+
foldercreation: bool = True,
|
|
334
|
+
defaultext: Optional[str] = None,
|
|
335
|
+
geometry: Tuple[str, str] = ("1320x720", "500x400"),
|
|
336
|
+
title: str = "CTkFileDialog",
|
|
337
|
+
) -> str | None:
|
|
338
|
+
"""Displays a save file dialog and returns the selected path."""
|
|
339
|
+
normalized = normalize_filetypes(filetypes)
|
|
340
|
+
if style == "Default":
|
|
341
|
+
app = _DrawApp(
|
|
342
|
+
filetypes=normalized,
|
|
343
|
+
current_path=initial_dir,
|
|
344
|
+
hidden=hidden,
|
|
345
|
+
preview_img=preview_img,
|
|
346
|
+
method="asksaveasfilename",
|
|
347
|
+
autocomplete=autocomplete,
|
|
348
|
+
video_preview=video_preview,
|
|
349
|
+
tool_tip=tool_tip,
|
|
350
|
+
foldercreation=foldercreation,
|
|
351
|
+
geometry=geometry[0],
|
|
352
|
+
title=title,
|
|
353
|
+
)
|
|
354
|
+
app.app.wait_window()
|
|
355
|
+
return apply_defaultext(app.selected_file, defaultext) if app.selected_file else None
|
|
356
|
+
elif style == "Mini":
|
|
357
|
+
app = _MiniDialog(
|
|
358
|
+
filetypes=normalized,
|
|
359
|
+
initial_dir=initial_dir,
|
|
360
|
+
hidden=hidden,
|
|
361
|
+
method="asksaveasfilename",
|
|
362
|
+
autocomplete=autocomplete,
|
|
363
|
+
foldercreation=foldercreation,
|
|
364
|
+
geometry=geometry[1],
|
|
365
|
+
title=title,
|
|
366
|
+
)
|
|
367
|
+
return apply_defaultext(app.selected_path, defaultext) if app.selected_path else None
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
@typechecked
|
|
371
|
+
def asksaveasfile(
|
|
372
|
+
style: Literal["Default", "Mini"] = "Default",
|
|
373
|
+
mode: Literal["r", "rb", "r+", "rb+", "r+b", "w", "wb", "w+", "wb+", "a", "ab", "a+", "ab+", "x", "xb"] = "w",
|
|
374
|
+
filetypes: Optional[List[Union[str, Tuple[str, str]]]] = None,
|
|
375
|
+
hidden: bool = False,
|
|
376
|
+
preview_img: bool = False,
|
|
377
|
+
autocomplete: bool = False,
|
|
378
|
+
video_preview: bool = False,
|
|
379
|
+
initial_dir: str = ".",
|
|
380
|
+
tool_tip: bool = False,
|
|
381
|
+
foldercreation: bool = True,
|
|
382
|
+
defaultext: Optional[str] = None,
|
|
383
|
+
geometry: Tuple[str, str] = ("1320x720", "500x400"),
|
|
384
|
+
title: str = "CTkFileDialog",
|
|
385
|
+
**kwargs,
|
|
386
|
+
) -> TextIO | None:
|
|
387
|
+
"""Displays a save dialog and returns an open file object."""
|
|
388
|
+
normalized = normalize_filetypes(filetypes)
|
|
389
|
+
if style == "Default":
|
|
390
|
+
app = _DrawApp(
|
|
391
|
+
filetypes=normalized,
|
|
392
|
+
current_path=initial_dir,
|
|
393
|
+
hidden=hidden,
|
|
394
|
+
preview_img=preview_img,
|
|
395
|
+
method="asksaveasfile",
|
|
396
|
+
autocomplete=autocomplete,
|
|
397
|
+
video_preview=video_preview,
|
|
398
|
+
tool_tip=tool_tip,
|
|
399
|
+
foldercreation=foldercreation,
|
|
400
|
+
geometry=geometry[0],
|
|
401
|
+
title=title,
|
|
402
|
+
)
|
|
403
|
+
app.app.wait_window()
|
|
404
|
+
selected = apply_defaultext(app.selected_file, defaultext)
|
|
405
|
+
return open(selected, mode=mode, **kwargs) if selected else None
|
|
406
|
+
elif style == "Mini":
|
|
407
|
+
app = _MiniDialog(
|
|
408
|
+
filetypes=normalized,
|
|
409
|
+
initial_dir=initial_dir,
|
|
410
|
+
hidden=hidden,
|
|
411
|
+
method="asksaveasfile",
|
|
412
|
+
foldercreation=foldercreation,
|
|
413
|
+
geometry=geometry[1],
|
|
414
|
+
title=title,
|
|
415
|
+
)
|
|
416
|
+
selected = apply_defaultext(app.selected_path, defaultext)
|
|
417
|
+
return open(selected, mode=mode, **kwargs) if selected else None
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
@typechecked
|
|
421
|
+
def askopenfile(
|
|
422
|
+
style: Literal["Mini", "Default"] = "Default",
|
|
423
|
+
mode: Literal["r", "rb", "r+", "rb+", "r+b", "w", "wb", "w+", "wb+", "a", "ab", "a+", "ab+", "x", "xb"] = "r",
|
|
424
|
+
hidden: bool = False,
|
|
425
|
+
filetypes: Optional[List[Union[str, Tuple[str, str]]]] = None,
|
|
426
|
+
preview_img: bool = False,
|
|
427
|
+
autocomplete: bool = False,
|
|
428
|
+
video_preview: bool = False,
|
|
429
|
+
initial_dir: str = ".",
|
|
430
|
+
tool_tip: bool = False,
|
|
431
|
+
foldercreation: bool = True,
|
|
432
|
+
geometry: Tuple[str, str] = ("1320x720", "500x400"),
|
|
433
|
+
title: str = "CTkFileDialog",
|
|
434
|
+
**kwargs,
|
|
435
|
+
) -> TextIO | None:
|
|
436
|
+
"""Displays an open file dialog and returns an open file object."""
|
|
437
|
+
normalized = normalize_filetypes(filetypes)
|
|
438
|
+
if style == "Default":
|
|
439
|
+
app = _DrawApp(
|
|
440
|
+
filetypes=normalized,
|
|
441
|
+
current_path=initial_dir,
|
|
442
|
+
hidden=hidden,
|
|
443
|
+
preview_img=preview_img,
|
|
444
|
+
method="askopenfile",
|
|
445
|
+
autocomplete=autocomplete,
|
|
446
|
+
video_preview=video_preview,
|
|
447
|
+
tool_tip=tool_tip,
|
|
448
|
+
foldercreation=foldercreation,
|
|
449
|
+
geometry=geometry[0],
|
|
450
|
+
title=title,
|
|
451
|
+
)
|
|
452
|
+
app.app.wait_window()
|
|
453
|
+
return open(app.selected_file, mode=mode, **kwargs) if app.selected_file else None
|
|
454
|
+
elif style == "Mini":
|
|
455
|
+
app = _MiniDialog(
|
|
456
|
+
filetypes=normalized,
|
|
457
|
+
initial_dir=initial_dir,
|
|
458
|
+
hidden=hidden,
|
|
459
|
+
method="askopenfile",
|
|
460
|
+
autocomplete=autocomplete,
|
|
461
|
+
foldercreation=foldercreation,
|
|
462
|
+
geometry=geometry[1],
|
|
463
|
+
title=title,
|
|
464
|
+
)
|
|
465
|
+
return open(app.selected_path, mode=mode, **kwargs) if app.selected_path else None
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
@typechecked
|
|
469
|
+
def askopenfiles(
|
|
470
|
+
style: Literal["Default", "Mini"] = "Default",
|
|
471
|
+
mode: Literal["r", "rb", "r+", "rb+", "r+b", "w", "wb", "w+", "wb+", "a", "ab", "a+", "ab+", "x", "xb"] = "r",
|
|
472
|
+
hidden: bool = False,
|
|
473
|
+
filetypes: Optional[List[Union[str, Tuple[str, str]]]] = None,
|
|
474
|
+
preview_img: bool = False,
|
|
475
|
+
autocomplete: bool = False,
|
|
476
|
+
video_preview: bool = False,
|
|
477
|
+
initial_dir: str = ".",
|
|
478
|
+
tool_tip: bool = False,
|
|
479
|
+
foldercreation: bool = True,
|
|
480
|
+
geometry: Tuple[str, str] = ("1320x720", "500x400"),
|
|
481
|
+
title: str = "CTkFileDialog",
|
|
482
|
+
**kwargs,
|
|
483
|
+
) -> tuple[TextIO, ...] | None:
|
|
484
|
+
"""Displays a multi-file open dialog and returns multiple open file objects."""
|
|
485
|
+
normalized = normalize_filetypes(filetypes)
|
|
486
|
+
if style == "Default":
|
|
487
|
+
app = _DrawApp(
|
|
488
|
+
filetypes=normalized,
|
|
489
|
+
current_path=initial_dir,
|
|
490
|
+
hidden=hidden,
|
|
491
|
+
preview_img=preview_img,
|
|
492
|
+
method="askopenfilenames",
|
|
493
|
+
autocomplete=autocomplete,
|
|
494
|
+
video_preview=video_preview,
|
|
495
|
+
tool_tip=tool_tip,
|
|
496
|
+
foldercreation=foldercreation,
|
|
497
|
+
geometry=geometry[0],
|
|
498
|
+
title=title,
|
|
499
|
+
)
|
|
500
|
+
app.app.wait_window()
|
|
501
|
+
return (
|
|
502
|
+
tuple(open(f, mode=mode, **kwargs) for f in app.selected_objects)
|
|
503
|
+
if app.selected_objects
|
|
504
|
+
else None
|
|
505
|
+
)
|
|
506
|
+
elif style == "Mini":
|
|
507
|
+
app = _MiniDialog(
|
|
508
|
+
filetypes=normalized,
|
|
509
|
+
initial_dir=initial_dir,
|
|
510
|
+
hidden=hidden,
|
|
511
|
+
autocomplete=autocomplete,
|
|
512
|
+
method="askopenfilenames",
|
|
513
|
+
foldercreation=foldercreation,
|
|
514
|
+
geometry=geometry[1],
|
|
515
|
+
title=title,
|
|
516
|
+
)
|
|
517
|
+
return (
|
|
518
|
+
tuple(open(f, mode=mode, **kwargs) for f in app.selected_paths)
|
|
519
|
+
if app.selected_paths
|
|
520
|
+
else None
|
|
521
|
+
)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Core non-UI logic: filesystem, sorting, search."""
|
|
2
|
+
from .filesystem import create_folder, get_file_info, list_directory, prompt_create_folder
|
|
3
|
+
from .search import filter_by_query
|
|
4
|
+
from .sorting import sort_files
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"list_directory",
|
|
8
|
+
"create_folder",
|
|
9
|
+
"prompt_create_folder",
|
|
10
|
+
"get_file_info",
|
|
11
|
+
"sort_files",
|
|
12
|
+
"filter_by_query",
|
|
13
|
+
]
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
"""Filesystem operations used by the dialogs."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import time
|
|
7
|
+
from typing import Any, Callable, List, Optional
|
|
8
|
+
|
|
9
|
+
from CTkMessagebox import CTkMessagebox
|
|
10
|
+
|
|
11
|
+
from ..system.platform import find_owner
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def list_directory(
|
|
15
|
+
path: str,
|
|
16
|
+
*,
|
|
17
|
+
method: str,
|
|
18
|
+
hidden: bool = False,
|
|
19
|
+
filetypes: Optional[List[str]] = None,
|
|
20
|
+
) -> List[str]:
|
|
21
|
+
"""Return names of entries in *path* filtered by dialog mode and options.
|
|
22
|
+
|
|
23
|
+
Directories are always included (unless hidden). Files are included
|
|
24
|
+
unless the method is a pure directory-picker, and must match *filetypes*
|
|
25
|
+
when provided.
|
|
26
|
+
"""
|
|
27
|
+
dir_only = method in ("askdirectory", "askdirectories")
|
|
28
|
+
result: List[str] = []
|
|
29
|
+
try:
|
|
30
|
+
for entry in os.scandir(path):
|
|
31
|
+
if entry.name.startswith(".") and not hidden:
|
|
32
|
+
continue
|
|
33
|
+
if entry.is_dir():
|
|
34
|
+
result.append(entry.name)
|
|
35
|
+
elif not dir_only and entry.is_file():
|
|
36
|
+
if not filetypes or any(entry.name.endswith(ext) for ext in filetypes):
|
|
37
|
+
result.append(entry.name)
|
|
38
|
+
except (PermissionError, FileNotFoundError, OSError):
|
|
39
|
+
raise
|
|
40
|
+
return result
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def create_folder(parent: str, name: str) -> Optional[str]:
|
|
44
|
+
"""Create a new folder under *parent*.
|
|
45
|
+
|
|
46
|
+
Returns the new path on success, or ``None`` on failure (after showing
|
|
47
|
+
a message box). Raises nothing — errors are reported via UI.
|
|
48
|
+
"""
|
|
49
|
+
name = (name or "").strip()
|
|
50
|
+
if not name:
|
|
51
|
+
return None
|
|
52
|
+
new_path = os.path.join(parent, name)
|
|
53
|
+
try:
|
|
54
|
+
os.makedirs(new_path, exist_ok=False)
|
|
55
|
+
return new_path
|
|
56
|
+
except FileExistsError:
|
|
57
|
+
CTkMessagebox(
|
|
58
|
+
message="A file or folder with that name already exists!",
|
|
59
|
+
title="Error",
|
|
60
|
+
icon="cancel",
|
|
61
|
+
)
|
|
62
|
+
except PermissionError:
|
|
63
|
+
CTkMessagebox(message="Permission denied!", title="Error", icon="cancel")
|
|
64
|
+
except OSError as e:
|
|
65
|
+
CTkMessagebox(
|
|
66
|
+
message=f"Could not create folder: {e}",
|
|
67
|
+
title="Error",
|
|
68
|
+
icon="cancel",
|
|
69
|
+
)
|
|
70
|
+
return None
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def get_file_info(path: str) -> str:
|
|
74
|
+
"""Return a multi-line tooltip string for *path*."""
|
|
75
|
+
try:
|
|
76
|
+
st = os.stat(path)
|
|
77
|
+
owner = find_owner(path)
|
|
78
|
+
fecha = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(st.st_ctime))
|
|
79
|
+
return (
|
|
80
|
+
f"File: {os.path.basename(path)}\n"
|
|
81
|
+
f" creation: {fecha}\n"
|
|
82
|
+
f" owner: {owner}\n"
|
|
83
|
+
f" path: {path}\n"
|
|
84
|
+
f" "
|
|
85
|
+
)
|
|
86
|
+
except Exception as e:
|
|
87
|
+
return f"Error getting info: {e}"
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def prompt_create_folder(parent_path: str, on_success: Optional[Callable[[], Any]] = None) -> None:
|
|
91
|
+
"""Show an input dialog, create the folder, then call *on_success*."""
|
|
92
|
+
import customtkinter as ctk
|
|
93
|
+
|
|
94
|
+
dialog = ctk.CTkInputDialog(text="Enter new folder name:", title="New Folder")
|
|
95
|
+
name = dialog.get_input()
|
|
96
|
+
if create_folder(parent_path, name or "") and on_success:
|
|
97
|
+
on_success()
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
"""Search / filter helpers."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import List
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def filter_by_query(files: List[str], query: str) -> List[str]:
|
|
9
|
+
"""Case-insensitive substring filter on file names."""
|
|
10
|
+
q = (query or "").lower().strip()
|
|
11
|
+
if not q:
|
|
12
|
+
return list(files)
|
|
13
|
+
return [f for f in files if q in f.lower()]
|