blueprint module

Supplemental script which handles data manipulation.

Read an XML file and produce a layout list, which is then used by the main script cardassembler.

class blueprint.Blueprint(file_path)[source]

Blueprint information handling class.

Can read XML file, produce layout list and palette.

Parameters

file_path (str or None) – Folder containing XML blueprint

SPECIAL_TAGS = ['next', 'text']

Those tags are always stored in a list & have extra treatment in _step_in().

_load(file_path)[source]

Load XML file blueprint into a dictionary tree.

Parameters

file_path (str) – Path to the XML file to load

Returns

Tree structure of cards data

Return type

dict

_ElementTree_to_dict(parent)[source]

Translation from xml.etree.ElementTree to dict tree from the given node down.

Tags in SPECIAL_TAGS are stored in a list.

Parameters

parent (ElementTree.Element) – A node of ElementTree

Returns

Dictionary representation of the given tree

Return type

dict

_parse(text, target_type)[source]

ElementTree.element.text to various python types.

Input parsed as tuple can have any length. Its elements will be parsed as int

Parameters
  • text (str) – Text to be parsed

  • target_type (str) – Either “int”, “float” or “tuple”

Raises

ValueError – If target type is not known

Returns

Parsed value

Return type

int or float or tuple

generate_layout(start_by)[source]

Generate card layout given starting position.

Starting position children are sorted alphabetically (name them accordingly).

Parameters

start_by (str) – Space separated path through data tree leading to the starting node

Returns

Layout of the chosen card

Return type

list

_step_in(layout, this_step)[source]

Browse data guided by the next tag.

Do not overwrite (first in stays). Further next tags are served successively in the order according to the XML file. If there are multiple text tags, join them by \n

Parameters
  • layout (dict) – Input layout

  • this_step (str) – Where does this step leads

Returns

Filled layout

Return type

dict

_goto(next_steps)[source]

Find target dict tree node and return its sub tree.

Analogous to successive application of dict.get().

Parameters

next_steps (str) – Space separated key sequence.

Raises

KeyError – If one of the given keys doesn’t exist.

Returns

Sub-tree of the self.data dict tree.

Return type

dict

generate_palette(start_by)[source]

Make palette out of colors used by cards.

To be used in another mini plug-in to import palette into Gimp.

Parameters

start_by (str) – Path through the data tree (space separated)

Returns

Pairs of name and color

Return type

list

_harvest_leaves(color_tree)[source]

Find the path to the leaves of the given tree, whose tag is color.

Kinda inverse to _goto().

Parameters

color_tree (dict) – Part of the data (dict tree) to look for colors in

Returns

List colors as tuple of space delimited path and color code

Return type

list