This file is indexed.

/usr/lib/python3/dist-packages/pyraf/MplCanvasAdapter.py is in python3-pyraf 2.1.14+dfsg-6.

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
#!/usr/bin/env python

"""
$Id$
"""

 # confidence high

import os, matplotlib
matplotlib.use('TkAgg') # set backend
import matplotlib.backends.backend_tkagg as tkagg
from .Ptkplot import hideTkCursor
from .Ptkplot import FullWindowCursor
from .wutil import moveCursorTo, WUTIL_USING_X


class MplCanvasAdapter(tkagg.FigureCanvasTkAgg):
    """ Is a FigureCanvasTkAgg, with extra methods to look like Canvas """

    def __init__(self, gkikernel, figure, master=None):
        tkagg.FigureCanvasTkAgg.__init__(self, figure, master,
                                         self.resize_event)
        # members
        self.__theGwidget = self.get_tk_widget() # THE gwidget
        self.__gkiKernel = gkikernel
        self.__doIdleRedraw = 0
        self.__doIdleSWCursor = 0
        self.ignoreNextRedraw = 0 # used externally to this class ...

        # Add a placeholder software cursor attribute. If it is None,
        # that means no software cursor is in effect. If it is not None,
        # then it will be used to render the cursor.
        self.__isSWCursorActive = 0
        self.__SWCursor = None

        # Basic bindings for the virtual trackball.
        # ! Do NOT set these without undergoing a major GkiMpl design
        # check !  Binding Expose to tkExpose forces tkRedraw to be
        # called WAY too many times during a window resize. This uses the
        # draw buffer, which is slow and unnecessary for resizes.
#       self.__theGwidget.bind('<Expose>', self.tkExpose)
#       self.__theGwidget.bind('<Configure>', self.tkExpose) # init draw issue

    def pack(self, **kw):

        """ delegate to the gwidget """
        self.__theGwidget.pack(kw)

    def winfo_id(self):

        """ delegate to the gwidget """
        self.__theGwidget.winfo_id()

    def gwidgetize(self, width, height):

        """ This is a one-stop shopping spot to add all the extra attributes
        to the gwidget object it needs to be seen as a "gwidget" in the GKI
        sense. See requirements in GkiInteractiveTkBase. """

        gw = self.__theGwidget

        # Add attributes to the gwidget
        gw.lastX              = None
        gw.lastY              = None
        gw.width              = width
        gw.height             = height

        # Add our functions to the gwidget
        gw.activateSWCursor   = self.activateSWCursor
        gw.deactivateSWCursor = self.deactivateSWCursor
        gw.isSWCursorActive   = self.isSWCursorActive
        gw.getSWCursor        = self.getSWCursor
        gw.moveCursorTo       = self.moveCursorTo
        gw.tkRedraw           = self.tkRedraw

    def resize_event(self, evt=None):

        # See also get/set_size_inches, figure.get_window_extent().  The latter
        # is Bbox, use .width/.height()
        #
        #  before rsz: w = self.figure.get_window_extent().width # not func .98
        #  before rsz: h = self.figure.get_window_extent().height() # is in .91

        # Note that the 'evt' arg was always part of the signature for
        # versions before MPL v 0.98.5.2, when it became optional.
        # So see if it is there.  Always use it if present, it is accurate.
        if evt != None:
            curW = evt.width
            curH = evt.height
        else:
            dpi = self.figure.get_dpi()
            curW = self.figure.get_figwidth() * dpi
            curH = self.figure.get_figheight() * dpi

        # Need to deactivate cursor before resizing, then re-act. after
        self.wrappedRedrawOrResize(w=curW, h=curH)

        # also update the widget's w/h attrs; we will need this for the cursor
        self.__theGwidget.width  = curW
        self.__theGwidget.height = curH

    def flush(self):

        self.__doIdleRedraw = 0

    # show and draw could be defined to catch events before passing through
