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

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_elementQRCElement [read-only]

The root of the tree

property tagstr [read-only]

The tag name of the element

property attribtyping.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_hashtyping.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 pathPath [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 filenamePath

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

property filename_absPath

Absolute filename including the parent base_path

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

property aliastyping.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