Skip to main content

Purses3d

The goal is to keep panda3d in control as much as possible while providing a console of sorts to print to, not to emulate ncurses as closely as possible. It's currently pretty barebones but with some workarounds can be made to do anything ncurses can except beep().

  • Only works with monospaced fonts that contain the U+2588 "full block" unicode character for solid character backgrounds. For this reason hack.ttf is in this repo, which is MIT licensed.
  • Meant to be used to make ascii/text-based games, GUIs, HUDs, etc.
  • Either combine with panda3d's other capabilities or consider this the wrong way to draw text to a screen.

To see a colorful display of functionality, run

 $ git clone http://github.com/momojohobo/panda3d-purses
 $ cd panda3d-purses
 $ pip install -r requirements.txt
 $ python purses3d/__init__.py 

It is also avaiable on pypi.

 $ pip install panda3d-purses3d

TODO:

  • Steal more handy functions from ncurses.

License

Either MIT or Public Domain (CC0), take your pick.

How to use:

# Import sys, panda3d and purses
import sys
from direct.showbase.ShowBase import ShowBase
from purses3d import Purses, Window

# Run panda3d
base = ShowBase()
base.accept("escape", sys.exit)
base.run()

# Initialize purses with a console size of 40x20 characters
# It will be automatically scaled to fill the entire screen
purses = Purses(40, 20)

# Make a window in the center, taking up half the screen
window = Window(x=10, y=5, columns=20, lines=10)  

# Move that window's cursor to where we want to write
window.move(3, 0)

# Write something in that window
window.addstr("hello world")

# Or move and print in one go
window.addstr(3, 0, "hello world")

# Copy it to the main purses window
purses.copyfrom(window)

# Because Purses() is also a window, we can write something on it too
purses.addstr(0, 0, "purses!")

# Update the screen
purses.refresh()

Colors / Properties

To add colors (amongst other need things) we'll need panda3d's TextPropertiesManager

from panda3d.core import TextProperties, TextPropertiesManager

# Get panda3d's global property manager
manager = TextPropertiesManager.getGlobalPtr()

# Make some property, in this case something telling it to print the text red (in rgba)
red = TextProperties()
red.setTextColor((1,0,0,1))

# Add it to panda's global mananger
manager.addProperties("myRedColor", red) 

# And use it to print the characters foreground (with a transparent background)
purses.addstr(0, 0, "purses!", ("myRedColor", None))

# ...or to print the characters background in that color
purses.addstr(0, 0, "purses!", (None, "myRedColor"))

purses.refresh()

# We can reposition this purses instance too so it doesn't take up the entire screen
purses.node.setScale(0.5)
purses.node.setPos(-0.3, 0, 0)

# Or parent it to the world as a 3d object COOOL!
purses.node.reparentTo(render)

You can change any properties found in the panda3d TextProperties class, though they're mostly untested. Especially changing text size could screw things up I imagine.

Text input

Because panda3d is a realtime system and curses is not, text input is handled a little differently.

# Get user input string at (10, 5) from main purses screen
string = purses.getstr(10, 5)

# You can also supply a different window to echo the string to
# Or give it fg and bg attributes
string = purses.getstr(10, 5, window=my_window, attr=("red", "blue"))

# If the string is closed (with enter), it is returned instead of None.
if string:
    # If used types hello
    if string == "hello":
        # Print this answer
        purses.addstr("why hello there buddy!")

Functions so far

purses.move(x, y) # Place the cursor at position
purses.increment(n=1) # Increment the cursor location

purses.scrollup() # Scroll everything in window up
purses.scrolldown() # Scroll everything in window down

purses.fill(character) # Fills the entire window with a char (or empty if none is specified)
purses.delete(x, y) # Delete a single character
purses.addch(x, y, char, properties) # Add a single character
purses.addstr(x, y, string, properties) # Add a string 

# Draw horizontal and vertical lines respectively
purses.linehori(start_x, start_y, length, character, properties)
purses.linevert(start_x, start_y, length, character, properties)

# Draw a border around the window, left, right, top, bottom and its corners.
# Each character should be complete with properties ("c", (None, None))
purses.border(ls, rs, ts, bs, tl, tr, bl, br) 
purses.box(horizontal_sides, vertical_sides)

# These calls only work from the main Purses() window.
purses.refresh() # Refresh screen (place its state to the screen)
# Return the mouse coordinates in characters, only callable from Purses()
# If window is specified it will return its relative coordinates
purses.getmouse(window) 
# Return a string as written by user
purses.getstr(x, y, window=None, attr=(None, None))

Release files for panda3d-purses3d 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for panda3d-purses3d 0.0.9
File Size Uploaded
panda3d-purses3d-0.0.9.tar.gz 159.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for panda3d-purses3d 0.0.9
File Interpreter ABI Platform
panda3d_purses3d-0.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 320.5 kB

Release files / panda3d-purses3d-0.0.9.tar.gz

Download URL panda3d-purses3d-0.0.9.tar.gz
Size 159.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5431c32ea3d60c8918c2fcf091492636f584a74e241f2c346de770a2594f916b
BLAKE2b-256 checksum
How to use checksums
fdd19a838e3cd77cba549779452e8060e364c1e7483f271d9f9ad7310b2dfa64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Release files / panda3d_purses3d-0.0.9-py3-none-any.whl

Download URL panda3d_purses3d-0.0.9-py3-none-any.whl
Size 160.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
34839ee6321a8c2c35f4881e91d87e213f027c1b00ce42096923356d1682ca06
BLAKE2b-256 checksum
How to use checksums
3f0f135043627e2c601ecab6ccddbae5b671b6da22e3ee7c2a400c0b675f00aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.0.9 This release

2 release files

0.0.8

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page