zensols.rend package¶
Submodules¶
zensols.rend.app module¶
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:
objectProbe screen, open and set the viewing application extends.
- __init__(browser_manager, width=None, height=None)¶
-
browser_manager:
BrowserManager¶ Detects and controls the screen.
- show(locations, location_type=None)[source]¶
Open and display a file with the application’s extents set for the display.
- Parameters:
location – the file(s) or URL(s) to display
location_type (
LocationType) – specify either a URL or file; determined by default
zensols.rend.browser module¶
Domain classes and the a screen manager class.
- class zensols.rend.browser.Browser(file_type_filter)[source]¶
Bases:
DictableAn abstract base class for browsers the can visually display files.
- __init__(file_type_filter)¶
- file_type_filter: FileTypeFilter¶
Filters locations either by file name or the contents of the file.
- 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:
objectManages 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
datacontent on the screen and optionally resize the window toextent.- Parameters:
data (
Union[str,Path,Presentation,Location,DataFrame,Sequence]) – the data (image file, URL, Pandas dataframe) to displayextent (
Extent) – the position and size of the window after browsing
- to_presentation(data, extent=None)[source]¶
Create a presentation instance from a string, path, or other presentation.
- Parameters:
data (
Union[str,Path,Presentation,Location,DataFrame,Sequence]) – the data (image file, URL, Pandas dataframe) to displayextent (
Extent) – the position and size of the window after browsing
- Return type:
-
transmuters:
tuple[LocationTransmuter,...]¶ A list of transmuters that map concrete locations to the ephemeral.
- class zensols.rend.browser.FileTypeFilter(name_regex, mime_regex)[source]¶
Bases:
DictableFilters locations either by file name or the contents of the file.
- __init__(name_regex, mime_regex)¶
- mime_regex: re.Pattern | str¶
A regular expression that matches mime types (determined by file content) to keep.
- name_regex: re.Pattern | str¶
A regular expression that matches locations to keep.
zensols.rend.cli module¶
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
- classmethod render(data)[source]¶
Render
datausingBrowserManager.show().
zensols.rend.darwin module¶
macOS bindings for displaying.
- exception zensols.rend.darwin.ApplescriptError[source]¶
Bases:
RenderFileErrorRaised for macOS errors.
- __firstlineno__ = 21¶
- __module__ = 'zensols.rend.darwin'¶
- __static_attributes__ = ()¶
- class zensols.rend.darwin.DarwinBrowser(file_type_filter, config_factory, script_paths, web_extensions, applescript_warns, update_page=False, switch_back_app=None, mangle_url=False, safari_always_reposition=True, safari_refresh=False)[source]¶
Bases:
BrowserA browser that uses Preview.app and Safari.app on macOS.
- __init__(file_type_filter, config_factory, script_paths, web_extensions, applescript_warns, update_page=False, switch_back_app=None, mangle_url=False, safari_always_reposition=True, safari_refresh=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
Browserinstance for URL viewing.
-
safari_always_reposition:
bool= True¶ Whether to always reposition and resize the Safari window when rerendering. If
False, the browser will only refresh when the same URL is rerendered.
-
safari_refresh:
bool= False¶ Whether to refresh the browser on update, which updates the content but does not change the position of the text in the window. Otherwise, the window is reset and then reloaded, which resets the window to the beginning of the HTML content.
-
script_paths:
dict[str,Path]¶ The applescript file paths used for managing show apps (
Preview.appandSafari.app).
-
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 module¶
Web browser default implementation.
zensols.rend.df module¶
Classes that render Pandas dataframes.
- class zensols.rend.df.CachedDataFrameSource(df, name=None)[source]¶
Bases:
DataFrameSourceReturns
dfas 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:
LocationTransmuterTransmutes locations to deallocatable
TerminalDashServerLocationinstances 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
TerminalDashServerentry.
-
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:
LocationLike
DataFrameLocationbut 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:
bool|None= None¶ Whether to render the dataframe using
formatted_dataframe. If not set, theDataDescriberLocationTransmuter.table_formatdefault 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='auto')[source]¶
Bases:
DashServerLocationTransmuterLike
DataFrameLocationTransmuterbut create server locations fromDataDescriberin memory instances.- __init__(config_factory, dash_server_name, layout_factory_name, start_port=8050, run_servers=True, table_format='auto')¶
-
table_format:
str|bool= 'auto'¶ Whether to render the dataframe using
formatted_dataframe.
- transmute(location)[source]¶
Transmute the location if possible. The subclass can eelect to replace
locationby returning a non-zero tuple of locations. Otherwiselocationwill be added to thePresentation.
- 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, column_meta_format='{c}: {v}', index_meta_format=None)[source]¶
Bases:
DataFrameLayoutFactoryA 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, column_meta_format='{c}: {v}', index_meta_format=None)¶
-
index_meta_format:
str= None¶ Used as the index metadata on
sourcewhen 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:
LayoutFactoryCreate 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:
LocationA 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:
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:
DashServerLocationTransmuterTransmutes spreadsheet like files (Excel, CSV, etc.) to deallocatable
TerminalDashServerLocationinstances that use a Dash server to render the data.- __init__(config_factory, dash_server_name, layout_factory_name, start_port=8050, run_servers=True)¶
- transmute(location)[source]¶
Transmute the location if possible. The subclass can eelect to replace
locationby returning a non-zero tuple of locations. Otherwiselocationwill be added to thePresentation.
- 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:
DataFrameLayoutFactoryUses a
DataFrameSourceto 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:
objectA factory class that creates a layout to be used with
dash.Dash. This is designed to be used byTerminalDashServerto render a page and then (optionally) quit for single use page rendering- __init__(title='Untitled', description=())¶
- abstract create_layout()[source]¶
Create the root application
divHTML element component.- Return type:
Div
- class zensols.rend.df.PathDataFrameSource(path, sheet_name=0)[source]¶
Bases:
DataFrameSourceReads a dataframe from a file.
- __init__(path, sheet_name=0)¶
-
path:
Path¶ The path to either an Excel, TSV, CSV file.
- class zensols.rend.df.TerminalDashServer(layout_factory, port, host='localhost', sleep_secs=1, timeout_secs=5)[source]¶
Bases:
objectA 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
Cfrom parent processP.Cstarts the Flask service, which binds to a port on localhost.The framework in
Pcontinues 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,
Pwaits for the child process via IPC.The terminate callback in
Csends a queue (IPC) message toP.Upon receiving this message, the
PterminatesC.
- __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,DeallocatableA location started by a
TerminalDashServerwhich 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 module¶
Contains application domain classes.
- class zensols.rend.domain.Display(width, height, name, target)[source]¶
Bases:
SizeThe 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:
SizeThe 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:
RenderFileErrorRaised when a location is a file, but the file isn’t found.
- __annotations__ = {}¶
- __firstlineno__ = 27¶
- __module__ = 'zensols.rend.domain'¶
- __static_attributes__ = ('path',)¶
- class zensols.rend.domain.Location(source, type=None)[source]¶
Bases:
PersistableContainer,DictableHas 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
pathwill 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:
objectTransmutes concrete locations to their ephemeral counterparts, which usually need additional resources.
- __init__()¶
- abstract transmute(location)[source]¶
Transmute the location if possible. The subclass can eelect to replace
locationby returning a non-zero tuple of locations. Otherwiselocationwill be added to thePresentation.
- class zensols.rend.domain.LocationType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
EnumIdentifies a URL or a file name.
- file = 1¶
- url = 2¶
- class zensols.rend.domain.Presentation(locations, extent=None)[source]¶
Bases:
PersistableContainer,DictableContains 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
zensols.rend.figure module¶
Figure rendering and transmuter.
- class zensols.rend.figure.FigureLocation(source, type=None, timeout_secs=0)[source]¶
Bases:
LocationA location that points to an image file. This location deletes the image when deallocated to clean up after rendering by the
FigureTransmuter.- __init__(source, type=None, timeout_secs=0)¶
-
timeout_secs:
float= 0¶ Wait time before the
sourcefile is deleted indeallocate().
- class zensols.rend.figure.FigureTransmuter(timeout_secs, figure_params)[source]¶
Bases:
LocationTransmuterTransmutes to rendered figure images.
- __init__(timeout_secs, figure_params)¶
- property renderable_factory: RenderableFactory¶
Creates instances of
Renderablefrom file paths.
- transmute(location)[source]¶
Transmute the location if possible. The subclass can eelect to replace
locationby returning a non-zero tuple of locations. Otherwiselocationwill be added to thePresentation.
zensols.rend.maptrans module¶
Mapped transmutator implementation.
- class zensols.rend.maptrans.MappedLocationTransmuter(trans_stash, transmuters)[source]¶
Bases:
LocationTransmuterA composite-like transmuter that uses other transmuters mapped from file names when
Location.has_pathisTrue.- __init__(trans_stash, transmuters)¶
-
trans_stash:
Stash¶ A stash that creates instances of
LocationTransmuter.
- transmute(location)[source]¶
Transmute the location if possible. The subclass can eelect to replace
locationby returning a non-zero tuple of locations. Otherwiselocationwill be added to thePresentation.
- class zensols.rend.maptrans.RegexFactoryStash(config_factory, pattern, exclude_keys=(), new_instance=False)[source]¶
Bases:
ReadOnlyStashA stash that loads configuration objects as loaded items.
- __init__(config_factory, pattern, exclude_keys=(), new_instance=False)¶
-
config_factory:
ConfigFactory¶ Creates config objects as loaded stash items..
- exists(name)[source]¶
Return
Trueif data with keynameexists.Implementation note: This
Stash.exists()method is very inefficient and should be overriden.- Return type:
- load(name)[source]¶
Load a data value from the pickled data with key
name. Semantically, this method loads the using the stash’s implementation. For exampleDirectoryStashloads the data from a file if it exists, but factory type stashes will always re-generate the data.- See:
get()- Return type:
-
new_instance:
bool= False¶ Use
new_instance()to create new instances (new instance every time) ifTrue. Otherwise, get singleton instances.