This file is indexed.

/usr/share/pyshared/plwm/input.py is in python-plwm 2.6a+20080530-1.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
#
# input.py -- input editing for PLWM
#
#    Copyright (C) 2001  Mike Meyer <mwm@mired.org>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


"input - a tool for getting input from the user."

from Xlib import X, Xatom
from keys import KeyGrabKeyboard, allmap
from wmanager import Window

class InputKeyHandler(KeyGrabKeyboard):
    """Template for handling user input.

    InputKeyHandler defines the following event handler methods:

    _insert - insert the character typed. The latin1 character set is
            bound to this by default.

    _forw, _back - move the cursor forward or backward in the input

    _delforw, _delback - delete the character forward or backward in the input

    _end, _begin - move the cursor to the end or beginning of the input

    _deltoend - remove all characters to the end of the input

    _paste - paste the current selection into the intput. The handler
             must be an instance of wmanager.Window for this to work

    _done - run action on the current string

    _abort - exit without doing anything

    _history_up - scroll to newer events

    _history_down - scroll to older events"""

    timeout = None

    def __init__(self, handler, display, history):
        """Init with a handler and display.

        handler is a handler object appropriate for KeyGrabKeyboard.
        display has show(left, right), do(string) and abort() methods.
            both abort() and do() should clean up the object.
        history is a list of strings we let the user scroll through."""

        KeyGrabKeyboard.__init__(self, handler, X.CurrentTime)
        self.display = display
        self.handler = handler
        self.history = history
        self.history_index = len(history)
        self.left = ""
        self.right = ""
        if isinstance(handler, Window):
            self.selection = self.wm.display.intern_atom("SELECTION")
            self.wm.dispatch.add_handler(X.SelectionNotify,
                                       self._paste_selection, handlerid = self)
        display.show(self.left, self.right)

    def _paste_selection(self, event):
        if event.property:
            sel = self.handler.window.get_full_property(self.selection, Xatom.STRING)
            if sel and sel.format == 8:
                self.left = self.left + sel.value
                self.display.show(self.left, self.right)

    def _paste(self, event):
        if isinstance(self.handler, Window):
            self.handler.window.convert_selection(Xatom.PRIMARY, Xatom.STRING,
                                                self.selection, X.CurrentTime)

    def _insert(self, event):
        if event.type != X.KeyPress: return
        sym = self.wm.display.keycode_to_keysym(event.detail,
                                                event.state & X.ShiftMask != 0)
        chr = self.wm.display.lookup_string(sym)
        if chr: self.left = self.left + chr
        self.display.show(self.left, self.right)

    def _forw(self, event):
        if self.right:
            self.left = self.left + self.right[0]
            self.right = self.right[1:]
        self.display.show(self.left, self.right)

    def _back(self, event):
        if self.left:
            self.right = self.left[-1] + self.right
            self.left = self.left[:-1]
        self.display.show(self.left, self.right)

    def _delforw(self, event):
        if self.right:
            self.right = self.right[1:]
        self.display.show(self.left, self.right)

    def _delback(self, event):
        if self.left:
            self.left = self.left[:-1]
        self.display.show(self.left, self.right)

    def _deltoend(self, event):
        self.right = ""
        self.display.show(self.left, self.right)

    def _end(self, event):
        self.left = self.left + self.right
        self.right = ""
        self.display.show(self.left, self.right)

    def _begin(self, event):
        self.right = self.left + self.right
        self.left = ""
        self.display.show(self.left, self.right)

    def _done(self, event):
        res = self.left + self.right
        self.history.append(res)
        self.display.do(res)
        self.wm.dispatch.remove_handler(self)
        self._cleanup()

    def _abort(self, event):
        self.display.abort()
        self.wm.dispatch.remove_handler(self)
        self._cleanup()

    def _history_up(self, event):
        if len(self.history):
            if self.history_index > 0:
                self.history_index -= 1
                self.left = self.history[self.history_index]
                self.right = ""
                self.display.show(self.left, self.right)

    def _history_down(self, event):
        if len(self.history):
            if self.history_index <(len(self.history)-1):
                self.history_index += 1
                self.left = self.history[self.history_index]
                self.right = ""
                self.display.show(self.left, self.right)

