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: pathlib.Path, rc_script: pathlib.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: pathlib.Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/jvconnected/envs/latest/lib/python3.7/site-packages/jvconnected-0.0.1-py3.7.egg/jvconnected/ui/images.qrc'), img_dir: pathlib.Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/jvconnected/envs/latest/lib/python3.7/site-packages/jvconnected-0.0.1-py3.7.egg/jvconnected/ui/img'), qrc_script: pathlib.Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/jvconnected/envs/latest/lib/python3.7/site-packages/jvconnected-0.0.1-py3.7.egg/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_rcc is True)

  • 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: pathlib.Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/jvconnected/envs/latest/lib/python3.7/site-packages/jvconnected-0.0.1-py3.7.egg/jvconnected/ui/qml.qrc'), qml_dir: pathlib.Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/jvconnected/envs/latest/lib/python3.7/site-packages/jvconnected-0.0.1-py3.7.egg/jvconnected/ui/qml'), qrc_script: pathlib.Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/jvconnected/envs/latest/lib/python3.7/site-packages/jvconnected-0.0.1-py3.7.egg/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_rcc is True)

  • build_rcc (bool) – If True, compile the resources to a Python module using rcc()

jvconnected.ui.tools.build_qrc.build_style(conf_file: pathlib.Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/jvconnected/envs/latest/lib/python3.7/site-packages/jvconnected-0.0.1-py3.7.egg/jvconnected/ui/qtquickcontrols2.conf'), qrc_file: pathlib.Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/jvconnected/envs/latest/lib/python3.7/site-packages/jvconnected-0.0.1-py3.7.egg/jvconnected/ui/style.qrc'), qrc_script: pathlib.Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/jvconnected/envs/latest/lib/python3.7/site-packages/jvconnected-0.0.1-py3.7.egg/jvconnected/ui/rc_style.py'))[source]

Build the Qt Quick Controls Configuration File into the Qt Resouce System

Parameters
  • conf_file – The configuration file

  • qrc_file – The qrc filename to register the config file in

  • qrc_script – Filename for the rcc() script to generate

class jvconnected.ui.tools.build_qrc.BuildQRC(dist, **kw)[source]

Bases: setuptools.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 hashlib algorithm to use for creating file hashes

class jvconnected.ui.tools.qrc_utils.QRCElement(**kwargs)[source]

Bases: object

An element within a QRC document tree

Attributes
  • parent (QRCElement, optional) – The parent element. If this element is the document root, this is None

  • element (ET.Element) – The xml.etree.ElementTree.Element associated with this element

  • children (List[QRCElement]) – Direct descendants of this element

TAG: ClassVar[Optional[str]] = None

The default tag name

tostring() str[source]

Build the XML representation of the tree

write(filename: pathlib.Path)[source]

Save the contents of tostring() as a QRC file

Note

This may only be called on the root element

classmethod create(**kwargs) jvconnected.ui.tools.qrc_utils.QRCElement[source]

Create an instance of QRCElement

The 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.Element to use as the root element

  • tag (str, optional) – If no element is provided, this will be the tag name of the root element. If both element and tag are None, the TAG attribute of the class will be used.

classmethod cls_for_tag(tag: str)[source]

Find a subclass of QRCElement matching the given tag

property root_element QRCElement   [read-only]

The root of the tree

property tag str   [read-only]

The tag name of the element

property attrib typing.Dict   [read-only]

The element attributes

property text

The element text

add_child(**kwargs) jvconnected.ui.tools.qrc_utils.QRCElement[source]

Create a child instance using create() and add it to this element’s children

remove_child(child: jvconnected.ui.tools.qrc_utils.QRCElement)[source]

Remove an child element the tree

walk() Iterator[jvconnected.ui.tools.qrc_utils.QRCElement][source]

Iterate over this element and all of its descendants

class jvconnected.ui.tools.qrc_utils.QRCDocument(**kwargs)[source]

Bases: jvconnected.ui.tools.qrc_utils.QRCElement

A QRCElement subclass 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)

TAG: ClassVar[str] = 'RCC'

The default tag name

classmethod from_file(filename: pathlib.Path) jvconnected.ui.tools.qrc_utils.QRCDocument[source]

Create a tree from an existing qrc file

property current_hash typing.Union[str, NoneType]

