This file is indexed.

/usr/lib/python2.7/dist-packages/vigra/pyqt/quickdialog.py is in python-vigra 1.10.0+git20160211.167be93+dfsg-5ubuntu1.

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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
#######################################################################
#                                                                      
#         Copyright 2009-2010 by Ullrich Koethe                        
#                                                                      
#    This file is part of the VIGRA computer vision library.           
#    The VIGRA Website is                                              
#        http://hci.iwr.uni-heidelberg.de/vigra/                       
#    Please direct questions, bug reports, and contributions to        
#        ullrich.koethe@iwr.uni-heidelberg.de    or                    
#        vigra@informatik.uni-hamburg.de                               
#                                                                      
#    Permission is hereby granted, free of charge, to any person       
#    obtaining a copy of this software and associated documentation    
#    files (the "Software"), to deal in the Software without           
#    restriction, including without limitation the rights to use,      
#    copy, modify, merge, publish, distribute, sublicense, and/or      
#    sell copies of the Software, and to permit persons to whom the    
#    Software is furnished to do so, subject to the following          
#    conditions:                                                       
#                                                                      
#    The above copyright notice and this permission notice shall be    
#    included in all copies or substantial portions of the             
#    Software.                                                         
#                                                                      
#    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND    
#    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES   
#    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND          
#    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT       
#    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,      
#    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING      
#    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR     
#    OTHER DEALINGS IN THE SOFTWARE.                                   
#                                                                      
#######################################################################

import PyQt4.QtGui  as qt
import PyQt4.QtCore as qcore
from PyQt4.QtCore import SIGNAL
import os

def alignLabels(*args):
    m = 0
    for dialogElement in args:
        fontMetrics = qt.QFontMetrics(dialogElement.font())
        for line in dialogElement.label.text().ascii().split('\n'):
            labelWidth = fontMetrics.width(line)
            m = max(m, labelWidth)
    for dialogElement in args:
        dialogElement.label.setFixedWidth(m+10)

class FileDialog(qt.QFrame):
    def __init__(self, parent, label, filter):
        qt.QFrame.__init__(self, parent)
        parent.addWidget(self)
        self.filter = filter
        self.label = qt.QLabel(label)
        self.filename = qt.QLineEdit()
        self.filebrowser = qt.QPushButton("Browse...")
        self.filebrowser.setFocusPolicy(qcore.Qt.NoFocus)

        self._layout = qt.QHBoxLayout()
        self._layout.setSpacing(5)
        self._layout.addWidget(self.label)
        self._layout.addWidget(self.filename, 1)
        self._layout.addWidget(self.filebrowser)
        
        self.setLayout(self._layout)
            
    def text(self):
        return str(qcore.QFile.encodeName(self.filename.text()))
        
    def setFocus(self):
        self.filename.setFocus()

class InputFile(FileDialog):
    def __init__(self, parent, label, filter):
        FileDialog.__init__(self, parent, label, filter)
        self.connect(self.filebrowser, SIGNAL("clicked()"), self.browse)
        
    def browse(self):
        fn = qt.QFileDialog.getOpenFileName( "", self.filter, self)
        if not fn.isNull():
            self.filename.setText(fn)
        
    def validate(self):
        try:
            filename = str(qcore.QFile.encodeName(self.filename.text()))
            file = open(filename)
            file.close()
            return True
        except IOError:
            qt.QMessageBox.critical(None, "Error", "File '" + filename + "' not found")
            return False

class OutputFile(FileDialog):
    def __init__(self, parent, label, filter):
        FileDialog.__init__(self, parent, label, filter)
        self.connect(self.filebrowser, SIGNAL("clicked()"), self.browse)
        
    def browse(self):
        fn = qt.QFileDialog.getSaveFileName( self, "Save File", "", self.filter)
        if not fn.isNull():
            self.filename.setText(fn)
        
    def validate(self):
        try:
            filename = str(qcore.QFile.encodeName(self.filename.text()))
            file = open(filename)
            file.close()
            return not qt.QMessageBox.warning(
                None, "Warning", "File '" + filename + "' exists",
                "Overwrite", "Cancel")
        except IOError:
            return True

class _OptionalValueInput(qt.QFrame):
    def __init__(self, parent, label):
        qt.QFrame.__init__(self, parent)
        parent.addWidget(self)
        self.label = qt.QLabel(label)
        self.variable = qt.QLineEdit()
        self.variable.setValidator(self._QValidator(self.variable))

        self._layout = qt.QHBoxLayout()
        self._layout.setSpacing(5)
        self._layout.addWidget(self.label)
        self._layout.addWidget(self.variable, 1)
        
        self.setLayout(self._layout)
                    
    def setFocus(self):
        self.variable.setFocus()
        
    def setValue(self, text):
        self.variable.setText(str(self._text2Value(text)))
    
    def value(self):
        text = self.text()
        if text == "":
            return None
        return self._text2Value(text)

    def text(self):
        return str(self.variable.text())
        
    def validate(self):
        try:
            v = self.value()
            if v == None:
                return True
        except:
            qt.QMessageBox.critical(None, "Error",
                qcore.QString("Field '%1' must contain "+self._mustContain).arg(
                    self.label.text()))
            return False
        try:
            if v < self.min:
                qt.QMessageBox.critical(None, "Error",
                    qcore.QString("Field '%1' value must be >= "+str(self.min)).arg(
                        self.label.text()))
                return False
        except AttributeError:
            pass
        try:
            if v > self.max:
                qt.QMessageBox.critical(None, "Error",
                    qcore.QString("Field '%1' value must be <= "+str(self.max)).arg(
                        self.label.text()))
                return False
        except AttributeError:
            pass
        return True
            
