Prepare entry for FormLayout. *d* is a mapping of shorthands to style names (a single style may have multiple shorthands, in particular the shorthands `None`, `"None"`, `"none"` and `""` are synonyms); *init* is one shorthand of the initial style. T
(d, init)
| 84 | curves = [] |
| 85 | |
| 86 | def prepare_data(d, init): |
| 87 | """ |
| 88 | Prepare entry for FormLayout. |
| 89 | |
| 90 | *d* is a mapping of shorthands to style names (a single style may |
| 91 | have multiple shorthands, in particular the shorthands `None`, |
| 92 | `"None"`, `"none"` and `""` are synonyms); *init* is one shorthand |
| 93 | of the initial style. |
| 94 | |
| 95 | This function returns a list suitable for initializing a |
| 96 | FormLayout combobox, namely `[initial_name, (shorthand, |
| 97 | style_name), (shorthand, style_name), ...]`. |
| 98 | """ |
| 99 | if init not in d: |
| 100 | d = {**d, init: str(init)} |
| 101 | # Drop duplicate shorthands from dict (by overwriting them during |
| 102 | # the dict comprehension). |
| 103 | name2short = {name: short for short, name in d.items()} |
| 104 | # Convert back to {shorthand: name}. |
| 105 | short2name = {short: name for name, short in name2short.items()} |
| 106 | # Find the kept shorthand for the style specified by init. |
| 107 | canonical_init = name2short[d[init]] |
| 108 | # Sort by representation and prepend the initial value. |
| 109 | return ([canonical_init] + |
| 110 | sorted(short2name.items(), |
| 111 | key=lambda short_and_name: short_and_name[1])) |
| 112 | |
| 113 | for label, line in labeled_lines: |
| 114 | color = mcolors.to_hex( |
no outgoing calls
no test coverage detected
searching dependent graphs…