CTKFileDialog-plus 2.2.0__py3-none-any.whl → 2.2.1__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.
@@ -122,11 +122,29 @@ class DrawApp:
122
122
 
123
123
  def close_app(self) -> None:
124
124
  if self.method in ("asksaveasfilename", "asksaveasfile"):
125
- if not os.path.isdir(self.PathEntry.get()):
126
- self.selected_file = self.PathEntry.get()
127
- self.protocol_windows()
128
- self.app.destroy()
125
+ filename = self.FileNameEntry.get().strip()
126
+ if not filename:
127
+ return
128
+ path = os.path.expanduser(os.path.expandvars(filename))
129
+ if not os.path.isabs(path):
130
+ path = os.path.join(self.current_path, path)
131
+ path = os.path.abspath(path)
132
+ if os.path.isdir(path):
129
133
  return
134
+ if os.path.exists(path):
135
+ msg = CTkMessagebox(
136
+ message="This file exists. Do you want to overwrite it?",
137
+ icon="warning",
138
+ title="Warning",
139
+ option_1="Yes",
140
+ option_2="No",
141
+ )
142
+ if msg.get() == "No":
143
+ return
144
+ self.selected_file = path
145
+ self.protocol_windows()
146
+ self.app.destroy()
147
+ return
130
148
 
131
149
  if self._temp_item:
132
150
  self.protocol_windows()
@@ -194,17 +212,10 @@ class DrawApp:
194
212
  return
195
213
 
196
214
  if self.method in ("asksaveasfile", "asksaveasfilename"):
197
- if os.path.isfile(path):
198
- msg = CTkMessagebox(
199
- message="This file exists. Do you want to overwrite it?",
200
- icon="warning",
201
- title="Warning",
202
- option_1="Yes",
203
- option_2="No",
204
- )
205
- if msg.get() == "No":
206
- return
207
- self._temp_item = path
215
+ self.current_path = os.path.dirname(path)
216
+ self.update_entry(path=self.current_path)
217
+ self.FileNameEntry.delete(0, ctk.END)
218
+ self.FileNameEntry.insert(0, os.path.basename(path))
208
219
  self.close_app()
209
220
  return
210
221
 
@@ -313,6 +324,18 @@ class DrawApp:
313
324
  )
314
325
  self.PathEntry.bind("<Alt-Left>", lambda e: self.btn_back(master=master))
315
326
 
327
+ if self.method in ("asksaveasfilename", "asksaveasfile"):
328
+ filename_frame = ctk.CTkFrame(master=master, fg_color="transparent")
329
+ filename_frame.pack(side="bottom", fill="x", padx=10, pady=10)
330
+ ctk.CTkLabel(filename_frame, text="File name:").pack(
331
+ side="left", padx=(0, 10)
332
+ )
333
+ self.FileNameEntry = ctk.CTkEntry(
334
+ master=filename_frame, placeholder_text="Enter file name..."
335
+ )
336
+ self.FileNameEntry.pack(side="left", fill="x", expand=True)
337
+ self.FileNameEntry.bind("<Return>", lambda _: self.close_app())
338
+
316
339
  ctk.CTkButton(
317
340
  master=top,
318
341
  text="",
@@ -143,6 +143,18 @@ class MiniDialog:
143
143
  side=ctk.RIGHT, padx=10
144
144
  )
145
145
 
146
+ if self.method in ("asksaveasfilename", "asksaveasfile"):
147
+ filename_frame = ctk.CTkFrame(self.frame)
148
+ filename_frame.pack(side=ctk.BOTTOM, fill=ctk.X, padx=10, pady=(0, 10))
149
+ ctk.CTkLabel(filename_frame, text="File name:").pack(
150
+ side=ctk.LEFT, padx=(0, 10)
151
+ )
152
+ self.filename_entry = ctk.CTkEntry(
153
+ filename_frame, placeholder_text="Enter file name..."
154
+ )
155
+ self.filename_entry.pack(expand=True, fill=ctk.X, side=ctk.LEFT)
156
+ self.filename_entry.bind("<Return>", lambda _: self._on_select())
157
+
146
158
  def _build_center(self) -> None:
147
159
  self.tree_frame = ctk.CTkFrame(self.frame)
148
160
  self.tree_frame.pack(fill=ctk.BOTH, expand=True, padx=10, pady=5)
@@ -326,7 +338,18 @@ class MiniDialog:
326
338
  self.master.destroy()
327
339
 
328
340
  def _on_select(self) -> None:
329
- path = self.path_entry.get().strip() if hasattr(self, "path_entry") else ""
341
+ if self.method in ("asksaveasfilename", "asksaveasfile"):
342
+ filename = self.filename_entry.get().strip()
343
+ if not filename:
344
+ return
345
+ directory = self.path_entry.get().strip()
346
+ if os.path.isfile(directory):
347
+ directory = os.path.dirname(directory)
348
+ path = os.path.expanduser(os.path.expandvars(filename))
349
+ if not os.path.isabs(path):
350
+ path = os.path.join(directory or self.initial_dir, path)
351
+ else:
352
+ path = self.path_entry.get().strip() if hasattr(self, "path_entry") else ""
330
353
  if path:
