This file is indexed.

/usr/lib/python2.7/dist-packages/avc/avcwx.py is in python-avc 0.8.3-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
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
# .+
# .context    : Application View Controller
# .title      : AVC wx bindings
# .kind	      : python source
# .author     : Fabrizio Pollastri
# .site	      : Torino - Italy
# .creation   :	23-Nov-2007
# .copyright  :	(c) 2007-2008 Fabrizio Pollastri
# .license    : GNU General Public License (see below)
#
# This file is part of "AVC, Application View Controller".
#
# AVC 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 3 of the License, or
# (at your option) any later version.
#
# AVC 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 AVC.  If not, see <http://www.gnu.org/licenses/>.
#
# .-


#### IMPORT REQUIRED MODULES

import wx			# wx tool kit bindings

import string			# string operations


#### GENERAL ABSTRACTION METHODS

def toplevel_widgets():
  "Return the list of all top level widgets"
  return [wx.GetApp().GetTopWindow()]

def init(core):
  "Do init specific to this widget toolkit"
  # mapping between the real widget and the wal widget
  core['avccd'].widget_map = { \
    wx.BitmapButton:	core['Button'], \
    wx.Button:		core['Button'], \
    wx.CheckBox:	core['ToggleButton'], \
    wx.ComboBox:	core['ComboBox'],\
    wx.Choice:		core['ComboBox'],\
    wx.Gauge:		core['ProgressBar'], \
    wx.ListCtrl:	core['ListView'], \
    wx.RadioBox:	core['RadioButton'], \
    wx.Slider:		core['Slider'], \
    wx.SpinCtrl:	core['SpinButton'], \
    wx.StaticText:	core['Label'], \
    wx.StatusBar:	core['StatusBar'],
    wx.TextCtrl:	core['Entry'],
    wx.ToggleButton:	core['ToggleButton'], \
    wx.TreeCtrl:	core['TreeView']}
  # get toolkit version
  core['avccd'].toolkit_version = wx.VERSION_STRING

def widget_children(widget):
  "Return the list of all children of the widget"
  # Widgets that are not a subclass of gtk.Container have no children.
  if isinstance(widget,wx.Window):
    return widget.GetChildren()
  else:
    return []

def widget_name(widget):
  "Return the widget name"
  return widget.GetName()

def timer(function,period):
  "Create and start a timer calling 'function' every 'period' time"
  first_toplevel = toplevel_widgets()[0]
  timer = wx.Timer(first_toplevel,wx.NewId())
  first_toplevel.Bind(wx.EVT_TIMER,lambda event: function(),timer)
  timer.Start(int(period * 1000.0),oneShot=False)
  return timer


class error(Exception):
  "A generic error exception"
  def __init__(self, value):
    self.value = value
  def __str__(self):
    return repr(self.value)


#### WIDGETS ABSTRACTION LAYER (widget toolkit side)

class Widget:
  "wx Widget Abstraction Layer abstract class"

  def delete_method_filter(self,event):
    "Ignore destroy events not coming from current widget"
    if self.widget.GetId() == event.GetId():
      self.delete_method()

  def connect_delete(self,widget,delete_method):
    "Connect widget delete method to window destroy event"
    self.delete_method = delete_method
    #widget.Bind(wx.EVT_WINDOW_DESTROY,delete_method)
    widget.Bind(wx.EVT_WINDOW_DESTROY,self.delete_method_filter)


class ListTreeView(Widget):
  "Support to ListView and TreeView abstractors"

  def __init__(self):
    "Init operations common to ListView and TreeView"
    pass


class Button(Widget):
  "wx Button widget abstractor"

  def __init__(self):
    # create button press status variable
    self.widget.value = False
    # connect relevant signals
    self.widget.Bind(wx.EVT_LEFT_DOWN,
      lambda event: wx.CallAfter(
      lambda: self.connection.coget.__set__(
        '',True,self.widget,self.connection))
      or event.Skip())
    self.widget.Bind(wx.EVT_LEFT_UP,
      lambda event: wx.CallAfter(
      lambda: self.connection.coget.__set__(
        '',False,self.widget,self.connection))
      or event.Skip())

  def read(self):
    "Get button status"
    return self.widget.value

  def write(self,value):
    "Set button status"
    self.widget.value = value


