zensols.rend package#
Submodules#
zensols.rend.app#
Invoke Preview.pp on macOS and set extents of based on screen profiles.
- class zensols.rend.app.Application(browser_manager, width=None, height=None)[source]#
Bases:
object
Probe screen, open and set the viewing application extends.
- __init__(browser_manager, width=None, height=None)#
-
browser_manager:
BrowserManager
# Detects and controls the screen.
- show(location, location_type=None, delimiter=',')[source]#
Open and display a file with the application’s extents set for the display.
- Parameters:
location (
str
) – the file or URL to displaylocation_type (
LocationType
) – specify either a URL or file; determined by defaultdelimiter (
str
) – the string used to split location strings
zensols.rend.browser#
Domain classes and the a screen manager class.
- class zensols.rend.browser.Browser[source]#
Bases:
Dictable
An abstract base class for browsers the can visually display files.
- __init__()#
- abstract show(presentation)[source]#
Display the content.
- Parameters:
presentation (
Presentation
) – the file/PDF (or image) to display
- class zensols.rend.browser.BrowserManager(config_factory, default_browser_name, browser=None, display_names=<factory>, transmuters=<factory>)[source]#
Bases:
object
Manages configured browsers and invoking them to display files and URLs. It also contains configuration for application extents based configured displays.
- __init__(config_factory, default_browser_name, browser=None, display_names=<factory>, transmuters=<factory>)#
-
config_factory:
ConfigFactory
# Set by the framework and used to get other configurations.
-
display_names:
Sequence
[str
]# The configured display names, used to fetch displays in the configuration.
- show(data, extent=None)[source]#
Display
data
content on the screen and optionally resize the window toextent
.
- to_presentation(data, extent=None, transmute=True)[source]#
Create a presentation instance from a string, path, or other presentation.
- Parameters:
data (Union[str, Path, Presentation, Location, DataFrame, List]) – the data (image file, URL, Pandas dataframe) to display
extent (Extent) – the position and size of the window after browsing
transmute (bool) – whether to apply :class:`.LocationTransmuter`s
- Return type:
Presentation
-
transmuters:
Tuple
[LocationTransmuter
]# A list of transmuters that map concrete locations to the ephemeral.
zensols.rend.cli#
Command line entry point to the application.
- class zensols.rend.cli.ApplicationFactory(*args, **kwargs)[source]#
Bases:
ApplicationFactory
- classmethod get_browser_manager(args=None)[source]#
Get a new instance of the browser manager.
- Return type:
- get_instance(args=None)[source]#
Create the invokable instance of the application.
- Parameters:
args (
Union
[List
[str
],str
]) – the arguments to the application; if this is a string, it will be converted to a list by splitting on whitespace; this defaults to the output of_get_default_args()
- Raises:
ActionCliError – for any missing data or misconfigurations
- Return type:
- Returns:
the invokable instance of the application
zensols.rend.darwin#
macOS bindings for displaying.
- exception zensols.rend.darwin.ApplescriptError[source]#
Bases:
RenderFileError
Raised for macOS errors.
- __module__ = 'zensols.rend.darwin'#
- class zensols.rend.darwin.DarwinBrowser(config_factory, script_paths, web_extensions, applescript_warns, update_page=False, switch_back_app=None, mangle_url=False)[source]#
Bases:
Browser
- __init__(config_factory, script_paths, web_extensions, applescript_warns, update_page=False, switch_back_app=None, mangle_url=False)#
-
applescript_warns:
Dict
[str
,str
]# A set of string warning messages to log instead raise as an
ApplicationError
.
-
config_factory:
ConfigFactory
# The configuration factory used to create a default
Browser
instance for URL viewing.
-
script_paths:
Dict
[str
,Path
]# The applescript file paths used for managing show apps (
Preview.app
andSafari.app
).
- show(presentation)[source]#
Display the content.
- Parameters:
presentation (
Presentation
) – the file/PDF (or image) to display
-
update_page:
Union
[bool
,int
] = False# How to update the page in Preview.app after the window displays. If
True
, then record page before refresh, then go to the page after rendered. This is helpful when the PDF has changed and preview goes back to the first page. If this is a number, then go to that page number in Preview.app.
zensols.rend.default#
Web browser default implementation.
zensols.rend.df#
Classes that render Pandas dataframes.
- class zensols.rend.df.CachedDataFrameSource(df, name=None)[source]#
Bases:
DataFrameSource
Returns
df
as the dataframe.- __init__(df, name=None)#
-
df:
DataFrame
# get_dataframe.
- Type:
The cached datagrame to return in meth
- class zensols.rend.df.DashServerLocationTransmuter(config_factory, dash_server_name, layout_factory_name, start_port=8050, run_servers=True)[source]#
Bases:
LocationTransmuter
Transmutes locations to deallocatable
TerminalDashServerLocation
instances that use a Dash server to render the data.- __init__(config_factory, dash_server_name, layout_factory_name, start_port=8050, run_servers=True)#
-
config_factory:
ConfigFactory
# Used to create layout factory instances of
DataFrameLocationTransmuter
.
-
dash_server_name:
str
# The app config section name of the dash server
TerminalDashServer
entry.
-
layout_factory_name:
str
# The app config section name of the
DataFrameLocationTransmuter
.
- class zensols.rend.df.DataDescriberLocation(source, type=None, table_format=None)[source]#
Bases:
Location
Like
DataFrameLocation
but renders additional tool tips from metadata in theDataDescriber
. Use this as a way to programmatically render data in Python applications.- __init__(source, type=None, table_format=None)#
-
source:
DataDescriber
# The used to as the source rather than
source
.
-
table_format:
Optional
[bool
] = None# Whether to render the dataframe using
formatted_dataframe
. If not set, theDataDescriberLocationTransmuter.table_format
default is used.
- validate()[source]#
Validate the location such as confirming file locations exist.
- Raises:
FileNotFoundError – if the location points to a non-existant file
- class zensols.rend.df.DataDescriberLocationTransmuter(config_factory, dash_server_name, layout_factory_name, start_port=8050, run_servers=True, table_format=False)[source]#
Bases:
DashServerLocationTransmuter
Like
DataFrameLocationTransmuter
but create server locations fromDataDescriber
in memory instances.- __init__(config_factory, dash_server_name, layout_factory_name, start_port=8050, run_servers=True, table_format=False)#
-
table_format:
bool
= False# Whether to render the dataframe using
formatted_dataframe
.
- class zensols.rend.df.DataFrameDescriberLayoutFactory(title=None, description=(), page_size=100, cell_wrap=False, column_deletable=True, column_sort=True, column_filterable=False, column_width_px=90, row_deletable=False, row_height_px=25, data_font_size=12, source=None, index_meta_format=None)[source]#
Bases:
DataFrameLayoutFactory
A layout that renderes data from a
DataFrameDescriber
.- __init__(title=None, description=(), page_size=100, cell_wrap=False, column_deletable=True, column_sort=True, column_filterable=False, column_width_px=90, row_deletable=False, row_height_px=25, data_font_size=12, source=None, index_meta_format=None)#
-
index_meta_format:
str
= None# Used as the index metadata on
source
when creating the dataframe withdf_with_index_meta()
.
-
source:
DataFrameDescriber
= None# The data source.
- class zensols.rend.df.DataFrameLayoutFactory(title='Untitled', description=(), page_size=100, cell_wrap=False, column_deletable=True, column_sort=True, column_filterable=False, column_width_px=90, row_deletable=False, row_height_px=25, data_font_size=12)[source]#
Bases:
LayoutFactory
Create a layout with a top title and a resizable
DataTable
. The layout optionally creates a callback that is used to terminate theTerminalDashServer
.- __init__(title='Untitled', description=(), page_size=100, cell_wrap=False, column_deletable=True, column_sort=True, column_filterable=False, column_width_px=90, row_deletable=False, row_height_px=25, data_font_size=12)#
- class zensols.rend.df.DataFrameLocation(source, type=None)[source]#
Bases:
Location
A location of an in memory Pandas dataframe of
DataFrameSource
. Use this as a way to programmatically render data in Python applications.- __init__(source, type=None)#
-
source:
Union
[DataFrame
,DataFrameSource
]# The used to as the source rather than
source
.
- validate()[source]#
Validate the location such as confirming file locations exist.
- Raises:
FileNotFoundError – if the location points to a non-existant file
- class zensols.rend.df.DataFrameLocationTransmuter(config_factory, dash_server_name, layout_factory_name, start_port=8050, run_servers=True)[source]#
Bases:
DashServerLocationTransmuter
Transmutes spreadsheet like files (Excel, CSV, etc.) to deallocatable
TerminalDashServerLocation
instances that use a Dash server to render the data.- __init__(config_factory, dash_server_name, layout_factory_name, start_port=8050, run_servers=True)#
- class zensols.rend.df.DataSourceFrameLayoutFactory(title='Untitled', description=(), page_size=100, cell_wrap=False, column_deletable=True, column_sort=True, column_filterable=False, column_width_px=90, row_deletable=False, row_height_px=25, data_font_size=12, source=None)[source]#
Bases:
DataFrameLayoutFactory
Uses a
DataFrameSource
to create the dataframe.- __init__(title='Untitled', description=(), page_size=100, cell_wrap=False, column_deletable=True, column_sort=True, column_filterable=False, column_width_px=90, row_deletable=False, row_height_px=25, data_font_size=12, source=None)#
-
source:
DataFrameSource
= None# The dataframe source used to create the frame for the data.
- class zensols.rend.df.LayoutFactory(title='Untitled', description=())[source]#
Bases:
object
A factory class that creates a layout to be used with
dash.Dash
. This is designed to be used byTerminalDashServer
to render a page and then (optionally) quit for single use page rendering- __init__(title='Untitled', description=())#
- abstract create_layout()[source]#
Create the root application
div
HTML element component.- Return type:
Div
- class zensols.rend.df.PathDataFrameSource(path, sheet_name=0)[source]#
Bases:
DataFrameSource
Reads a dataframe from a file.
- __init__(path, sheet_name=0)#
- classmethod is_supported_extension(ext)[source]#
Return whether the file extesion
ext
is supported by this class.- Return type:
- class zensols.rend.df.TerminalDashServer(layout_factory, port, host='localhost', sleep_secs=1, timeout_secs=5)[source]#
Bases:
object
A server that takes a single incoming request, renderes the client’s page, the exists the interpreter. This server can continue to run to serve requests without a terminating callback. The lifecycle includes:
Create a multiprocessing queue.
Fork a child process
C
from parent processP
.C
starts the Flask service, which binds to a port on localhost.The framework in
P
continues to renderer any other queued data.The client browser creates a single request to render the Dash data.
Once the browser renders, a callback indicates to terminate the server.
After rendering all data,
P
waits for the child process via IPC.The terminate callback in
C
sends a queue (IPC) message toP
.Upon receiving this message, the
P
terminatesC
.
- __init__(layout_factory, port, host='localhost', sleep_secs=1, timeout_secs=5)#
-
layout_factory:
LayoutFactory
# The layout to use for the page and callback to exit.
- shutdown(timeout_secs=None)[source]#
Optionally wait, and then kill the child server processes.
- Parameters:
timeout_secs (
float
) – the number of seconds to wait before the server subprocess is killed
-
sleep_secs:
float
= 1# The time to wait and allow the Dash server to start and the URL available for the browser.
- class zensols.rend.df.TerminalDashServerLocation(source, type=None, server=None)[source]#
Bases:
Location
,Deallocatable
A location started by a
TerminalDashServer
which waits and kills the child process when it is complete during deallocation.- See:
- __init__(source, type=None, server=None)#
-
server:
TerminalDashServer
= None# The server used to render this location.
zensols.rend.domain#
Contains application domain classes.
- class zensols.rend.domain.Display(width, height, name, target)[source]#
Bases:
Size
The screen display.
- __init__(width, height, name, target)#
- name: str#
The name of the display as the section name in the configuration.
- target: Extent#
The extends of the display or what to use for the Preview app.
- class zensols.rend.domain.Extent(width, height, x=0, y=0)[source]#
Bases:
Size
The size (parent class) and the position of the screen.
- __init__(width, height, x=0, y=0)#
- x: int = 0#
- y: int = 0#
- exception zensols.rend.domain.FileNotFoundError(path)[source]#
Bases:
RenderFileError
Raised when a location is a file, but the file isn’t found.
- __annotations__ = {}#
- __module__ = 'zensols.rend.domain'#
- class zensols.rend.domain.Location(source, type=None)[source]#
Bases:
PersistableContainer
,Dictable
Has the ability to find the data and how to view it.
Important: All instances of this class must be deallocated using
deallocate()
. Failure to do so will result in Python interpreter hanging on exit.- __init__(source, type=None)#
- coerce_type(location_type)[source]#
Change to the location from a file to a URL or vica versa if possible.
- property has_path: bool#
Whether this location has a path and that access to
path
will not raise an error.
- property path: Path#
The path of the location.
- Raises:
RenderFileError – if the location does not point to a path or not a URL path
- source: Union[str, Path]#
Where to find the data to display.
- type: LocationType = None#
The type of resource (PDF or URL) to display.
- validate()[source]#
Validate the location such as confirming file locations exist.
- Raises:
FileNotFoundError – if the location points to a non-existant file
- class zensols.rend.domain.LocationTransmuter[source]#
Bases:
object
Transmutes concrete locations to their ephemeral counterparts, which usually need additional resources.
- __init__()#
- class zensols.rend.domain.LocationType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
Enum
Identifies a URL or a file name.
- file = 1#
- url = 2#
- class zensols.rend.domain.Presentation(locations, extent=None)[source]#
Bases:
PersistableContainer
,Dictable
Contains all the data to view all at once and where on the screen to display it.
Important: All instances of this class must be deallocated using
deallocate()
. Failure to do so will result in Python interpreter hanging on exit. Only a deallocation of objects of this class are necessary, and not containedLocation
.- __init__(locations, extent=None)#
- extent: Extent = None#
Where to display the content.
- static from_str(location_defs, delimiter=',', extent=None)[source]#
Create a presentation from a comma-delimited list of locations.
- Return type:
- property location_type_set: Set[LocationType]#
A set of
locations
.
- locations: Tuple[Location]#
The locations of the content to display