Expand|Select|Wrap|Line Numbers
- def OnTextEntered(self, evt):
- text = self.GetValue()
- if re.search('\[', text) and not re.search('\]', text):
- text.replace('[', '\[')
- if self.DoSearch(text, evt):
- if text not in self.searches:
- self.searches.append(text)
- if len(self.searches) > self.maxSearches:
- del self.searches[0]
- self.SetMenu(self.MakeMenu())
Expand|Select|Wrap|Line Numbers
- def DoSearch(self, text, event=None):
- if not len(self.data_bak):
- return False
- # 10014 is the Event type for wx.EVT_MENU
- # 10164 is the Event type for wx.EVT_TEXT (adaptive search)
- # 10165 is the Event type for wx.EVT_TEXT_ENTER
- valid_events = [10014, 10165]
- regex = re.compile(text.upper())
- tool = self.tb.FindById(Global.OnTB_ActSearch_Id)
- if tool.IsToggled():
- self.lc.DeleteAllItems()
- for entry in range(len(self.data_bak)):
- if text:
- if regex.search(self.data_bak[entry][0].upper()):
- self.lc.Append(self.data_bak[entry])
- else:
- self.lc.Append(self.data_bak[entry])
- return False
- elif not tool.IsToggled() and event.GetEventType() in valid_events:
- idx = self.lc.FindItem(self.currentItem + 1, text, True)
- if idx != -1:
- self.lc.Focus(idx)
- self.lc.Select(idx)
- return True
This 'active search' will modify what the user sees in the listctrl (making sure to update the back-up as well), just as they type it (I wanted to reproduce the Search function from the upper right corner of iTunes). The toggle check is there because the user has a toggle button on the toolbar to turn this active search on or off.
So if anybody has any ideas as to how to replace '[' in a string with literally '\[' I would appreciate it. I've played around with raw strings and even tried using a crazy combination of raw strings and the repr function to no avail.
An example of parameter names is P_SWID_PrmID[0].
To reiterate, I simply need to take the user input and escape any bracket characters so that the regex.search function does not mistake it for the start/end of a regular expression character class.