Skip to content

Commit 807fe5f

Browse files
authored
2.11.3
Fix assorted bugs and add filedialog cancel
1 parent 53a88cc commit 807fe5f

File tree

7 files changed

+93
-77
lines changed

7 files changed

+93
-77
lines changed

README.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,25 @@ to provide the basic curses functionality
1313

1414
## What's New?
1515

16-
## Version 2.11
17-
18-
-Add checkboxlist
16+
## Patch 2.11.3
1917

20-
-Choose one or more options from the list
18+
- Fix bug in filedialog in empty directory
2119

22-
-Add banned characters in cursesinput
20+
- Add optional flag: allowcancel
2321

24-
-Fix blinking in textview
22+
- This controls if you are allowed to cancel
2523

26-
## Version 2.10
24+
- Cancel by pressing C (or SHIFT C in openfilesdialog)
2725

28-
-Add more advanced option menu under coloured_option_menu()
29-
30-
-Set custom colouring
26+
## Version 2.11
3127

32-
-Fix bugs in Windows filedialogue
28+
- Add checkboxlist
3329

34-
## Version 2.9
30+
- Choose one or more options from the list
3531

36-
-Move curses transitions to transitions module
32+
- Add banned characters in cursesinput
3733

38-
-Remains backwards-compatible
34+
- Fix blinking in textview
3935

4036
## Documentation
4137

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.0"]
33
build-backend = "setuptools.build_meta"
44
[project]
55
name = "cursesplus"
6-
version = "2.11.2"
6+
version = "2.11.3"
77
authors = [{name="Enderbyte Programs",email="[email protected]"},]
88
description = "An extension program to curses that offers option menus, message boxes, file dialogs and more"
99
readme = "README.md"

src/__cptest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
e = ""
55
def __test__(stdscr):
66
global e
7-
cursesplus.textview(stdscr,file="src/cursesplus/cp.py",message="LICENSE",isagreement=True,requireyes=True)
8-
#e = filedialog.openfiledialog(stdscr)
7+
#cursesplus.textview(stdscr,file="src/cursesplus/cp.py",message="LICENSE",isagreement=True,requireyes=True)
8+
e = cursesplus.filedialog.openfiledialog(stdscr,allowcancel=False)
99
#e = cursesplus.checkboxlist(stdscr,{"Create Desktop Shortcut":False,"Create Start Menu Shortcut":True,"Register MIME type":True},"Choose optional features for installation",2,3)
1010
#cursesplus.textview(stdscr,file="/home/jordan/Coding/cursesplus/src/cursesplus/cp.py")
11-
cursesplus.cursesinput(stdscr,"Hello",bannedcharacters="")
11+
#cursesplus.cursesinput(stdscr,"Hello",bannedcharacters="")
1212
if __name__ == "__main__":
1313
#Testing things
1414
curses.wrapper(__test__)

src/cursesplus.egg-info/PKG-INFO

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: cursesplus
3-
Version: 2.11.2
3+
Version: 2.11.3
44
Summary: An extension program to curses that offers option menus, message boxes, file dialogs and more
55
Author-email: Enderbyte Programs <[email protected]>
66
Project-URL: Homepage, https://github.com/Enderbyte-Programs/Curses-Plus
@@ -27,29 +27,25 @@ to provide the basic curses functionality
2727

2828
## What's New?
2929

30-
## Version 2.11
31-
32-
-Add checkboxlist
30+
## Patch 2.11.3
3331

34-
-Choose one or more options from the list
32+
- Fix bug in filedialog in empty directory
3533

36-
-Add banned characters in cursesinput
34+
- Add optional flag: allowcancel
3735

38-
-Fix blinking in textview
36+
- This controls if you are allowed to cancel
3937

40-
## Version 2.10
38+
- Cancel by pressing C (or SHIFT C in openfilesdialog)
4139

42-
-Add more advanced option menu under coloured_option_menu()
43-
44-
-Set custom colouring
40+
## Version 2.11
4541

46-
-Fix bugs in Windows filedialogue
42+
- Add checkboxlist
4743