The hash of the contents when the qrc file was last saved

hashes_match() bool[source]

Determine if the contents defined within the document have changed on the local filesystem

Compares the current_hash against the result of hash_contents()

add_file(filename: pathlib.Path, prefix: Optional[str] = None, **kwargs) jvconnected.ui.tools.qrc_utils.QRCFile[source]

Add a QRCFile to the document if it does not currently exist

Parameters
  • filename (pathlib.Path) – The filename to add

  • prefix (str, optional) – The prefix to use for the QRCResource. If not given, it will default to "/"

  • **kwargs – Extra keyword arguments to pass to the QRCFile creation

find_resource(prefix: str) Optional[jvconnected.ui.tools.qrc_utils.QRCResource][source]

Search for a QRCResource matching the given prefix

If one is not found, None will be returned

search_for_file(filename: pathlib.Path) Optional[jvconnected.ui.tools.qrc_utils.QRCFile][source]

Search for the QRCFile element matching the given filename

remove_missing_files() List[jvconnected.ui.tools.qrc_utils.QRCFile][source]

Find and remove any QRCFile elements whose filenames do not currently exist in the filesystem.

The elements that were removed (if any) are returned

iter_resources() Iterator[jvconnected.ui.tools.qrc_utils.QRCResource][source]

Iterate over child QRCResource instances

iter_files() Iterator[jvconnected.ui.tools.qrc_utils.QRCFile][source]

Iterate through all QRCFile instances in the tree

hash_contents() str[source]

Create a single hash from all QRCFile data on the local filesystem using QRCFile.hash_contents()

tostring() str[source]

Build the XML representation of the tree

class jvconnected.ui.tools.qrc_utils.QRCResource(**kwargs)[source]

Bases: jvconnected.ui.tools.qrc_utils.QRCElement

A QRCElement subclass representing a qresource element

TAG: ClassVar[str] = 'qresource'

The default tag name

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.

property path Path   [read-only]

Alias for base_path of the root_element

add_file(filename: pathlib.Path, **kwargs) jvconnected.ui.tools.qrc_utils.QRCFile[source]

Add a QRCFile to the resource if it does not currently exist

Parameters
  • filename (pathlib.Path) – The filename to add

  • **kwargs – Extra keyword arguments to pass to the QRCFile creation

normailize_child_filename(filename: pathlib.Path) pathlib.Path[source]

Translate the given path to be relative to the base_path.

If the filename given is not absolute, the base_path will be prepended to it.

search_for_file(filename: pathlib.Path) Optional[jvconnected.ui.tools.qrc_utils.QRCFile][source]

Search within this qresource for the QRCFile element matching the given filename

iter_files() Iterator[jvconnected.ui.tools.qrc_utils.QRCFile][source]

Iterate over all QRCFile instances within this qresource

class jvconnected.ui.tools.qrc_utils.QRCFile(**kwargs)[source]

Bases: jvconnected.ui.tools.qrc_utils.QRCElement

A QRCElement subclass representing a file resource

Keyword Arguments

Note

Only one of the filename arguments may be present as keyword arguments

TAG: ClassVar[str] = 'file'

The default tag name

property filename Path

The filename as a pathlib.Path (relative to the parent QRCResource)

property filename_abs Path

Absolute filename including the parent base_path

When set, the filename will be updated using normailize_child_filename()

property alias typing.Union[str, NoneType]

The file alias as described in the qrc documentation

exists() bool[source]

Returns whether the file exists in the filesystem

hash_contents() str[source]

Create a hash of the file data using hashlib algorithm defined by HASH_ALGO

jvconnected.ui.tools.colorgradients

jvconnected.ui.tools.colorgradients.build_wb_img(width: int = 64) numpy.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

Return type

numpy.ndarray

jvconnected.ui.tools.colorgradients.build_wb_img_file(filename: pathlib.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: object

Context manager to download a fontawesome archive to a temporary directory

root: Optional[pathlib.Path] = None

Root of the temporary directory. Will be None until the context is acquired

archive_file: Optional[pathlib.Path] = None

Path of the archive file once it has been downloaded

archive_dir: Optional[pathlib.Path] = None

The root of the extracted archive_file

url: str = 'https://use.fontawesome.com/releases/v5.15.2/fontawesome-free-5.15.2-desktop.zip'

The url of the archive to download

class jvconnected.ui.tools.fontawesome.Style(value)[source]

Bases: enum.Flag

Flags 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: List[str] = <factory>, icons: Dict[str, jvconnected.ui.tools.fontawesome.Icon] = <factory>)[source]

