Skip to content

Commit 6da0499

Browse files
authored
3.1
Do some more moving
1 parent fa421fd commit 6da0499

File tree

10 files changed

+118
-66
lines changed

10 files changed

+118
-66
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ cursesplus is getting a widgets based system. The old utilities have been moved
2727

2828
- cursesplus.cp is now imported under cursesplus.classic
2929

30+
- There is now a default ctrl_C detector.
31+
3032
# Documentation
3133

3234
## Two Ways to Use

src/__cptest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44

55
if __name__ == "__main__":
66
win = cursesplus.show_ui()
7-
8-
cursesplus.classic.optionmenu(win.screen,["hello","goodbyte"])
7+
cursesplus.classic.displayops(win.screen,["Hlel","Goodbye"])
98
cursesplus.shutdown_ui()

src/cursesplus.egg-info/PKG-INFO

Lines changed: 45 additions & 16 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.4
3+
Version: 3.1
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,33 +27,62 @@ to provide the basic curses functionality
2727

2828
## What's New?
2929

30-
## Patch 2.11.4
30+
### THE SWITCH TO 3.0
3131

32-
- transitions.random_blocks speed now actually does something
32+
cursesplus is getting a widgets based system. The old utilities have been moved to a classic class. filedialogues and message boxes remain. The program will likely be hard to use until everything is finalized.
3333

34-
- Write some docs
34+
**DANGER: THIS IS A TRULY BACKWARDS INCOMPATIBLE UPDATE. LOTS OF CODE WILL NEED TO BE REFACTORED!**
3535

36-
## Patch 2.11.3
36+
- Add TUI base module
3737

38-
- Fix bug in filedialog in empty directory
38+
- Add widgets module
3939

40-
- Add optional flag: allowcancel
40+
- Move colours to constants module
4141

42-
- This controls if you are allowed to cancel
42+
- cursesplus.cp is now imported under cursesplus.classic
4343

44-
- Cancel by pressing C (or SHIFT C in openfilesdialog)
44+
- There is now a default ctrl_C detector.
4545

46-
## Version 2.11
46+
# Documentation
4747

48-
- Add checkboxlist
48+
## Two Ways to Use
4949

50-
- Choose one or more options from the list
50+
### 1. New Way
5151

52-
- Add banned characters in cursesinput
53-
.
54-
- Fix blinking in textview
52+
The new way is currently under construction, so expect some bugs. The New Way does not need any fooling around with bare curses. The new way is an abstration of curses, almost a "replacement" if you will. To start, do something like this. Only one function is required:
5553

56-
# Documentation
54+
```
55+
import cursesplus
56+
57+
win = cursesplus.show_ui()
58+
59+
#See below for how to use classic utilities in a 3.x environment
60+
```
61+
62+
### 2. The Old Way
63+
64+
If you have been using cursesplus since before 3.0, you know what to do. You need to manually call initscr or wrapper and pass the stdscr to each function individually. For example
65+
```
66+
import cursesplus
67+
import curses
68+
69+
def main(stdscr):
70+
cursesplus.classic.displaymsg(stdscr,["This is a message"])
71+
72+
curses.wrapper(main)
73+
```
74+
75+
### 1A. Using classic utilities in a new set-up
76+
77+
To use Old-Style utility functions in a new way, see this code. This does the same as the example in part 2
78+
```
79+
import cursesplus
80+
81+
win = cursesplus.show_ui()
82+
cursesplus.classic.displaymsg(win.screen,["This is a message"])
83+
84+
cursesplus.shutdown_ui() #Good practice to close down after
85+
```
5786

5887
## transitions.py
5988

src/cursesplus.egg-info/SOURCES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ LICENSE
22
README.md
33
pyproject.toml
44
src/cursesplus/__init__.py
5+
src/cursesplus/constants.py
56
src/cursesplus/cp.py
67
src/cursesplus/filedialog.py
78
src/cursesplus/messagebox.py
89
src/cursesplus/transitions.py
10+
src/cursesplus/tuibase.py
11+
src/cursesplus/utils.py
12+
src/cursesplus/widgets.py
913
src/cursesplus.egg-info/PKG-INFO
1014
src/cursesplus.egg-info/SOURCES.txt
1115
src/cursesplus.egg-info/dependency_links.txt

