@@ -78,29 +78,51 @@ def figure_edit(axes, parent=None):
78
78
continue
79
79
linedict [label ] = line
80
80
curves = []
81
- linestyles = list (six .iteritems (LINESTYLES ))
82
- drawstyles = list (six .iteritems (DRAWSTYLES ))
83
- markers = list (six .iteritems (MARKERS ))
81
+
82
+ def prepare_data (d , init ):
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), ...]`.
93
+ """
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 ]))
105
+
84
106
curvelabels = sorted (linedict .keys ())
85
107
for label in curvelabels :
86
108
line = linedict [label ]
87
109
color = rgb2hex (colorConverter .to_rgb (line .get_color ()))
88
110
ec = rgb2hex (colorConverter .to_rgb (line .get_markeredgecolor ()))
89
111
fc = rgb2hex (colorConverter .to_rgb (line .get_markerfacecolor ()))
90
- curvedata = [( 'Label' , label ),
91
- sep ,
92
- ( None , '<b>Line</b>' ) ,
93
- ( ' Line Style' , [ line . get_linestyle ()] + linestyles ),
94
- ( 'Draw Style' , [ line .get_drawstyle ()] + drawstyles ),
95
- ( 'Width ' , line .get_linewidth ( )),
96
- ( 'Color ' , color ),
97
- sep ,
98
- ( None , '<b>Marker</b>' ) ,
99
- ( 'Style' , [ line . get_marker ()] + markers ),
100
- ( 'Size ' , line .get_markersize ( )),
101
- ( 'Facecolor ' , fc ),
102
- ( 'Edgecolor ' , ec ),
103
- ]
112
+ curvedata = [
113
+ ( 'Label' , label ) ,
114
+ sep ,
115
+ ( None , '<b> Line</b>' ),
116
+ ( 'Line Style' , prepare_data ( LINESTYLES , line .get_linestyle ()) ),
117
+ ( 'Draw Style ' , prepare_data ( DRAWSTYLES , line .get_drawstyle () )),
118
+ ( 'Width ' , line . get_linewidth () ),
119
+ ( 'Color' , color ) ,
120
+ sep ,
121
+ ( None , '<b>Marker</b>' ),
122
+ ( 'Style ' , prepare_data ( MARKERS , line .get_marker () )),
123
+ ( 'Size ' , line . get_markersize () ),
124
+ ( 'Facecolor ' , fc ),
125
+ ( 'Edgecolor' , ec ) ]
104
126
curves .append ([curvedata , label , "" ])
105
127
106
128
# make sure that there is at least one displayed curve
0 commit comments