CTKFileDialog-plus 0.5.2__py3-none-any.whl → 0.5.3__py3-none-any.whl

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/Dialog.py CHANGED
@@ -212,17 +212,26 @@ class _DrawApp():
212
212
 
213
213
  # If it's a file and we're in save-as mode
214
214
  if self.method in ['asksaveasfile', 'asksaveasfilename']:
215
- # In save-as mode, we just select the file path
216
- # The file will be created/overwritten when user confirms
215
+ if os.path.isfile(path):
216
+ msg = CTkMessagebox(
217
+ message='This file exists. Do you want to overwrite it?',
218
+ icon='warning',
219
+ title='Warning',
220
+ option_1='Yes',
221
+ option_2='No'
222
+ )
223
+ if msg.get() == 'No':
224
+ return
217
225
  self._temp_item = path
218
- self.update_entry(path)
226
+ self.close_app()
219
227
  return
220
228
 
221
229
  if self.method == 'askopenfile':
222
230
  if not os.path.isfile(path):
231
+
223
232
  CTkMessagebox(message='File not found!', title='Error', icon='cancel')
224
233
  self.PathEntry.delete(0, ctk.END)
225
- self.PathEntry.insert(0, str(self.current_path))
234
+ self.PathEntry.insert(0, self.current_path)
226
235
  return
227
236
 
228
237
  self._temp_item = path
@@ -242,104 +251,38 @@ class _DrawApp():
242
251
  return
243
252
 
244
253
  except PermissionError:
254
+
245
255
  CTkMessagebox(message='Permission denied!', title='Error', icon='cancel')
246
- except FileNotFoundError:
256
+ except FileNotFoundError:
257
+
247
258
  CTkMessagebox(message='File Not Found!', title='Error', icon='cancel')
248
259
 
249
260
  def close_app(self):
250
- # Handle save-as filename dialog
251
261
  if self.method == 'asksaveasfilename':
252
- path = self.PathEntry.get().strip()
253
- if not path:
254
- CTkMessagebox(message='Please enter a filename!', title='Error', icon='cancel')
255
- return
256
-
257
- # Check if it's a valid path
258
- path = os.path.abspath(os.path.expanduser(os.path.expandvars(path)))
259
-
260
- # Don't allow directories as filenames
261
- if os.path.isdir(path):
262
- CTkMessagebox(message='A directory with this name exists. Please enter a filename.', title='Error', icon='cancel')
263
- return
264
-
265
- # Check if file exists and ask for confirmation
266
- if os.path.exists(path):
267
- msg = CTkMessagebox(
268
- message='This file already exists. Do you want to overwrite it?',
269
- icon='warning',
270
- title='File Exists',
271
- option_1='Yes',
272
- option_2='No'
273
- )
274
- if msg.get() == 'No':
275
- return
276
-
277
- self.selected_file = path
278
- self.protocol_windows()
279
- self.app.destroy()
280
- return
281
-
282
- # Handle save-as file dialog
283
- if self.method == 'asksaveasfile':
284
- path = self.PathEntry.get().strip()
285
- if not path:
286
- CTkMessagebox(message='Please enter a filename!', title='Error', icon='cancel')
287
- return
288
-
289
- path = os.path.abspath(os.path.expanduser(os.path.expandvars(path)))
290
-
291
- if os.path.isdir(path):
292
- CTkMessagebox(message='A directory with this name exists. Please enter a filename.', title='Error', icon='cancel')
293
- return
294
-
295
- if os.path.exists(path):
296
- msg = CTkMessagebox(
297
- message='This file already exists. Do you want to overwrite it?',
298
- icon='warning',
299
- title='File Exists',
300
- option_1='Yes',
301
- option_2='No'
302
- )
303
- if msg.get() == 'No':
304
- return
305
-
306
- self.selected_file = path
307
- self.protocol_windows()
308
- self.app.destroy()
309
- return
262
+ if not os.path.isdir(self.PathEntry.get()): self.selected_file = self.PathEntry.get()
310
263
 
311
- # Handle single file open
312
- if self.method == 'askopenfile':
313
- if not self._temp_item:
314
- CTkMessagebox(message='Please select a file!', title='Error', icon='cancel')
315
- return
316
-
317
- self.selected_file = self._temp_item
318
- self.protocol_windows()
264
+ if self._temp_item:
265
+ self.protocol_windows()
319
266
  self.app.destroy()
320
- return
321
-
322
- # Handle single file/directory selection
323
- if self.method in ['askopenfilename', 'askdirectory']:
324
- if not self._temp_item:
325
- CTkMessagebox(message='Please select a file or directory!', title='Error', icon='cancel')
267
+ if self.method == 'asksaveasfile':
268
+ self.selected_file = self._temp_item
269
+ return
270
+ elif self.method == 'askopenfile':
271
+ self.selected_file = self._temp_item
272
+ else:
273
+ self.selected_file = self._temp_item
326
274
  return
327
-
328
- self.selected_file = self._temp_item
329
- self.protocol_windows()
330
- self.app.destroy()
331
- return
332
275
 
333
- # Handle multiple files selection
334
276
  if len(self._temp_items) >= 1:
335
277
  self.protocol_windows()
336
278
  self.app.destroy()
337
- if self.method in ["askopenfilenames", "askopenfiles"]:
279
+ if self.method == "askopenfilenames" or self.method == "askopenfiles":
338
280
  seen = set()
339
281
  self.selected_objects = [
340
282
  f for f in self._temp_items
341
283
  if not os.path.isdir(f) and f not in seen and not seen.add(f)
342
284
  ]
285
+
343
286
  return
344
287
 
345
288
 
@@ -557,37 +500,54 @@ class _DrawApp():
557
500
 
558
501
 
559
502
  def event_scroll(self):