331
354
  path = os.path.abspath(os.path.expandvars(os.path.expanduser(path)))
332
355
  if not os.path.dirname(path):
@@ -437,6 +460,10 @@ class MiniDialog:
437
460
  self.path_entry.insert(0, self.selected_item)
438
461
  self.list_files()
439
462
  return
463
+ if self.method in ("asksaveasfilename", "asksaveasfile"):
464
+ self.filename_entry.delete(0, ctk.END)
465
+ self.filename_entry.insert(0, os.path.basename(self.selected_item))
466
+ return
440
467
  self.path_entry.delete(0, ctk.END)
441
468
  self.path_entry.insert(0, self.selected_item)
442
469
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: CTKFileDialog-plus
3
- Version: 2.2.0
3
+ Version: 2.2.1
4
4
  Summary: A modern file dialog for CustomTkinter
5
5
  Home-page: https://github.com/hmidani-abdelilah/CTkFileDialog-plus
6
6
  Author: abdelilah
@@ -354,6 +354,9 @@ def save_as_filename():
354
354
  # You can also auto-append an extension if the user doesn't type one:
355
355
  # path = asksaveasfilename(autocomplete=True, defaultext=".txt")
356
356
 
357
+ # Save dialogs provide separate fields for the destination folder and file name
358
+ # in both Default and Mini styles.
359
+
357
360
  app = ctk.CTk()
358
361
  app.title("asksaveasfilename Demo")
359
362
  app.geometry("500x200")
@@ -36,13 +36,13 @@ CTkFileDialog/resources/icons.py,sha256=QdEf9X_ymJD3-JlIg4GQr-TMzpbY9E8nvOzUWkix
36
36
  CTkFileDialog/system/__init__.py,sha256=g5a0tNbBNLSyn7oiAZxq15b1CRxWTVvlH1uF_HzlNzU,110
37
37
  CTkFileDialog/system/platform.py,sha256=PZgz_IERcgZwi9Q9Wq-FzyrRAzEN2OFWnGKo98PiPV8,2143
38
38
  CTkFileDialog/ui/__init__.py,sha256=cBIQwkhviy7EbySbpmbLwIREtooswo52CyESugQPtNg,201
39
- CTkFileDialog/ui/default_dialog.py,sha256=Mz6sHpVdeKcQ01HBhskDWnTSpHlKqIWrda78bhXpayk,35890
40
- CTkFileDialog/ui/mini_dialog.py,sha256=WIa1Nx-ZeDWejK2coMG9TNVpmdmrSGAIsENZz9p8wW4,16041
39
+ CTkFileDialog/ui/default_dialog.py,sha256=x0ii_-b9EHJyq6NhnQdRpEV16jJpf2o4i7q6uniqJts,36970
40
+ CTkFileDialog/ui/mini_dialog.py,sha256=h-oZnbU12LZ_wE-iBjTESx4SYL3aC7SiZV9sCjrOM0w,17398
41
41
  CTkFileDialog/ui/tooltip.py,sha256=jYJdexJ8BuHjReXdlIQrF3aDeuOpU6JlzIENTSq7MYI,657
42
42
  CTkFileDialog/utils/__init__.py,sha256=Rqmpg3kxA1Kd6yGZstg-HxUHxFwRfH_TDZnqBHExQc8,206
43
43
  CTkFileDialog/utils/helpers.py,sha256=0fULuzBsMVBRGko2rAYz8xP1iph_KB57SY9Xi-sxBiE,1939
44
- ctkfiledialog_plus-2.2.0.dist-info/licenses/LICENSE,sha256=-yP77ZlJiG2GIaFVx8f6KkUncC84D8RcW0lZEalE7og,1074
45
- ctkfiledialog_plus-2.2.0.dist-info/METADATA,sha256=d--ms3wLwdFysUXtT7vxeWRZE_oO4nPsji5qaIqDHnk,19519
46
- ctkfiledialog_plus-2.2.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
47
- ctkfiledialog_plus-2.2.0.dist-info/top_level.txt,sha256=ghUwgLRHcaJhcemQYVMRWwbJ8_sWqVyl4S8icnMBI1s,14
48
- ctkfiledialog_plus-2.2.0.dist-info/RECORD,,
44
+ ctkfiledialog_plus-2.2.1.dist-info/licenses/LICENSE,sha256=-yP77ZlJiG2GIaFVx8f6KkUncC84D8RcW0lZEalE7og,1074
45
+ ctkfiledialog_plus-2.2.1.dist-info/METADATA,sha256=BA6M1VF4uqj6Nvo8_jB9MQGIqjORpNTLeW7SRMZIqcw,19635
46
+ ctkfiledialog_plus-2.2.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
47
+ ctkfiledialog_plus-2.2.1.dist-info/top_level.txt,sha256=ghUwgLRHcaJhcemQYVMRWwbJ8_sWqVyl4S8icnMBI1s,14
48
+ ctkfiledialog_plus-2.2.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (84.0.0)
2
+ Generator: setuptools (84.2.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5