Base class for Screen classes (raw_display.Screen, .. etc)
Register a set of palette entries.
palette – a list of (name, like_other_name) or (name, foreground, background, mono, foreground_high, background_high) tuples
The (name, like_other_name) format will copy the settings from the palette entry like_other_name, which must appear before this tuple in the list.
The mono and foreground/background_high values are optional ie. the second tuple format may have 3, 4 or 6 values. See register_palette_entry() for a description of the tuple values.
Register a single palette entry.
name – new entry/attribute name
foreground – a string containing a comma-separated foreground color and settings
Color values: ‘default’ (use the terminal’s default foreground), ‘black’, ‘dark red’, ‘dark green’, ‘brown’, ‘dark blue’, ‘dark magenta’, ‘dark cyan’, ‘light gray’, ‘dark gray’, ‘light red’, ‘light green’, ‘yellow’, ‘light blue’, ‘light magenta’, ‘light cyan’, ‘white’
Settings: ‘bold’, ‘underline’, ‘blink’, ‘standout’
Some terminals use ‘bold’ for bright colors. Most terminals ignore the ‘blink’ setting. If the color is not given then ‘default’ will be assumed.
background – a string containing the background color
Background color values: ‘default’ (use the terminal’s default background), ‘black’, ‘dark red’, ‘dark green’, ‘brown’, ‘dark blue’, ‘dark magenta’, ‘dark cyan’, ‘light gray’
mono – a comma-separated string containing monochrome terminal settings (see “Settings” above.)
None = no terminal settings (same as ‘default’)
foreground_high – a string containing a comma-separated foreground color and settings, standard foreground colors (see “Color values” above) or high-colors may be used
High-color example values: ‘#009’ (0% red, 0% green, 60% red, like HTML colors) ‘#fcc’ (100% red, 80% green, 80% blue) ‘g40’ (40% gray, decimal), ‘g#cc’ (80% gray, hex), ‘#000’, ‘g0’, ‘g#00’ (black), ‘#fff’, ‘g100’, ‘g#ff’ (white) ‘h8’ (color number 8), ‘h255’ (color number 255)
None = use foreground parameter value
background_high – a string containing the background color, standard background colors (see “Background colors” above) or high-colors (see “High-color example values” above) may be used
None = use background parameter value
Initialize a screen that directly prints escape codes to an output terminal.
Force the screen to be completely repainted on the next call to draw_screen().
Paint screen with rendered canvas.
Return the terminal dimensions (num columns, num rows).
Return pending input as a list.
raw_keys – return raw keycodes as well as translated versions
This function will immediately return all the input since the last time it was called. If there is no input pending it will wait before returning an empty list. The wait time may be configured with the set_input_timeouts function.
If raw_keys is False (default) this function will return a list of keys pressed. If raw_keys is True this function will return a ( keys pressed, raw keycodes ) tuple instead.
Examples of keys returned:
When a narrow encoding is not enabled:
When a wide encoding is enabled:
When utf8 encoding is enabled:
Examples of mouse events returned:
(‘meta mouse press’, 2, 17, 23)
(‘mouse drag’, 1, 17, 13), (‘ctrl mouse drag’, 1, 18, 13)
(‘ctrl mouse release’, 0, 17, 23)
Return a list of integer file descriptors that should be polled in external event loops to check for user input.
Use this method if you are implementing yout own event loop.
Return a (next_input_timeout, keys_pressed, raw_keycodes) tuple.
Use this method if you are implementing your own event loop.
When there is input waiting on one of the descriptors returned by get_input_descriptors() this method should be called to read and process the input.
This method expects to be called in next_input_timeout seconds (a floating point number) if there is no input waiting.
entries - list of (index, red, green, blue) tuples.
Attempt to set part of the terminal pallette (this does not work on all terminals.) The changes are sent as a single escape sequence so they should all take effect at the same time.
0 <= index < 256 (some terminals will only have 16 or 88 colors) 0 <= red, green, blue < 256
Attempt to set the terminal palette to default values as taken from xterm. Uses number of colors from current set_terminal_properties() screen setting.
Call start to initialize screen, then call fn. When fn exits call stop to restore the screen to normal.
Set the get_input timeout values. All values are in floating point numbers of seconds.
Enable mouse tracking.
After calling this function get_input will include mouse click events along with keystrokes.
Called in the startup of run wrapper to set the SIGWINCH and SIGCONT signal handlers.
Override this function to call from main thread in threaded applications.
Called in the finally block of run wrapper to restore the SIGWINCH and SIGCONT signal handlers.
Override this function to call from main thread in threaded applications.
Initialize the screen and input mode.
alternate_buffer – use alternate screen buffer
Restore the screen.
Force the screen to be completely repainted on the next call to draw_screen().
Paint screen with rendered canvas.
Return the terminal dimensions (num columns, num rows).
Return pending input as a list.
raw_keys – return raw keycodes as well as translated versions
This function will immediately return all the input since the last time it was called. If there is no input pending it will wait before returning an empty list. The wait time may be configured with the set_input_timeouts function.
If raw_keys is False (default) this function will return a list of keys pressed. If raw_keys is True this function will return a ( keys pressed, raw keycodes ) tuple instead.
Examples of keys returned:
When a narrow encoding is not enabled:
When a wide encoding is enabled:
When utf8 encoding is enabled:
Examples of mouse events returned:
(‘meta mouse press’, 2, 17, 23)
(‘ctrl mouse release’, 0, 17, 23)
Call fn in fullscreen mode. Return to normal on exit.
This function should be called to wrap your main program loop. Exception tracebacks will be displayed in normal mode.
Set the get_input timeout values. All values have a granularity of 0.1s, ie. any value between 0.15 and 0.05 will be treated as 0.1 and any value less than 0.05 will be treated as 0. The maximum timeout value for this module is 25.5 seconds.
Enable mouse tracking.
After calling this function get_input will include mouse click events along with keystrokes.
Initialize the screen and input mode.
Restore the screen.
Force the screen to be completely repainted on the next call to draw_screen().
(does nothing for web_display)
Send a screen update to the client.
Return the screen size.
Return pending input as a list.
Register a list of palette entries.
calls self.register_palette_entry for each item in l
Register a single palette entry.
name – new entry/attribute name foreground – foreground colour background – background colour mono – monochrome terminal attribute
See curses_display.register_palette_entry for more info.
Run the application main loop, calling start() first and stop() on exit.
Not yet implemented
This function reads the initial screen size, generates a unique id and handles cleanup when fn exits.
web_display.set_preferences(..) must be called before calling this function for the preferences to take effect
Restore settings and clean up.
Do nothing.
Force the screen to be completely repainted on the next call to draw_screen().
(does nothing for html_fragment)
Create an html fragment from the render object. Append it to HtmlGenerator.fragments list.
Return the next screen size in HtmlGenerator.sizes.
Return the next list of keypresses in HtmlGenerator.keys.
Call fn.
Not yet implemented
Replace curses_display.Screen and raw_display.Screen class with HtmlGenerator.
Call this function before executing an application that uses curses_display.Screen to have that code use HtmlGenerator instead.
Lists of keys may include “window resize” to force the application to call get_cols_rows and read a new screen size.
Return screenshots as a list of HTML fragments.
Common methods for Crystal Fontz LCD displays
device_path – eg. ‘/dev/ttyUSB0’ baud – baud rate
Crystal Fontz 635 display
20x4 character display + cursor no foreground/background colors or settings supported
see CGROM for list of close unicode matches to characters available
6 button input up, down, left, right, enter (check mark), exit (cross)
device_path – eg. ‘/dev/ttyUSB0’ baud – baud rate repeat_delay – seconds to wait before starting to repeat keys repeat_next – time between each repeated key key_map – the keys to send for this device’s buttons
return the fd from our serial device so we get called on input and responses
Return a (next_input_timeout, keys_pressed, raw_keycodes) tuple.
The protocol for our device requires waiting for acks between each command, so this method responds to those as well as key press and release events.
Key repeat events are simulated here as the device doesn’t send any for us.
raw_keycodes are the bytes of messages we received, which might not seem to have any correspondence to keys_pressed.
Program character data. Characters available as chr(0) through chr(7), and repeated as chr(8) through chr(15).
index – 0 to 7 index of character to program
data – list of 8, 6-bit integer values top to bottom with MSB on the left side of the character.
Set backlight brightness
value – 0 to 100
value – 0 to 255
led – 0 to 3 rg – 0 for red, 1 for green value – 0 to 100
Provide simulated repeat key events when given press and release events.
If two or more keys are pressed disable repeating until all keys are released.
repeat_delay – seconds to wait before starting to repeat keys repeat_next – time between each repeated key
Return (remaining, key) where remaining is the number of seconds (float) until the key repeat event should be sent, or None if no events are pending.
Cakk this method when you have sent a key repeat event so the timer will be reset for the next event