48-
## Version 2.9
44+
- Choose one or more options from the list
4945

50-
-Move curses transitions to transitions module
46+
- Add banned characters in cursesinput
5147

52-
-Remains backwards-compatible
48+
- Fix blinking in textview
5349

5450
## Documentation
5551

src/cursesplus/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
"""
2121

22-
__version__ = "2.11.2"
22+
__version__ = "2.11.3"
2323
__author__ = "Enderbyte Programs"
2424
__package__ = "cursesplus"
2525

805 Bytes
Binary file not shown.

src/cursesplus/filedialog.py

Lines changed: 67 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def __init__(self,path: str) -> None:
5858
self.sizestr = parse_size(self.size)
5959
self.strippedpath = path.replace("\\","/").split("/")[-1]
6060

61-
def openfiledialog(stdscr,title: str = "Please choose a file",filter: str = [["*","All Files"]],directory: str = os.getcwd()) -> str:
61+
def openfiledialog(stdscr,title: str = "Please choose a file",filter: str = [["*","All Files"]],directory: str = os.getcwd(),allowcancel=True) -> str:
6262
"""Start a filedialog to open a file. title is the prompt the use recieves. filter is the file filter. The filter syntax is the same as TK syntax. The first
6363
filter provided is the main filter.
6464
Filter Syntax:
@@ -168,19 +168,22 @@ def openfiledialog(stdscr,title: str = "Please choose a file",filter: str = [["*
168168
yoffset = 0
169169
refresh = True
170170
elif ch == cp.curses.KEY_ENTER or ch == 10 or ch == 13:
171-
if masterlist[selected].isdir:
172-
try:
173-
os.listdir(masterlist[selected].path)
174-
except:
175-
messagebox.showerror(stdscr,["Directory Access Forbidden"])
176-
else:
177-
directory = masterlist[selected].path
178-
selected = 0
179-
refresh = True
180-
yoffset = 0
181-
directory = directory.replace("\\","/").replace("//","/")
171+
if len(masterlist) == 0:
172+
messagebox.showwarning(stdscr,["This directory is empty"])
182173
else:
183-
return masterlist[selected].path.replace("\\","/")
174+
if masterlist[selected].isdir:
175+
try:
176+
os.listdir(masterlist[selected].path)
177+
except:
178+
messagebox.showerror(stdscr,["Directory Access Forbidden"])
179+
else:
180+
directory = masterlist[selected].path
181+
selected = 0
182+
refresh = True
183+
yoffset = 0
184+
directory = directory.replace("\\","/").replace("//","/")
185+
else:
186+
return masterlist[selected].path.replace("\\","/")
184187
elif ch == cp.curses.KEY_SLEFT or ch == 98:
185188
directory = "/".join(directory.split("/")[0:-1])
186189
selected = 0
@@ -191,6 +194,11 @@ def openfiledialog(stdscr,title: str = "Please choose a file",filter: str = [["*
191194
directory = directory.replace("\\","/").replace("//","/")
192195
elif ch == 114:
193196
refresh = True#Refresh files list
197+
elif ch == 99 or cp.curses.keyname(ch) == b"^C":
198+
if allowcancel:
199+
return None
200+
else:
201+
messagebox.showwarning(stdscr,["Cancel is not allowed."])
194202
elif ch == 108:
195203
npath = cp.cursesinput(stdscr,"Please enter new path").replace("\n","")
196204
if os.path.isdir(npath):
@@ -201,7 +209,7 @@ def openfiledialog(stdscr,title: str = "Please choose a file",filter: str = [["*
201209
else:
202210
messagebox.showwarning(stdscr,["Path does not exist"])
203211
elif ch == 104:
204-
cp.displaymsg(stdscr,["List of Keybinds","Down Arrow: Scroll down","Up Arrow: Scroll up","Left Arrow: Scroll left","Right Arrow: Scroll right","Shift-left arrow: Move up to parent Directory","Enter: Open/select","F: Change filter","L: Change location","Shift-D: Choose drive (WINDOWS ONLY)"])
212+
cp.displaymsg(stdscr,["List of Keybinds","Down Arrow: Scroll down","Up Arrow: Scroll up","Left Arrow: Scroll left","Right Arrow: Scroll right","Shift-left arrow: Move up to parent Directory","Enter: Open/select","F: Change filter","L: Change location","Shift-D: Choose drive (WINDOWS ONLY)","Ctrl-C / C: Cancel"])
205213
elif ch == 68 and WINDOWS:
206214
#Drive letter select
207215
drives = __get_drives()
@@ -213,7 +221,7 @@ def openfiledialog(stdscr,title: str = "Please choose a file",filter: str = [["*
213221
yoffset = 0
214222
#masterlist.clear()
215223

216-
def openfolderdialog(stdscr,title: str = "Please choose a folder",directory: str = os.getcwd()) -> str:
224+
def openfolderdialog(stdscr,title: str = "Please choose a folder",directory: str = os.getcwd(),allowcancel=True) -> str:
217225
"""Start a filedialog to open a file. title is the prompt the use recieves. filter is the file filter. The filter syntax is the same as TK syntax. The first
218226
filter provided is the main filter.
219227
Filter Syntax:
@@ -304,19 +312,22 @@ def openfolderdialog(stdscr,title: str = "Please choose a folder",directory: str
304312
yoffset += 1
305313
selected += 1
306314
elif ch == cp.curses.KEY_ENTER or ch == 10 or ch == 13:
307-
if masterlist[selected].isdir:
308-
try:
309-
os.listdir(masterlist[selected].path)
310-
except:
311-
messagebox.showerror(stdscr,["Directory Access Forbidden"])
312-
else:
313-
directory = masterlist[selected].path
314-
selected = 0
315-
refresh = True
316-
yoffset = 0
317-
directory = directory.replace("//","/")
315+
if len(masterlist) == 0:
316+
messagebox.showwarning(stdscr,["This directory is empty"])
318317
else:
319-
return masterlist[selected].path.replace("\\","/")
318+
if masterlist[selected].isdir:
319+
try:
320+
os.listdir(masterlist[selected].path)
321+
except:
322+
messagebox.showerror(stdscr,["Directory Access Forbidden"])
323+
else:
324+
directory = masterlist[selected].path
325+
selected = 0
326+
refresh = True
327+
yoffset = 0
328+
directory = directory.replace("//","/")
329+
else:
330+
return masterlist[selected].path.replace("\\","/")
320331
elif ch == 115:
321332
return masterlist[selected].path.replace("\\","/")
322333
elif ch == cp.curses.KEY_SLEFT or ch == 98:
@@ -330,6 +341,11 @@ def openfolderdialog(stdscr,title: str = "Please choose a folder",directory: str
330341
directory = directory.replace("//","/")
331342
elif ch == 114:
332343
refresh = True#Refresh files list
344+
elif ch == 99:
345+
if allowcancel:
346+
return None
347+
else:
348+
messagebox.showwarning(stdscr,["Cancel is not allowed."])
333349
elif ch == 108:
334350
npath = cp.cursesinput(stdscr,"Please enter new path").replace("\n","")
335351
if os.path.isdir(npath):
@@ -340,7 +356,7 @@ def openfolderdialog(stdscr,title: str = "Please choose a folder",directory: str
340356
else:
341357
messagebox.showwarning(stdscr,["Path does not exist"])
342358
elif ch == 104:
343-
cp.displaymsg(stdscr,["List of Keybinds","Down Arrow: Scroll down","Up Arrow: Scroll up","Left Arrow: Scroll left","Right Arrow: Scroll right","Shift-left arrow: Move up to parent Directory","Enter: Open","S: Choose folder","L: Change location"])
359+
cp.displaymsg(stdscr,["List of Keybinds","Down Arrow: Scroll down","Up Arrow: Scroll up","Left Arrow: Scroll left","Right Arrow: Scroll right","Shift-left arrow: Move up to parent Directory","Enter: Open","S: Choose folder","L: Change location","Shift-D: Choose drive (WINDOWS ONLY)","C: Cancel"])
344360
elif ch == 68 and WINDOWS:
345361
#Drive letter select
346362
drives = __get_drives()
@@ -352,7 +368,7 @@ def openfolderdialog(stdscr,title: str = "Please choose a folder",directory: str
352368
yoffset = 0
353369
#masterlist.clear()
354370

355-
def openfilesdialog(stdscr,title: str = "Please choose a file",filter: str = [["*","All Files"]],directory: str = os.getcwd()) -> list:
371+
def openfilesdialog(stdscr,title: str = "Please choose a file",filter: str = [["*","All Files"]],directory: str = os.getcwd(),allowcancel=True) -> list:
356372
"""Start a filedialog to select multiple files. title is the prompt the user recieves. filter is the file filter. The filter syntax is the same as TK syntax. The first
357373
filter provided is the main filter.
358374
Filter Syntax:
@@ -459,20 +475,23 @@ def openfilesdialog(stdscr,title: str = "Please choose a file",filter: str = [["
459475
yoffset = 0
460476
update = True
461477
elif ch == cp.curses.KEY_ENTER or ch == 10 or ch == 13:
462-
if masterlist[selected].isdir:
463-
try:
464-
os.listdir(masterlist[selected].path)
465-
except:
466-
messagebox.showerror(stdscr,["Directory Access Forbidden"])
467-
else:
468-
directory = masterlist[selected].path
469-
selected = 0
470-
update = True
471-
yoffset = 0
472-
directory = directory.replace("//","/")
478+
if len(masterlist) == 0:
479+
messagebox.showwarning(stdscr,["This directory is empty"])
473480
else:
474-
chosen.clear()
475-
chosen.append(masterlist[selected].path)
481+
if masterlist[selected].isdir:
482+
try:
483+
os.listdir(masterlist[selected].path)
484+
except:
485+
messagebox.showerror(stdscr,["Directory Access Forbidden"])
486+
else:
487+
directory = masterlist[selected].path
488+
selected = 0
489+
update = True
490+
yoffset = 0
491+
directory = directory.replace("//","/")
492+
else:
493+
chosen.clear()
494+
chosen.append(masterlist[selected].path)
476495
elif ch == 115:
477496
#s for add to selection
478497
if not masterlist[selected].isdir:
@@ -490,6 +509,11 @@ def openfilesdialog(stdscr,title: str = "Please choose a file",filter: str = [["
490509
directory = directory.replace("//","/")
491510
elif ch == 114:
492511
update = True#Refresh files list
512+
elif ch == 67:
513+
if allowcancel:
514+
return None
515+
else:
516+
messagebox.showwarning(stdscr,["Cancel is not allowed."])
493517
elif ch == 100 or cp.curses.keyname(ch).decode() == "^X":
494518
return [c.replace("\\","/") for c in chosen if os.path.isfile(c) and c.replace(" ","") != ""]#Only return files that still exist
495519
elif ch == 99:
@@ -504,7 +528,7 @@ def openfilesdialog(stdscr,title: str = "Please choose a file",filter: str = [["
504528
else:
505529
messagebox.showwarning(stdscr,["Path does not exist"])
506530
elif ch == 104:
507-
cp.displaymsg(stdscr,["List of Keybinds","Down Arrow: Scroll down","Up Arrow: Scroll up","Left Arrow: Scroll left","Right Arrow: Scroll right","Shift-left arrow: Move up to parent Directory","Enter: Open/select","F: Change filter","S: Append / Remove from selection","D/Ctrl-X: Done","C: Clear selection","R: Refresh files list","L: Change location"])
531+
cp.displaymsg(stdscr,["List of Keybinds","Down Arrow: Scroll down","Up Arrow: Scroll up","Left Arrow: Scroll left","Right Arrow: Scroll right","Shift-left arrow: Move up to parent Directory","Enter: Open/select","F: Change filter","S: Append / Remove from selection","D/Ctrl-X: Done","C: Clear selection","R: Refresh files list","L: Change location","Shift-C: Cancel","Shift-D: Choose drive (WINDOWS)"])
508532
elif ch == 68 and WINDOWS:
509533
#Drive letter select
510534
drives = __get_drives()

0 commit comments

Comments
 (0)