This file is indexed.

/usr/share/pyshared/mayavi/modules/labels.py is in mayavi2 4.1.0-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
# Author: Prabhu Ramachandran <prabhu [at] aero . iitb . ac . in>
# Copyright (c) 2008, Enthought, Inc.
# License: BSD Style.

# Standard library imports.

# Enthought library imports.
from traits.api import Int, Instance, Str, TraitError
from traitsui.api import View, Group, Item
from tvtk.api import tvtk
from apptools.persistence import state_pickler

# Local imports.
from mayavi.core.common import error
from mayavi.core.pipeline_base import PipelineBase
from mayavi.core.pipeline_info import PipelineInfo
from mayavi.core.module import Module
from mayavi.filters.optional import Optional
from mayavi.filters.mask_points import MaskPoints
from mayavi.filters.user_defined import UserDefined
from mayavi.components.actor2d import Actor2D
from mayavi.core.common import handle_children_state


################################################################################
# `Labels` class.
################################################################################
class Labels(Module):

    """
    Allows a user to label the current dataset or the current actor of
    the active module.
    """

    # Used for persistence.
    __version__ = 0

    # The object which we are labeling.
    object = Instance(PipelineBase, record=False)

    # The label format string.
    label_format = Str('', enter_set=True, auto_set=False,
                       desc='the label format string')

    # Number of points to label.
    number_of_labels = Int(25, enter_set=True, auto_set=False,
                           desc='the number of points to label')

    # The filter used for masking of the points.
    mask = Instance(MaskPoints, record=True)

    # Filter to select visible points.
    visible_points = Instance(Optional, record=True)

    # The 2D actor for the labels.
    actor = Instance(Actor2D, record=True)

    # The text property of the labels.
    property = Instance(tvtk.TextProperty, record=True)

    # The mapper for the labels.
    mapper = Instance(tvtk.LabeledDataMapper, args=(), record=True)

    input_info = PipelineInfo(datasets=['any'],
                              attribute_types=['any'],
                              attributes=['any'])

    ########################################
    # Private traits.

    # The input used for the labeling.
    input = Instance(PipelineBase)

    # The id of the object in the modulemanager only used for
    # persistence.
    object_id = Int(-2)


    ########################################
    # View related traits.


    view = View(Group(Item(name='number_of_labels'),
                      Item(name='label_format'),
                      Item(name='mapper',
                           style='custom',
                           show_label=False,
                           resizable=True),
                      Item(name='mask',
                           style='custom',
                           resizable=True,
                           show_label=False),
                      label='Labels'
                      ),
                Group(
                      Item(name='visible_points',
                           style='custom',
                           resizable=True,
                           show_label=False),
                      label='VisiblePoints'
                      ),
                Group(Item(name='property',
                           style='custom',
                           show_label=False,
                           resizable=True),
                      label='TextProperty'
                     ),
                 resizable=True
                )

    ######################################################################
    # `object` interface.
    ######################################################################
    def __get_pure_state__(self):
        self._compute_object_id()
        d = super(Labels, self).__get_pure_state__()
        for name in ('object', 'mapper', 'input'):
            d.pop(name, None)
        # Must pickle the components.
        d['components'] = self.components
        return d

    def __set_pure_state__(self, state):
        handle_children_state(self.components, state.components)
        state_pickler.set_state(self, state)
        self.update_pipeline()

    ######################################################################
    # `Module` interface.
    ######################################################################
    def setup_pipeline(self):
        mask = MaskPoints()
        mask.filter.set(generate_vertices=True, random_mode=True)
        self.mask = mask
        v = UserDefined(filter=tvtk.SelectVisiblePoints(),
                        name='VisiblePoints')
        self.visible_points = Optional(filter=v, enabled=False)
        mapper = tvtk.LabeledDataMapper()
        self.mapper = mapper
        self.actor = Actor2D(mapper=mapper)
        self.property = mapper.label_text_property
        self.property.on_trait_change(self.render)
        self.components = [self.mask, self.visible_points, self.actor]

    def update_pipeline(self):
        mm = self.module_manager
        if mm is None:
            return

        self._find_input() # Calculates self.input
        self.mask.inputs = [self.input]
        self.visible_points.inputs = [self.mask]
        self.actor.inputs = [self.visible_points]
        self._number_of_labels_changed(self.number_of_labels)
        self._label_format_changed(self.label_format)

    ######################################################################
    # Non-public interface.
    ######################################################################
    def _find_input(self):
        mm = self.module_manager
        if self.object is None:
            if self.object_id == -1:
                self.input = mm.source
            elif self.object_id > -1:
                obj = mm.children[self.object_id]
                if hasattr(obj, 'actor'):
                    self.set(object=obj, trait_change_notify=False)
                    self.input = obj.actor.inputs[0]
                else:
                    self.input = mm.source
        else:
            o = self.object
            if hasattr(o, 'module_manager'):
                # A module.
                if hasattr(o, 'actor'):
                    self.input = o.actor.inputs[0]
                else:
                    self.input = o.module_manager.source

        if self.input is None:
            if self.object_id == -2:
                self.input = mm.source
            else:
                error('No object to label!')
                return

    def _number_of_labels_changed(self, value):
        if self.input is None:
            return
        f = self.mask.filter
        inp = self.input.outputs[0]
        inp.update()
        npts = inp.number_of_points
        typ = type(f.on_ratio)
        f.on_ratio = typ(max(npts/value, 1))
        if self.mask.running:
            f.update()
            self.mask.data_changed = True

    def _label_format_changed(self, value):
        if len(value) > 0:
            self.mapper.label_format = value
            self.render()
        else:
            try:
                self.mapper.label_format = None
            except TraitError:
                self.mapper.label_format = '%g'
            self.render()

    def _object_changed(self, value):
        self.update_pipeline()

    def _compute_object_id(self):
        mm = self.module_manager
        input = self.input
        self.object_id = -2
        if input is mm.source:
            self.object_id = -1
            return
        for id, child in enumerate(mm.children):
            if child is self.object:
                self.object_id = id
                return

    def _scene_changed(self, old, new):
        self.visible_points.filter.filter.renderer = new.renderer
        super(Labels, self)._scene_changed(old, new)