/usr/share/pyshared/provami/QueryTextCtrl.py is in provami 5.18-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 | import wx
from provami.Model import ModelListener
class QueryTextCtrl(wx.TextCtrl, ModelListener):
def __init__(self, parent, model, filterTag, updateFunc = None, isValid = None):
wx.TextCtrl.__init__(self, parent)
self.model = model
self.model.registerUpdateListener(self)
# tag to identify the model filter changes to which we react
self.filterTag = filterTag
self.updateFunc = updateFunc
if isValid is None:
self.isValid = lambda x: True
else:
self.isValid = isValid
self.defaultBackground = self.GetBackgroundColour()
self.invalidBackground = wx.Colour(0xff, 0xbb, 0xbb)
self.dirtyBackground = wx.Colour(0xff, 0xff, 0xbb)
self.Bind(wx.EVT_TEXT, self.onChanged)
self.Bind(wx.EVT_CHAR, self.onChar)
self.updating = False
def updateColour(self):
if not self.isValid(self.GetValue()):
self.SetBackgroundColour(self.invalidBackground)
elif self.readValue() != self.model.filter.get(self.filterTag, None):
self.SetBackgroundColour(self.dirtyBackground)
else:
self.SetBackgroundColour(self.defaultBackground)
def readValue(self):
res = str(self.GetValue()).strip()
if res == "": return None
return res
def onChanged(self, event):
if self.updating: return
self.updateColour()
def onChar(self, event):
c = event.GetKeyCode()
if c == 13:
self.activated(event)
else:
event.Skip()
def activated(self, event):
#print "Activated", self.GetValue()
if self.updateFunc is not None:
self.updateFunc(self.readValue())
def filterChanged(self, what):
if what == self.filterTag:
self.updating = True
text = self.model.filter.get(self.filterTag, None)
if text is not None:
self.SetValue(text)
else:
self.SetValue("")
self.updateColour()
self.updating = False
def invalidate(self):
self.Enable(False)
def hasData(self, what):
if what == "all":
self.Enable(True)
|