src/cursesplus/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
NOTICE! CP UTILITIES ARE COMPLETELY INCOMPATIBLE WITH TUIBASE. TO USE THEM, CALL your BaseWindows.screen for the stdscr argument.
2424
"""
2525

26-
__version__ = "3.0-b1"
26+
__version__ = "3.1"
2727
__author__ = "Enderbyte Programs"
2828
__package__ = "cursesplus"
2929

src/cursesplus/cp.py

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import textwrap
88
import threading
99
from .constants import *
10+
from .utils import *
1011

1112
_C_INIT = False
1213

@@ -66,20 +67,7 @@ def displaymsgnodelay(stdscr,message: list):
6667
mi += 1
6768
stdscr.addstr(int(y//2+mi),int(x//2-len(msgl)//2),msgl)
6869
stdscr.refresh()
69-
def __retr_nbl_lst(input:list)->list:
70-
return [l for l in input if str(l) != ""]
71-
def __calc_nbl_list(input:list)->int:
72-
x = 0
73-
for ls in input:
74-
x += len(ls)
75-
return x
7670

77-
def str_contains_word(s:str,string:str) -> bool:
78-
d = s.lower().split(" ")
79-
return string in d
80-
81-
def list_get_maxlen(l:list) -> int:
82-
return max([len(s) for s in l])
8371

8472
def coloured_option_menu(stdscr,options:list[str],title="Please choose an option from the list below",colouring=[["back",RED]]) -> int:
8573
"""An alternate optionmenu that has colours"""
@@ -215,7 +203,7 @@ def cursesinput(stdscr,prompt: str,lines=1,maxlen=0,passwordchar:str=None,retrem
215203

216204
curses.beep()
217205
elif ch == curses.KEY_RIGHT:
218-
if col < len(__retr_nbl_lst(text[ln])):
206+
if col < len(retr_nbl_lst(text[ln])):
219207
col += 1
220208
if col-xoffset > mx-2:
221209
xoffset += 1
@@ -260,7 +248,7 @@ def cursesinput(stdscr,prompt: str,lines=1,maxlen=0,passwordchar:str=None,retrem
260248
stdscr.erase()
261249
else:
262250
#append
263-
if __calc_nbl_list(text) == maxlen and maxlen != 0:
251+
if calc_nbl_list(text) == maxlen and maxlen != 0:
264252
curses.beep()
265253
ERROR = f" You have reached the character limit ({maxlen}) "
266254
else:
@@ -384,34 +372,6 @@ def askyesno_old(stdscr,title: str) -> bool:
384372
return True
385373
else:
386374
return False
387-
_AVAILABLE_COL = list(range(1,255,1))
388-
_COL_INDEX = {}
389-
def set_colour(background: int, foreground: int) -> int:
390-
global _C_INIT
391-
global _COL_INDEX
392-
global _AVAILABLE_COL
393-
"""Set a colour object. Use the constants provided. z
394-
For attributes use | [ATTR] for example set_colour(RED,GREEN) | sdf
395-
"""
396-
if not _C_INIT:
397-
curses.start_color()
398-
curses.use_default_colors()
399-
_C_INIT = True
400-
401-
if str(foreground) in _COL_INDEX.keys() and str(background) in _COL_INDEX[str(foreground)].keys():
402-
return curses.color_pair(_COL_INDEX[str(foreground)][str(background)])
403-
if len(_AVAILABLE_COL) == 0:
404-
raise Warning("Out of colours!")
405-
_AVAILABLE_COL = list(range(1,255,1))#Replenish list
406-
i = _AVAILABLE_COL.pop(0)
407-
curses.init_pair(i,foreground,background)
408-
if not str(foreground) in _COL_INDEX.keys():
409-
_COL_INDEX[str(foreground)] = {}
410-
_COL_INDEX[str(foreground)][str(background)] = i
411-
return curses.color_pair(i)
412-
413-
def set_color(background: int,foreground: int) -> int:
414-
return set_colour(background,foreground)
415375

416376
def displayerror(stdscr,e,msg: str):
417377
"""

