This file is indexed.

/usr/share/pyshared/pyface/image_widget.py is in python-pyface 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
230
231
232
233
234
235
236
237
238
239
240
241
#------------------------------------------------------------------------------
# Copyright (c) 2005, Enthought, Inc.
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in enthought/LICENSE.txt and may be redistributed only
# under the conditions described in the aforementioned license.  The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
# Thanks for using Enthought open source!
#
# Author: Enthought, Inc.
# Description: <Enthought pyface package component>
#------------------------------------------------------------------------------
""" A clickable/draggable widget containing an image. """
from __future__ import absolute_import

# Major package imports.
import wx

# Enthought library imports.
from traits.api import Any, Bool, Event

# Locak imports.
from .widget import Widget


class ImageWidget(Widget):
    """ A clickable/draggable widget containing an image. """

    #### 'ImageWidget' interface ##############################################

    # The bitmap.
    bitmap = Any

    # Is the widget selected?
    selected = Bool(False)

    #### Events ####

    # A key was pressed while the tree is in focus.
    key_pressed = Event

    # A node has been activated (ie. double-clicked).
    node_activated = Event

    # A drag operation was started on a node.
    node_begin_drag = Event

    # A (non-leaf) node has been collapsed.
    node_collapsed = Event

    # A (non-leaf) node has been expanded.
    node_expanded = Event

    # A left-click occurred on a node.
    node_left_clicked = Event

    # A right-click occurred on a node.
    node_right_clicked = Event

    #### Private interface ####################################################

    _selected = Any

    ###########################################################################
    # 'object' interface.
    ###########################################################################

    def __init__ (self, parent, **traits):
        """ Creates a new widget. """

        # Base class constructors.
        super(ImageWidget, self).__init__(**traits)

        # Add some padding around the image.
        size = (self.bitmap.GetWidth() + 10, self.bitmap.GetHeight() + 10)

        # Create the toolkit-specific control.
        self.control = wx.Window(parent, -1, size=size)
        self.control.__tag__ = 'hack'

        self._mouse_over  = False
        self._button_down = False

        # Set up mouse event handlers:
        wx.EVT_ENTER_WINDOW(self.control, self._on_enter_window)
        wx.EVT_LEAVE_WINDOW(self.control, self._on_leave_window)
        wx.EVT_LEFT_DCLICK(self.control, self._on_left_dclick)
        wx.EVT_LEFT_DOWN(self.control, self._on_left_down)
        wx.EVT_LEFT_UP(self.control, self._on_left_up)
        wx.EVT_PAINT(self.control, self._on_paint)

        # Pens used to draw the 'selection' marker:
        # ZZZ: Make these class instances when moved to the wx toolkit code.
        self._selectedPenDark = wx.Pen(
            wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DSHADOW), 1, wx.SOLID
        )

        self._selectedPenLight = wx.Pen(
            wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DHIGHLIGHT), 1, wx.SOLID
        )

        return

    ###########################################################################
    # Private interface.
    ###########################################################################

    #### Trait event handlers #################################################

    def _bitmap_changed(self, bitmap):
        """ Called when the widget's bitmap is changed. """

        if self.control is not None:
            self.control.Refresh()

        return

    def _selected_changed(self, selected):
        """ Called when the selected state of the widget is changed. """

        if selected:
            for control in self.GetParent().GetChildren():
                if hasattr(control, '__tag__'):
                    if control.Selected():
                      control.Selected(False)
                      break

                self.Refresh()

        return

    #### wx event handlers ####################################################

    def _on_enter_window(self, event):
        """ Called when the mouse enters the widget. """

        if self._selected is not None:
            self._mouse_over = True
            self.Refresh()

        return

    def _on_leave_window(self, event):
        """ Called when the mouse leaves the widget. """

        if self._mouse_over:
            self._mouse_over = False
            self.Refresh()

        return

    def _on_left_dclick(self, event):
        """ Called when the left mouse button is double-clicked. """

        #print 'left dclick'

        event.Skip()

        return

    def _on_left_down ( self, event = None ):
        """ Called when the left mouse button goes down on the widget. """

        #print 'left down'

        if self._selected is not None:
            self.CaptureMouse()
            self._button_down = True
            self.Refresh()

        event.Skip()

        return

    def _on_left_up ( self, event = None ):
        """ Called when the left mouse button goes up on the widget. """

        #print 'left up'

        need_refresh = self._button_down
        if need_refresh:
            self.ReleaseMouse()
            self._button_down = False

        if self._selected is not None:
            wdx, wdy = self.GetClientSizeTuple()
            x        = event.GetX()
            y        = event.GetY()
            if (0 <= x < wdx) and (0 <= y < wdy):
                if self._selected != -1:
                    self.Selected( True )
                elif need_refresh:
                    self.Refresh()

                return

        if need_refresh:
            self.Refresh()

        event.Skip()

        return

    def _on_paint ( self, event = None ):
        """ Called when the widget needs repainting. """

        wdc      = wx.PaintDC( self.control )
        wdx, wdy = self.control.GetClientSizeTuple()
        bitmap   = self.bitmap
        bdx      = bitmap.GetWidth()
        bdy      = bitmap.GetHeight()
        wdc.DrawBitmap( bitmap, (wdx - bdx) / 2, (wdy - bdy) / 2, True )

        pens = [ self._selectedPenLight, self._selectedPenDark ]
        bd   = self._button_down
        if self._mouse_over:
            wdc.SetBrush( wx.TRANSPARENT_BRUSH )
            wdc.SetPen( pens[ bd ] )
            wdc.DrawLine( 0, 0, wdx, 0 )
            wdc.DrawLine( 0, 1, 0, wdy )
            wdc.SetPen( pens[ 1 - bd ] )
            wdc.DrawLine( wdx - 1, 1, wdx - 1, wdy )
            wdc.DrawLine( 1, wdy - 1, wdx - 1, wdy - 1 )

        if self._selected == True:
            wdc.SetBrush( wx.TRANSPARENT_BRUSH )
            wdc.SetPen( pens[ bd ] )
            wdc.DrawLine( 1, 1, wdx - 1, 1 )
            wdc.DrawLine( 1, 1, 1, wdy - 1 )
            wdc.DrawLine( 2, 2, wdx - 2, 2 )
            wdc.DrawLine( 2, 2, 2, wdy - 2 )
            wdc.SetPen( pens[ 1 - bd ] )
            wdc.DrawLine( wdx - 2, 2, wdx - 2, wdy - 1 )
            wdc.DrawLine( 2, wdy - 2, wdx - 2, wdy - 2 )
            wdc.DrawLine( wdx - 3, 3, wdx - 3, wdy - 2 )
            wdc.DrawLine( 3, wdy - 3, wdx - 3, wdy - 3 )

        return

#### EOF ######################################################################