CTKFileDialog-plus 0.5.5__tar.gz → 1.0.0__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.
Files changed (39) hide show
  1. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTKFileDialog_plus.egg-info/PKG-INFO +121 -4
  2. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTKFileDialog_plus.egg-info/SOURCES.txt +1 -0
  3. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/Constants/__init__.py +9 -1
  4. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/Constants/constants.py +15 -1
  5. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/Dialog.py +125 -16
  6. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/__init__.py +10 -1
  7. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/_functions.py +223 -19
  8. ctkfiledialog_plus-1.0.0/LICENSE +21 -0
  9. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/PKG-INFO +121 -4
  10. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/README.md +118 -3
  11. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/pyproject.toml +1 -1
  12. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/setup.py +1 -1
  13. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTKFileDialog_plus.egg-info/dependency_links.txt +0 -0
  14. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTKFileDialog_plus.egg-info/requires.txt +0 -0
  15. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTKFileDialog_plus.egg-info/top_level.txt +0 -0
  16. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/_system.py +0 -0
  17. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/_IconsMini/file.png +0 -0
  18. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/_IconsMini/folder.png +0 -0
  19. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/bash.png +0 -0
  20. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/conf.png +0 -0
  21. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/css.png +0 -0
  22. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/exe.png +0 -0
  23. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/folder.png +0 -0
  24. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/gz.png +0 -0
  25. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/html.png +0 -0
  26. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/image.png +0 -0
  27. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/ini.png +0 -0
  28. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/javascript.png +0 -0
  29. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/js.png +0 -0
  30. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/json.png +0 -0
  31. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/markdown.png +0 -0
  32. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/odt.png +0 -0
  33. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/pdf.png +0 -0
  34. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/php.png +0 -0
  35. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/python.png +0 -0
  36. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/text.png +0 -0
  37. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/CTkFileDialog/icons/video.png +0 -0
  38. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/MANIFEST.in +0 -0
  39. {ctkfiledialog_plus-0.5.5 → ctkfiledialog_plus-1.0.0}/setup.cfg +0 -0
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: CTKFileDialog-plus
3
- Version: 0.5.5
3
+ Version: 1.0.0
4
4
  Summary: A modern file dialog for CustomTkinter
5
5
  Home-page: https://github.com/hmidani-abdelilah/CTkFileDialog-plus
6
6
  Author: abdelilah
7
7
  Requires-Python: >=3.7
8
8
  Description-Content-Type: text/markdown
9
+ License-File: LICENSE
9
10
  Requires-Dist: customtkinter
10
11
  Requires-Dist: Pillow
11
12
  Requires-Dist: opencv-python
@@ -13,6 +14,7 @@ Requires-Dist: CTkMessagebox
13
14
  Requires-Dist: CTkToolTip
14
15
  Requires-Dist: typeguard
15
16
  Dynamic: home-page
17
+ Dynamic: license-file
16
18
  Dynamic: requires-python
17
19
 
18
20
  <h1 align="center">CTkFileDialog</h1>
@@ -31,8 +33,10 @@ Dynamic: requires-python
31
33
  - � Search/filter files in real-time
32
34
  - 🖼️ Live image preview
33
35
  - 🎥 Video thumbnail preview
34
- - 📁 Directory selection
35
- - 💾 Save file dialog (return path or open file)
36
+ - 📁 Directory selection (single or multiple)
37
+ - 📄📁 Combined file-or-folder selection (single or multiple)
38
+ - ➕ Create new folders from within the dialog (`foldercreation`)
39
+ - 💾 Save file dialog (return path or open file), with automatic extension (`defaultext`)
36
40
  - ❔ Tooltip support
37
41
  - 🖥️ Shell Path Syntax Support
38
42
  - ⌨️ Backspace using Alt + Left Arrow shortcut
@@ -171,7 +175,113 @@ app.mainloop()
171
175
 
172
176
  ---
173
177
 