class OptionalIntegerInput(_OptionalValueInput):
    _QValidator = qt.QIntValidator
    _text2Value = int
    _mustContain = "an integer"

class IntegerInput(OptionalIntegerInput):
    def value(self):
        return int(self.text())

class OptionalFloatInput(_OptionalValueInput):
    _QValidator = qt.QDoubleValidator
    _text2Value = float
    _mustContain = "a float"

class FloatInput(OptionalFloatInput):
    def value(self):
        return float(self.text())

class OptionalStringInput(qt.QFrame):
    def __init__(self, parent, label):
        qt.QFrame.__init__(self, parent)
        parent.addWidget(self)
        self.label = qt.QLabel(label)
        self.variable = qt.QLineEdit()

        self._layout = qt.QHBoxLayout()
        self._layout.setSpacing(5)
        self._layout.addWidget(self.label)
        self._layout.addWidget(self.variable, 1)
        
        self.setLayout(self._layout)
                    
    def setFocus(self):
        self.variable.setFocus()
            
    def setText(self, text):
        self.variable.setText(text)
    
    def text(self):
        return str(self.variable.text())
    
    def unicode(self):
        return unicode(self.variable.text())

class StringInput(OptionalStringInput):
    def __init__(self, parent, label):
        OptionalStringInput.__init__(self, parent, label)
            
    def validate(self):
        if self.text() == "":
            qt.QMessageBox.critical(
                None, "Error",
                qcore.QString("Field '%1' empty").arg(self.label.text()))
            return False
        return True

OutputVariable = StringInput
InputVariable = StringInput
OptionalInputVariable = OptionalStringInput

class CheckBox(qt.QCheckBox):
    def __init__(self, parent, label):
        qt.QCheckBox.__init__(self, label, parent)
        parent.addWidget(self)

    def selection(self):
        return self.isChecked()


class Choice(qt.QFrame):
    def __init__(self, parent, label, vertical = 0):
        qt.QFrame.__init__(self, parent)
        parent.addWidget(self)
        
        self.buttonBox = qt.QGroupBox(label, self)
        if vertical:
            self.buttonBox.layout = qt.QVBoxLayout(self.buttonBox)
        else:
            self.buttonBox.layout = qt.QHBoxLayout(self.buttonBox)
        
        self.layout = qt.QHBoxLayout(self)
        self.layout.addWidget(self.buttonBox)
        self.layout.addStretch(5)
        
        self.buttons = []
        self.results = []
    
    def addButton(self, label, result):
        self.buttons.append(qt.QRadioButton(label))
        self.buttonBox.layout.addWidget(self.buttons[-1])
        self.results.append(result)
        self.buttons[0].setChecked(True)
        
    def addSpacing(self, spacing):
        self.buttonBox.addSpace(spacing)
        
    def selectButton(self, index):
        if index >= 0 and index < len(self.buttons):
            self.buttons[index].setChecked(True)
        
    def selection(self):
        for k in range(len(self.buttons)):
            if self.buttons[k].isChecked():
                return self.results[k]
        return None # should never happen

class HChoice(Choice):
    def __init__(self, parent, label):
        Choice.__init__(self, parent, label, 0)
        
class VChoice(Choice):
    def __init__(self, parent, label):
        Choice.__init__(self, parent, label, 1)
        
class DialogGroup(qt.QFrame):
    def __init__(self, parent, vertical = 0):
        qt.QFrame.__init__(self, parent)
        parent.addWidget(self)
        if vertical:
            self.layout = qt.QVBoxLayout(self)
            self.defaultAlignment = qcore.Qt.AlignLeft
        else:
            self.layout = qt.QHBoxLayout(self)
            self.defaultAlignment = qcore.Qt.AlignTop
        self.widgets = []
               
    def addWidget(self, widget, stretch = 0, alignment = None):
        if alignment is None:
            alignment = self.defaultAlignment
        self.layout.addWidget(widget, stretch, alignment)
        self.widgets.append(widget)
        
    def addSpacing(self, spacing):
        self.layout.addSpacing(spacing)

    def addStretch(self, stretch):
        self.layout.addStretch(stretch)
        
    def addLabel(self, labelString):
        label = qt.QLabel(labelString, self)
        self.addWidget(label, 0, qcore.Qt.AlignLeft)
        
    def validate(self):
        for i in self.widgets:
            try:
                if i.validate() == 0:
                    return False
            except AttributeError:
                continue
        return True

