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
hashlibalgorithm to use for creating file hashes
-
class
jvconnected.ui.tools.qrc_utils.QRCElement(**kwargs)[source]¶ Bases:
objectAn element within a QRC document tree
- Attributes
parent (QRCElement, optional) – The parent element. If this element is the document root, this is
Noneelement (ET.Element) – The
xml.etree.ElementTree.Elementassociated with this elementchildren (List[QRCElement]) – Direct descendants of this element
-
write(filename: pathlib.Path)[source]¶ Save the contents of
tostring()as a QRC fileNote
This may only be called on the root element
-
classmethod
create(**kwargs) → jvconnected.ui.tools.qrc_utils.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 [read-only]¶ The root of the tree
-
property
attrib→ typing.Dict [read-only]¶ The element
attributes
-
add_child(**kwargs) → jvconnected.ui.tools.qrc_utils.QRCElement[source]¶ Create a child instance using
create()and add it to this element’schildren
-
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.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: 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_hashagainst the result ofhash_contents()
-
add_file(filename: pathlib.Path, prefix: Optional[str] = None, **kwargs) → jvconnected.ui.tools.qrc_utils.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[jvconnected.ui.tools.qrc_utils.QRCResource][source]¶ Search for a
QRCResourcematching the given prefixIf one is not found,
Nonewill be returned
-
search_for_file(filename: pathlib.Path) → Optional[jvconnected.ui.tools.qrc_utils.QRCFile][source]¶ Search for the
QRCFileelement matching the given filename
-
remove_missing_files() → List[jvconnected.ui.tools.qrc_utils.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[jvconnected.ui.tools.qrc_utils.QRCResource][source]¶ Iterate over child
QRCResourceinstances
-
iter_files() → Iterator[jvconnected.ui.tools.qrc_utils.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:
jvconnected.ui.tools.qrc_utils.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.
-
property
path→ Path [read-only]¶ Alias for
base_pathof theroot_element
-
add_file(filename: pathlib.Path, **kwargs) → jvconnected.ui.tools.qrc_utils.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: 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_pathwill be prepended to it.
-
search_for_file(filename: pathlib.Path) → Optional[jvconnected.ui.tools.qrc_utils.QRCFile][source]¶ Search within this qresource for the
QRCFileelement matching the given filename
-
iter_files() → Iterator[jvconnected.ui.tools.qrc_utils.QRCFile][source]¶ Iterate over all
QRCFileinstances within this qresource
-
property
-
class
jvconnected.ui.tools.qrc_utils.QRCFile(**kwargs)[source]¶ Bases:
jvconnected.ui.tools.qrc_utils.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→ typing.Union[str, NoneType]¶ The file alias as described in the qrc documentation
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
- The output data with shape
- Return type
-
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)