Skip to content

Commit

Permalink
3.1
Browse files Browse the repository at this point in the history
Do some more moving
  • Loading branch information
Enderbyte09 authored Oct 26, 2023
1 parent fa421fd commit 6da0499
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 66 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ cursesplus is getting a widgets based system. The old utilities have been moved

- cursesplus.cp is now imported under cursesplus.classic

- There is now a default ctrl_C detector.

# Documentation

## Two Ways to Use
Expand Down
3 changes: 1 addition & 2 deletions src/__cptest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@

if __name__ == "__main__":
win = cursesplus.show_ui()

cursesplus.classic.optionmenu(win.screen,["hello","goodbyte"])
cursesplus.classic.displayops(win.screen,["Hlel","Goodbye"])
cursesplus.shutdown_ui()
61 changes: 45 additions & 16 deletions src/cursesplus.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: cursesplus
Version: 2.11.4
Version: 3.1
Summary: An extension program to curses that offers option menus, message boxes, file dialogs and more
Author-email: Enderbyte Programs <enderbyte09@gmail.com>
Project-URL: Homepage, https://github.com/Enderbyte-Programs/Curses-Plus
Expand All @@ -27,33 +27,62 @@ to provide the basic curses functionality

## What's New?

## Patch 2.11.4
### THE SWITCH TO 3.0

- transitions.random_blocks speed now actually does something
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.

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

## Patch 2.11.3
- Add TUI base module

- Fix bug in filedialog in empty directory
- Add widgets module

- Add optional flag: allowcancel
- Move colours to constants module

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

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

## Version 2.11
# Documentation

- Add checkboxlist
## Two Ways to Use

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

- Add banned characters in cursesinput
.
- Fix blinking in textview
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:

# Documentation
```
import cursesplus

win = cursesplus.show_ui()

#See below for how to use classic utilities in a 3.x environment
```

### 2. The Old Way

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
```
import cursesplus
import curses

def main(stdscr):
cursesplus.classic.displaymsg(stdscr,["This is a message"])

curses.wrapper(main)
```

### 1A. Using classic utilities in a new set-up

To use Old-Style utility functions in a new way, see this code. This does the same as the example in part 2
```
import cursesplus

win = cursesplus.show_ui()
cursesplus.classic.displaymsg(win.screen,["This is a message"])

cursesplus.shutdown_ui() #Good practice to close down after
```

## transitions.py

