Skip to content

Commit

Permalink
3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Enderbyte09 authored Oct 27, 2023
1 parent 6da0499 commit 09e96c6
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 22 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ cursesplus is getting a widgets based system. The old utilities have been moved

- There is now a default ctrl_C detector.

### 3.2

- Add rectangle drawing for windows

- Remove ctrl c handler

- Move colours set to utils. For backwards compatibility, it is automatically imported to root level

- Utils.coord is now imported on root level

# Documentation

## Two Ways to Use
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 = "3.0"
version = "3.2"
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
10 changes: 8 additions & 2 deletions src/__cptest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import cursesplus
import curses
import random

import cursesplus.utils
from time import sleep
if __name__ == "__main__":
win = cursesplus.show_ui()
cursesplus.classic.displayops(win.screen,["Hlel","Goodbye"])
subwin = win.create_child_window(cursesplus.Coord(5,5),cursesplus.Coord(10,5))
subwin.drawWindowBoundary = True
subwin.update()
#cursesplus.utils.draw_bold_rectangle(subwin.screen,cursesplus.Coord(5,5),cursesplus.Coord(10,10))
win.update()
win.screen.getch()
cursesplus.shutdown_ui()
12 changes: 11 additions & 1 deletion 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: 3.1
Version: 3.2
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 Down Expand Up @@ -43,6 +43,16 @@ cursesplus is getting a widgets based system. The old utilities have been moved

- There is now a default ctrl_C detector.

### 3.2

- Add rectangle drawing for windows

- Remove ctrl c handler

- Move colours set to utils. For backwards compatibility, it is automatically imported to root level

- Utils.coord is now imported on root level

# Documentation

## Two Ways to Use
Expand Down
3 changes: 2 additions & 1 deletion src/cursesplus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@
from . import filedialog
from .widgets import *
from . import cp as classic
from . import messagebox
from .utils import Coord,set_color,set_colour
from . import messagebox
12 changes: 11 additions & 1 deletion src/cursesplus/constants.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import curses

#Colours
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
MAGENTA = curses.COLOR_MAGENTA

#Terminal drawing characters

DOUBLE_TL_CORNER = "╔"
DOUBLE_TR_CORNER = "╗"
DOUBLE_BL_CORNER = "╚"
DOUBLE_BR_CORNER = "╝"
DOUBLE_HORIZ = "═"
DOUBLE_VERT = "║"
52 changes: 37 additions & 15 deletions src/cursesplus/tuibase.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,61 @@
import curses
import os
from . import messagebox
from . import messagebox,utils
import signal
import sys

id_ind = 0
def get_new_winid() -> int:
global id_ind
id_ind += 1
return id_ind

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:

"""A class for the base terminal. You may only use this once. To interface with this as if it were a window, use (self).tui_window which is a Window object set to the bounds of the screen."""
def __init__(self,screen):
global __SCREEN
self.screen = screen
self.children: list[Window] = []
__SCREEN = screen
self.size_x, self.size_y = os.get_terminal_size()
self.size_y -= 2
self.size_x -= 1
self.tui_window = Window(self,self.screen,self.size_x,self.size_y,0,0)
self.tui_window.drawWindowBoundary = False

#self.tui_window.update()
def create_child_window(self,offset:utils.Coord,size:utils.Coord):
"""Create and return a window object"""
return Window(self,self.screen,size.x,size.y,offset.x,offset.y)
def update(self):
"""Update and refresh the screen"""
for w in self.children:
w.update()
self.screen.refresh()

class Window:
def __init__(self,parent:BaseWindow,screen,size_x,size_y):
self.screen = screen
drawWindowBoundary = True
def __init__(self,parent:BaseWindow,screen,size_x: int,size_y:int,offset_x:int,offset_y:int):
self.screen: curses._CursesWindow = screen
self.parent: BaseWindow = parent

self.size_x = size_x
self.size_y = size_y
self.maximum_coords = Coord(size_x,size_y)
self.id = get_new_winid()
self.size_coords = utils.Coord(size_x,size_y)
self.offset_x =offset_x
self.offset_y = offset_y
self.offset_coords = utils.Coord(offset_x,offset_y)
self.parent.children.append(self)
#signal.signal(signal.SIGINT,__base_signal_handler)#Register base shutdown
def update(self):
if self.drawWindowBoundary:
utils.draw_bold_rectangle(self.screen,self.offset_coords,self.size_coords+self.offset_coords)
self.screen.refresh()

def show_ui() -> BaseWindow:
"""Start the user interface. Returns a BaseWindow you can use for editing"""
Expand All @@ -59,4 +82,3 @@ def __base_signal_handler(signal,frame):
shutdown_ui()
#sys.exit()

signal.signal(signal.SIGINT,__base_signal_handler)#Register base shutdown
34 changes: 33 additions & 1 deletion src/cursesplus/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
import curses
from . import constants
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)
def __add__(self,other):
if not isinstance(other,Coord):
raise TypeError("Must be Coord type")
else:
return Coord(self.x+other.x,self.y+other.y)
def __sub__(self,other):
if not isinstance(other,Coord):
raise TypeError("Must be Coord type")
else:
return Coord(self.x-other.x,self.y-other.y)
_C_INIT = False
def retr_nbl_lst(input:list)->list:
return [l for l in input if str(l) != ""]
Expand Down Expand Up @@ -42,4 +61,17 @@ def set_colour(background: int, foreground: int) -> int:
return curses.color_pair(i)

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

def draw_bold_rectangle(stdscr,ulc:Coord,brc:Coord):
stdscr.addstr(ulc.y,ulc.x,constants.DOUBLE_TL_CORNER)
stdscr.addstr(ulc.y,brc.x,constants.DOUBLE_TR_CORNER)
stdscr.addstr(brc.y,ulc.x,constants.DOUBLE_BL_CORNER)
stdscr.addstr(brc.y,brc.x,constants.DOUBLE_BR_CORNER)
stdscr.addstr(ulc.y,ulc.x+1,constants.DOUBLE_HORIZ*(brc.x-ulc.x-1))
stdscr.addstr(brc.y,ulc.x+1,constants.DOUBLE_HORIZ*(brc.x-ulc.x-1))
#stdscr.addstr(ulc.y+1,ulc.x,constants.DOUBLE_VERT*(brc.y - ulc.y-2))
#stdscr.addstr(ulc.y+1,brc.x,constants.DOUBLE_VERT*(brc.y - ulc.y-2))
for ln in range(ulc.y+1,brc.y,1):
stdscr.addstr(ln,ulc.x,constants.DOUBLE_VERT)
stdscr.addstr(ln,brc.x,constants.DOUBLE_VERT)
1 change: 1 addition & 0 deletions src/cursesplus/widgets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import utils

0 comments on commit 09e96c6

Please sign in to comment.