class ComboBox(Widget):
  "wx ComboBox widget abstractor"

  def __init__(self):
    # connect relevant signals
    if self.widget.__class__ == wx.ComboBox:
      event_type = wx.EVT_COMBOBOX
    else:
      event_type = wx.EVT_CHOICE
    self.widget.Bind(event_type,self.value_changed)

  def read(self):
    "Get index of selected item"
    return self.widget.GetSelection()

  def write(self,value):
    "Set selected item by its index value"
    self.widget.SetSelection(value)


class Entry(Widget):
  "wx Entry widget abstractor"

  def __init__(self):
    # create entry text value variable
    self.widget.value =  self.widget.GetValue()
    # connect relevant signals
    self.widget.Bind(wx.EVT_TEXT,self.value_changed)

  def read(self):
    "Get text from Entry"
    text = self.widget.GetValue()
    # when TextCtrl text is set by program, the event EVT_TEXT is
    # triggered twice: first time with an empty string, second time with
    # the correct value. Substitute first (wrong) value with the old one.
    if text:
      return text
    else:
      return self.widget.value
    
  def write(self,value):
    "Set text into Entry"
    self.widget.SetValue(str(value))
    self.widget.value = str(value)
 

class Label(Widget):
  "wx Label widget abstractor"

  def __init__(self):
    pass

  def read(self):
    "Get value from Label"
    return self.widget.GetLabel()

  def write(self,value):
    "Set text into Label"
    self.widget.SetLabel(value)


class ListView(ListTreeView):
  "wx ListView widget abstractor"

  def __init__(self):
    # connect relevant signals
    self.widget.Bind(wx.EVT_LIST_END_LABEL_EDIT,
      lambda event: wx.CallAfter(self.value_changed) or event.Skip())

  def append_column(self,col_num,text):
    "Append a column to the ListView"
    self.widget.InsertColumn(col_num,text)
   
  def read(self):
    "Get values displayed by widget"
    # get head
    head = [str(self.widget.GetColumn(col_num).GetText()) \
      for col_num in range(self.widget.GetColumnCount())]
    # get data rows
    body = []
    for row_num in range(self.widget.GetItemCount()):
      row = []
      for col_num in range(self.widget.GetColumnCount()):
        try:
          row.append(self.row_types[col_num](
            self.widget.GetItem(row_num,col_num).GetText()))
        except:
          if self.row_types[col_num] == int:
            row.append(0)
          elif self.row_types[col_num] == float:
            row.append(0.0)
      body.append(row)
    # return
    return {'head': head,'body': body}

  def write(self,value):
    "Set values displayed by widget"
    # set header
    if value.has_key('head'):
      for col_num in range(self.widget.GetColumnCount()):
        col_item = self.widget.GetColumn(col_num)
        col_item.SetText(value['head'][col_num])
        self.widget.SetColumn(col_num,col_item)
    # set data rows
    body = value['body']
    self.widget.DeleteAllItems()
    if type(body[0]) == list:
      for row_num,row in enumerate(body):
        index = self.widget.InsertStringItem(row_num,'')
        for col_num,item in enumerate(row):
          self.widget.SetStringItem(row_num,col_num,str(item))
    else:
      for row_num,row in enumerate(body):
        self.widget.InsertStringItem(row_num,str(row))


class ProgressBar(Widget):
  "wx ProgressBar widget abstractor"

  def __init__(self):
    self.widget.SetRange(100)

  def read(self):
    "Get progress bar position"
    return self.widget.GetValue() / 100.
    
  def write(self,value):
    "Set progress bar position"
    # negative values pulse the bar, positive values position the bar. 
    if value < 0:
      self.widget.Pulse()
    else:
      self.widget.SetValue(int(round(value * 100)))
 

class RadioButton(Widget):
  "wx RadioButton widget abstractor"

  def __init__(self):
    # connect relevant signals
    if self.widget.__class__ == wx.RadioBox:
      event_type = wx.EVT_RADIOBOX
    else:
      event_type = wx.EVT_RADIOBUTTON
    self.widget.Bind(event_type,self.value_changed)

  def read(self):
    "Get index of activated button"
    return self.widget.GetSelection()

  def write(self,value):
    "Set activate button indexed by value"
    self.widget.SetSelection(value)


