@@ -81,14 +81,27 @@ def figure_edit(axes, parent=None):
81
81
82
82
def prepare_data (d , init ):
83
83
"""Prepare entry for FormLayout.
84
+
85
+ `d` is a mapping of shorthands to style names (a single style may
86
+ have multiple shorthands, in particular the shorthands `None`,
87
+ `"None"`, `"none"` and `""` are synonyms); `init` is one shorthand
88
+ of the initial style.
89
+
90
+ This function returns an list suitable for initializing a
91
+ FormLayout combobox, namely `[initial_name, (shorthand,
92
+ style_name), (shorthand, style_name), ...]`.
84
93
"""
85
- # List items in dict, dropping duplicate values, sorting by values.
86
- kvs = [(k , v ) for v , k in
87
- sorted ({v : k for k , v in d .items ()}.items ())]
88
- # Find the unique kept key with the same value as the init value.
89
- canonical_init , = ({k for k , v in d .items () if v == d [init ]}.
90
- intersection (k for k , v in kvs ))
91
- return [canonical_init ] + kvs
94
+ # Drop duplicate shorthands from dict (by overwriting them during
95
+ # the dict comprehension).
96
+ name2short = {name : short for short , name in d .items ()}
97
+ # Convert back to {shorthand: name}.
98
+ short2name = {short : name for name , short in name2short .items ()}
99
+ # Find the kept shorthand for the style specified by init.
100
+ canonical_init = name2short [d [init ]]
101
+ # Sort by representation and prepend the initial value.
102
+ return ([canonical_init ] +
103
+ sorted (short2name .items (),
104
+ key = lambda short_and_name : short_and_name [1 ]))
92
105
93
106
curvelabels = sorted (linedict .keys ())
94
107
for label in curvelabels :
0 commit comments