560
-
503
+ """Bind mouse-wheel events so file list scrolls in Default dialog.
504
+
505
+ Previous code attached handlers to the internal canvas only which
506
+ meant wheel rotation would sometimes be ignored (especially when
507
+ focus was on another widget). On X11 ``<MouseWheel>`` may not
508
+ fire at all, so we also listen for ``<Button-4>``/``<Button-5>``.
509
+ The handler performs a hit-test to ensure scrolling only occurs
510
+ when the pointer is above the scrollable area.
511
+ """
512
+
561
513
  canvas = self.CenterSideFrame._parent_canvas
562
514
 
563
515
  def _on_mousewheel(event):
564
516
  try:
565
- x_root, y_root = event.x_root, event.y_root
566
-
567
- # Coordinates and size of the scrollable frame
568
- x1 = self.CenterSideFrame.winfo_rootx()
569
- y1 = self.CenterSideFrame.winfo_rooty()
570
- x2 = x1 + self.CenterSideFrame.winfo_width()
571
- y2 = y1 + self.CenterSideFrame.winfo_height()
572
- if x1 <= x_root <= x2 and y1 <= y_root <= y2:
573
-
574
- if event.num == 4:
517
+ # only scroll when pointer is over the frame
518
+ x_root = getattr(event, 'x_root', None)
519
+ y_root = getattr(event, 'y_root', None)
520
+ if x_root is not None and y_root is not None:
521
+ x1 = self.CenterSideFrame.winfo_rootx()
522
+ y1 = self.CenterSideFrame.winfo_rooty()
523
+ x2 = x1 + self.CenterSideFrame.winfo_width()
524
+ y2 = y1 + self.CenterSideFrame.winfo_height()
525
+ if not (x1 <= x_root <= x2 and y1 <= y_root <= y2):
526
+ return
527
+
528
+ # handle scroll events from different platforms
529
+ if hasattr(event, 'num'):
530
+ if event.num == 4:
575
531
  canvas.yview_scroll(-1, "units")
576
- elif event.num == 5:
532
+ self._check_scroll(self.app)
533
+ return "break"
534
+ elif event.num == 5:
577
535
  canvas.yview_scroll(1, "units")
578
- else:
579
- canvas.yview_scroll(-int(event.delta / 120), "units")
580
-
581
- # Trigger lazy loading check
536
+ self._check_scroll(self.app)
537
+ return "break"
538
+
539
+ if hasattr(event, 'delta'):
540
+ canvas.yview_scroll(-int(event.delta / 120), "units")
582
541
  self._check_scroll(self.app)
583
542
  return "break"
584
- except Exception as e:
543
+ except Exception:
585
544
  pass
586
545
 
587
- canvas.bind_all("<MouseWheel>", _on_mousewheel)
588
- canvas.bind("<Button-4>", _on_mousewheel)
589
- canvas.bind("<Button-5>", _on_mousewheel)
590
- canvas.bind("<MouseWheel>", _on_mousewheel)
546
+ # bind to the top–level window so scrolling works regardless of
547
+ # focus or which child widget generated the event
548
+ self.app.bind_all("<MouseWheel>", _on_mousewheel)
549
+ self.app.bind_all("<Button-4>", _on_mousewheel)
550
+ self.app.bind_all("<Button-5>", _on_mousewheel)
591
551
 
592
552
  # Bind to all child widgets
593
553
  for widget in canvas.winfo_children():
@@ -644,12 +604,8 @@ class _DrawApp():
644
604
  hover_color="#8da3ae",
645
605
  text_color="#000000" if self.current_theme.lower() == 'light' else '#cccccc',
646
606
  )
647
- if os.path.isdir(r):
607
+ if os.path.isdir(r):
648
608
  self.navigate_to(path=r, master=master)
649
- elif self.method in ['asksaveasfile', 'asksaveasfilename']:
650
- # In save-as mode, select the file (don't navigate)
651
- self._temp_item = r
652
- self.update_entry(r)
653
609
  else:
654
610
  self._temp_items.append(r)
655
611
 
@@ -1378,20 +1334,13 @@ class _MiniDialog():
1378
1334
  path = os.path.join(self.initial_dir, path)
1379
1335
 
1380
1336
  if self.method in ['asksaveasfile', 'asksaveasfilename']:
1381
- # Validate filename
1382
- if not path:
1383
- CTkMessagebox(message='Please enter a filename!', title='Error', icon='cancel')
1384
- return
1385
-
1386
- if os.path.isdir(path):
1387
- CTkMessagebox(message='A directory with this name exists. Please enter a filename.', title='Error', icon='cancel')
1337
+ if not path or os.path.isdir(path):
1388
1338
  return
1389
1339
 
