This file is indexed.

/usr/share/pyshared/spyderlib/widgets/figureoptions.py is in python-spyderlib 2.1.9-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# -*- coding: utf-8 -*-
#
# Copyright © 2009-2010 Pierre Raybaut
# Licensed under the terms of the MIT License
# (see spyderlib/__init__.py for details)

"""Module that provides a GUI-based editor for matplotlib's figure options"""

from spyderlib.widgets.formlayout import fedit
from spyderlib.config import get_icon

import matplotlib.cm, matplotlib.image
from matplotlib.colors import rgb2hex, is_color_like


COLORMAPS = matplotlib.cm.datad.keys()
INTERPOLATIONS = matplotlib.image.AxesImage._interpd.keys()

LINESTYLES = {
              '-': 'solid "-"',
              '--': 'dashed "--"',
              '-.': 'dash_dot "-."',
              ':': 'dotted ":"',
              'none': 'None',
              }

# LINESTYLES2 is required because the matplotlib API does not support the same linestyles for patches as for lines 
LINESTYLES2 = {
              'solid': 'solid -',
              'dashed': 'dashed --',
              'dashdot': 'dashdot -.',
              'dotted': 'dotted :',
              }
              
LEG_locs  =  {
             0  : 'best         0',
             1  : 'upper right  1',
             2  : 'upper left   2',
             3  : 'lower left   3',
             4  : 'lower right  4',
             5  : 'right        5',
             6  : 'center left  6',
             7  : 'center right 7',
             8  : 'lower center 8',
             9  : 'upper center 9',
             10 : 'center      10',
             }
MARKERS = {
           'none': 'None',
           'o': 'circle "o"',
           '^': 'triangle_up "^"',
           'v': 'triangle_down "v"',
           '<': 'triangle_left "<"',
           '>': 'triangle_right ">"',
           's': 'square "s"',
           '+': 'plus "+"',
           'x': 'cross "x"',
           '*': 'star "*"',
           'D': 'diamond "D"',
           'd': 'thin_diamond "d"',
           '1': 'tripod_down "1"',
           '2': 'tripod_up "2"',
           '3': 'tripod_left "3"',
           '4': 'tripod_right "4"',
           'h': 'hexagon "h"',
           'H': 'rotated_hexagon "H"',
           'p': 'pentagon "p"',
           '|': 'vertical_line "|"',
           '_': 'horizontal_line "_"',
           '.': 'dot "."',
           ',': 'pixel ","',
           }

COLORS = {'b': '#0000ff', 'g': '#008000', 'r': '#ff0000', 'c': '#00ffff',
          'm': '#ff00ff', 'y': '#ffff00', 'k': '#000000', 'w': '#ffffff'}


def col2hex(color):
    """Convert matplotlib color to hex"""
    if isinstance(color, tuple) and len(color) == 3:
        output = rgb2hex(color) #RGB tuple format 
    else :
        output = COLORS.get(color, color)
    return output

