UI Module
This module is responsible for providing a high-level interface for elements of Curses UI and general user interaction with the app,
- class canopen_monitor.ui.Column(name: str, attr_name: str, fmt_fn: callable = <class 'str'>, padding: int = 2)[source]
-
- property header: str
- class canopen_monitor.ui.InputPopup(parent: any, header: str = 'Alert', footer: str = 'ESC: close', style: Optional[any] = None, input_len: int = 30)[source]
Input form creates a popup window for retrieving text input from the user
- Parameters
parent – parent ui element
header – header text of popup window
footer – footer text of popup window
style – style of window
input_len – Maximum length of input text
- Type
any
- Type
str
- Type
str
- Type
any
- Type
int
- _abc_impl = <_abc_data object>
- get_value() str [source]
Get the value of user input without trailing spaces :return: user input value :type: str
- class canopen_monitor.ui.MessagePane(cols: [Column], types: [MessageType], name: str = '', parent: any = None, height: int = 1, width: int = 1, y: int = 0, x: int = 0, message_table: MessageTable = <canopen_monitor.can.message_table.MessageTable object>)[source]
A derivative of Pane customized specifically to list miscellaneous CAN messages stored in a MessageTable
- Parameters
name (str) – The name of the pane (to be printed in the top left)
cols (dict) – A dictionary describing the pane layout. The key is the Pane collumn name, the value is a tuple containing the Message attribute to map the collumn to, and the max collumn width respectively.
selected (bool) – An indicator that the current Pane is selected
table (MessageTable) – The message table
- __check_col_widths(messages: [Message]) None
Check the width of the message in Pane column.
- Parameters
messages (list) – The list of the messages
- __draw_header() None
Draw the table header at the top of the Pane
This uses the cols dictionary to determine what to write
- _abc_impl = <_abc_data object>
- _reset_scroll_positions() None [source]
Reset the scroll positions. Initialize the y position to be zero. Initialize the x position to be zero.
- resize(height: int, width: int) None [source]
A wrapper for Pane.resize(). This intercepts a call for a resize in order to upate MessagePane-specific details that change on a resize event. The parent resize() gets called first and then MessagePane’s details are updated.
- Parameters
height (int) – New virtual height
width (int) – New virtual width
- scroll_down(rate: int = 1) None [source]
This overrides Pane.scroll_up(). Instead of shifting the pad vertically, the slice of messages from the MessageTable is shifted.
- Parameters
rate (int) – Number of messages to scroll by
- property scroll_limit_x: int
The maximim columns the pad is allowed to shift by when scrolling
- property scroll_limit_y: int
The maximim rows the pad is allowed to shift by when scrolling
- class canopen_monitor.ui.Pane(parent: Optional[any] = None, height: int = 1, width: int = 1, y: int = 0, x: int = 0, border: bool = True, color_pair: int = 0)[source]
Abstract Pane Class, contains a PAD and a window
- Parameters
v_height (int) – The virtual height of the embedded pad
v_width (int) – The virtual width of the embedded pad
d_height (int) – The drawn height of the embedded pad
d_width (int) – The drawn width of the embedded pad
border (bool) – A style option for drawing a border around the pane
- __reset_draw_dimensions() None
Reset the pane dimensions. You can change the width and height of the pane.
- _abc_impl = <_abc_data object>
- add_line(line: str, y: Optional[int] = None, x: Optional[int] = None, bold: bool = False, underline: bool = False, highlight: bool = False, color: Optional[any] = None) None [source]
Adds a line of text to the Pane and if needed, it handles the process of resizing the embedded pad
- Parameters
line (str) – Text to write to the Pane
y (int) – Line’s row position
x (int) – Line’s collumn position
bold (bool) – A style option to bold the line written
highlight (bool) – A syle option to highlight the line writte
style (curses.style) – A color option for the line
- clear() None [source]
Clear all contents of pad and parent window
Warning
This should only be used if an event changing the entire pane occurs. If used on every cycle, a flickering effect will occur, due to the slowness of the operation.
- clear_line(y: int, style: Optional[any] = None) None [source]
Clears a single line of the Pane
- Parameters
y (int) – The line to clear
style (int) – The background color to set when clearing the line
- abstract draw() None [source]
Abstract draw method, must be overwritten in child class draw should first resize the pad using: super().resize(w, h) then add content using: self._pad.addstr() then refresh using: super().refresh()
abstract method will clear and handle border
child class should also set _scroll_limit_x and _scroll_limit_y here
- resize(height: int, width: int) None [source]
Resize the virtual pad and change internal variables to reflect that
- Parameters
height (int) – New virtual height
width (int) – New virtual width
- scroll_down(rate: int = 1) bool [source]
Scroll pad downwards
Note
Scroll limit must be set by child class
- Parameters
rate (int) – Number of lines to scroll by
- Returns
Indication of whether a limit was reached. False indicates a limit was reached and the pane cannot be scrolled further in that direction
- Return type
bool
- scroll_left(rate: int = 1) bool [source]
Scroll pad left
Note
Scroll limit must be set by child class
- Parameters
rate (int) – Number of lines to scroll by
- Returns
Indication of whether a limit was reached. False indicates a limit was reached and the pane cannot be scrolled further in that direction
- Return type
bool
- property scroll_limit_x: int
Limit the scroll on the x axis
- property scroll_limit_y: int
Limit the scroll on the y axis
- scroll_right(rate: int = 1) bool [source]
Scroll pad right
Note
Scroll limit must be set by child class
- Parameters
rate (int) – Number of lines to scroll by
- Returns
Indication of whether a limit was reached. False indicates a limit was reached and the pane cannot be scrolled further in that direction
- Return type
bool
- scroll_up(rate: int = 1) bool [source]
Scroll pad upwards
Note
Scroll limit must be set by child class
- Parameters
rate (int) – Number of lines to scroll by
- Returns
Indication of whether a limit was reached. False indicates a limit was reached and the pane cannot be scrolled further in that direction
- Return type
bool
- class canopen_monitor.ui.PopupWindow(parent: any, header: str = 'Alert', content: [str] = [], footer: str = 'ESC: close', style: any = None)[source]
Add the footer to the window
- __draw_content()
Read each line of the content and add to the window
- __draw_header() None
Add the header line to the window
- _abc_impl = <_abc_data object>
- apply_line_to_content_array(content, i, line, mid)[source]
Apply the line break to the content array
- draw() None [source]
Abstract draw method, must be overwritten in child class draw should first resize the pad using: super().resize(w, h) then add content using: self._pad.addstr() then refresh using: super().refresh()
abstract method will clear and handle border
child class should also set _scroll_limit_x and _scroll_limit_y here
- class canopen_monitor.ui.SelectionPopup(parent: any, header: str = 'Alert', footer: str = 'ESC: close', style: Optional[any] = None)[source]
Input form creates a popup window for selecting from a list of options
- Parameters
parent – parent ui element
header – header text of popup window
footer – footer text of popup window
style – style of window
- Type
any
- Type
str
- Type
str
- Type
any
Add the footer to the window
- __draw_content() None
Read each line of the content and add to the window
- __draw_header() None
Add the header line to the window
- _abc_impl = <_abc_data object>
- draw() None [source]
Abstract draw method, must be overwritten in child class draw should first resize the pad using: super().resize(w, h) then add content using: self._pad.addstr() then refresh using: super().refresh()
abstract method will clear and handle border
child class should also set _scroll_limit_x and _scroll_limit_y here