jvconnected.ui.tools
These modules contain tools used to build resources and other items to be included in released packages. They are not necessary for running the project itself.
jvconnected.ui.tools.build_qrc
Generate resources needed for the UI and compile them using the Qt Resouce System
- jvconnected.ui.tools.build_qrc.rcc(qrc_file: Path, rc_script: Path)[source]
Run pyside2-rcc, the PySide2 wrapper for rcc to compile resources into a python module
- Parameters
qrc_file (pathlib.Path) – The qrc filename containing resource definitions
rc_script (pathlib.Path) – The filename for the python module to generate
- jvconnected.ui.tools.build_qrc.build_images(qrc_file: Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/jvconnected/envs/latest/lib/python3.8/site-packages/jvconnected/ui/images.qrc'), img_dir: Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/jvconnected/envs/latest/lib/python3.8/site-packages/jvconnected/ui/img'), qrc_script: Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/jvconnected/envs/latest/lib/python3.8/site-packages/jvconnected/ui/rc_images.py'), build_rcc: bool = True, sizes: Sequence[int] = (64, 128, 256))[source]
Generate and/or compile the YUV plane images used for the white balance paint control
- Parameters
qrc_file (pathlib.Path) – The qrc filename to register the images in
img_dir (pathlib.Path) – Directory to build images in
qrc_script (pathlib.Path) – Filename for script to generate (if
build_rccisTrue)build_rcc (bool) – If True, compile the resources to a Python module using
rcc()sizes (Sequence[int]) – The image sizes to create
- jvconnected.ui.tools.build_qrc.pack_qml(qrc_file: Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/jvconnected/envs/latest/lib/python3.8/site-packages/jvconnected/ui/qml.qrc'), qml_dir: Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/jvconnected/envs/latest/lib/python3.8/site-packages/jvconnected/ui/qml'), qrc_script: Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/jvconnected/envs/latest/lib/python3.8/site-packages/jvconnected/ui/rc_qml.py'), build_rcc: bool = True)[source]
Find all qml files found in the given directory then add definitions for them in the given qrc file.
- Parameters
qrc_file (pathlib.Path) – The qrc filename to register the files in
qml_dir (pathlib.Path) – The root directory containing qml files
qrc_script (pathlib.Path) – Filename for script to generate (if
build_rccisTrue)build_rcc (bool) – If True, compile the resources to a Python module using
rcc()
- jvconnected.ui.tools.build_qrc.build_style(conf_file: Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/jvconnected/envs/latest/lib/python3.8/site-packages/jvconnected/ui/qtquickcontrols2.conf'), qrc_file: Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/jvconnected/envs/latest/lib/python3.8/site-packages/jvconnected/ui/style.qrc'), qrc_script: Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/jvconnected/envs/latest/lib/python3.8/site-packages/jvconnected/ui/rc_style.py'))[source]
Build the Qt Quick Controls Configuration File into the Qt Resouce System
- class jvconnected.ui.tools.build_qrc.BuildQRC(dist, **kw)[source]
Bases:
Command- initialize_options()[source]
Set default values for all the options that this command supports. Note that these defaults may be overridden by other commands, by the setup script, by config files, or by the command-line. Thus, this is not the place to code dependencies between options; generally, ‘initialize_options()’ implementations are just a bunch of “self.foo = None” assignments.
This method must be implemented by all command classes.
- finalize_options()[source]
Set final values for all the options that this command supports. This is always called as late as possible, ie. after any option assignments from the command-line or from other commands have been done. Thus, this is the place to code option dependencies: if ‘foo’ depends on ‘bar’, then it is safe to set ‘foo’ from ‘bar’ as long as ‘foo’ still has the same value it was assigned in ‘initialize_options()’.
This method must be implemented by all command classes.
- run()[source]
A command’s raison d’etre: carry out the action it exists to perform, controlled by the options initialized in ‘initialize_options()’, customized by other commands, the setup script, the command-line, and config files, and finalized in ‘finalize_options()’. All terminal output and filesystem interaction should be done by ‘run()’.
This method must be implemented by all command classes.
jvconnected.ui.tools.qrc_utils
- jvconnected.ui.tools.qrc_utils.HASH_ALGO = 'sha1'
The
hashlibalgorithm to use for creating file hashes
- class jvconnected.ui.tools.qrc_utils.QRCElement(**kwargs)[source]
Bases:
objectAn element within a QRC document tree
- parent
The parent element. If this element is the document root, this is
None- Type
QRCElement, optional
- element
The
xml.etree.ElementTree.Elementassociated with this element- Type
ET.Element
- children
Direct descendants of this element
- Type
List[QRCElement]
- write(filename: Path)[source]
Save the contents of
tostring()as a QRC fileNote
This may only be called on the root element
- classmethod create(**kwargs) QRCElement[source]
Create an instance of
QRCElementThe subclass will be chosen using the given element or tag keyword arguments
- Keyword Arguments
element (ET.Element, optional) – If provided, an instance of
xml.etree.ElementTree.Elementto use as the root elementtag (str, optional) – If no element is provided, this will be the tag name of the root element. If both
elementandtagareNone, theTAGattribute of the class will be used.
- classmethod cls_for_tag(tag: str)[source]
Find a subclass of
QRCElementmatching the given tag
- property root_element: QRCElement
The root of the tree
- property attrib: Dict
The element
attributes
- add_child(**kwargs) QRCElement[source]
Create a child instance using
create()and add it to this element’schildren
- remove_child(child: QRCElement)[source]
Remove an child element the tree
- walk() Iterator[QRCElement][source]
Iterate over this element and all of its descendants
- class jvconnected.ui.tools.qrc_utils.QRCDocument(**kwargs)[source]
Bases:
QRCElementA
QRCElementsubclass to be used as the document root- Keyword Arguments
base_path (pathlib.Path) – The filesystem path representing the root directory for the document (usually the document’s directory)
- classmethod from_file(filename: Path) QRCDocument[source]
Create a tree from an existing qrc file
- hashes_match() bool[source]
Determine if the contents defined within the document have changed on the local filesystem
Compares the
current_hashagainst the result ofhash_contents()
- add_file(filename: Path, prefix: Optional[str] = None, **kwargs) QRCFile[source]
Add a
QRCFileto the document if it does not currently exist- Parameters
filename (pathlib.Path) – The filename to add
prefix (str, optional) – The
prefixto use for theQRCResource. If not given, it will default to"/"**kwargs – Extra keyword arguments to pass to the
QRCFilecreation
- find_resource(prefix: str) Optional[QRCResource][source]
Search for a
QRCResourcematching the given prefixIf one is not found,
Nonewill be returned
- search_for_file(filename: Path) Optional[QRCFile][source]
Search for the
QRCFileelement matching the given filename
- remove_missing_files() List[QRCFile][source]
Find and remove any
QRCFileelements whose filenames do not currently exist in the filesystem.The elements that were removed (if any) are returned
- iter_resources() Iterator[QRCResource][source]
Iterate over child
QRCResourceinstances
- iter_files(missing_ok: bool = True) Iterator[QRCFile][source]
Iterate through all
QRCFileinstances in the tree
- hash_contents() str[source]
Create a single hash from all
QRCFiledata on the local filesystem usingQRCFile.hash_contents()
- class jvconnected.ui.tools.qrc_utils.QRCResource(**kwargs)[source]
Bases:
QRCElementA
QRCElementsubclass representing a qresource element- property prefix
The prefix to be used for all children of this
qresource.This only affects the way the child resources are accessed from within the Qt Resource System and has no impact on local file paths.
- add_file(filename: Path, **kwargs) QRCFile[source]
Add a
QRCFileto the resource if it does not currently exist- Parameters
filename (pathlib.Path) – The filename to add
**kwargs – Extra keyword arguments to pass to the
QRCFilecreation
- normailize_child_filename(filename: Path) Path[source]
Translate the given path to be relative to the
base_path.If the filename given is not absolute, the
base_pathwill be prepended to it.
- class jvconnected.ui.tools.qrc_utils.QRCFile(**kwargs)[source]
Bases:
QRCElementA
QRCElementsubclass representing a file resource- Keyword Arguments
filename – See
filenamefilename_abs – See
filename_absalias – See
alias
Note
Only one of the filename arguments may be present as keyword arguments
- property filename: Path
The filename as a
pathlib.Path(relative to the parentQRCResource)
- property filename_abs: Path
Absolute filename including the parent
base_pathWhen set, the
filenamewill be updated usingnormailize_child_filename()
- property alias: Optional[str]
The file alias as described in the qrc documentation
jvconnected.ui.tools.colorgradients
- jvconnected.ui.tools.colorgradients.build_wb_img(width: int = 64) ndarray[source]
Generate RGB pixel data for a YUV color plane
- Parameters
width (int) – The size of the output array along the first axis. This will also be used for “height”
- Returns
- The output data with shape
(width, height, 3)where the last axis contains the color values as floats (0..1) of red, green and blue
- The output data with shape
- Return type
- jvconnected.ui.tools.colorgradients.build_wb_img_file(filename: Path, width: int = 64)[source]
Build a YUV color plane using
build_wb_img()and save it as an image file.- Parameters
filename (pathlib.Path) – The filename for the output image. The image type will be determined from the extension as described in
PIL.Image.Image.save()width (int) – The image width (and height)
jvconnected.ui.tools.fontawesome
- class jvconnected.ui.tools.fontawesome.FaDownload(url: Optional[str] = None)[source]
Bases:
objectContext manager to download a fontawesome archive to a temporary directory
- root: Optional[Path] = None
Root of the temporary directory. Will be
Noneuntil the context is acquired
- archive_dir: Optional[Path] = None
The root of the extracted
archive_file
- class jvconnected.ui.tools.fontawesome.Style(value)[source]
Bases:
FlagFlags to indicate which styles are available for
Icon- NONE = 1
No value, used as a default
- BRANDS = 2
Brands style
- REGULAR = 4
Regular style
- SOLID = 8
Solid style
- ALL = 14
All styles
- class jvconnected.ui.tools.fontawesome.Category(name: str, label: str, icon_names: ~typing.List[str] = <factory>, icons: ~typing.Dict[str, ~jvconnected.ui.tools.fontawesome.Icon] = <factory>)[source]
Bases:
objectCategory assigned to
Icon
- class jvconnected.ui.tools.fontawesome.Icon(name: str, label: str, code_point: str, styles: ~jvconnected.ui.tools.fontawesome.Style = Style.NONE, category_names: set = <factory>)[source]
Bases:
objectAn icon (svg) file
- get_svgs(icon_root: Path, styles: Optional[Style] = None) Iterable[Tuple[Style, Path]][source]
Get icon svg filenames matching the given
Styleflags.- Parameters
- Yields
style (
Style) – style flag for the filenamefilename (
pathlib.Path) – The svg filename withinicon_root
- get_svg(icon_root: Path, style: Style) Path[source]
Get the icon svg filename with the given style
- Parameters
- Raises
ValueError – if the given style is invalid (
Style.NONEorStyle.ALL) or the icon is not available in the style
- copy_to_icon_dir(icon_root: Path, dest: Path, styles: Optional[Style] = None) Iterable[Tuple[Style, Path]][source]
Copy the icon svg file into the given destination, maintaining the relative sub-directories
- Parameters
- Yields
style (
Style) – style flag for the filenamefilename (
pathlib.Path) – The svg filename withinicon_root
- jvconnected.ui.tools.fontawesome.parse_categories(metadata_dir: Path, icons: Dict[str, Icon]) Dict[str, Category][source]
Parse icon categories from the fontawesome metadata
- jvconnected.ui.tools.fontawesome.parse_icons(metadata_dir: Path) Dict[str, Icon][source]
Parse icons from the fontawesome metadata
- jvconnected.ui.tools.fontawesome.parse_all(metadata_dir: Path) Tuple[Dict[str, Icon], Dict[str, Category]][source]
Parse icons and categories using
parse_icons()andparse_categories()
- jvconnected.ui.tools.fontawesome.build_qml_names(icons: Dict[str, Icon], outfile: Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/jvconnected/envs/latest/lib/python3.8/site-packages/jvconnected/ui/qml/Fonts/IconFontNames.qml'), qtquick_version: str = '2.15')[source]
Generate a qml document mapping icon names to their
Icon.code_point
- jvconnected.ui.tools.fontawesome.build_theme(fa_root: Path, theme_name: str, category_names: Optional[Sequence[str]] = None)[source]
Copy and process fontawesome resources and prep them for the Qt Resouce System
- Parameters
fa_root (Path) – Root directory of the unpacked fontawesome archive (
FaDownload.archive_dir)theme_name (str) – The name of the icon theme to generate formatted according to the freedesktop specification
category_names (Optional[Sequence[str]]) – A list of fontawesome categories to include. If not provided, use all available categories.