class Slider(Widget):
  "wx Slider widget abstractor"

  def __init__(self):
    # connect relevant signals
    self.widget.Bind(wx.EVT_LEFT_UP,
      lambda event: wx.CallAfter(self.value_changed) or event.Skip())
 
  def read(self):
    "Get Slider value"
    return self.widget.GetValue()

  def write(self,value):
    "Set Slider value"
    self.widget.SetValue(value)


class SpinButton(Widget):
  "wx SpinButton widget abstractor"

  def __init__(self):
    # connect relevant signals to handlers
    wx.EVT_SPINCTRL(self.widget,self.widget.GetId(),self.value_changed)


  def read(self):
    "Get spinbutton value"
    return self.widget.GetValue()

  def write(self,value):
    "Set spinbutton value"
    self.widget.SetValue(value)


class StatusBar(Widget):
  "wx StatusBar widget abstractor"

  def __init__(self):
    pass

  def write(self,value):
    "Set StatusBar value (only field 1)"
    self.widget.SetStatusText(value)


class TextView(Widget):
  "wx TextView widget abstractor"

  def __init__(self):
    # connect relevant signals to handlers
    self.widget.get_buffer().connect("changed",self.value_changed)

  def read(self):
    "Get text from TextView"
    textbuf = self.widget.get_buffer()
    return textbuf.get_text(textbuf.get_start_iter(),textbuf.get_end_iter())
    
  def write(self,value):
    "Set text into TextView"
    self.widget.get_buffer().set_text(str(value))


class ToggleButton(Widget):
  "wx ToggleButton widget abstractor"

  def __init__(self):
    # connect relevant signals
    if self.widget.__class__ == wx.CheckBox:
      event_type = wx.EVT_CHECKBOX
    else:
      event_type = wx.EVT_TOGGLEBUTTON
    self.widget.Bind(event_type,self.value_changed)

  def read(self):
    "Get button status"
    return bool(self.widget.GetValue())

  def write(self,value):
    "Set button status"
    self.widget.SetValue(value)


class TreeView(ListTreeView):
  "wx TreeView widget abstractor"

  def __init__(self):

    # check for allowed control type
    if self.connection.control_value.get('head',None):
      raise error, "%s widget do not support header." \
        % self.widget.__class__.__name__
    key,row = self.connection.control_value.get('body',None).iteritems().next()
    if type(row) == list and not len(row) == 1:
      raise error,"%s widget do not allow data rows with more than one column."\
        % self.widget.__class__.__name__

    # connect relevant signals
    self.widget.Bind(wx.EVT_TREE_END_LABEL_EDIT,
      lambda event: wx.CallAfter(self.value_changed) or event.Skip())

  def append_column(self,col_num,text):
    "wx TreeCtrl has no columns support"
    pass
   
  def read(self):
    "Get values displayed by widget"
    # get data rows
    body = {}
    # recursive depth first tree data node reader
    def read_node(node_id,node_path):
      try:
        body[string.join(map(str,node_path),'.')] = \
          self.row_types[0](self.widget.GetItemText(node_id))
      except:
        if self.row_types[0] == int:
          body[string.join(map(str,node_path),'.')] = [0]
        elif self.row_types[0] == float:
          body[string.join(map(str,node_path),'.')] = [0.0]
      child_id,child = self.widget.GetFirstChild(node_id)
      child_num = 1
      while child_id:
        read_node(child_id,node_path+[child_num])
        child_id,child = self.widget.GetNextChild(node_id,child)
        child_num += 1
    root_id = self.widget.GetRootItem()
    child_id,child = self.widget.GetFirstChild(root_id)
    child_num = 1
    while child_id:
      read_node(child_id,[child_num])
      child_id,child = self.widget.GetNextChild(root_id,child)
      child_num += 1
    # return
    return {'body': body}

  def write_head(self,head):
    "Header not supported"
    pass

  def root_node(self):
    "Clean tree and return the root node"
    self.widget.DeleteAllItems()
    return self.widget.AddRoot('')

  def add_node(self,parent,last_node,current_depth,data):
    "Add current node to the tree"
    return self.widget.AppendItem(parent,str(data))

#### END