#   def show(self):  tkagg.FigureCanvasTkAgg.show(self)
#   def draw(self):  tkagg.FigureCanvasTkAgg.draw(self)

    def wrappedRedrawOrResize(self, w=None, h=None):

        """Wrap the redraw (or resize) with a deactivate and then re-activate
        of the cursor.  If w or h are provided then we are only resizing."""

        # need to indicate cursor is not visible before this, since
        # cursor sleeps are now issued by redraw. The presumption is that
        # redraw/resize will affect cursor visibility, so we set it first
        resizing = w != None
        cursorActivate = 0

        if self.__isSWCursorActive:
            # deactivate cursor for duration of redraw
            # otherwise it slows the redraw to a glacial pace
            cursorActivate = 1
            x = self.__SWCursor.lastx
            y = self.__SWCursor.lasty
            self.deactivateSWCursor()

        if resizing:
            self.__gkiKernel.resizeGraphics(w, h)
        else:
            # should document how this line gets to GkiMplKernel.redraw()
            self.__theGwidget.redraw(self.__theGwidget)

        if cursorActivate:
            # Need to activate it, but don't draw it if only resizing, there is
            # a bug where the previous crosshair cursor is drawn too.
            self.activateSWCursor(x, y, drawToo=(not resizing))

    # tkRedraw() is used as if it belonged to the gwidget's class
    def tkRedraw(self, *dummy):

        """ delegate to the gwidget """
        gw = self.__theGwidget
        self.__doIdleRedraw = 1
        gw.after_idle(self.idleRedraw)

    def idleRedraw(self):

        """Do a redraw, then set buffer so no more happen on this idle cycle"""
        if self.__doIdleRedraw:
            self.__doIdleRedraw = 0
            self.wrappedRedrawOrResize()

    # isSWCursorActive() is used as if it belonged to the gwidget's class
    def isSWCursorActive(self):

        """ getter """
        return self.__isSWCursorActive

    # activateSWCursor() is used as if it belonged to the gwidget's class
    def activateSWCursor(self, x=None, y=None, type=None, drawToo=True):

        gw = self.__theGwidget
        hideTkCursor(gw) # from Ptkplot
        # ignore type for now since only one type of software cursor
        # is implemented
        gw.update_idletasks()
        if not self.__isSWCursorActive:
            if not self.__SWCursor:
                self.__SWCursor = FullWindowCursor(0.5, 0.5, gw)
            self.__isSWCursorActive = 1
            gw.bind("<Motion>",self.moveCursor)
        if drawToo and not self.__SWCursor.isVisible():
            self.__SWCursor.draw()

    # deactivateSWCursor() is used as if it belonged to the gwidget's class
    def deactivateSWCursor(self):

        gw = self.__theGwidget
        gw.update_idletasks()
        if self.__isSWCursorActive:
            self.__SWCursor.erase()
            gw.unbind("<Motion>")
            self.__SWCursor.isLastSWmove = 1
            self.__isSWCursorActive = 0
            gw['cursor'] = 'arrow' # set back to normal

    # getSWCursor() is used as if it belonged to the gwidget's class
    def getSWCursor(self):

        """ getter """
        return self.__SWCursor

    def SWCursorWake(self):

        """ Wake cursor only after idle """
        self.__doIdleSWCursor = 1
        self.after_idle(self.idleSWCursorWake)

    def idleSWCursorWake(self):

        """Do cursor redraw, then reset so no more happen on this idle cycle"""
        if self.__doIdleSWCursor:
            self.__doIdleSWCursor = 0
            self.SWCursorImmediateWake()

    def SWCursorImmediateWake(self):

        if self.__isSWCursorActive:
            self.__SWCursor.draw()

    def moveCursor(self, event):

        """Call back for mouse motion events"""
        # Kludge to handle the fact that MacOS X (X11) doesn't remember
        # software driven moves, the first move will just move nothing
        # but will properly update the coordinates.  Do not do this under Aqua.
        gw = self.__theGwidget
        if WUTIL_USING_X and self.__SWCursor.isLastSWmove:
            x = self.__SWCursor.lastx
            y = self.__SWCursor.lasty
            # call the wutil version
            moveCursorTo(gw.winfo_id(),
                         gw.winfo_rootx(),
                         gw.winfo_rooty(),
                         int(x*gw.winfo_width()),
                         int((1.-y)*gw.winfo_height()))
        else:
            x = (event.x+0.5)/gw.winfo_width()
            y = 1.-(event.y+0.5)/gw.winfo_height()
        self.__SWCursor.moveTo(x,y,SWmove=0)

    # moveCursorTo() is used as if it belonged to the gwidget's class
    def moveCursorTo(self, x, y, SWmove=0):

        self.__SWCursor.moveTo(float(x)/self.__theGwidget.width,
                              float(y)/self.__theGwidget.height,
                              SWmove)

    def activate(self):

        """Not really needed for Tkplot widgets"""
        pass

    def tkExpose(self, *dummy):

        """Redraw the widget upon the tkExpose event.
        Make it active, update tk events, call redraw procedure."""
        if self.ignoreNextRedraw:
            self.ignoreNextRedraw = 0
        else:
            self.tkRedraw()