174
- ### 💾 Save As (get path only)
178
+ ### 📁 Select Single Directory (askopendirname)
179
+
180
+ ```python
181
+ import customtkinter as ctk
182
+ from CTkFileDialog import askopendirname
183
+
184
+ ctk.set_appearance_mode("Dark")
185
+ ctk.set_default_color_theme("blue")
186
+
187
+ def select_directory():
188
+ folder = askopendirname(autocomplete=True)
189
+ if folder:
190
+ result_label.configure(text=f"Selected directory:\n{folder}")
191
+
192
+ app = ctk.CTk()
193
+ app.title("askopendirname Demo")
194
+ app.geometry("500x200")
195
+
196
+ ctk.CTkButton(app, text="Select Directory", command=select_directory).pack(pady=20)
197
+ result_label = ctk.CTkLabel(app, text="Waiting for directory selection...")
198
+ result_label.pack()
199
+
200
+ app.mainloop()
201
+ ```
202
+
203
+ ---
204
+
205
+ ### 📁 Select Multiple Directories (askopendirnames)
206
+
207
+ ```python
208
+ import customtkinter as ctk
209
+ from CTkFileDialog import askopendirnames
210
+
211
+ ctk.set_appearance_mode("Dark")
212
+ ctk.set_default_color_theme("blue")
213
+
214
+ def select_directories():
215
+ # Hold Ctrl or Shift while clicking to select several folders
216
+ folders = askopendirnames(autocomplete=True)
217
+ if folders:
218
+ result_label.configure(text="Selected directories:\n" + "\n".join(folders))
219
+
220
+ app = ctk.CTk()
221
+ app.title("askopendirnames Demo")
222
+ app.geometry("500x300")
223
+
224
+ ctk.CTkButton(app, text="Select Directories", command=select_directories).pack(pady=20)
225
+ result_label = ctk.CTkLabel(app, text="Waiting for directory selection...", wraplength=450)
226
+ result_label.pack()
227
+
228
+ app.mainloop()
229
+ ```
230
+
231
+ ---
232
+
233
+ ### 📄📁 Select a File or a Folder (askopenpathname)
234
+
235
+ ```python
236
+ import customtkinter as ctk
237
+ from CTkFileDialog import askopenpathname
238
+
239
+ ctk.set_appearance_mode("Dark")
240
+ ctk.set_default_color_theme("blue")
241
+
242
+ def select_path():
243
+ path = askopenpathname(autocomplete=True)
244
+ if path:
245
+ result_label.configure(text=f"Selected:\n{path}")
246
+
247
+ app = ctk.CTk()
248
+ app.title("askopenpathname Demo")
249
+ app.geometry("500x200")
250
+
251
+ ctk.CTkButton(app, text="Select File or Folder", command=select_path).pack(pady=20)
252
+ result_label = ctk.CTkLabel(app, text="Waiting for selection...")
253
+ result_label.pack()
254
+
255
+ app.mainloop()
256
+ ```
257
+
258
+ ---
259
+
260
+ ### 📄📁 Select Multiple Files and/or Folders (askopenpathnames)
261
+
262
+ ```python
263
+ import customtkinter as ctk
264
+ from CTkFileDialog import askopenpathnames
265
+
266
+ ctk.set_appearance_mode("Dark")
267
+ ctk.set_default_color_theme("blue")
268
+
269
+ def select_paths():
270
+ # Hold Ctrl or Shift while clicking to mix files and folders in one selection
271
+ items = askopenpathnames(autocomplete=True)
272
+ if items:
273
+ result_label.configure(text="Selected:\n" + "\n".join(items))
274
+
275
+ app = ctk.CTk()
276
+ app.title("askopenpathnames Demo")
277
+ app.geometry("500x300")
278
+
279
+ ctk.CTkButton(app, text="Select Files/Folders", command=select_paths).pack(pady=20)
280
+ result_label = ctk.CTkLabel(app, text="Waiting for selection...", wraplength=450)
281
+ result_label.pack()
282
+
283
+ app.mainloop()
284
+ ```
175
285
 
