This file is indexed.

/usr/lib/python2.7/dist-packages/chaco/overlays/simple_inspector_overlay.py is in python-chaco 4.4.1-1.2.

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
"""A simple inspector overlay for plots

This module provides the SimpleInspectorOverlay for displaying
information gathered from an inspector tool in a TextGrid.  By default
it is configured to work with a SimpleInspectorTool.

The module also provides some helper factory functions for creating text
formatters for dictionary values.
"""

from numpy import array

from traits.api import Any, List, Callable, Enum, Bool

from text_grid_overlay import TextGridOverlay

def basic_formatter(key, decimals):
    """Create a basic '<key>: <value>' formatting function

    This factory creates a function that formats a specified key and with a
    numerical value from a dictionary into a string.

    Parameters
    ----------

    key
        The dictionary key to format.
    decimals
        The number of decimal places to show.

    Returns
    -------

    format
        A factory function that takes a dictionary and returns a string.
    """
    format_string = '%s: %%(%s).%df' % (key, key, decimals)
    def format(**kwargs):
        return format_string % kwargs
    return format

def datetime_formatter(key, time_format='%Y/%m/%d %H:%M:%S'):
    """Create a datetime formatting function

    This factory creates a function that formats a specified key and with a
    timestamp value from a dictionary into a string.

    Parameters
    ----------

    key
        The dictionary key to format.  The corresponding value should be a
        timestamp.
    time_format
        A format string suitable for strftime().

    Returns
    -------

    format
        A factory function that takes a dictionary and returns a string.
    """
    import datetime
    def format(**kwargs):
        dt = datetime.datetime.fromtimestamp(kwargs[key])
        return key+': '+dt.strftime(time_format)
    return format

def time_formatter(key):
    """Create a time formatting function

    This factory creates a function that formats a specified key and with a
    timestamp value from a dictionary into a 'HH:MM:SS' format string.

    Parameters
    ----------

    key
        The dictionary key to format.  The corresponding value should be a
        timestamp.

    Returns
    -------

    format
        A factory function that takes a dictionary and returns a string.
    """
    return datetime_formatter(key, time_format='%H:%M:%S')

def date_formatter(key):
    """Create a date formatting function

    This factory creates a function that formats a specified key and with a
    timestamp value from a dictionary into a 'yyyy/mm/dd' format string.

    Parameters
    ----------

    key
        The dictionary key to format.  The corresponding value should be a
        timestamp.

    Returns
    -------

    format
        A factory function that takes a dictionary and returns a string.
    """
    return datetime_formatter(key, time_format='%Y/%m/%d')


class SimpleInspectorOverlay(TextGridOverlay):
    """ Simple inspector overlay for plots

    This is a simple overlay that listens for new_value events on a
    SimpleInspectorTool and displays formatted values in a grid.

    By default this displays the 'x' and 'y' values provided by the
    SimpleInspectorTool, but instances can provide a field_formatters
    trait which is a list of lists of callables which extract values
    from a dictionary and formats them.  Each callable corresponds to a
    cell in the underlying TextGrid component.

    Although by default this works with the SimpleInspectorTool, with
    appropriate field_formatters this class can be used with any inspector
    tool that follows the same API.
    """
    # XXX We should probably refactor this into a BaseInspectorOverlay
    # which handles the visibility and basic event handling, and smaller
    # version of this class which handles inserting values into a text grid

    # the inspector that I am listening to.  This should have a new_value
    # event and a visible trait for me to listen to.
    inspector = Any

    # fields to display
    field_formatters = List(List(Callable))

    # Anchor the text to the mouse?  (If False, then the text is in one of the
    # corners.)  Use the **align** trait to determine which corner.
    tooltip_mode = Bool(False)

    # The default state of the overlay is visible.
    visible = True

    # Whether the overlay should auto-hide and auto-show based on the
    # tool's location, or whether it should be forced to be hidden or visible.
    visibility = Enum("auto", True, False)

    #########################################################################
    # Traits Handlers
    #########################################################################

    def _field_formatters_default(self):
        return [[basic_formatter('x', 2)], [basic_formatter('y', 2)]]

    def _new_value_updated(self, event):
        if event is None:
            self.text_grid = array()
            if self.visibility == "auto":
                self.visibility = False
        elif self.visibility == "auto":
            self.visible = True

        if self.tooltip_mode:
            self.alternate_position = self.inspector.last_mouse_position

        d = event
        text = []
        self.text_grid.string_array = array([[formatter(**d) for formatter in row]
            for row in self.field_formatters])

        self.text_grid.request_redraw()

    def _visible_changed(self):
        if self.component:
            self.request_redraw()

    def _inspector_changed(self, old, new):
        if old:
            old.on_trait_event(self._new_value_updated, 'new_value', remove=True)
            old.on_trait_change(self._tool_visible_changed, "visible", remove=True)
        if new:
            new.on_trait_event(self._new_value_updated, 'new_value')
            new.on_trait_change(self._tool_visible_changed, "visible")
            self._tool_visible_changed()

    def _tool_visible_changed(self):
        self.visibility = self.inspector.visible
        if self.visibility != "auto":
            self.visible = self.visibility