Bases: object

Category assigned to Icon

name: str

Category name

label: str

Category label

icon_names: List[str]

The icon names in the category

icons: Dict[str, jvconnected.ui.tools.fontawesome.Icon]

Mapping of icon names to Icon instances

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: object

An icon (svg) file

name: str

Icon name

label: str

Icon label

code_point: str

Unicode value for the icon

styles: jvconnected.ui.tools.fontawesome.Style = 1

Indicates the styles available

category_names: set

Names of Category the icon belongs to

add_to_category(category: jvconnected.ui.tools.fontawesome.Category)[source]

Add the icon to the given Category

get_svgs(icon_root: pathlib.Path, styles: Optional[jvconnected.ui.tools.fontawesome.Style] = None) Iterable[Tuple[jvconnected.ui.tools.fontawesome.Style, pathlib.Path]][source]

Get icon svg filenames matching the given Style flags.

Parameters
  • icon_root – The directory containing all icon subdirectories ('svgs' within the fontawesome root)

  • styles – The Style flags to filter by. If not given, the instance styles will be used.

Yields
  • style (Style) – style flag for the filename

  • filename (pathlib.Path) – The svg filename within icon_root

get_svg(icon_root: pathlib.Path, style: jvconnected.ui.tools.fontawesome.Style) pathlib.Path[source]

Get the icon svg filename with the given style

Parameters
  • icon_root – The directory containing all icon subdirectories ('svgs' within the fontawesome root)

  • style – The style flag

Raises

ValueError – if the given style is invalid (Style.NONE or Style.ALL) or the icon is not available in the style

copy_to_icon_dir(icon_root: pathlib.Path, dest: pathlib.Path, styles: Optional[jvconnected.ui.tools.fontawesome.Style] = None) Iterable[Tuple[jvconnected.ui.tools.fontawesome.Style, pathlib.Path]][source]

Copy the icon svg file into the given destination, maintaining the relative sub-directories

Parameters
  • icon_root – The directory containing all icon subdirectories ('svgs' within the fontawesome root)

  • dest – The destination directory

  • stylesStyle flags to include (see get_svgs())

Yields
  • style (Style) – style flag for the filename

  • filename (pathlib.Path) – The svg filename within icon_root

jvconnected.ui.tools.fontawesome.parse_categories(metadata_dir: pathlib.Path, icons: Dict[str, jvconnected.ui.tools.fontawesome.Icon]) Dict[str, jvconnected.ui.tools.fontawesome.Category][source]

Parse icon categories from the fontawesome metadata

Parameters
  • metadata_dir – The fontawesome metadata directory

  • icons – Mapping of Icon instances as provided by parse_icons()

Returns

Mapping of Category.name to Category

jvconnected.ui.tools.fontawesome.parse_icons(metadata_dir: pathlib.Path) Dict[str, jvconnected.ui.tools.fontawesome.Icon][source]

Parse icons from the fontawesome metadata

Parameters

metadata_dir – The fontawesome metadata directory

Returns

Mapping of Icon.name to Icon

jvconnected.ui.tools.fontawesome.parse_all(metadata_dir: pathlib.Path) Tuple[Dict[str, jvconnected.ui.tools.fontawesome.Icon], Dict[str, jvconnected.ui.tools.fontawesome.Category]][source]

Parse icons and categories using parse_icons() and parse_categories()

Parameters

metadata_dir – The fontawesome metadata directory

Returns

  • icons – The parsed icons

  • categories – The parsed categories

jvconnected.ui.tools.fontawesome.build_qml_names(icons: Dict[str, jvconnected.ui.tools.fontawesome.Icon], outfile: pathlib.Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/jvconnected/envs/latest/lib/python3.7/site-packages/jvconnected-0.0.1-py3.7.egg/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: pathlib.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 – Root directory of the unpacked fontawesome archive (FaDownload.archive_dir)

  • theme_name – The name of the icon theme to generate formatted according to the freedesktop specification

  • category_names – A list of fontawesome categories to include. If not provided, use all available categories.