Skip to content

Commit

Permalink
3.0
Browse files Browse the repository at this point in the history
So many changes... So hard to keep track of
  • Loading branch information
Enderbyte09 authored Oct 26, 2023
1 parent 7068302 commit fa421fd
Show file tree
Hide file tree
Showing 18 changed files with 193 additions and 53 deletions.
57 changes: 42 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,60 @@ 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)
# Documentation

## Version 2.11
## Two Ways to Use

- Add checkboxlist
### 1. New Way

- Choose one or more options from the list
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:

- Add banned characters in cursesinput
.
- Fix blinking in textview
```
import cursesplus
# Documentation
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
[project]
name = "cursesplus"
version = "2.11.3"
version = "3.0"
authors = [{name="Enderbyte Programs",email="enderbyte09@gmail.com"},]
description = "An extension program to curses that offers option menus, message boxes, file dialogs and more"
readme = "README.md"
Expand Down
16 changes: 5 additions & 11 deletions src/__cptest.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import cursesplus
import curses
import random
e = ""
def __test__(stdscr):
global e
#cursesplus.textview(stdscr,file="src/cursesplus/cp.py",message="LICENSE",isagreement=True,requireyes=True)
e = cursesplus.filedialog.openfiledialog(stdscr,allowcancel=False)
#e = cursesplus.checkboxlist(stdscr,{"Create Desktop Shortcut":False,"Create Start Menu Shortcut":True,"Register MIME type":True},"Choose optional features for installation",2,3)
#cursesplus.textview(stdscr,file="/home/jordan/Coding/cursesplus/src/cursesplus/cp.py")
#cursesplus.cursesinput(stdscr,"Hello",bannedcharacters="")

if __name__ == "__main__":
#Testing things
curses.wrapper(__test__)
print(e)
win = cursesplus.show_ui()

cursesplus.classic.optionmenu(win.screen,["hello","goodbyte"])
cursesplus.shutdown_ui()
70 changes: 66 additions & 4 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.3
Version: 2.11.4
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,6 +27,12 @@ to provide the basic curses functionality

## What's New?

## Patch 2.11.4

- transitions.random_blocks speed now actually does something

- Write some docs

## Patch 2.11.3

- Fix bug in filedialog in empty directory
Expand All @@ -44,9 +50,65 @@ to provide the basic curses functionality
- Choose one or more options from the list

- Add banned characters in cursesinput

.
- Fix blinking in textview

## Documentation
# Documentation

## transitions.py

transitions contains many transitions to add animations to your program

### _old(stdscr,func_to_call=None,args=(),type=0)

This is the old transitions function found in cursesplus prior to like 2.8 or something. It has since been replaced by horizontal_bars() and random_blocks()

- `stdscr` is a curses window object

- `func_to_call` is a function. If it is set to none, no function is called

- `args` is a tuple. The tuple will be passed to the function as arguments

- `type` is an int. It may be 0 or 1. If it is 0, there are horizontal bars. If it is 1, it is random blocks

### __exec(func,args)

**NOTE: THIS IS AN INTERNAL FUNCTION, IT IS NOT MEANT TO BE USED BY THE COMMON USER**

This executes `func(args)`

### horizontal_bars(stdscr,func_to_call=None,args=(),speed=1)

This is a replacement function to old's type zero. It fills the screen from the top down with horizontal white bars. It then replaces them with black bars in the same configuration.

- `stdscr` is a curses window object

- `func_to_call` is a function. If it is set to none, no function is called

- `args` is a tuple. The tuple will be passed to the function as arguments

- `speed` is an int. A higher value increases the animation speed. A lower value (0 - 1) makes it slower. If you set speed to 0, the program will crash.

### random_blocks(stdscr,func_to_call=None,args=(),speed=1)

This is a replacement for old's type one transition. It fills random characters of the screen with blocks until the whole screen is covered, then it removes it in the same fashion.

- `stdscr` is a curses window object

- `func_to_call` is a function. If it is set to none, no function is called

- `args` is a tuple. The tuple will be passed to the function as arguments

- `speed` is an int. A higher value increases the animation speed. A lower value (0 - 1) makes it slower. If you set speed to 0, the program will crash.

### vertical_bars(stdscr,func_to_call=None,args=(),speed=1)

This is an all new transition. It functions like horizontal bars except they are vertical and go left to right.

- `stdscr` is a curses window object

- `func_to_call` is a function. If it is set to none, no function is called

- `args` is a tuple. The tuple will be passed to the function as arguments

TODO
- `speed` is an int. A higher value increases the animation speed. A lower value (0 - 1) makes it slower. If you set speed to 0, the program will crash.
26 changes: 16 additions & 10 deletions src/cursesplus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,29 @@
Available on the Python Package Index
## Sub-Packages List
cursesplus.cp : Standard utilities. Automatically imported by just `import cursesplus`
cursesplus.__init__ : Wrapper for standard utilites but with __package__ and __version__
cursesplus.tuibase Auto imported. Base utilties
cursesplus.filedialog : Advanced menus for user-friendly file selection.
cursesplus.filedialog Advanced dialogues for file selection
cursesplus.messagebox : Package for message-boxes which are messages displayed on top of data instead of over-writing it.
cursesplus.messagebox Assorted messageboxes
cursesplus.transitions : Module for transitions
cursesplus.transitions Animated transitions
cursesplus.widgets Auto imported. Contains Widget classes for drawing UI
cursesplus.cp Old-style utilities. Imported as classic namespace
NOTICE! CP UTILITIES ARE COMPLETELY INCOMPATIBLE WITH TUIBASE. TO USE THEM, CALL your BaseWindows.screen for the stdscr argument.
"""

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

from .cp import *# Maintain backwards compatibility
from . import transitions as transitions
from . import filedialog as filedialog
from . import messagebox as messagebox
from .tuibase import *
from . import transitions
from . import filedialog
from .widgets import *
from . import cp as classic
from . import messagebox
Binary file modified src/cursesplus/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file added src/cursesplus/__pycache__/constants.cpython-311.pyc
Binary file not shown.
Binary file modified src/cursesplus/__pycache__/cp.cpython-311.pyc
Binary file not shown.
Binary file modified src/cursesplus/__pycache__/filedialog.cpython-311.pyc
Binary file not shown.
Binary file modified src/cursesplus/__pycache__/messagebox.cpython-311.pyc
Binary file not shown.
Binary file modified src/cursesplus/__pycache__/transitions.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file added src/cursesplus/__pycache__/widgets.cpython-311.pyc
Binary file not shown.
10 changes: 10 additions & 0 deletions src/cursesplus/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import curses

BLACK = curses.COLOR_BLACK
WHITE = curses.COLOR_WHITE
RED = curses.COLOR_RED
YELLOW = curses.COLOR_YELLOW
GREEN = curses.COLOR_GREEN
CYAN = curses.COLOR_CYAN
BLUE = curses.COLOR_BLUE
MAGENTA = curses.COLOR_MAGENTA
11 changes: 1 addition & 10 deletions src/cursesplus/cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@
from .transitions import _old as cursestransition
import textwrap
import threading

#DEFINE SOME CONSTANTS
BLACK = curses.COLOR_BLACK
WHITE = curses.COLOR_WHITE
RED = curses.COLOR_RED
YELLOW = curses.COLOR_YELLOW
GREEN = curses.COLOR_GREEN
CYAN = curses.COLOR_CYAN
BLUE = curses.COLOR_BLUE
MAGENTA = curses.COLOR_MAGENTA
from .constants import *

_C_INIT = False

Expand Down
4 changes: 2 additions & 2 deletions src/cursesplus/transitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def random_blocks(stdscr,func_to_call=None,args=(),speed=1):
stdscr.refresh()
except:
break
sleep(0.01)
sleep(0.01/speed)
_grid = [(x,y) for y in range(my-1) for x in range(mx-1)]
while _grid:
for i in range(round(((my*mx)/(24*80))*20)):
Expand All @@ -89,7 +89,7 @@ def random_blocks(stdscr,func_to_call=None,args=(),speed=1):
stdscr.refresh()
except:
break
sleep(0.01)
sleep(0.01/speed)
if func_to_call is not None:
__exec(func_to_call,args)

Expand Down
50 changes: 50 additions & 0 deletions src/cursesplus/tuibase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import curses
import os
from .constants import *
__SCREEN = None
class AlreadyInitializedError(Exception):
def __init__(self,message):
self.message = message

class Coord:
def __init__(self,x,y):
self.x = x
self.y = y
def as_tuple(self) -> tuple:
return (self.x,self.y)
def as_inverted_tuple(self) -> tuple:
return (self.y,self.x)

class BaseWindow:

def __init__(self,screen):
global __SCREEN
self.screen = screen
__SCREEN = screen
self.size_x, self.size_y = os.get_terminal_size()
self.size_x -= 1

class Window:
def __init__(self,parent:BaseWindow,screen,size_x,size_y):
self.screen = screen
self.parent: BaseWindow = parent
self.size_x = size_x
self.size_y = size_y
self.maximum_coords = Coord(size_x,size_y)

def show_ui() -> BaseWindow:
"""Start the user interface. Returns a BaseWindow you can use for editing"""
global stdscr
stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
curses.start_color()
stdscr.keypad(True)
return BaseWindow(stdscr)

def shutdown_ui():
"""Shut down the UI and return the terminal to its normal state"""
curses.nocbreak()
stdscr.keypad(False)
curses.echo()
curses.endwin()
Empty file added src/cursesplus/widgets.py
Empty file.

0 comments on commit fa421fd

Please sign in to comment.