Expand Down
4 changes: 4 additions & 0 deletions src/cursesplus.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ LICENSE
README.md
pyproject.toml
src/cursesplus/__init__.py
src/cursesplus/constants.py
src/cursesplus/cp.py
src/cursesplus/filedialog.py
src/cursesplus/messagebox.py
src/cursesplus/transitions.py
src/cursesplus/tuibase.py
src/cursesplus/utils.py
src/cursesplus/widgets.py
src/cursesplus.egg-info/PKG-INFO
src/cursesplus.egg-info/SOURCES.txt
src/cursesplus.egg-info/dependency_links.txt
Expand Down
2 changes: 1 addition & 1 deletion src/cursesplus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
NOTICE! CP UTILITIES ARE COMPLETELY INCOMPATIBLE WITH TUIBASE. TO USE THEM, CALL your BaseWindows.screen for the stdscr argument.
"""

__version__ = "3.0-b1"
__version__ = "3.1"
__author__ = "Enderbyte Programs"
__package__ = "cursesplus"

Expand Down
46 changes: 3 additions & 43 deletions src/cursesplus/cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import textwrap
import threading
from .constants import *
from .utils import *

_C_INIT = False

Expand Down Expand Up @@ -66,20 +67,7 @@ def displaymsgnodelay(stdscr,message: list):
mi += 1
stdscr.addstr(int(y//2+mi),int(x//2-len(msgl)//2),msgl)
stdscr.refresh()
def __retr_nbl_lst(input:list)->list:
return [l for l in input if str(l) != ""]
def __calc_nbl_list(input:list)->int:
x = 0
for ls in input:
x += len(ls)
return x

def str_contains_word(s:str,string:str) -> bool:
d = s.lower().split(" ")
return string in d

def list_get_maxlen(l:list) -> int:
return max([len(s) for s in l])

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

curses.beep()
elif ch == curses.KEY_RIGHT:
if col < len(__retr_nbl_lst(text[ln])):
if col < len(retr_nbl_lst(text[ln])):
col += 1
if col-xoffset > mx-2:
xoffset += 1
Expand Down Expand Up @@ -260,7 +248,7 @@ def cursesinput(stdscr,prompt: str,lines=1,maxlen=0,passwordchar:str=None,retrem
stdscr.erase()
else:
#append
if __calc_nbl_list(text) == maxlen and maxlen != 0:
if calc_nbl_list(text) == maxlen and maxlen != 0:
curses.beep()
ERROR = f" You have reached the character limit ({maxlen}) "
else:
Expand Down Expand Up @@ -384,34 +372,6 @@ def askyesno_old(stdscr,title: str) -> bool:
return True
else:
return False
_AVAILABLE_COL = list(range(1,255,1))
_COL_INDEX = {}
def set_colour(background: int, foreground: int) -> int:
global _C_INIT
global _COL_INDEX
global _AVAILABLE_COL
"""Set a colour object. Use the constants provided. z
For attributes use | [ATTR] for example set_colour(RED,GREEN) | sdf
"""
if not _C_INIT:
curses.start_color()
curses.use_default_colors()
_C_INIT = True

if str(foreground) in _COL_INDEX.keys() and str(background) in _COL_INDEX[str(foreground)].keys():
return curses.color_pair(_COL_INDEX[str(foreground)][str(background)])
if len(_AVAILABLE_COL) == 0:
raise Warning("Out of colours!")
_AVAILABLE_COL = list(range(1,255,1))#Replenish list
i = _AVAILABLE_COL.pop(0)
curses.init_pair(i,foreground,background)
if not str(foreground) in _COL_INDEX.keys():
_COL_INDEX[str(foreground)] = {}
_COL_INDEX[str(foreground)][str(background)] = i
return curses.color_pair(i)

def set_color(background: int,foreground: int) -> int:
return set_colour(background,foreground)

def displayerror(stdscr,e,msg: str):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/cursesplus/filedialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def openfiledialog(stdscr,title: str = "Please choose a file",filter: str = [["*
directory = directory.replace("\\","/").replace("//","/")
elif ch == 114:
refresh = True#Refresh files list
elif ch == 99 or cp.curses.keyname(ch) == b"^C":
elif ch == 99:
if allowcancel:
return None
else:
Expand Down
18 changes: 15 additions & 3 deletions src/cursesplus/tuibase.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import curses
import os
from .constants import *
__SCREEN = None
from . import messagebox
import signal
import sys

class AlreadyInitializedError(Exception):
def __init__(self,message):
self.message = message
Expand Down Expand Up @@ -47,4 +49,14 @@ def shutdown_ui():
curses.nocbreak()
stdscr.keypad(False)
curses.echo()
curses.endwin()
curses.reset_shell_mode()
curses.endwin()
sys.exit()

def __base_signal_handler(signal,frame):
if messagebox.askyesno(stdscr,["Are you sure you wish to exit?"]):
stdscr.erase()
shutdown_ui()
#sys.exit()

signal.signal(signal.SIGINT,__base_signal_handler)#Register base shutdown
45 changes: 45 additions & 0 deletions src/cursesplus/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import curses
_C_INIT = False
def retr_nbl_lst(input:list)->list:
return [l for l in input if str(l) != ""]
def calc_nbl_list(input:list)->int:
x = 0
for ls in input:
x += len(ls)
return x

def str_contains_word(s:str,string:str) -> bool:
d = s.lower().split(" ")
return string in d

def list_get_maxlen(l:list) -> int:
return max([len(s) for s in l])

_AVAILABLE_COL = list(range(1,255,1))
_COL_INDEX = {}
def set_colour(background: int, foreground: int) -> int:
global _C_INIT
global _COL_INDEX
global _AVAILABLE_COL
"""Set a colour object. Use the constants provided. z
For attributes use | [ATTR] for example set_colour(RED,GREEN) | sdf
"""
if not _C_INIT:
curses.start_color()
curses.use_default_colors()
_C_INIT = True

if str(foreground) in _COL_INDEX.keys() and str(background) in _COL_INDEX[str(foreground)].keys():
return curses.color_pair(_COL_INDEX[str(foreground)][str(background)])
if len(_AVAILABLE_COL) == 0:
raise Warning("Out of colours!")
_AVAILABLE_COL = list(range(1,255,1))#Replenish list
i = _AVAILABLE_COL.pop(0)
curses.init_pair(i,foreground,background)
if not str(foreground) in _COL_INDEX.keys():
_COL_INDEX[str(foreground)] = {}
_COL_INDEX[str(foreground)][str(background)] = i
return curses.color_pair(i)

def set_color(background: int,foreground: int) -> int:
return set_colour(background,foreground)
1 change: 1 addition & 0 deletions upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
rm dist/*
set -e
mv src/__cptest.py .
rm -rf src/cursesplus/__pycache__
python3 -m build
python3 -m twine upload dist/*
mv __cptest.py src

0 comments on commit 6da0499

Please sign in to comment.