Name | bwk JSON |
Version |
1.1.0
JSON |
| download |
home_page | None |
Summary | A simple Python windowing kit module for use with Blessed terminal formatting. |
upload_time | 2024-12-21 12:44:00 |
maintainer | None |
docs_url | None |
author | Charlie Koch |
requires_python | <4.0,>=3.9 |
license | BSD-2-Clause |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Blessed Window Kit (bwk)
A simple Python windowing kit module for use with _**Blessed**_ terminal formatting.
* Documentation: [https:blessed.readthedocs.io/en/1.20.0/https:blessed.readthedocs.io/en/1.20.0/](https:blessed.readthedocs.io/en/1.20.0/)
* Source Code: [https:github.com/jquast/blessedhttps:github.com/jquast/blessed](https:github.com/jquast/blessed)
* Installation: ``` pip3 install blessed==1.20.0 ```
- Use in your project by importing the module:
- ```from bwk import Border, Window, echo, flush```
## ``` bwk.characters.UnicodeChars```
A struct-like class which contains Unicode characters commonly used in Text-Based User Interfaces (TUI's).
## ``` bwk```
**Constants:**
* ```DEFAULT_WINDOW_BORDER```: a ```borderchar```string (see ```Border```object) which uses the solid line Unicode characters
#### ``` def echo(str, end='', flush=False):```
**Parameters:**
* ```str```: the string to output
* ```end```: a suffix to append to the string
* ```flush```: whether or not to flush the buffer of the output stream
A convenience method for working with _**Blessed**_ . This method will use the built-in Python ```print()```method but with the above parameters defaulted differently. It is intended to be used as a way to buffer output for the current outstream without flushing it.
#### ``` def flush():```
A convenience method which flushes the current output stream. Equivalent to ``` print('', end='', flush=True) ``` .
#### ``` def window_shopper(termstuff, *args, **kwargs):```
**Parameters:**
* ```termstuff```: a function to execute within a _**Blessed**_ terminal context
* ```args```: arguments to be passed to ```termstuff```
* ```kwargs```: keyword arguments to be passed to ```termstuff```
This method provides a default terminal context to preview window layouts. The terminal context provided is A fullscreen ```blessed.Terminal```with a hidden cursor. Pressing any key ends the terminal context.
The ```termstuff```function must receive the ```Terminal```object as its first argument, it must include ```*args```and ```**kwargs```, and has no return value.
```
def mywindowfunc(term, *args, **kwargs):
# do window layout here
```
**NOTE:** The terminal context will automaticaly flush the stream, so you do not need to use the ```flush()```method, only ```echo()```.
## ``` class Border:```
A class for defining the borders of a ```Window```object.
**Attributes:**
* ```upper_left_corner```: ( **default:** ```''```)
* ```top_border```: ( **default:** ```''```)
* ```upper_right_corner```: ( **default:** ```''```)
* ```right_border```: ( **default:** ```''```)
* ```lower_right_corner```: ( **default:** ```''```)
* ```bottom_border```: ( **default:** ```''```)
* ```lower_left_corner```: ( **default:** ```''```)
* ```left_border```: ( **default:** ```''```)
#### ``` def __init__(self, borderchars=''):```
**Parameters:**
* ```borderchars```: a string of characters to use for the border
Creates a new ```Border```object. The ```borderchars```string must be exactly 8 characters long. If it is not, then no border is used. The characters form the corners and sides starting with the upper left corner and going clockwise.
**Example:** ```borderchars='1=2:3+4|```'
```
1=====2
| :
| :
4+++++3
```
You can also directly alter any of the border characters via the object's attributes (see **Attributes** above)
## ``` class Window:```
A rectangular container for displaying content.
**Constants:**
* ```TITLE_ALIGNS```: A set of strings to identify the alignment of the window ```title```
**Attributes:**
* ```term```: the ```blessed.Terminal```object used for display
* ```x```: the column of the terminal that the upper left corner is placed
* ```y```: the row of the terminal that the upper left corner is placed
* ```height```: the total height of the window (including the borders)
* ```width```: the total width of the window (including borders)
* ```border```: a ```Border```object which defines the border display of the window
* ```title```: the title displayed at the top of the window
* ```title_align```: the alignment of the ```title```
* ```content```: a string of characters to display in the window
**NOTE:** When a ```Window```is defined, there must be content added to it, either by setting the ```content```attribute directly, or by overriding the ```render_content()```method. The window is not buffered to the output stream unless the ```render()```method is called.
#### ``` def __init__(self, term, x, y, height=None, width=None, fore_color=None, bg_color=None, border=DEFAULT_WINDOW_BORDER, title='', title_align='center'):```
**Parameters:**
* ```term```: the ```blessed.Terminal```object used for display
* ```x```: the column of the terminal that the upper left corner is placed
* ```y```: the row of the terminal that the upper left corner is placed
* ```height```: the total height of the window (including the borders)
* ```width```: the total width of the window (including borders)
* ```fore_color```: _not yet implemented_
* ```bg_color```: _not yet implemented_
* ```border```: a ```borderchar```string or a ```Border```object
* ```title```: the title displayed at the top of the window
* ```title_align```: the alignment of the ```title```
If ```height```or ```width```is not provided, then that dimension will stretch all the way to the edge of the terminal. If ```border```is set to ```None```, then no border will be drawn. The ```title```will not be displayed unless there is a ```border```with at least the ```top_border```attribute set. The ```title_align```string must be one of the following values: ```left```, ```center```, or ```right```.
#### ``` def render(self):```
Echoes the window to the output stream buffer (via the ```echo()```function). The content of the window is limited by the ```height```and ```width```of the window (minus the height and width of the border). Any characters which are beyond the dimensions of the window will not be displayed.
#### ``` def render_content(self, max_width, max_height):```
**Parameters:**
* ```max_width```: the total width of the window (minus the width of the borders)
* ```max_height```: the total height of the window (minus the height of the borders)
**Returns:** A string or list of strings which will fit in the dimensions of the window.
This method is provided to be overriden, either by overwriting the instance attrbute ```render_content```with a different function, or by overriding this function in a subclass. By default, this method simply returns the window's ```content```string.
This method is called by the ```render()```method. If the return value is a string, ```render()```will iterate over the each line (delimited by a ```n```). If the return value is a list of strings, ```render()```will iterate over the list.
# Blessed Window Kit Screen Tools (bwk.screen)
An extension of the Blessed Window Kit (BWK) for quickly building Text-Based User Interface (TUI) applications.
- Use in your project by importing the module:
- ```import bwk.screen```
## ``` class Screen:```
A barebones implementation for rendering output to a terminal and processing input. This can be used with or without the BWK itself (see the ```ScreenManager```classes below).
**Attributes:**
* ```man```: a ```ScreenManager```which the sceen is associated to.
* ```name```: the name of the screen
* ```commands```: a dictionary of commands. Each value is a function which will execute when input matching its key is received by the screen.
#### ``` def __init__(self, manager, name, commands={}):```
**Parameters:**
* ```man```: a ```ScreenManager```which the sceen is associated to.
* ```name```: the name of the screen
* ```commands```: a dictionary of commands. Each value is a function which will execute when input matching its key is received by the screen.
#### ``` def set_commands(self):```
Identify keystrokes which correlate with logic to trigger. This should be overridden in subclasses to set the keys used in that mode.
For each keyboard key, set a string as the key in the ```self.commands```dictionary and the value as a method to call when the key is pressed. The method which is called is passed no arguments (except ```self```, if it is a class method).
```
self.commands['h'] = self.show_help
```
If the key is a Unicode printable character, such as a letter, number, or punctuation, use the string representation of that key.
**NOTE:** The Space key is a printable character ( ```'```' ) and should be indicated as such.
**NOTE:** If an uppercase (or otherwised altered via the Shift key, such as the symbols on number keys) is used, this will require the Shift key to be held when pressing the key to get a ppropriate result. This is an easy way to incorporate modifier keys by using Shift as the modifier.
If the key is a non-printable character (such as the Backspace, Enter, Esc, F# keys), the name of the constant as defined in the Blessed documentation is used. See the documentation for a list of supported names: [https:blessed.readthedocs.io/en/latest/keyboard.html#keycodeshttps:blessed.readthedocs.io/en/latest/keyboard.html#keycodes](https:blessed.readthedocs.io/en/latest/keyboard.html#keycodes)
**NOTE:** Keys on the numpad are different keycodes, and as such, they can only be identified by the name of their constant. All numpad key constants start with ```Key_KP_```. For example, ```9```on the numpad would be ```KEY_KP_9```.
| Line | Key(s) |
|---|---|
| self.commands['h'] = self.show_help_ | ```H``` |
| self.commands['H'] = self.show_help_ | ```Shift```+ ```H``` |
| self.commands['KEY_ESCAPE'] = self.back | ```Esc``` |
| self.commands['9'] = self.options | ```9``` |
| self.commands['KEY_KP_9'] = self.options | ```9```on the numpad |
| self.commands[' '] = self.select_item_ | ```Space``` |
| self.commands['1'] = self.action_menu_ | ```1``` |
| self.commands['!'] = self.second_menu_ | ```Shift```+ ```1``` |
#### ``` def pre_process_input(self, userin):```
**Parameters:**
* ```userin```: the input received to the screen
This method executes after a screen receives input, but before a matching command is executed.
#### ``` def post_process_input(self, userin):```
**Parameters:**
* ```userin```: the input received to the screen
This method executes after the input has been processed by the screen (which may be a command, or an error).
#### ``` def process_input(self, userin):```
**Parameters:**
* ```userin```: the input received to the screen
This is the main method which handles input to the screen. It executes the following steps in order:
* ```self.pre_process_input(userin)```
* if ```userin```matches a key in ```self.commands,```executes the corresponding function
* if ```userin```does not match a key in ```self.commands,```executes ```self.process_input_error(userin)```
* ```self.post_process_input(userin)```
#### ``` def process_input_error(self, userin):```
**Parameters:**
* ```userin```: the input received to the screen
This method executes when an input does not match any key in ```self.commands```.
#### ``` def render(self):```
This method will render the screen content to the terminal.
## ``` class GenericScreenManager:```
A barebones implementation for running an application loop with ```Screen```objects.
**Attributes:**
* ```running```: a boolean indicating if the run loop should continue
* ```curr_screen```: the current ```Screen```object being used to render output and process input
#### ``` def __init__(self):```
Initializes the manager.
#### ``` def pre_run(self):```
This method executes before the run loop begins. Any necessary preparation before the application starts should be done here. By default it is empty and should be overridden as necessary.
#### ``` def post_run(self):```
This method executes after the run loop ends. Any necessary cleanup after the application has ended should be done here. By default it is empty and should be overridden as necessary.
#### ``` def run(self):```
This is the main entrypoint for the ```ScreenManager```. Execute this method to begin the application loop, including the ```pre_run()```and ```post_run()```methods.
#### ``` def run_loop(self):```
The actual implementation of the application loop. It executes the follwoing setps in order:
* ```self.pre_render()```
* ```self.render()```
* ```self.pre_input()```
* ```self.get_user_input()```
* ```self.process_input(userin)```
The above steps will continue to execute until ```self.running```is False or there is no ```self.curr_screen```set (meaning that there is no way to display output or process input).
#### ``` def pre_render(self):```
This method executes at the beginning of each iteration of the run loop before the screen is rendered. By default it is empty and should be overridden as necessary.
#### ``` def render(self):```
Renders output to the terminal. This is typically done via ```self.curr_screen.render()```.
#### ``` def pre_input(self):```
This method executes after each iteration of the render in the run loop, but before user input is received. By default it is empty and should be overridden as necessary.
#### ``` def get_user_input(self):```
Gets input from the user. This can be overriden for specific input types. By default, it uses Python's ```input()```method.
#### ``` def process_input(self, userin):```
**Parameters:**
* ```userin```: the input received from the user
Processes the input received from the user. This is typically done via ```self.curr_screen.process_input(userin)```.
#### ``` def quit(self):```
A convenience method for ending the application loop. By default, this simply sets ```self.running```to False.
**Parameters:**
* ```exc```: the ```Exception```raised during the application loop
In the event that an exception is not caught during the application loop, the manager will gracefully catch the exception and handle it here. After this method executes, the ```post_run()```method executes, to ensure that all necessary cleanup is still performed despite the program crashing.
## ``` class BwkScreenManager(GenericScreenManager):```
A screen manager specifically for handling screens which utilize the Blessed Window Kit for rendering.
**Attributes:**
* ```running```: a boolean indicating if the run loop should continue
* ```curr_screen```: the current ```Screen```object being used to render output and process input
* ```term```: the ```blessed.Terminal```object used to render screens
* ```auto_flush```: if set to ```True```, a ```bwk.flush()```is called after the current screen is rendered
#### ``` def __init__(self, term=None, auto_flush=False):```
**Parameters:**
* ```term```: the ```blessed.Terminal```object used to render screens
* ```auto_flush```: if set to ```True```, a ```bwk.flush()```is called after the current screen is rendered
Initializes the screen manager. If no ```term```is provided, a default ```Terminal()```is used.
#### ``` def run(self):```
Overrides the original ```run()```with special context managers for BWK:
* ```term.fullscreen```
* ```term.cbreak```
* ```term.hidden_cursor```
This ensures that the application behaves similarly to the ```window_shopper()```method provided by the BWK to simplify building and managing screens.
#### ``` def get_user_input(self):```
Overrides this method to use the ```self.term.inkey()```method to get user input, rather than the default Python ```input()```method.
#### ``` def process_input(self, userin):```
Overrides this method to ensure that proper key name is sent to the screen's ```process_input()```method.
#### ``` def render(self):```
Renders output to the terminal. This is typically done via ```self.curr_screen.render()```. If ```self.auto_flush=True```, then a ```flush()```command is issued after the current screen is rendered.
Raw data
{
"_id": null,
"home_page": null,
"name": "bwk",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Charlie Koch",
"author_email": "charles@cerrax.com",
"download_url": "https://files.pythonhosted.org/packages/1a/87/3409302c48c821f560f6277633f8a27162ae83756d9f8c64a0db3563be9f/bwk-1.1.0.tar.gz",
"platform": null,
"description": "# Blessed Window Kit (bwk)\n\n\n A simple Python windowing kit module for use with _**Blessed**_ terminal formatting.\n\n* Documentation: [https:blessed.readthedocs.io/en/1.20.0/https:blessed.readthedocs.io/en/1.20.0/](https:blessed.readthedocs.io/en/1.20.0/)\n* Source Code: [https:github.com/jquast/blessedhttps:github.com/jquast/blessed](https:github.com/jquast/blessed)\n* Installation: ``` pip3 install blessed==1.20.0 ```\n\n\n- Use in your project by importing the module:\n - ```from bwk import Border, Window, echo, flush```\n\n\n## ``` bwk.characters.UnicodeChars```\n\n\n\n A struct-like class which contains Unicode characters commonly used in Text-Based User Interfaces (TUI's).\n\n## ``` bwk```\n\n\n**Constants:**\n\n* ```DEFAULT_WINDOW_BORDER```: a ```borderchar```string (see ```Border```object) which uses the solid line Unicode characters\n\n\n#### ``` def echo(str, end='', flush=False):```\n\n**Parameters:**\n\n* ```str```: the string to output\n* ```end```: a suffix to append to the string\n* ```flush```: whether or not to flush the buffer of the output stream\n\n\n\n A convenience method for working with _**Blessed**_ . This method will use the built-in Python ```print()```method but with the above parameters defaulted differently. It is intended to be used as a way to buffer output for the current outstream without flushing it.\n\n#### ``` def flush():```\n\n\n A convenience method which flushes the current output stream. Equivalent to ``` print('', end='', flush=True) ``` .\n\n#### ``` def window_shopper(termstuff, *args, **kwargs):```\n\n**Parameters:**\n\n* ```termstuff```: a function to execute within a _**Blessed**_ terminal context\n* ```args```: arguments to be passed to ```termstuff```\n* ```kwargs```: keyword arguments to be passed to ```termstuff```\n\n\n\n This method provides a default terminal context to preview window layouts. The terminal context provided is A fullscreen ```blessed.Terminal```with a hidden cursor. Pressing any key ends the terminal context.\n\n\n The ```termstuff```function must receive the ```Terminal```object as its first argument, it must include ```*args```and ```**kwargs```, and has no return value.\n\n```\ndef mywindowfunc(term, *args, **kwargs):\n # do window layout here\n\n```\n\n\n**NOTE:** The terminal context will automaticaly flush the stream, so you do not need to use the ```flush()```method, only ```echo()```.\n\n\n## ``` class Border:```\n\n\n\n A class for defining the borders of a ```Window```object.\n\n**Attributes:**\n\n* ```upper_left_corner```: ( **default:** ```''```)\n* ```top_border```: ( **default:** ```''```)\n* ```upper_right_corner```: ( **default:** ```''```)\n* ```right_border```: ( **default:** ```''```)\n* ```lower_right_corner```: ( **default:** ```''```)\n* ```bottom_border```: ( **default:** ```''```)\n* ```lower_left_corner```: ( **default:** ```''```)\n* ```left_border```: ( **default:** ```''```)\n\n\n#### ``` def __init__(self, borderchars=''):```\n\n**Parameters:**\n\n* ```borderchars```: a string of characters to use for the border\n\n\n\n Creates a new ```Border```object. The ```borderchars```string must be exactly 8 characters long. If it is not, then no border is used. The characters form the corners and sides starting with the upper left corner and going clockwise.\n\n\n **Example:** ```borderchars='1=2:3+4|```'\n\n```\n1=====2\n| :\n| :\n4+++++3\n\n```\n\n\n\n You can also directly alter any of the border characters via the object's attributes (see **Attributes** above)\n\n## ``` class Window:```\n\n\n\n A rectangular container for displaying content.\n\n**Constants:**\n\n* ```TITLE_ALIGNS```: A set of strings to identify the alignment of the window ```title```\n\n\n**Attributes:**\n\n* ```term```: the ```blessed.Terminal```object used for display\n* ```x```: the column of the terminal that the upper left corner is placed\n* ```y```: the row of the terminal that the upper left corner is placed\n* ```height```: the total height of the window (including the borders)\n* ```width```: the total width of the window (including borders)\n* ```border```: a ```Border```object which defines the border display of the window\n* ```title```: the title displayed at the top of the window\n* ```title_align```: the alignment of the ```title```\n* ```content```: a string of characters to display in the window\n\n\n**NOTE:** When a ```Window```is defined, there must be content added to it, either by setting the ```content```attribute directly, or by overriding the ```render_content()```method. The window is not buffered to the output stream unless the ```render()```method is called.\n\n\n#### ``` def __init__(self, term, x, y, height=None, width=None, fore_color=None, bg_color=None, border=DEFAULT_WINDOW_BORDER, title='', title_align='center'):```\n\n**Parameters:**\n\n* ```term```: the ```blessed.Terminal```object used for display\n* ```x```: the column of the terminal that the upper left corner is placed\n* ```y```: the row of the terminal that the upper left corner is placed\n* ```height```: the total height of the window (including the borders)\n* ```width```: the total width of the window (including borders)\n* ```fore_color```: _not yet implemented_\n* ```bg_color```: _not yet implemented_\n* ```border```: a ```borderchar```string or a ```Border```object\n* ```title```: the title displayed at the top of the window\n* ```title_align```: the alignment of the ```title```\n\n\n\n If ```height```or ```width```is not provided, then that dimension will stretch all the way to the edge of the terminal. If ```border```is set to ```None```, then no border will be drawn. The ```title```will not be displayed unless there is a ```border```with at least the ```top_border```attribute set. The ```title_align```string must be one of the following values: ```left```, ```center```, or ```right```.\n\n#### ``` def render(self):```\n\n\n Echoes the window to the output stream buffer (via the ```echo()```function). The content of the window is limited by the ```height```and ```width```of the window (minus the height and width of the border). Any characters which are beyond the dimensions of the window will not be displayed.\n\n#### ``` def render_content(self, max_width, max_height):```\n\n**Parameters:**\n\n* ```max_width```: the total width of the window (minus the width of the borders)\n* ```max_height```: the total height of the window (minus the height of the borders)\n\n\n**Returns:** A string or list of strings which will fit in the dimensions of the window.\n\n\n\n This method is provided to be overriden, either by overwriting the instance attrbute ```render_content```with a different function, or by overriding this function in a subclass. By default, this method simply returns the window's ```content```string.\n\n\n This method is called by the ```render()```method. If the return value is a string, ```render()```will iterate over the each line (delimited by a ```n```). If the return value is a list of strings, ```render()```will iterate over the list.\n\n# Blessed Window Kit Screen Tools (bwk.screen)\n\n\n An extension of the Blessed Window Kit (BWK) for quickly building Text-Based User Interface (TUI) applications.\n\n- Use in your project by importing the module:\n - ```import bwk.screen```\n\n\n## ``` class Screen:```\n\n\n\n A barebones implementation for rendering output to a terminal and processing input. This can be used with or without the BWK itself (see the ```ScreenManager```classes below).\n\n**Attributes:**\n\n* ```man```: a ```ScreenManager```which the sceen is associated to.\n* ```name```: the name of the screen\n* ```commands```: a dictionary of commands. Each value is a function which will execute when input matching its key is received by the screen.\n\n\n#### ``` def __init__(self, manager, name, commands={}):```\n\n**Parameters:**\n\n* ```man```: a ```ScreenManager```which the sceen is associated to.\n* ```name```: the name of the screen\n* ```commands```: a dictionary of commands. Each value is a function which will execute when input matching its key is received by the screen.\n\n\n#### ``` def set_commands(self):```\n\n\n Identify keystrokes which correlate with logic to trigger. This should be overridden in subclasses to set the keys used in that mode.\n\n\n For each keyboard key, set a string as the key in the ```self.commands```dictionary and the value as a method to call when the key is pressed. The method which is called is passed no arguments (except ```self```, if it is a class method).\n\n```\nself.commands['h'] = self.show_help\n\n```\n\n\n\n If the key is a Unicode printable character, such as a letter, number, or punctuation, use the string representation of that key.\n\n**NOTE:** The Space key is a printable character ( ```'```' ) and should be indicated as such.\n\n\n**NOTE:** If an uppercase (or otherwised altered via the Shift key, such as the symbols on number keys) is used, this will require the Shift key to be held when pressing the key to get a ppropriate result. This is an easy way to incorporate modifier keys by using Shift as the modifier.\n\n\n\n If the key is a non-printable character (such as the Backspace, Enter, Esc, F# keys), the name of the constant as defined in the Blessed documentation is used. See the documentation for a list of supported names: [https:blessed.readthedocs.io/en/latest/keyboard.html#keycodeshttps:blessed.readthedocs.io/en/latest/keyboard.html#keycodes](https:blessed.readthedocs.io/en/latest/keyboard.html#keycodes)\n\n**NOTE:** Keys on the numpad are different keycodes, and as such, they can only be identified by the name of their constant. All numpad key constants start with ```Key_KP_```. For example, ```9```on the numpad would be ```KEY_KP_9```.\n\n\n\n\n| Line | Key(s) |\n|---|---|\n| self.commands['h'] = self.show_help_ | ```H``` |\n| self.commands['H'] = self.show_help_ | ```Shift```+ ```H``` |\n| self.commands['KEY_ESCAPE'] = self.back | ```Esc``` |\n| self.commands['9'] = self.options | ```9``` |\n| self.commands['KEY_KP_9'] = self.options | ```9```on the numpad |\n| self.commands[' '] = self.select_item_ | ```Space``` |\n| self.commands['1'] = self.action_menu_ | ```1``` |\n| self.commands['!'] = self.second_menu_ | ```Shift```+ ```1``` |\n\n\n#### ``` def pre_process_input(self, userin):```\n\n**Parameters:**\n\n* ```userin```: the input received to the screen\n\n\n\n This method executes after a screen receives input, but before a matching command is executed.\n\n#### ``` def post_process_input(self, userin):```\n\n**Parameters:**\n\n* ```userin```: the input received to the screen\n\n\n\n This method executes after the input has been processed by the screen (which may be a command, or an error).\n\n#### ``` def process_input(self, userin):```\n\n**Parameters:**\n\n* ```userin```: the input received to the screen\n\n\n\n This is the main method which handles input to the screen. It executes the following steps in order:\n\n* ```self.pre_process_input(userin)```\n* if ```userin```matches a key in ```self.commands,```executes the corresponding function\n* if ```userin```does not match a key in ```self.commands,```executes ```self.process_input_error(userin)```\n* ```self.post_process_input(userin)```\n\n\n#### ``` def process_input_error(self, userin):```\n\n**Parameters:**\n\n* ```userin```: the input received to the screen\n\n\n\n This method executes when an input does not match any key in ```self.commands```.\n\n#### ``` def render(self):```\n\n\n This method will render the screen content to the terminal.\n\n## ``` class GenericScreenManager:```\n\n\n\n A barebones implementation for running an application loop with ```Screen```objects.\n\n**Attributes:**\n\n* ```running```: a boolean indicating if the run loop should continue\n* ```curr_screen```: the current ```Screen```object being used to render output and process input\n\n\n#### ``` def __init__(self):```\n\n\n Initializes the manager.\n\n#### ``` def pre_run(self):```\n\n\n This method executes before the run loop begins. Any necessary preparation before the application starts should be done here. By default it is empty and should be overridden as necessary.\n\n#### ``` def post_run(self):```\n\n\n This method executes after the run loop ends. Any necessary cleanup after the application has ended should be done here. By default it is empty and should be overridden as necessary.\n\n#### ``` def run(self):```\n\n\n This is the main entrypoint for the ```ScreenManager```. Execute this method to begin the application loop, including the ```pre_run()```and ```post_run()```methods.\n\n#### ``` def run_loop(self):```\n\n\n The actual implementation of the application loop. It executes the follwoing setps in order:\n\n* ```self.pre_render()```\n* ```self.render()```\n* ```self.pre_input()```\n* ```self.get_user_input()```\n* ```self.process_input(userin)```\n\n\n\n The above steps will continue to execute until ```self.running```is False or there is no ```self.curr_screen```set (meaning that there is no way to display output or process input).\n\n#### ``` def pre_render(self):```\n\n\n This method executes at the beginning of each iteration of the run loop before the screen is rendered. By default it is empty and should be overridden as necessary.\n\n#### ``` def render(self):```\n\n\n Renders output to the terminal. This is typically done via ```self.curr_screen.render()```.\n\n#### ``` def pre_input(self):```\n\n\n This method executes after each iteration of the render in the run loop, but before user input is received. By default it is empty and should be overridden as necessary.\n\n#### ``` def get_user_input(self):```\n\n\n Gets input from the user. This can be overriden for specific input types. By default, it uses Python's ```input()```method.\n\n#### ``` def process_input(self, userin):```\n\n**Parameters:**\n\n* ```userin```: the input received from the user\n\n\n\n Processes the input received from the user. This is typically done via ```self.curr_screen.process_input(userin)```.\n\n#### ``` def quit(self):```\n\n\n A convenience method for ending the application loop. By default, this simply sets ```self.running```to False.\n\n**Parameters:**\n\n* ```exc```: the ```Exception```raised during the application loop\n\n\n\n In the event that an exception is not caught during the application loop, the manager will gracefully catch the exception and handle it here. After this method executes, the ```post_run()```method executes, to ensure that all necessary cleanup is still performed despite the program crashing.\n\n## ``` class BwkScreenManager(GenericScreenManager):```\n\n\n\n A screen manager specifically for handling screens which utilize the Blessed Window Kit for rendering.\n\n**Attributes:**\n\n* ```running```: a boolean indicating if the run loop should continue\n* ```curr_screen```: the current ```Screen```object being used to render output and process input\n* ```term```: the ```blessed.Terminal```object used to render screens\n* ```auto_flush```: if set to ```True```, a ```bwk.flush()```is called after the current screen is rendered\n\n\n#### ``` def __init__(self, term=None, auto_flush=False):```\n\n**Parameters:**\n\n* ```term```: the ```blessed.Terminal```object used to render screens\n* ```auto_flush```: if set to ```True```, a ```bwk.flush()```is called after the current screen is rendered\n\n\n\n Initializes the screen manager. If no ```term```is provided, a default ```Terminal()```is used.\n\n#### ``` def run(self):```\n\n\n Overrides the original ```run()```with special context managers for BWK:\n\n* ```term.fullscreen```\n* ```term.cbreak```\n* ```term.hidden_cursor```\n\n\n\n This ensures that the application behaves similarly to the ```window_shopper()```method provided by the BWK to simplify building and managing screens.\n\n#### ``` def get_user_input(self):```\n\n\n Overrides this method to use the ```self.term.inkey()```method to get user input, rather than the default Python ```input()```method.\n\n#### ``` def process_input(self, userin):```\n\n\n Overrides this method to ensure that proper key name is sent to the screen's ```process_input()```method.\n\n#### ``` def render(self):```\n\n\n Renders output to the terminal. This is typically done via ```self.curr_screen.render()```. If ```self.auto_flush=True```, then a ```flush()```command is issued after the current screen is rendered.\n\n",
"bugtrack_url": null,
"license": "BSD-2-Clause",
"summary": "A simple Python windowing kit module for use with Blessed terminal formatting.",
"version": "1.1.0",
"project_urls": {
"Changelog": "https://gitlab.com/charles.w.koch/blessed-window-kit/-/blob/main/CHANGELOG.md",
"Homepage": "http://cerrax.com",
"Repository": "https://gitlab.com/charles.w.koch/blessed-window-kit"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2e5a1dbdc0a615d23de42330e0931b671bae3cae5875f156d82ad0ca1ce4dbaf",
"md5": "79266983708d5b1d715cb20cf48f752a",
"sha256": "cda0454c409aee39e85a8bb9e045a88a48b18c4f59df2ba967cb4e40de86a481"
},
"downloads": -1,
"filename": "bwk-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "79266983708d5b1d715cb20cf48f752a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 14078,
"upload_time": "2024-12-21T12:43:58",
"upload_time_iso_8601": "2024-12-21T12:43:58.476978Z",
"url": "https://files.pythonhosted.org/packages/2e/5a/1dbdc0a615d23de42330e0931b671bae3cae5875f156d82ad0ca1ce4dbaf/bwk-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1a873409302c48c821f560f6277633f8a27162ae83756d9f8c64a0db3563be9f",
"md5": "aec03117c1992b5d64e6d945c592607c",
"sha256": "0e3a842b2c8c7cd05ca5d24245a818315214fcca5cc5da114bac34215e594315"
},
"downloads": -1,
"filename": "bwk-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "aec03117c1992b5d64e6d945c592607c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 13864,
"upload_time": "2024-12-21T12:44:00",
"upload_time_iso_8601": "2024-12-21T12:44:00.807487Z",
"url": "https://files.pythonhosted.org/packages/1a/87/3409302c48c821f560f6277633f8a27162ae83756d9f8c64a0db3563be9f/bwk-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-21 12:44:00",
"github": false,
"gitlab": true,
"bitbucket": false,
"codeberg": false,
"gitlab_user": "charles.w.koch",
"gitlab_project": "blessed-window-kit",
"lcname": "bwk"
}