176
286
  ```python
177
287
  import customtkinter as ctk
@@ -185,6 +295,9 @@ def save_as_filename():
185
295
  if path:
186
296
  result_label.configure(text=f"Save file as:\n{path}")
187
297
 
298
+ # You can also auto-append an extension if the user doesn't type one:
299
+ # path = asksaveasfilename(autocomplete=True, defaultext=".txt")
300
+
188
301
  app = ctk.CTk()
189
302
  app.title("asksaveasfilename Demo")
190
303
  app.geometry("500x200")
@@ -301,6 +414,8 @@ app.mainloop()
301
414
  | `autocomplete` | Enable path autocompletion with `Tab`, `Up`, and `Down`. |
302
415
  | `initial_dir` | Set the initial directory when opening the dialog. |
303
416
  | `tool_tip` | Enable the tool tip. |
417
+ | `foldercreation`| Enable a "New Folder" button so the user can create folders from within the dialog (`True` by default). |
418
+ | `defaultext` | *(`asksaveasfilename`/`asksaveasfile` only)* Extension appended to the filename if the user didn't type one (default is none). |
304
419
  | `style` | Defines the dialog style, by default it will be 'Default' but you can choose a small one ('Mini'). |
305
420
  | `geometry` | You define the geometry string in a tuple: Example ('NormalGM', 'MiniGeometry'). |
306
421
  | `title` | Define the title from the app, default will be "CTkFileDialog". |
@@ -388,6 +503,8 @@ root.mainloop()
388
503
  | `PATH` | System PATH split into a list of directories |
389
504
  | `DATA_DIR` | XDG-compliant user data directory (default: ~/.local/share) |
390
505
  | `VENV` | Active Python virtual environment (venv or conda), fallback to PWD |
506
+ | `DOWNLOAD_DIR` | Default download directory (e.g., ~/Downloads or C:\Users\user\Download). |
507
+ | `DOWNLOAD_DIR_VIDEO` | Default video download directory (e.g., ~/Downloads/Video or C:\Users\user\Download\Video).|
391
508
 
392
509
 
393
510
  </div>
@@ -1,3 +1,4 @@
1
+ LICENSE
1
2
  MANIFEST.in
2
3
  README.md
3
4
  pyproject.toml
@@ -17,12 +17,18 @@ Available constants:
17
17
  - DATA_DIR: XDG-compliant user data directory (e.g., ~/.local/share).
18
18
  - PATH: List of directories in the system PATH environment variable.
19
19
  - VENV: Path to the active Python virtual environment (VIRTUAL_ENV or CONDA_PREFIX).
20
+ - DOWNLOAD_DIR: Default download directory (e.g., ~/Downloads).
21
+ - DOWNLOAD_DIR_VIDEO: Default video download directory (e.g., ~/Downloads/Video).
20
22
 
21
23
  Author: Flick
22
24
  Repository: https://github.com/FlickGMD/CTkFileDialog
25
+
26
+ Modified: by abdelilah
27
+ https://github.com/hmidani-abdelilah/CTkFileDialog-plus
28
+
23
29
  """
24
30
 
25
- from .constants import PWD, HOME, PATH, TEMP, CONFIG_DIR, CACHE_DIR, DATA_DIR, VENV, PATHS
31
+ from .constants import PWD, HOME, PATH, TEMP, CONFIG_DIR, CACHE_DIR, DATA_DIR, VENV, PATHS ,DOWNLOAD_DIR, DOWNLOAD_DIR_VIDEO
26
32
 
27
33
  __all__ = [
28
34
  'PWD',
@@ -34,4 +40,6 @@ __all__ = [
34
40
  'DATA_DIR',
35
41
  'VENV',
36
42
  'PATHS',
43
+ 'DOWNLOAD_DIR',
44
+ 'DOWNLOAD_DIR_VIDEO',
37
45
  ]
@@ -8,6 +8,8 @@ PWD = str(Path.cwd())
8
8
  # User's home directory (e.g., /home/user or C:\Users\user)
9
9
  HOME = str(Path.home())
10
10
 
11
+
12
+
11
13
  # System PATH split into a list of directories
12
14
  PATH = os.getenv('PATH').split(os.pathsep)
13
15
 
@@ -26,6 +28,16 @@ DATA_DIR = os.getenv('XDG_DATA_HOME', str(Path(HOME) / '.local' / 'share'))
26
28
  # Active Python virtual environment (venv or conda), fallback to PWD
27
29
  VENV = os.getenv("VIRTUAL_ENV") or os.getenv("CONDA_PREFIX") or PWD
28
30
 
31
+ # Download directory windows and linux (default: ~/Downloads)
32
+ DOWNLOAD_DIR = str(Path(HOME) / 'Downloads')
33
+
34
+ # Download directory Video windows and linux (default: ~/Downloads/Video )
35
+ DOWNLOAD_DIR_VIDEO = str(Path(DOWNLOAD_DIR) / 'Video')
36
+ # create the directory if it doesn't exist
37
+ if not os.path.exists(DOWNLOAD_DIR_VIDEO):
38
+ os.makedirs(DOWNLOAD_DIR_VIDEO)
39
+
40
+
29
41
  # All paths in a single dictionary for easy access
30
42
  PATHS = {
31
43
  "HOME": HOME,
@@ -35,5 +47,7 @@ PATHS = {
35
47
  "DATA_DIR": DATA_DIR,
36
48
  "CACHE_DIR": CACHE_DIR,
37
49
  "PATH": PATH,
38
- 'VENV': VENV
50
+ 'VENV': VENV,
51
+ 'DOWNLOAD_DIR': DOWNLOAD_DIR,
52
+ 'DOWNLOAD_DIR_VIDEO': DOWNLOAD_DIR_VIDEO
39
53
  }
@@ -59,9 +59,11 @@ class _DrawApp():
59
59
  autocomplete: bool = False,
60
60
  video_preview: bool = False,
61
61
  tool_tip: bool = False,
62
+ foldercreation: bool = True,
62
63
  title: str = 'CTkFileDialog',
63
64
  geometry: str = '1320x720') -> None:
64
65
 
66
+ self.foldercreation = foldercreation
65
67
  self.current_path = current_path
66
68
 
67
69
  if not self.current_path:
@@ -203,7 +205,7 @@ class _DrawApp():
203
205
 
204
206
  # If it's a directory
205
207
  if os.path.isdir(path):
206
- if self.method == 'askdirectory':
208
+ if self.method in ('askdirectory', 'askopenpathname'):
207
209
  self._temp_item = path
208
210
  self.current_path = Path(path)
209
211
  self.update_entry(path=self.current_path)
@@ -284,8 +286,48 @@ class _DrawApp():
284
286
  ]
285
287
 
286
288
  return
289
+
290
+ if self.method == "askdirectories":
291
+ seen = set()
292
+ self.selected_objects = [
293
+ f for f in self._temp_items
294
+ if os.path.isdir(f) and f not in seen and not seen.add(f)
295
+ ]
296
+ return
297
+
298
+ if self.method == "askopenpathnames":
299
+ seen = set()
300
+ self.selected_objects = [
301
+ f for f in self._temp_items
302
+ if f not in seen and not seen.add(f)
303
+ ]
304
+ return
287
305
 
288
306
 
307
+ def _create_new_folder(self):
308
+ if not self.foldercreation:
309
+ return
310
+ dialog = ctk.CTkInputDialog(text='Enter new folder name:', title='New Folder')
311
+ name = dialog.get_input()
312
+ if not name:
313
+ return
314
+ name = name.strip()
315
+ if not name:
316
+ return
317
+ new_path = os.path.join(str(self.current_path), name)
318
+ try:
319
+ os.makedirs(new_path, exist_ok=False)
320
+ except FileExistsError:
321
+ CTkMessagebox(message='A file or folder with that name already exists!', title='Error', icon='cancel')
322
+ return
323
+ except PermissionError:
324
+ CTkMessagebox(message='Permission denied!', title='Error', icon='cancel')
325
+ return
326
+ except OSError as e:
327
+ CTkMessagebox(message=f'Could not create folder: {e}', title='Error', icon='cancel')
328
+ return
329
+ self._list_files(master=self.app)
330
+
289
331
  @staticmethod
290
332
  def _is_video(video: str):
291
333
 
@@ -362,6 +404,11 @@ class _DrawApp():
362
404
  ButtonOk = ctk.CTkButton(master=TopBar, text='Ok', font=('Hack Nerd Font', 15), width=70, command = lambda: self.close_app())
363
405
  ButtonOk.pack(side='left', fill='x', padx=10, pady=10)
364
406
 
407
+ # New folder button
408
+ if self.foldercreation:
409
+ ButtonNewFolder = ctk.CTkButton(master=TopBar, text='New Folder', font=('Hack Nerd Font', 15), width=100, command=self._create_new_folder)
410
+ ButtonNewFolder.pack(side='left', fill='x', padx=10, pady=10)
411
+
365
412
  if self.autocomplete:
366
413
 
367
414
  self.PathEntry.bind('<Down>', lambda event: self._autocomplete(event))
@@ -583,7 +630,7 @@ class _DrawApp():
583
630
 
584
631
  if event.state & 0x0004:
585
632
 
586
- if self.method in ['askopenfilenames', 'askopenfiles']:
633
+ if self.method in ['askopenfilenames', 'askopenfiles', 'askdirectories', 'askopenpathnames']:
587
634
  if r not in self._temp_items:
588
635
  self._temp_items.append(r)
589
636
  boton.configure(fg_color="blue")
@@ -595,7 +642,7 @@ class _DrawApp():
595
642
 
596
643
  else:
597
644
  self._temp_items.clear()
598
- if self.method in ['askopenfilenames', 'askopenfiles']:
645
+ if self.method in ['askopenfilenames', 'askopenfiles', 'askdirectories', 'askopenpathnames']:
599
646
  self._temp_items.append(r)
600
647
 
601
648
  for btn in self._all_buttons:
@@ -643,7 +690,7 @@ class _DrawApp():
643
690
  file = self.files[self.LOADED]
644
691
  full_path = os.path.join(path, file)
645
692
 
646
- if self.method == 'askdirectory' and os.path.isfile(full_path):
693
+ if self.method in ('askdirectory', 'askdirectories') and os.path.isfile(full_path):
647
694
  self.LOADED += 1
648
695
  continue
649
696
 
@@ -673,7 +720,7 @@ class _DrawApp():
673
720
  fixed_name = self.fix_name(name=file)
674
721
 
675
722
  command = None
676
- if self.method not in ['askopenfilenames']:
723
+ if self.method not in ['askopenfilenames', 'askdirectories', 'askopenpathnames']:
677
724
  command = lambda r=full_path: self.navigate_to(path=r, master=master)
678
725
 
679
726
  boton = ctk.CTkButton(
@@ -692,7 +739,7 @@ class _DrawApp():
692
739
 
693
740
  if self.tool_tip:
694
741
  _CustomToolTip(widget=boton, message=self._get_info(full_path))
695
- if self.method in ['askopenfilenames', 'askopenfiles']:
742
+ if self.method in ['askopenfilenames', 'askopenfiles', 'askdirectories', 'askopenpathnames']:
696
743
  boton.bind('<Button-1>', lambda event, r=full_path, b=boton: self._handle_click(event, r, master, b))
697
744
  boton.grid(row=row, column=col, padx=10, pady=10)
698
745
  col += 1
@@ -820,7 +867,7 @@ class _DrawApp():
820
867
  while self.LOADED < len(self.display_files) and cantidad > 0:
821
868
  file = self.display_files[self.LOADED]
822
869
 
823
- if self.method == 'askdirectory' and os.path.isfile(os.path.join(self.current_path, file)):
870
+ if self.method in ('askdirectory', 'askdirectories') and os.path.isfile(os.path.join(self.current_path, file)):
824
871
  self.LOADED += 1
825
872
  continue
826
873
 
@@ -852,7 +899,7 @@ class _DrawApp():
852
899
  fixed_name = self.fix_name(name=file)
853
900
 
854
901
  command = None
855
- if self.method not in ['askopenfilenames']:
902
+ if self.method not in ['askopenfilenames', 'askdirectories', 'askopenpathnames']:
856
903
  command = lambda r=full_path: self.navigate_to(path=r, master=self.app)
857
904
 
858
905
  row = self.LOADED // columnas
@@ -874,7 +921,7 @@ class _DrawApp():
874
921
 
875
922
  if self.tool_tip:
876
923
  _CustomToolTip(widget=boton, message=self._get_info(full_path))
877
- if self.method in ['askopenfilenames', 'askopenfiles']:
924
+ if self.method in ['askopenfilenames', 'askopenfiles', 'askdirectories', 'askopenpathnames']:
878
925
  boton.bind('<Button-1>', lambda event, r=full_path, b=boton: self._handle_click(event, r, self.app, b))
879
926
  boton.grid(row=row, column=col, padx=10, pady=10)
880
927
 
@@ -942,7 +989,7 @@ class _DrawApp():
942
989
  while self.LOADED < len(self.display_files) and cantidad > 0:
943
990
  file = self.display_files[self.LOADED]
944
991
 
945
- if self.method == 'askdirectory' and os.path.isfile(os.path.join(self.current_path, file)):
992
+ if self.method in ('askdirectory', 'askdirectories') and os.path.isfile(os.path.join(self.current_path, file)):
946
993
  self.LOADED += 1
947
994
  continue
948
995
 
@@ -988,7 +1035,7 @@ class _DrawApp():
988
1035
  info_text = f"{file}\n{file_type} • {size_str} • {mod_time}"
989
1036
 
990
1037
  command = None
991
- if self.method not in ['askopenfilenames']:
1038
+ if self.method not in ['askopenfilenames', 'askdirectories', 'askopenpathnames']:
992
1039
  command = lambda r=full_path: self.navigate_to(path=r, master=self.app)
993
1040
 
994
1041
  boton = ctk.CTkButton(
@@ -1004,7 +1051,7 @@ class _DrawApp():
1004
1051
  )
1005
1052
  boton.pack(expand=True, fill="both", side="left")
1006
1053
 
1007
- if self.method in ['askopenfilenames', 'askopenfiles']:
1054
+ if self.method in ['askopenfilenames', 'askopenfiles', 'askdirectories', 'askopenpathnames']:
1008
1055
  boton.bind('<Button-1>', lambda event, r=full_path, b=boton: self._handle_click(event, r, self.app, b))
1009
1056
 
1010
1057
  self.LOADED += 1
@@ -1032,7 +1079,7 @@ class _DrawApp():
1032
1079
  self.files = [
1033
1080
  f.name for f in os.scandir(path)
1034
1081
  if (
1035
- (f.is_dir() or (self.method != 'askdirectory' and f.is_file())) and
1082
+ (f.is_dir() or (self.method not in ('askdirectory', 'askdirectories') and f.is_file())) and
1036
1083
  (self.hidden or not f.name.startswith('.')) and
1037
1084
  (f.is_dir() or not self.filetypes or
1038
1085
  any(f.name.endswith(ext) for ext in self.filetypes))
@@ -1063,6 +1110,7 @@ class _MiniDialog():
1063
1110
  autocomplete: bool = False,
1064
1111
  initial_dir: str = '.',
1065
1112
  _extra_method: str = '',
1113
+ foldercreation: bool = True,
1066
1114
  geometry: str = '500x400',
1067
1115
  title: str = 'CTkFileDialog'):
1068
1116
 
@@ -1070,6 +1118,7 @@ class _MiniDialog():
1070
1118
  self.master.geometry(geometry_string=geometry)
1071
1119
  self.master.title(title)
1072
1120
  self._extra_method = _extra_method
1121
+ self.foldercreation = foldercreation
1073
1122
  self.tab_index = -1
1074
1123
  self.method = method
1075
1124
  self.hidden = hidden
@@ -1110,6 +1159,30 @@ class _MiniDialog():
1110
1159
 
1111
1160
  return os.path.abspath(os.path.expandvars(os.path.expanduser(self.initial_dir)))
1112
1161
 
1162
+ def _create_new_folder(self):
1163
+ if not self.foldercreation:
1164
+ return
1165
+ dialog = ctk.CTkInputDialog(text='Enter new folder name:', title='New Folder')
1166
+ name = dialog.get_input()
1167
+ if not name:
1168
+ return
1169
+ name = name.strip()
1170
+ if not name:
1171
+ return
1172
+ new_path = os.path.join(self.initial_dir, name)
1173
+ try:
1174
+ os.makedirs(new_path, exist_ok=False)
1175
+ except FileExistsError:
1176
+ CTkMessagebox(message='A file or folder with that name already exists!', title='Error', icon='cancel')
1177
+ return
1178
+ except PermissionError:
1179
+ CTkMessagebox(message='Permission denied!', title='Error', icon='cancel')
1180
+ return
1181
+ except OSError as e:
1182
+ CTkMessagebox(message=f'Could not create folder: {e}', title='Error', icon='cancel')
1183
+ return
1184
+ self.list_files()
1185
+
1113
1186
  def _TopSide(self):
1114
1187
 
1115
1188
  self.frame = ctk.CTkFrame(self.master)
@@ -1132,6 +1205,12 @@ class _MiniDialog():
1132
1205
  )
1133
1206
 
1134
1207
  self.up_btn.pack(side=ctk.RIGHT, padx=10, pady=10)
1208
+
1209
+ if self.foldercreation:
1210
+ self.new_folder_btn = ctk.CTkButton(
1211
+ self.path_frame, text="+", width=30, command=self._create_new_folder
1212
+ )
1213
+ self.new_folder_btn.pack(side=ctk.RIGHT, padx=(0, 10), pady=10)
1135
1214
 
1136
1215
  # Search bar
1137
1216
  self.search_frame = ctk.CTkFrame(self.frame)
@@ -1169,7 +1248,7 @@ class _MiniDialog():
1169
1248
 
1170
1249
  for f in os.scandir(path):
1171
1250
  if (
1172
- (f.is_dir() or (self.method != 'askdirectory' and f.is_file())) and
1251
+ (f.is_dir() or (self.method not in ('askdirectory', 'askdirectories') and f.is_file())) and
1173
1252
  (self.hidden or not f.name.startswith('.')) and
1174
1253
  (f.is_dir() or not self.filetypes or
1175
1254
  any(f.name.endswith(ext) for ext in self.filetypes))
@@ -1287,7 +1366,7 @@ class _MiniDialog():
1287
1366
  style.map("Treeview",
1288
1367
  background=[('selected', '#E0E0E0')],
1289
1368
  foreground=[('selected', '#000000')])
1290
- self.tree = ttk.Treeview(self.tree_frame, show="tree", selectmode='extended' if self.method in ['askopenfilenames', 'askopenfiles'] else 'browse')
1369
+ self.tree = ttk.Treeview(self.tree_frame, show="tree", selectmode='extended' if self.method in ['askopenfilenames', 'askopenfiles', 'askdirectories', 'askopenpathnames'] else 'browse')
1291
1370
  self.tree.bind("<Double-1>", self._on_click)
1292
1371
  self.tree.bind("<Button-1>", self._on_select_item)
1293
1372
  self.tree.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
@@ -1365,7 +1444,32 @@ class _MiniDialog():
1365
1444
  self.master.destroy()
1366
1445
  return
1367
1446
 
1368
- elif self.method in ['askopenfilename', 'askopenfile', 'askdirectory']:
1447
+ elif self.method == 'askdirectories':
1448
+ selected_items = self.tree.selection()
1449
+ selected_paths = [
1450
+ self.absolute_paths[self.tree.index(item)]
1451
+ for item in selected_items
1452
+ if os.path.isdir(self.absolute_paths[self.tree.index(item)])
1453
+ ]
1454
+
1455
+ if selected_paths:
1456
+ self.selected_paths = selected_paths
1457
+ self.master.destroy()
1458
+ return
1459
+
1460
+ elif self.method == 'askopenpathnames':
1461
+ selected_items = self.tree.selection()
1462
+ selected_paths = [
1463
+ self.absolute_paths[self.tree.index(item)]
1464
+ for item in selected_items
1465
+ ]
1466
+
1467
+ if selected_paths:
1468
+ self.selected_paths = selected_paths
1469
+ self.master.destroy()
1470
+ return
1471
+
1472
+ elif self.method in ['askopenfilename', 'askopenfile', 'askdirectory', 'askopenpathname']:
1369
1473
  if not self.selected_item:
1370
1474
  return
1371
1475
 
@@ -1379,6 +1483,11 @@ class _MiniDialog():
1379
1483
  self.master.destroy()
1380
1484
  return
1381
1485
 
1486
+ elif self.method == 'askopenpathname':
1487
+ self.selected_path = self.selected_item
1488
+ self.master.destroy()
1489
+ return
1490
+
1382
1491
  def _on_select_item(self, event=None):
1383
1492
  selected_item = self.tree.focus()
1384
1493
  items = self.tree.get_children()
@@ -10,7 +10,12 @@ File dialog created in custom Tkinter and inspired by the Tkinter dialog.
10
10
  - Github: https://github.com/hmidani-abdelilah/CTkFileDialog-plus
11
11
  - License: MIT
12
12
  '''
13
- from ._functions import askopenfilename, askdirectory, askopenfile, askopenfiles, askopenfilenames, asksaveasfile, asksaveasfilename
13
+ from ._functions import (
14
+ askopenfilename, askdirectory, askopenfile, askopenfiles, askopenfilenames,
15
+ asksaveasfile, asksaveasfilename,
16
+ askopendirname, askopendirnames,
17
+ askopenpathname, askopenpathnames,
18
+ )
14
19
  from . import Constants
15
20
 
16
21
  __version__ = '0.3.3'
@@ -22,6 +27,10 @@ __all__ = [
22
27
  'askopenfilenames',
23
28
  'asksaveasfile',
24
29
  'asksaveasfilename',
30
+ 'askopendirname',
31
+ 'askopendirnames',
32
+ 'askopenpathname',
33
+ 'askopenpathnames',
25
34
  'Constants'
26
35
  ]
27
36