class HDialogGroup(DialogGroup):
    def __init__(self, parent):
        DialogGroup.__init__(self, parent, 0)
        
class VDialogGroup(DialogGroup):
    def __init__(self, parent):
        DialogGroup.__init__(self, parent, 1)
       
#class DialogStack(qt.QWidgetStack):
#    def __init__(self, parent, widgetMapping = None):
#        qt.QWidgetStack.__init__(self, parent)
#        parent.addWidget(self)
#        self.widgetMapping = widgetMapping
#        self.size = 0
#            
#    def raiseWidget(self, index):
#        if self.widgetMapping:
#            qt.QWidgetStack.raiseWidget(self, self.widgetMapping[index])
#        else:
#            qt.QWidgetStack.raiseWidget(self, index)
#
#    def addWidget(self, widget):
#        qt.QWidgetStack.addWidget(self, widget, self.size)
#        self.size = self.size + 1
#        
#    def validate(self):
#        try:
#            return self.visibleWidget().validate()
#        except AttributeError:
#            pass

class QuickDialog(qt.QDialog):
    def __init__(self, parent, title):
        qt.QDialog.__init__(self, parent)

        self.layout = qt.QVBoxLayout(self)
        self.layout.addStretch(5)
        self.layout.addSpacing(20)
        
        self.insertButtons()
        
        self.widgets = []
        self.setWindowTitle(title)
        self.setOrientation(qcore.Qt.Vertical)
        self.resize(500,-1)
        
    def insertButtons(self):
        self.buttons = qt.QFrame(self)
        self.buttons.OK = qt.QPushButton("OK", self.buttons)
        self.buttons.Cancel = qt.QPushButton("Cancel", self.buttons)
        self.buttons.OK.setDefault(1)
        self.connect(self.buttons.Cancel, SIGNAL("clicked()"), self.reject)
        self.connect(self.buttons.OK, SIGNAL("clicked()"), self.tryAccept)
        
        self.buttons.layout = qt.QHBoxLayout(self.buttons)
        self.buttons.layout.addStretch(5)
        self.buttons.layout.addWidget(self.buttons.OK)
        self.buttons.layout.addWidget(self.buttons.Cancel)
        self.layout.addWidget(self.buttons)
        
    def addWidget(self, widget, stretch = 0, alignment = None):
        if alignment is None:
            alignment = qcore.Qt.AlignTop
        self.layout.insertWidget(len(self.widgets), widget, stretch, alignment)
        self.widgets.append(widget)
        
    def addSpacing(self, spacing):
        self.layout.insertSpacing(len(self.widgets), spacing)
        self.widgets.append(None)

    def addStretch(self, stretch):
        self.layout.insertStretch(len(self.widgets), stretch)
        self.widgets.append(None)

    def addLabel(self, labelString):
        label = qt.QLabel(labelString, self)
        self.addWidget(label, 0, qcore.Qt.AlignLeft)
        
    def setHelp(self, *functionSeq):
        helpString = ""
        functionList = list(*functionSeq)
        while len(functionList) > 0:
            function = functionList.pop()
            if (len(functionList) == 0) and (function.__doc__):
                helpString = helpString + function.__doc__
            elif function.__doc__:
                helpString = helpString + function.__doc__ + os.linesep + \
                    "--------------------------------------------------------"+\
                    "--------------------------------" + os.linesep
        
        if not hasattr(self.buttons, "Help"):
            self.buttons.Help = qt.QPushButton("Help", self.buttons)
            self.buttons.Help.setToggleButton(1)
            self.buttons.layout.insertWidget(3, self.buttons.Help)
            self.connect(self.buttons.Help, SIGNAL("toggled(bool)"), self.showExtension)
        
        if int(qt.qVersion()[0]) < 3:
            self.help = qt.QMultiLineEdit(self)
            self.help.setText(helpString)
            if self.help.numLines() > 20:
                self.help.setFixedVisibleLines(20)
            else:
                self.help.setFixedVisibleLines(self.help.numLines()+1)

            self.help.setReadOnly(1)
            self.help.setWordWrap(qt.QMultiLineEdit.WidgetWidth)
        else:
            self.help = qt.QVBox(self)
            self.help.text = qcore.QtextEdit(self.help)
            self.help.text.setText(helpString)
            self.help.text.setReadOnly(1)
            self.help.text.setWordWrap(qt.QMultiLineEdit.WidgetWidth)
            total_height = self.help.text.heightForWidth(self.help.width())
            if  total_height > self.help.text.height():
                self.help.text.setMinimumSize(self.help.text.width(), min(300, total_height))
                
        self.setExtension(self.help)
        
    def tryAccept(self):
        for i in self.widgets:
            try:
                if i.validate() == 0:
                    return
            except AttributeError:
                continue
        self.accept()