allmap(InputKeyHandler, InputKeyHandler._insert)

class inputWindow:
    "Class to get a line of user input in a window."

    fontname= "9x15"
    foreground = "black"
    background = "white"
    borderwidth = 3
    bordercolor = "black"
    history = []

    def __init__(self, prompt, screen, length=30):

        if not prompt: prompt = ' '        # We have problems if there's no prompt, so add one.
        self.string = self.prompt = prompt
        self.offset = len(self.prompt)
        self.length = length + self.offset
        self.start = 0
        fg = screen.get_color(self.foreground)
        bg = screen.get_color(self.background)
        bc = screen.get_color(self.bordercolor)
        font = screen.wm.get_font(self.fontname, 'fixed')
        size = font.query()
        self.height = size.font_ascent + size.font_descent + 1
        self.width = font.query_text_extents(prompt).overall_width + \
                   font.query_text_extents(length * 'm').overall_width
        self.baseline = size.font_ascent + 1

        window = screen.root.create_window(0, 0, self.width, self.height,
                                           self.borderwidth,
                                           X.CopyFromParent, X.InputOutput,
                                           X.CopyFromParent,
                                           background_pixel = bg,
                                           border_pixel = bc,
                                           event_mask = (X.VisibilityChangeMask |
                                                         X.ExposureMask))

        self.gc = window.create_gc(font = font, function = X.GXinvert,
                                 foreground = fg, background = bg)

        self.font = font
        self.window = screen.add_internal_window(window)
        self.window.dispatch.add_handler(X.VisibilityNotify, self.raisewindow)
        self.window.dispatch.add_handler(X.Expose, self.redraw)

    def read(self, action, handlertype, x=0, y=0):
        "Open the window at x, y, using handlertype, and doing action."

        self.action = action
        x, y, width, height = self.window.keep_on_screen(x, y, self.width, self.height)
        self.window.configure(x = x, y = y, width = width, height = height)
        self.window.map()
        self.window.get_focus(X.CurrentTime)
        handlertype(self.window, self, self.history)

    def raisewindow(self, event):
        self.window.raisewindow()

    def redraw(self, event = None):
        length = len(self.string)

        if self.offset < length:
            wide = self.font.query_text_extents(self.string[self.offset]).overall_width
        else:
            wide = self.font.query_text_extents(' ').overall_width

        if self.start >= self.offset: self.start = self.offset - 1
        left = self.font.query_text_extents(self.string[self.start:self.offset]).overall_width

        if left + wide >= self.width:
            self.start = self.offset - self.length + 1
            left = self.font.query_text_extents(self.string[self.start:self.offset]).overall_width

        self.window.clear_area(width = self.width, height = self.height)
        self.window.image_text(self.gc, 0, self.baseline, self.string[self.start:])
        self.window.fill_rectangle(self.gc, left, 0, wide, self.height)


    def show(self, left, right):
        if left:
            self.string = self.prompt + left
        else:        # Display the prompt in this case.
            self.string = self.prompt
            self.start = 0
        self.offset = len(self.string)
        self.string = self.string + right
        self.redraw()

    def do(self, string):
        self.action(string)
        self.window.destroy()

    def abort(self):
        self.window.destroy()


class modeInput:
    "Class to get input via the modewindow."

    history = []

    def __init__(self, prompt, screen, length = None):
        # ignore length argument
        self.prompt = prompt
        self.screen = screen

    def read(self, action, handlertype, x = 0, y = 0):
        self.action = action
        self.status_msg = self.screen.modestatus_new(self.prompt + "_")
        handlertype(self.screen.modewindow_mw.window, self, self.history)

    def show(self, left, right):
        self.status_msg.set("%s%s_%s" % (self.prompt, left, right))

    def do(self, string):
        self.action(string)
        self.status_msg.pop()

    def abort(self):
        self.status_msg.pop()