src/cursesplus/filedialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def openfiledialog(stdscr,title: str = "Please choose a file",filter: str = [["*
194194
directory = directory.replace("\\","/").replace("//","/")
195195
elif ch == 114:
196196
refresh = True#Refresh files list
197-
elif ch == 99 or cp.curses.keyname(ch) == b"^C":
197+
elif ch == 99:
198198
if allowcancel:
199199
return None
200200
else:

src/cursesplus/tuibase.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import curses
22
import os
3-
from .constants import *
4-
__SCREEN = None
3+
from . import messagebox
4+
import signal
5+
import sys
6+
57
class AlreadyInitializedError(Exception):
68
def __init__(self,message):
79
self.message = message
@@ -47,4 +49,14 @@ def shutdown_ui():
4749
curses.nocbreak()
4850
stdscr.keypad(False)
4951
curses.echo()
50-
curses.endwin()
52+
curses.reset_shell_mode()
53+
curses.endwin()
54+
sys.exit()
55+
56+
def __base_signal_handler(signal,frame):
57+
if messagebox.askyesno(stdscr,["Are you sure you wish to exit?"]):
58+
stdscr.erase()
59+
shutdown_ui()
60+
#sys.exit()
61+
62+
signal.signal(signal.SIGINT,__base_signal_handler)#Register base shutdown

src/cursesplus/utils.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import curses
2+
_C_INIT = False
3+
def retr_nbl_lst(input:list)->list:
4+
return [l for l in input if str(l) != ""]
5+
def calc_nbl_list(input:list)->int:
6+
x = 0
7+
for ls in input:
8+
x += len(ls)
9+
return x
10+
11+
def str_contains_word(s:str,string:str) -> bool:
12+
d = s.lower().split(" ")
13+
return string in d
14+
15+
def list_get_maxlen(l:list) -> int:
16+
return max([len(s) for s in l])
17+
18+
_AVAILABLE_COL = list(range(1,255,1))
19+
_COL_INDEX = {}
20+
def set_colour(background: int, foreground: int) -> int:
21+
global _C_INIT
22+
global _COL_INDEX
23+
global _AVAILABLE_COL
24+
"""Set a colour object. Use the constants provided. z
25+
For attributes use | [ATTR] for example set_colour(RED,GREEN) | sdf
26+
"""
27+
if not _C_INIT:
28+
curses.start_color()
29+
curses.use_default_colors()
30+
_C_INIT = True
31+
32+
if str(foreground) in _COL_INDEX.keys() and str(background) in _COL_INDEX[str(foreground)].keys():
33+
return curses.color_pair(_COL_INDEX[str(foreground)][str(background)])
34+
if len(_AVAILABLE_COL) == 0:
35+
raise Warning("Out of colours!")
36+
_AVAILABLE_COL = list(range(1,255,1))#Replenish list
37+
i = _AVAILABLE_COL.pop(0)
38+
curses.init_pair(i,foreground,background)
39+
if not str(foreground) in _COL_INDEX.keys():
40+
_COL_INDEX[str(foreground)] = {}
41+
_COL_INDEX[str(foreground)][str(background)] = i
42+
return curses.color_pair(i)
43+
44+
def set_color(background: int,foreground: int) -> int:
45+
return set_colour(background,foreground)

upload.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
rm dist/*
44
set -e
55
mv src/__cptest.py .
6+
rm -rf src/cursesplus/__pycache__
67
python3 -m build
78
python3 -m twine upload dist/*
89
mv __cptest.py src

0 commit comments

Comments
 (0)