1390
- # Check if file exists and ask for confirmation
1391
- if os.path.exists(path):
1340
+ if os.path.exists(path) and self._extra_method != 'askopenfile':
1392
1341
  opts = CTkMessagebox(
1393
- message='This file already exists. Do you want to overwrite it?',
1394
- title='File Exists',
1342
+ message='This file already exists! Do you want to overwrite it?',
1343
+ title='Error',
1395
1344
  icon='warning',
1396
1345
  option_1='Yes',
1397
1346
  option_2='No'
@@ -1441,10 +1390,6 @@ class _MiniDialog():
1441
1390
  idx = items.index(selected_item)
1442
1391
  if hasattr(self, 'absolute_paths') and idx < len(self.absolute_paths):
1443
1392
  self.selected_item = self.absolute_paths[idx]
1444
-
1445
- # For save-as dialogs, update the path entry with selected file
1446
- if self.method in ['asksaveasfile', 'asksaveasfilename']:
1447
- self.update_entry(self.selected_item)
1448
1393
  except (ValueError, IndexError):
1449
1394
  pass
1450
1395
 
@@ -1468,10 +1413,6 @@ class _MiniDialog():
1468
1413
  # If it's a file:
1469
1414
  self.path_entry.delete(0, ctk.END)
1470
1415
  self.path_entry.insert(0, self.selected_item)
1471
-
1472
- # For files in open mode, auto-select and return
1473
- if self.method in ['askopenfile', 'askopenfilename']:
1474
- self._on_select()
1475
1416
 
1476
1417
 
1477
1418
  def _up(self):
@@ -1,11 +1,43 @@
1
1
  #!/usr/bin/env python
2
2
  from .Dialog import _DrawApp, _MiniDialog, Optional, List
3
- from typing import Tuple, Literal, TextIO
3
+ from typing import Tuple, Literal, TextIO, Union
4
+
5
+
6
+ def _normalize_filetypes(filetypes: Optional[List[Union[str, Tuple[str, str]]]]) -> Optional[List[str]]:
7
+ """Convert tkinter‑style filetypes list into simplified extensions.
8
+
9
+ * Accepts a list of strings (current behaviour) or a list of
10
+ ``(label, pattern)`` tuples where pattern may contain one or
11
+ more space‑separated globs (e.g. ``"*.txt *.md"``).
12
+ * ``"*"`` or ``"*.*"`` are treated as wildcard and produce an
13
+ empty string entry which passes every filename.
14
+ * Removes any leading ``*`` characters so filters like ``"*.py"``
15
+ become ``".py"`` (the form used internally by ``_DrawApp``).
16
+ """
17
+ if not filetypes:
18
+ return None
19
+ normalized: list[str] = []
20
+ for entry in filetypes:
21
+ if isinstance(entry, (tuple, list)) and len(entry) >= 2:
22
+ # ignore label (entry[0])
23
+ patterns = str(entry[1]).split()
24
+ for pat in patterns:
25
+ pat = pat.strip()
26
+ if pat in ("*", "*.*"):
27
+ # match everything
28
+ normalized.append("")
29
+ else:
30
+ # strip wildcards
31
+ pat = pat.lstrip("*")
32
+ normalized.append(pat)
33
+ else:
34
+ normalized.append(str(entry))
35
+ return normalized
4
36
  from typeguard import typechecked
5
37
 
6
38
  @typechecked
7
39
  def askopenfilename(style: Literal['Mini', 'Default'] = 'Default',
8
- filetypes: Optional[List[str]] = None,
40
+ filetypes: Optional[List[Union[str, Tuple[str, str]]]] = None,
9
41
  hidden: bool = False,
10
42
  preview_img: bool = False,
11
43
  autocomplete: bool = False,
@@ -22,7 +54,9 @@ def askopenfilename(style: Literal['Mini', 'Default'] = 'Default',
22
54
  and select a single file. Various display options can be configured.
23
55
 
24
56
  Args:
25
- filetypes: List of file type filters (e.g., ['.py', 'sh', '.md'])
57
+ filetypes: List of file type filters (e.g., ['.py', 'sh', '.md']).
58
+ You can also supply standard tkinter-style tuples
59
+ like [("Text files","*.txt"), ("All","*.*")].
26
60
  hidden: If True, shows hidden files/directories
27
61
  preview_img: Enables live preview of image files
28
62
  autocomplete: Enables path autocompletion in the input field
@@ -37,25 +71,30 @@ def askopenfilename(style: Literal['Mini', 'Default'] = 'Default',
37
71
  str: Absolute path to the selected file, or None if canceled
38
72
 
39
73
  Example:
74
+ >>> # basic form using plain extensions
75
+ >>> file_path = askopenfilename(filetypes=[".txt", ".md"])
76
+ >>>
77
+ >>> # or use tkinter-style tuples with labels and glob patterns
40
78
  >>> file_path = askopenfilename(
41
- ... filetypes=['.py', '.md', '.jpg', '.mp4', '.mvk'],
42
- ... preview_img=True
79
+ ... filetypes=[("Text files", "*.txt"), ("Python files", "*.py *.pyw"), ("All", "*.*")]
43
80
  ... )
44
81
  >>> print(f"Selected: {file_path}")
45
82
  """
83
+ # normalize filter list so _DrawApp receives simple extensions
84
+ normalized = _normalize_filetypes(filetypes)
46
85
  if style == 'Default':
47
86
 
48
- app = _DrawApp(filetypes=filetypes, current_path=initial_dir, hidden=hidden, preview_img=preview_img, method='askopenfilename', autocomplete=autocomplete, video_preview=video_preview, tool_tip=tool_tip, geometry=geometry[0], title=title)
87
+ app = _DrawApp(filetypes=normalized, current_path=initial_dir, hidden=hidden, preview_img=preview_img, method='askopenfilename', autocomplete=autocomplete, video_preview=video_preview, tool_tip=tool_tip, geometry=geometry[0], title=title)
49
88
  app.app.wait_window()
50
89
  return app.selected_file if app.selected_file else None
51
90
  elif style == 'Mini':
52
- app = _MiniDialog(method='askopenfilename', filetypes=filetypes, initial_dir=initial_dir, autocomplete=autocomplete, hidden=hidden, geometry=geometry[1], title=title)
91
+ app = _MiniDialog(method='askopenfilename', filetypes=normalized, initial_dir=initial_dir, autocomplete=autocomplete, hidden=hidden, geometry=geometry[1], title=title)
53
92
 
54
93
  return app.selected_path
55
94
 
56
95
  @typechecked
57
96
  def askdirectory(style: Literal['Default', 'Mini'] = 'Default',
58
- filetypes: Optional[List[str]] = None,
97
+ filetypes: Optional[List[Union[str, Tuple[str, str]]]] = None,
59
98
  hidden: bool = False,
60
99
  autocomplete: bool = False,
61
100
  initial_dir: str = '.',
@@ -72,7 +111,8 @@ def askdirectory(style: Literal['Default', 'Mini'] = 'Default',
72
111
  Args:
73
112
 
74
113
  style: You define the dialog style. There are two styles: the default one and a small one. (Default, Mini)
75
- filetypes: Optional file type filters (affects display in some implementations)
114
+ filetypes: Optional file type filters (affects display in some implementations).
115
+ Tuple syntax described above is accepted.
76
116
  hidden: Enables showing hidden directories when True
77
117
  autocomplete: Enables path autocompletion feature
78
118
  initial_dir: Starting directory (defaults to current working directory)
@@ -88,22 +128,25 @@ def askdirectory(style: Literal['Default', 'Mini'] = 'Default',
88
128
  ... initial_dir="~/Documents",
89
129
  ... hidden=True
90
130
  ... )
131
+ >>> # filetypes are ignored for directories but may still be passed
132
+ >>> dir_path = askdirectory(filetypes=[("All","*.*")])
91
133
  >>> if dir_path:
92
134
  ... print(f"Chose directory: {dir_path}")
93
135
  """
136
+ normalized = _normalize_filetypes(filetypes)
94
137
  if style == 'Default':
95
138
 
96
- app = _DrawApp(filetypes=filetypes, current_path=initial_dir, hidden=hidden, method='askdirectory', autocomplete=autocomplete, tool_tip=tool_tip, geometry=geometry[0], title=title)
139
+ app = _DrawApp(filetypes=normalized, current_path=initial_dir, hidden=hidden, method='askdirectory', autocomplete=autocomplete, tool_tip=tool_tip, geometry=geometry[0], title=title)
97
140
  app.app.wait_window()
98
141
  return app.selected_file if app.selected_file else None
99
142
 
100
143
  elif style == 'Mini':
101
- app = _MiniDialog(filetypes=filetypes, initial_dir=initial_dir, hidden=hidden, method='askdirectory', autocomplete=autocomplete, title=title, geometry=geometry[1])
144
+ app = _MiniDialog(filetypes=normalized, initial_dir=initial_dir, hidden=hidden, method='askdirectory', autocomplete=autocomplete, title=title, geometry=geometry[1])
102
145
  return app.selected_path if app.selected_path else None
103
146
 
104
147
  @typechecked
105
148
  def askopenfilenames(style: Literal['Default', 'Mini'] = 'Default',
106
- filetypes: Optional[List[str]] = None,
149
+ filetypes: Optional[List[Union[str, Tuple[str, str]]]] = None,
107
150
  hidden: bool = False,
108
151
  preview_img: bool = False,
109
152
  autocomplete: bool = False,
@@ -122,7 +165,8 @@ def askopenfilenames(style: Literal['Default', 'Mini'] = 'Default',
122
165
  Args:
123
166
 
124
167
  style: You define the dialog style. There are two styles: the default one and a small one. (Default, Mini)
125
- filetypes: File type filters (e.g., [("Images", "*.jpg *.png")])
168
+ filetypes: File type filters (e.g., [("Images", "*.jpg *.png")]).
169
+ Tkinter-style tuple lists are accepted as well.
126
170
  hidden: Shows hidden files when enabled
127
171
  preview_img: Enables image preview functionality
128
172
  autocomplete: Activates path autocompletion
@@ -136,8 +180,9 @@ def askopenfilenames(style: Literal['Default', 'Mini'] = 'Default',
136
180
  tuple[str, ...]: Tuple of selected file paths, or None if canceled
137
181
 
138
182
  Example:
183
+ >>> # wildcard tuple example
139
184
  >>> selected_files = askopenfilenames(
140
- ... filetypes=['.py', '.md'],
185
+ ... filetypes=[("Text files", "*.txt"), ("All files", "*.*")],
141
186
  ... preview_img=True
142
187
  ... )
143
188
  >>> if selected_files:
@@ -145,18 +190,19 @@ def askopenfilenames(style: Literal['Default', 'Mini'] = 'Default',
145
190
  ... process_file(file)
146
191
  """
147
192
 
193
+ normalized = _normalize_filetypes(filetypes)
148
194
  if style == 'Default':
149
- app = _DrawApp(filetypes=filetypes, current_path=initial_dir, hidden=hidden, preview_img=preview_img, method='askopenfilenames', autocomplete=autocomplete, video_preview=video_preview, tool_tip=tool_tip, geometry=geometry[0], title=title)
195
+ app = _DrawApp(filetypes=normalized, current_path=initial_dir, hidden=hidden, preview_img=preview_img, method='askopenfilenames', autocomplete=autocomplete, video_preview=video_preview, tool_tip=tool_tip, geometry=geometry[0], title=title)
150
196
  app.app.wait_window()
151
197
  return tuple(app.selected_objects) if app.selected_objects else None
152
198
  elif style == 'Mini':
153
- app = _MiniDialog(filetypes=filetypes, initial_dir=initial_dir, hidden=hidden, method='askopenfilenames', autocomplete=autocomplete, geometry=geometry[1], title=title)
199
+ app = _MiniDialog(filetypes=normalized, initial_dir=initial_dir, hidden=hidden, method='askopenfilenames', autocomplete=autocomplete, geometry=geometry[1], title=title)
154
200
 
155
201
  return tuple(app.selected_paths) if app.selected_paths else None
156
202
 
157
203
  @typechecked
158
204
  def asksaveasfilename(style: Literal['Default', 'Mini'] = 'Default',
159
- filetypes: Optional[List[str]] = None,
205
+ filetypes: Optional[List[Union[str, Tuple[str, str]]]] = None,
160
206
  hidden: bool = False,
161
207
  preview_img: bool = False,
162
208
  autocomplete: bool = False,
@@ -175,7 +221,8 @@ def asksaveasfilename(style: Literal['Default', 'Mini'] = 'Default',
175
221
  Args:
176
222
 
177
223
  style: You define the dialog style. There are two styles: the default one and a small one. (Default, Mini)
178
- filetypes: Suggested file extensions (e.g., ['.pdf', '.jpg'])
224
+ filetypes: Suggested file extensions (e.g., ['.pdf', '.jpg']).
225
+ Tuple syntax like [("PDF","*.pdf")] is also allowed.
179
226
  hidden: Shows hidden items when enabled
180
227
  preview_img: Enables preview of existing images
181
228
  autocomplete: Activates path suggestion
@@ -189,29 +236,36 @@ def asksaveasfilename(style: Literal['Default', 'Mini'] = 'Default',
189
236
  str: Path where file should be saved, or None if canceled
190
237
 
191
238
  Example:
239
+ >>> # simple extension list
192
240
  >>> save_path = asksaveasfilename(
193
241
  ... filetypes=['.txt', '.md'],
194
242
  ... initial_dir="~/Documents"
195
243
  ... )
244
+ >>>
245
+ >>> # tuple-style filter with label
246
+ >>> save_path = asksaveasfilename(
247
+ ... filetypes=[("Text files","*.txt")]
248
+ ... )
196
249
  >>> if save_path:
197
250
  ... with open(save_path, 'w') as f:
198
251
  ... f.write("File content")
199
252
  """
253
+ normalized = _normalize_filetypes(filetypes)
200
254
  if style == 'Default':
201
255
 
202
- app = _DrawApp(filetypes=filetypes, current_path=initial_dir, hidden=hidden, preview_img=preview_img, method='asksaveasfilename', autocomplete=autocomplete, video_preview=video_preview, tool_tip=tool_tip, geometry=geometry[0], title=title)
256
+ app = _DrawApp(filetypes=normalized, current_path=initial_dir, hidden=hidden, preview_img=preview_img, method='asksaveasfilename', autocomplete=autocomplete, video_preview=video_preview, tool_tip=tool_tip, geometry=geometry[0], title=title)
203
257
  app.app.wait_window()
204
258
  return app.selected_file if app.selected_file else None
205
259
  elif style == 'Mini':
206
260
 
207
- app = _MiniDialog(filetypes=filetypes, initial_dir=initial_dir, hidden=hidden, method='asksaveasfilename', autocomplete=autocomplete, geometry=geometry[1], title=title)
261
+ app = _MiniDialog(filetypes=normalized, initial_dir=initial_dir, hidden=hidden, method='asksaveasfilename', autocomplete=autocomplete, geometry=geometry[1], title=title)
208
262
 
209
263
  return app.selected_path if app.selected_path else None
210
264
 
211
265
  @typechecked
212
266
  def asksaveasfile(style: Literal['Default', 'Mini'] = 'Default',
213
267
  mode: Literal['r', 'rb', 'r+', 'rb+', 'r+b','w', 'wb', 'w+', 'wb+','a', 'ab', 'a+', 'ab+','x', 'xb'] = 'w',
214
- filetypes: Optional[List[str]] = None,
268
+ filetypes: Optional[List[Union[str, Tuple[str, str]]]] = None,
215
269
  hidden: bool = False,
216
270
  preview_img: bool = False,
217
271
  autocomplete: bool = False,
@@ -252,20 +306,21 @@ def asksaveasfile(style: Literal['Default', 'Mini'] = 'Default',
252
306
  ... f.write("Log entry\\n")
253
307
  ... f.close()
254
308
  """
309
+ normalized = _normalize_filetypes(filetypes)
255
310
  if style == 'Default':
256
- app = _DrawApp(filetypes=filetypes, current_path=initial_dir, hidden=hidden, preview_img=preview_img, method='asksaveasfile', autocomplete=autocomplete, video_preview=video_preview, tool_tip=tool_tip, geometry=geometry[0], title=title)
311
+ app = _DrawApp(filetypes=normalized, current_path=initial_dir, hidden=hidden, preview_img=preview_img, method='asksaveasfile', autocomplete=autocomplete, video_preview=video_preview, tool_tip=tool_tip, geometry=geometry[0], title=title)
257
312
  app.app.wait_window()
258
313
 
259
314
  return open(app.selected_file, mode=mode, **kwargs) if app.selected_file else None
260
315
  elif style == 'Mini':
261
- app = _MiniDialog(filetypes=filetypes, initial_dir=initial_dir, hidden=hidden, method='asksaveasfile', geometry=geometry[1], title=title)
316
+ app = _MiniDialog(filetypes=normalized, initial_dir=initial_dir, hidden=hidden, method='asksaveasfile', geometry=geometry[1], title=title)
262
317
  return open(app.selected_path, mode=mode, **kwargs) if app.selected_path else None
263
318
 
264
319
  @typechecked
265
320
  def askopenfile(style: Literal['Mini', 'Default'] = 'Default',
266
321
  mode: Literal['r', 'rb', 'r+', 'rb+', 'r+b','w', 'wb', 'w+', 'wb+','a', 'ab', 'a+', 'ab+','x', 'xb'] = 'r',
267
322
  hidden: bool = False,
268
- filetypes: Optional[List[str]] = None,
323
+ filetypes: Optional[List[Union[str, Tuple[str, str]]]] = None,
269
324
  preview_img: bool = False,
270
325
  autocomplete: bool = False,
271
326
  video_preview: bool = False,
@@ -286,7 +341,7 @@ def askopenfile(style: Literal['Mini', 'Default'] = 'Default',
286
341
  style: You define the dialog style. There are two styles: the default one and a small one. (Default, Mini)
287
342
  mode: File opening mode (defaults to 'r' for read)
288
343
  hidden: Shows hidden files when enabled
289
- filetypes: File type filters
344
+ filetypes: File type filters (tuple syntax accepted, e.g. [("Text","*.txt")])
290
345
  preview_img: Enables image preview
291
346
  autocomplete: Activates path completion
292
347
  video_preview: Enables video preview
@@ -300,18 +355,19 @@ def askopenfile(style: Literal['Mini', 'Default'] = 'Default',
300
355
  TextIOWrapper: Open file object, or None if canceled
301
356
 
302
357
  Example:
303
- >>> f = askopenfile(mode='rb', filetypes=[".bin"])
358
+ >>> f = askopenfile(mode='rb', filetypes=[("Binary","*.bin")])
304
359
  >>> if f:
305
360
  ... data = f.read()
306
361
  ... f.close()
307
362
  """
363
+ normalized = _normalize_filetypes(filetypes)
308
364
  if style == 'Default':
309
- app = _DrawApp(filetypes=filetypes, current_path=initial_dir, hidden=hidden, preview_img=preview_img, method='askopenfile', autocomplete=autocomplete, video_preview=video_preview, tool_tip=tool_tip, geometry=geometry[0], title=title)
365
+ app = _DrawApp(filetypes=normalized, current_path=initial_dir, hidden=hidden, preview_img=preview_img, method='askopenfile', autocomplete=autocomplete, video_preview=video_preview, tool_tip=tool_tip, geometry=geometry[0], title=title)
310
366
  app.app.wait_window()
311
367
 
312
368
  return open(app.selected_file, mode=mode, **kwargs) if app.selected_file else None
313
369
  elif style == 'Mini':
314
- app = _MiniDialog(filetypes=filetypes, initial_dir=initial_dir, hidden=hidden, method='asksaveasfile', autocomplete=autocomplete, _extra_method='askopenfile', geometry=geometry[1], title=title)
370
+ app = _MiniDialog(filetypes=normalized, initial_dir=initial_dir, hidden=hidden, method='asksaveasfile', autocomplete=autocomplete, _extra_method='askopenfile', geometry=geometry[1], title=title)
315
371
 
316
372
  return open(app.selected_path, mode=mode, **kwargs) if app.selected_path else None
317
373
 
@@ -319,7 +375,7 @@ def askopenfile(style: Literal['Mini', 'Default'] = 'Default',
319
375
  def askopenfiles(style: Literal['Default', 'Mini'] = 'Default',
320
376
  mode: Literal['r', 'rb', 'r+', 'rb+', 'r+b','w', 'wb', 'w+', 'wb+','a', 'ab', 'a+', 'ab+','x', 'xb'] = 'r',
321
377
  hidden: bool = False,
322
- filetypes: Optional[List[str]] = None,
378
+ filetypes: Optional[List[Union[str, Tuple[str, str]]]] = None,
323
379
  preview_img: bool = False,
324
380
  autocomplete: bool = False,
325
381
  video_preview: bool = False,
@@ -340,7 +396,7 @@ def askopenfiles(style: Literal['Default', 'Mini'] = 'Default',
340
396
  style: You define the dialog style. There are two styles: the default one and a small one. (Default, Mini)
341
397
  mode: File opening mode for all files (default 'r')
342
398
  hidden: Shows hidden files when True
343
- filetypes: File extension filters
399
+ filetypes: File extension filters (tuple syntax accepted)
344
400
  preview_img: Enables image preview
345
401
  autocomplete: Activates path completion
346
402
  video_preview: Enables video preview
@@ -354,20 +410,21 @@ def askopenfiles(style: Literal['Default', 'Mini'] = 'Default',
354
410
  tuple[TextIOWrapper]: Tuple of open file objects, or None if canceled
355
411
 
356
412
  Example:
357
- >>> files = askopenfiles(mode='r', filetypes=[".txt"])
413
+ >>> files = askopenfiles(mode='r', filetypes=[("Text","*.txt")])
358
414
  >>> if files:
359
415
  ... for f in files:
360
416
  ... print(f.read())
361
417
  ... f.close()
362
418
  """
419
+ normalized = _normalize_filetypes(filetypes)
363
420
  if style == 'Default':
364
- app = _DrawApp(filetypes=filetypes, current_path=initial_dir, hidden=hidden, preview_img=preview_img, method='askopenfilenames', autocomplete=autocomplete, video_preview=video_preview, tool_tip=tool_tip, geometry=geometry[0], title=title)
421
+ app = _DrawApp(filetypes=normalized, current_path=initial_dir, hidden=hidden, preview_img=preview_img, method='askopenfilenames', autocomplete=autocomplete, video_preview=video_preview, tool_tip=tool_tip, geometry=geometry[0], title=title)
365
422
  app.app.wait_window()
366
423
 
367
424
  return tuple(open(f, mode=mode, **kwargs) for f in app.selected_objects) if app.selected_objects else None
368
425
 
369
426
  elif style == 'Mini':
370
427
 
371
- app = _MiniDialog(filetypes=filetypes, initial_dir=initial_dir, hidden=hidden, autocomplete=autocomplete, method='askopenfilenames', geometry=geometry[1], title=title)
428
+ app = _MiniDialog(filetypes=normalized, initial_dir=initial_dir, hidden=hidden, autocomplete=autocomplete, method='askopenfilenames', geometry=geometry[1], title=title)
372
429
 
373
430
  return tuple(open(f, mode=mode, **kwargs) for f in app.selected_paths) if app.selected_paths else None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: CTKFileDialog-plus
3
- Version: 0.5.2
3
+ Version: 0.5.3
4
4
  Summary: A modern file dialog for CustomTkinter
5
5
  Home-page: https://github.com/hmidani-abdelilah/CTkFileDialog-plus
6
6
  Author: abdelilah
@@ -15,7 +15,7 @@ Requires-Dist: typeguard
15
15
  Dynamic: home-page
16
16
  Dynamic: requires-python
17
17
 
18
- <h1 align="center">CTkFileDialog-plus</h1>
18
+ <h1 align="center">CTkFileDialog</h1>
19
19
 
20
20
  <h3 align="center">A modern and fully customizable File Dialog for CustomTkinter — a must-have extension pack!</h3>
21
21
 
@@ -27,6 +27,7 @@ Dynamic: requires-python
27
27
  ## 🚀 Features
28
28
 
29
29
  - 🔍 Autocomplete in the path entry field (with `Tab`, `Up`, and `Down`)
30
+ - 🧩 Flexible filetype filters: accepts simple extensions **or** tkinter-style `(label, pattern)` tuples (patterns may contain multiple space‑separated globs). Wildcards like `*`/`*.*` are treated as match‑all.
30
31
  - � Search/filter files in real-time
31
32
  - 🖼️ Live image preview
32
33
  - 🎥 Video thumbnail preview
@@ -59,10 +60,10 @@ python3 -m venv .venv
59
60
  .\.venv\Scripts\activate.ps1 # In Powershell
60
61
  pip3 install -r requirements.txt
61
62
 
62
- # Or using pip
63
+ # Or ussing pip
63
64
 
64
65
  python3 -m venv .venv
65
- source .venv/bin/activate # In Powershell -> .\.venv\Scripts\activate.ps1
66
+ source .venv/bin/activate # In powershell -> .\.venv\Scripts\activate.ps1
66
67
  pip3 install CTkFileDialog-plus
67
68
 
68
69
  ```
@@ -84,7 +85,18 @@ ctk.set_appearance_mode("Dark")
84
85
  ctk.set_default_color_theme("blue")
85
86
 
86
87
  def open_file():
87
- path = askopenfilename(preview_img=True, autocomplete=True)
88
+ # you can pass simple extensions...
89
+ # path = askopenfilename(preview_img=True, autocomplete=True)
90
+ # or tkinter‑style tuples with labels and multiple globs:
91
+ path = askopenfilename(
92
+ filetypes=[
93
+ ("Text files","*.txt"),
94
+ ("Python","*.py *.pyw"),
95
+ ("All","*.*"),
96
+ ],
97
+ preview_img=True,
98
+ autocomplete=True,
99
+ )
88
100
  if path:
89
101
  result_label.configure(text=f"Selected file:\n{path}")
90
102
 
@@ -103,7 +115,6 @@ app.mainloop()
103
115
 
104
116
  ### 🗂️ Open Multiple Files
105
117
 
106
-
107
118
  ```python
108
119
  import customtkinter as ctk
109
120
  from CTkFileDialog import askopenfilenames
@@ -112,7 +123,11 @@ ctk.set_appearance_mode("Dark")
112
123
  ctk.set_default_color_theme("blue")
113
124
 
114
125
  def open_files():
115
- paths = askopenfilenames(preview_img=True, autocomplete=True)
126
+ paths = askopenfilenames(
127
+ filetypes=[("Images","*.jpg *.png"), ("All","*.*")],
128
+ preview_img=True,
129
+ autocomplete=True,
130
+ )
116
131
  if paths:
117
132
  result_label.configure(text="Selected files:\n" + "\n".join(paths))
118
133
 
@@ -193,11 +208,11 @@ ctk.set_appearance_mode("Dark")
193
208
  ctk.set_default_color_theme("blue")
194
209
 
195
210
  def save_as_file():
196
- f = asksaveasfile(autocomplete=True)
197
- if f:
198
- f.write("This file was created using the demo.")
199
- f.close()
200
- result_label.configure(text=f"File saved:\n{f.name}")
211
+ file = asksaveasfile(autocomplete=True)
212
+ if file:
213
+ file.write("This file was created using the demo.")
214
+ file.close()
215
+ result_label.configure(text=f"File saved:\n{file.name}")
201
216
 
202
217
  app = ctk.CTk()
203
218
  app.title("asksaveasfile Demo")
@@ -209,6 +224,68 @@ result_label.pack()
209
224
 
210
225
  app.mainloop()
211
226
  ```
227
+
228
+ ---
229
+
230
+ ### 📂 Open File as Object
231
+
232
+ ```python
233
+ import customtkinter as ctk
234
+ from CTkFileDialog import askopenfile
235
+
236
+ ctk.set_appearance_mode("Dark")
237
+ ctk.set_default_color_theme("blue")
238
+
239
+ def open_file_obj():
240
+ f = askopenfile(mode='rb',
241
+ filetypes=[("Binary","*.bin"), ("All","*.*")])
242
+ if f:
243
+ data = f.read()
244
+ f.close()
245
+ result_label.configure(text=f"Read {len(data)} bytes from {f.name}")
246
+
247
+ app = ctk.CTk()
248
+ app.title("askopenfile Demo")
249
+ app.geometry("500x200")
250
+
251
+ ctk.CTkButton(app, text="Open File Object", command=open_file_obj).pack(pady=20)
252
+ result_label = ctk.CTkLabel(app, text="Waiting for file selection...")
253
+ result_label.pack()
254
+
255
+ app.mainloop()
256
+ ```
257
+
258
+ ---
259
+
260
+ ### 📂 Open Multiple Files as Objects
261
+
262
+ ```python
263
+ import customtkinter as ctk
264
+ from CTkFileDialog import askopenfiles
265
+
266
+ ctk.set_appearance_mode("Dark")
267
+ ctk.set_default_color_theme("blue")
268
+
269
+ def open_files_obj():
270
+ files = askopenfiles(mode='r', filetypes=[("Text","*.txt")])
271
+ if files:
272
+ for f in files:
273
+ content = f.read()
274
+ f.close()
275
+ print(f"{f.name}: {len(content)} chars")
276
+ result_label.configure(text=f"Opened {len(files)} files, see console output.")
277
+
278
+ app = ctk.CTk()
279
+ app.title("askopenfiles Demo")
280
+ app.geometry("500x200")
281
+
282
+ ctk.CTkButton(app, text="Open Files Objects", command=open_files_obj).pack(pady=20)
283
+ result_label = ctk.CTkLabel(app, text="Waiting for file selection...")
284
+ result_label.pack()
285
+
286
+ app.mainloop()
287
+ ```
288
+
212
289
  ---
213
290
 
214
291
  ## 🧩 Parameters
@@ -217,15 +294,16 @@ app.mainloop()
217
294
 
218
295
  | Parameter | Description |
219
296
  |----------------|-----------------------------------------------------------------------------|
297
+ | `filetypes` | Optional filter list: either `['.txt', '.md']` or `[('Text','*.txt'),('Py','*.py *.pyw'),('All','*.*')]`. Wildcards are normalized internally. |
220
298
  | `hidden` | Show hidden files or directories (`False` by default). |
221
299
  | `preview_img` | Enable image preview in the file dialog. |
222
300
  | `video_preview` | Show first frame of video files as thumbnail (experimental). |
223
301
  | `autocomplete` | Enable path autocompletion with `Tab`, `Up`, and `Down`. |
224
302
  | `initial_dir` | Set the initial directory when opening the dialog. |
225
- | `tool_tip` | Enable the tool tip. |
226
- | `style` | Defines the dialog style, by default it will be 'Default' but you can choose a small one ('Mini') |
227
- | `geometry` | You define the geometry string in a tuple: Example ('NormalGM', 'MiniGeometry') |
228
- | `title` | Define the title from the app, default will be "CTkFileDialog" |
303
+ | `tool_tip` | Enable the tool tip. |
304
+ | `style` | Defines the dialog style, by default it will be 'Default' but you can choose a small one ('Mini'). |
305
+ | `geometry` | You define the geometry string in a tuple: Example ('NormalGM', 'MiniGeometry'). |
306
+ | `title` | Define the title from the app, default will be "CTkFileDialog". |
229
307
 
230
308
 
231
309
  </div>
@@ -318,7 +396,7 @@ root.mainloop()
318
396
 
319
397
  ## Mini Dialog
320
398
 
321
- The mini dialog is a compact alternative to the Default dialog. It does not support `tooltip`, `preview_img`, or `video_preview`.
399
+ This is a parameter of the file dialog, but it's more powerful than the default one. As I mentioned earlier, it doesn't support parameters like tooltip, preview_img, or video_preview.
322
400
 
323
401
  ## 🌙 Dark Mode Preview
324
402
 
@@ -333,9 +411,3 @@ The mini dialog is a compact alternative to the Default dialog. It does not supp
333
411
  </p>
334
412
 
335
413
  The mini design created by [user](https://github.com/limafresh), and the default design created by [user](https://github.com/SelfDreamer) and all credit goes to them. I also want to thank them for creating that design in advance.
336
-
337
- ## I translate the code to English and add this futures:
338
-
339
- - � Search/filter files in real-time
340
- - 👀 Multiple view modes (Grid and List view in Default dialog)
341
- - 📊 Sort files by name, date, size, type, or last modified
@@ -1,6 +1,6 @@
1
- CTkFileDialog/Dialog.py,sha256=V-VIrIzXb_V7gsWe0QDrXjOq00PlYJKJQCIFUWQSWFE,55035
1
+ CTkFileDialog/Dialog.py,sha256=3R6DGsGs2_ZAiWS0EFfMjncK88D5mTTG-Opv8MVqIRk,52766
2
2
  CTkFileDialog/__init__.py,sha256=eBXc4lNCdBVrOkOkI8fyk7lOp3nIb52cuF_fSbbbV-w,706
3
- CTkFileDialog/_functions.py,sha256=YedUMvbICa9_cRDkwaY_X3BR1x6vlglvd9Bv4jCyuw8,18292
3
+ CTkFileDialog/_functions.py,sha256=-YQDtlQDn7iR6-3WuVJIrIEOYekl7nImts5a_9Fmtps,21234
4
4
  CTkFileDialog/_system.py,sha256=0-iM6JDBRs90hOAfd1xNY3X7YPXJjr0hJYRJqxuHAlM,1641
5
5
  CTkFileDialog/Constants/__init__.py,sha256=VoStLTGCiLknlpm3TJuc6p5oDZVJSCEzSa4WDAcn1J8,1357
6
6
  CTkFileDialog/Constants/constants.py,sha256=0dRJ2S0O6ExXIuw_p_dBxGtyVi18aaOMZf1nYkUIKTY,1235
@@ -23,7 +23,7 @@ CTkFileDialog/icons/php.png,sha256=zF9fsZSN8JmgyHaX-8DCw8Va-pCnmNbPIpqhlrhO7FA,7
23
23
  CTkFileDialog/icons/python.png,sha256=tk7T2E_PTGt4E70iEKQ1IlLbzbVS_j_KouieamMYRYY,37415
24
24
  CTkFileDialog/icons/text.png,sha256=93GUIQ_se7zCIIuFOzMtjv8Q2SqnANj0jnib7Cm_q4Q,894
25
25
  CTkFileDialog/icons/video.png,sha256=ZxenlMzuhcHAgBJJcq_DETrvo0tPygMsZnil-IvypeM,6096
26
- ctkfiledialog_plus-0.5.2.dist-info/METADATA,sha256=IQqlmpAYhty7_R4RdYvftUhSkiOS1-qZtSWhstdMpVQ,10388
27
- ctkfiledialog_plus-0.5.2.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
28
- ctkfiledialog_plus-0.5.2.dist-info/top_level.txt,sha256=ghUwgLRHcaJhcemQYVMRWwbJ8_sWqVyl4S8icnMBI1s,14
29
- ctkfiledialog_plus-0.5.2.dist-info/RECORD,,
26
+ ctkfiledialog_plus-0.5.3.dist-info/METADATA,sha256=oa-AqwwCoCHCL2Xgr-I6KYuJFtWblKtVeOD1IHkmsSo,12541
27
+ ctkfiledialog_plus-0.5.3.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
28
+ ctkfiledialog_plus-0.5.3.dist-info/top_level.txt,sha256=ghUwgLRHcaJhcemQYVMRWwbJ8_sWqVyl4S8icnMBI1s,14
29
+ ctkfiledialog_plus-0.5.3.dist-info/RECORD,,