def figure_edit(axes, parent=None):
    """Edit matplotlib figure options"""
    sep = (None, None) # separator
    leg = axes.legend_
    loc = 0 if (leg is None) else leg._loc  
    has_legend = (leg is not None)
    has_curve = len(axes.get_lines()) > 0
    has_image = len(axes.get_images()) > 0
    has_patch = len(axes.patches)     > 0
    has_text  = len(axes.texts)       > 0

    # Get / General
    xmin, xmax = axes.get_xlim()
    ymin, ymax = axes.get_ylim()
    autoXY = (axes.get_autoscalex_on(), axes.get_autoscaley_on())
    general = [('Title', axes.get_title()),
               ('AutoXY', [autoXY, 
               ((0, 0), 'None'), ((1, 0), 'X only'), ((0, 1), 'Y only'), ((1, 1), 'All')]),
               ('Equal', axes.get_aspect()=='equal'),
               ('Legend', has_legend),
               ('Loc', [loc] + LEG_locs.items()),
               sep,
               (None, "<b>X-Axis</b>"),
               ('Min', xmin), ('Max', xmax),
               ('Label', axes.get_xlabel()),
               ('Scale', [axes.get_xscale(), 'linear', 'log']),
               sep,
               (None, "<b>Y-Axis</b>"),
               ('Min', ymin), ('Max', ymax),
               ('Label', axes.get_ylabel()),
               ('Scale', [axes.get_yscale(), 'linear', 'log'])
               ]

    def get_class_name(obj, prefix="matplotlib.patches."):
        """returns the Class Name"""
        return str(type(obj)).lstrip("<class '").lstrip(prefix).rstrip("'>")

    if has_curve:
        # Get / Curves
        linedict = {}
        for line in axes.get_lines():
            label = line.get_label()
            if label == '_nolegend_':
                continue
            linedict[label] = line
        curves = []
        linestyles = sorted(LINESTYLES.items())
        markers = sorted(MARKERS.items(), key=lambda (k,v): (v,k))
        curvelabels = sorted(linedict.keys())
        for label in curvelabels:
            line = linedict[label]
            markevery = 1 if line.get_markevery() is None else line.get_markevery()
            curvedata = [
                         ('Label', label),
                         ('Visible', line.get_visible()),
                         sep,
                         (None, '<b>Line</b>'),
                         ('Style', [line.get_linestyle()] + linestyles),
                         ('Width', line.get_linewidth()),
                         ('Color', col2hex(line.get_color())),
                         sep,
                         (None, '<b>Marker</b>'),
                         ('Style', [line.get_marker()] + markers),
                         ('Size', line.get_markersize()),
                         ('Facecolor', col2hex(line.get_markerfacecolor())),
                         ('Edgecolor', col2hex(line.get_markeredgecolor())),
                         ('Every', markevery),
                         ]
            curves.append([curvedata, label, ""])
        
    if has_image:
        # Get / Images
        imagedict = {}
        for image in axes.get_images():
            label = image.get_label()
            if label == '_nolegend_':
                continue
            imagedict[label] = image
        images = []
        interpolations = zip(INTERPOLATIONS, INTERPOLATIONS)
        colormaps = zip(COLORMAPS, COLORMAPS)
        imagelabels = sorted(imagedict.keys())
        for label in imagelabels:
            image = imagedict[label]
            xmin, xmax, ymin, ymax = image.get_extent()
            cmap_name = image.get_cmap().name
            imagedata = [
                         ('Label', label),
                         sep,
                         ('Colormap', [cmap_name] + colormaps),
                         ('Alpha', image.get_alpha()),
                         ('Interpolation',
                          [image.get_interpolation()] + interpolations),
                         ('Resize filter radius', image.get_filterrad()),
                         sep,
                         (None, '<b>Extent</b>'),
                         ('xmin', xmin), ('xmax', xmax),
                         ('ymin', ymin), ('ymax', ymax),
                         ]
            images.append([imagedata, label, ""])

    if has_patch:
        for i, elt in enumerate(axes.patches):
            if elt.get_label()=='':
                label=get_class_name(elt, prefix="matplotlib.patches.") 
                elt.set_label("_" + label.lower() + str(i).zfill(2))
        patchdict = {}
        linestyles = sorted(LINESTYLES2.items())
        for patch in axes.patches:
            label = patch.get_label()
            patchdict[label] = patch
        patches=[]
        patchlabels = sorted(patchdict.keys())
        for label in patchlabels:
            patch = patchdict[label]
            patchdata = [('Label', label),
                         ('Zorder', patch.get_zorder()),
                         ('Visible', patch.get_visible()),
                         sep,
                         (None, '<b>Patch Edge</b>'),
                         ('Style', [patch.get_linestyle()] + linestyles),
                         ('Width', patch.get_linewidth()),
                         ('Edgecolor', col2hex(patch.get_edgecolor())),                         
                         sep,
                         (None, '<b>Patch Face</b>'),
                         ('Fill', patch.get_fill()),                         
                         ('Facecolor', col2hex(patch.get_facecolor())),
                         ('Alpha', patch.get_alpha()),                                                 
                         ]
            patches.append([patchdata, label, ""])

    if has_text: 
        for i, elt in enumerate(axes.texts):
            if elt.get_label()=='':
                label=get_class_name(elt, prefix="matplotlib.text.") 
                elt.set_label("_" + label.lower() + str(i).zfill(2))
        textdict = {}
        for text in axes.texts:
            label = text.get_label()
            textdict[label] = text
        texts=[]
        textlabels = sorted(textdict.keys())
        for label in textlabels:
            text = textdict[label]
            xpos, ypos = text.get_position()
            is_bold = (text.get_weight() == "bold")
            fontcolor=text.get_color()
            textdata = [ ('Label', label),
                         ('Visible', text.get_visible()),
                         ('Content', text.get_text()),
                         sep,
                         (None, '<b>Position</b>'),
                         ('X', xpos),
                         ('Y', ypos),
                         ('Halign', [text.get_ha()] + ['left', 'center', 'right']),
                         ('Valign', [text.get_va()] + ['top', 'center', 'bottom', 'baseline']),
                         sep,
                         (None, '<b>Style</b>'),
                         ('Size', int(text.get_size())),
                         ('Bold', is_bold),
                         ('Color', col2hex(fontcolor)),
                         ]
            texts.append([textdata, label, ""])
        
    datalist = [(general, "Axes", "")]
    if has_curve:
        datalist.append((curves, "Curves", ""))
    if has_image:
        datalist.append((images, "Images", ""))
    if has_patch: 
        datalist.append((patches, "Patches", ""))
    if has_text:  
        datalist.append((texts,   "Texts",   ""))
        
    def apply_callback(data):
        """This function will be called to apply changes"""

        def validate_color(value):
            if not is_color_like(value): value='None'
            return value         

        general = data[0]
        ind = 0
        if has_curve:
            ind += 1
            curves = data[ind]
        if has_image:
            ind += 1
            images = data[ind]
        if has_patch:
            ind += 1
            patches = data[ind]
        if has_text:
            ind += 1
            texts = data[ind]
            
        # Set / General
        title, autoXY, equal, has_legend, loc, xmin, xmax, xlabel, \
            xscale, ymin, ymax, ylabel, yscale = general        
        autoX, autoY = autoXY
        axes.set_xscale(xscale)
        axes.set_yscale(yscale)
        axes.set_autoscalex_on(autoX)
        axes.set_autoscaley_on(autoY)
        axes.set_title(title)
        axes.set_xlim(xmin, xmax)
        axes.set_xlabel(xlabel)
        axes.set_ylim(ymin, ymax)
        axes.set_ylabel(ylabel)
        if equal : 
            axes.set_aspect("equal")
        else :
            axes.set_aspect("auto")
        
        has_label = False
        if has_curve:
            # Set / Curves
            for index, curveopts in enumerate(curves):
                line = linedict[curvelabels[index]]
                label, visible, linestyle, linewidth, color, marker, \
                    markersize, markerfacecolor, markeredgecolor, markevery = curveopts
                if not label.startswith('_') : 
                    has_label=True 
                line.set_label(label)
                line.set_visible(visible)

                line.set_linestyle(linestyle)
                line.set_linewidth(linewidth)                                    
                line.set_color(validate_color(color))
                line.set_markeredgecolor(validate_color(markeredgecolor))
                line.set_markerfacecolor(validate_color(markerfacecolor))
                line.set_markersize(markersize)
                if marker == 'none': 
                    marker='None'
                line.set_marker(marker)
                markevery = markevery if markevery>0 else 1
                line.set_markevery(markevery)	
        
        if has_image:
            # Set / Images
            for index, imageopts in enumerate(images):
                image = imagedict[imagelabels[index]]
                
                label, cmap_name, alpha, interpolation, \
                    filterrad, xmin, xmax, ymin, ymax = imageopts
                image.set_label(label)
                image.set_cmap(matplotlib.cm.get_cmap(cmap_name))
                if alpha >= 0 and alpha <= 1:
                    # Ignoring invalid values
                    image.set_alpha(alpha)
                image.set_interpolation(interpolation)
                if filterrad > 0:
                    # Ignoring invalid values
                    image.set_filterrad(filterrad)
                image.set_extent((xmin, xmax, ymin, ymax))
                
        if has_patch:
            for index, patch_elt in enumerate(patches):
                patch = patchdict[patchlabels[index]]
                label, zorder, visible, linestyle, linewidth, \
                    edgecolor, fill, facecolor, alpha = patch_elt
                if not label.startswith('_') :
                    has_label = True 
                patch.set_label(label)
                patch.set_zorder(zorder)
                patch.set_visible(visible)
                patch.set_ls(linestyle)
                patch.set_lw(linewidth)                                    
                patch.set_fill(fill)
                patch.set_alpha(alpha)
                patch.set_ec(validate_color(edgecolor))
                patch.set_fc(validate_color(facecolor))

        if has_text:
            for index, text_elt in enumerate(texts):
                text = textdict[textlabels[index]]                
                label, visible, text_content, xpos, ypos, halign, \
                    valign, fontsize, is_bold, fontcolor = text_elt
                text.set_label(label)

                text.set_visible(visible)
                text.set_text(text_content)
                text.set_x(xpos)
                text.set_y(ypos)
                text.set_ha(halign)
                text.set_va(valign)
                if is_bold : 
                    text.set_weight("bold")
                else: 
                    text.set_weight('normal')
                text.set_size(fontsize)
                text.set_color(validate_color(fontcolor))
                
        if has_curve: 
            if has_legend and has_label: 
                axes.legend(loc=loc)
            else:
                axes.legend_ = None
        elif has_legend: 
            axes.legend(loc=loc)
        else:
            axes.legend_ = None
            
        # Redraw
        if axes.get_legend() is not None:
            axes.legend()
        figure = axes.get_figure()
        figure.canvas.draw()
        
    data = fedit(datalist, title="Figure options", parent=parent,
                 icon=get_icon('options.svg'), apply=apply_callback)
    if data is not None:
        apply_callback(data)