From 2bec2e38b6ca44c0be44eaaae7742aa8b298718b Mon Sep 17 00:00:00 2001 From: HomeWorld Date: Sat, 11 Dec 2010 04:05:19 +0200 Subject: [PATCH] Made Display class 100% flicker free on wxMSW. --- gui/display.py | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/gui/display.py b/gui/display.py index c9865289e..71a367d9e 100644 --- a/gui/display.py +++ b/gui/display.py @@ -36,6 +36,9 @@ class Display(wx.ListCtrl): self.Bind(wx.EVT_LIST_COL_END_DRAG, self.resizeChecker) self.Bind(wx.EVT_LIST_COL_BEGIN_DRAG, self.resizeSkip) + if "wxMSW" in wx.PlatformInfo: + self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBk) + self.mainFrame = gui.mainFrame.MainFrame.getInstance() i = 0 @@ -68,6 +71,42 @@ class Display(wx.ListCtrl): self.imageListBase = self.imageList.ImageCount + + def OnEraseBk(self,event): + if self.GetItemCount() >0: + width, height = self.GetClientSize() + dc = event.GetDC() + + dc.DestroyClippingRegion() + dc.SetClippingRegion(0, 0, width, height) + x,y,w,h = dc.GetClippingBox() + + topItem = self.GetTopItem() + bottomItem = topItem + self.GetCountPerPage() + + if bottomItem >= self.GetItemCount(): + bottomItem = self.GetItemCount() - 1 + + topRect = self.GetItemRect(topItem, wx.LIST_RECT_LABEL) + bottomRect = self.GetItemRect(bottomItem, wx.LIST_RECT_BOUNDS) + + + items_rect = wx.Rect(topRect.left, 0, bottomRect.right - topRect.left, bottomRect.bottom ) + + updateRegion = wx.Region(x,y,w,h) + updateRegion.SubtractRect(items_rect) + + dc.DestroyClippingRegion() + dc.SetClippingRegionAsRegion(updateRegion) + + dc.SetBackground(wx.Brush(self.GetBackgroundColour(), wx.SOLID)) + dc.Clear() + + dc.DestroyClippingRegion() + + else: + event.Skip() + def addColumn(self, i, col): self.activeColumns.append(col) info = wx.ListItem() @@ -170,7 +209,6 @@ class Display(wx.ListCtrl): self.SetItemData(item, id) - # self.Freeze() if 'wxMSW' in wx.PlatformInfo: for i,col in enumerate(self.activeColumns):