--- a/SearchResultPanel.py Sun Oct 09 23:31:50 2011 +0200
+++ b/SearchResultPanel.py Mon Oct 10 02:22:26 2011 +0200
@@ -89,7 +89,7 @@
self.SearchResultsTree = CT.CustomTreeCtrl(id=ID_SEARCHRESULTPANELSEARCHRESULTSTREE,
name="SearchResultsTree", parent=self,
- pos=wx.Point(0, 0), style=0)
+ pos=wx.Point(0, 0), style=CT.TR_HAS_BUTTONS|CT.TR_NO_LINES|CT.TR_HAS_VARIABLE_ROW_HEIGHT)
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnSearchResultsTreeItemActivated,
id=ID_SEARCHRESULTPANELSEARCHRESULTSTREE)
@@ -138,6 +138,8 @@
def SetSearchResults(self, criteria, search_results):
self.Criteria = criteria
+ self.SearchResults = {}
+ self.ElementsOrder = []
for infos, start, end, text in search_results:
if infos[0] not in self.ElementsOrder:
@@ -155,9 +157,9 @@
self.RefreshView()
def RefreshView(self):
+ self.SearchResultsTree.DeleteAllItems()
if self.Criteria is None:
self.HeaderLabel.SetLabel(_("No search results available."))
- self.SearchResultsTree.DeleteAllItems()
self.ResetButton.Enable(False)
else:
matches_number = 0
@@ -259,37 +261,48 @@
else:
self.SearchResultsTree.SetItemImage(root, self.TreeImageDict[infos["type"]])
+ text = None
if infos["text"] is not None:
- text_ctrl = wx.TextCtrl(id=-1, parent=self.SearchResultsTree, pos=wx.Point(0, 0),
- value=infos["text"], style=wx.BORDER_NONE|wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_RICH2)
- width, height = wx.PaintDC(text_ctrl).GetTextExtent(infos["text"])
- text_ctrl.SetClientSize(wx.Size(width + 1, height))
- text_ctrl.SetBackgroundColour(self.SearchResultsTree.GetBackgroundColour())
+ text = infos["text"]
+ start, end = infos["data"][1:3]
+ text_lines = infos["text"].splitlines()
+ start_idx = start[1]
+ end_idx = reduce(lambda x, y: x + y, map(lambda x: len(x) + 1, text_lines[:end[0] - start[0]]), end[1] + 1)
+ style = wx.TextAttr(wx.BLACK, wx.Colour(206, 204, 247))
+ elif infos["type"] is not None and infos["matches"] > 1:
+ text = _("(%d matches)") % infos["matches"]
+ start_idx, end_idx = 0, len(text)
+ style = wx.TextAttr(wx.Colour(0, 127, 174))
+
+ if text is not None:
+ background_colour = self.SearchResultsTree.GetBackgroundColour()
+ if wx.Platform != '__WXMSW__':
+ text_ctrl = wx.TextCtrl(id=-1, parent=self.SearchResultsTree, pos=wx.Point(0, 0),
+ value=text, style=wx.BORDER_NONE|wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_RICH2)
+ width, height = text_ctrl.GetTextExtent(text)
+ text_ctrl.SetClientSize(wx.Size(width + 1, height))
+ self.SearchResultsTree.SetItemWindow(root, text_ctrl)
+ else:
+ panel = wx.Panel(id=-1, parent=self.SearchResultsTree)
+ panel.SetBackgroundColour(background_colour)
+ sizer = wx.BoxSizer(wx.HORIZONTAL)
+ if len(text.splitlines()) > 1:
+ text_ctrl = wx.TextCtrl(id=-1, parent=panel, pos=wx.Point(0, 0),
+ value=text, style=wx.BORDER_NONE|wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_RICH2)
+ else:
+ text_ctrl = wx.TextCtrl(id=-1, parent=panel, pos=wx.Point(0, 0),
+ value=text, size=wx.Size(0, 13), style=wx.BORDER_NONE|wx.TE_READONLY|wx.TE_RICH2)
+ width, height = text_ctrl.GetTextExtent(text)
+ sizer.AddWindow(text_ctrl, 1, border=0, flags=wx.ALIGN_CENTER_VERTICAL)
+ panel.SetSizer(sizer)
+ panel.SetClientSize(wx.Size(width + 1, height + 5))
+ self.SearchResultsTree.SetItemWindow(root, panel)
+
+ text_ctrl.SetBackgroundColour(background_colour)
text_ctrl.Bind(wx.EVT_LEFT_DOWN, self.GetTextCtrlClickFunction(root))
text_ctrl.Bind(wx.EVT_LEFT_DCLICK, self.GetTextCtrlDClickFunction(root))
- start, end = infos["data"][1:3]
- text_lines = infos["text"].splitlines()
- end_idx = reduce(lambda x, y: x + y, map(lambda x: len(x) + 1, text_lines[:end[0] - start[0]]), end[1] + 1)
text_ctrl.SetInsertionPoint(0)
- text_ctrl.SetStyle(start[1], end_idx, wx.TextAttr(wx.BLACK, wx.Colour(206, 204, 247)))
-
- self.SearchResultsTree.SetItemWindow(root, text_ctrl)
-
- elif infos["type"] is not None and infos["matches"] > 1:
- text = _("(%d matches)") % infos["matches"]
- text_ctrl = wx.TextCtrl(id=-1, parent=self.SearchResultsTree, pos=wx.Point(0, 0),
- value=text, style=wx.BORDER_NONE|wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_RICH2)
- width, height = wx.PaintDC(text_ctrl).GetTextExtent(text)
- text_ctrl.SetClientSize(wx.Size(width + 1, height))
- text_ctrl.SetBackgroundColour(self.SearchResultsTree.GetBackgroundColour())
- text_ctrl.Bind(wx.EVT_LEFT_DOWN, self.GetTextCtrlClickFunction(root))
- text_ctrl.Bind(wx.EVT_LEFT_DCLICK, self.GetTextCtrlDClickFunction(root))
-
- text_ctrl.SetInsertionPoint(0)
- text_ctrl.SetStyle(0, len(text), wx.TextAttr(wx.Colour(0, 127, 174)))
-
- self.SearchResultsTree.SetItemWindow(root, text_ctrl)
-
+ text_ctrl.SetStyle(start_idx, end_idx, style)
if wx.VERSION >= (2, 6, 0):
item, root_cookie = self.SearchResultsTree.GetFirstChild(root)
@@ -298,15 +311,9 @@
for child in infos["children"]:
if item is None:
item = self.SearchResultsTree.AppendItem(root, "")
- if wx.Platform != '__WXMSW__':
- item, root_cookie = self.SearchResultsTree.GetNextChild(root, root_cookie)
+ item, root_cookie = self.SearchResultsTree.GetNextChild(root, root_cookie)
self.GenerateSearchResultsTreeBranch(item, child)
item, root_cookie = self.SearchResultsTree.GetNextChild(root, root_cookie)
- while item is not None:
- to_delete.append(item)
- item, root_cookie = self.SearchResultsTree.GetNextChild(root, root_cookie)
- for item in to_delete:
- self.SearchResultsTree.Delete(item)
def ShowSearchResults(self, item):
data = self.SearchResultsTree.GetPyData(item)