Last active
March 12, 2016 04:08
-
-
Save blitzmann/ff4faba7faeda084e3e3 to your computer and use it in GitHub Desktop.
Testing slowdown on OS X 10.11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import wxversion | |
| wxversion.select('3.0') | |
| import wx | |
| SB_ITEM_NORMAL = 0 | |
| SB_ITEM_HIGHLIGHTED = 2 | |
| class LineItem(wx.Window): | |
| def __init__(self, parent, text="", id=wx.ID_ANY, pos=wx.DefaultPosition, size=(50,16)): | |
| wx.Window.__init__(self, parent, id, pos, size) | |
| self.highlighted = False | |
| self.bkBitmap = None | |
| self.padding = 4 | |
| self.text = text | |
| self.Bind(wx.EVT_PAINT, self.OnPaint) | |
| self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) | |
| self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterWindow) | |
| self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow) | |
| def OnEraseBackground(self, event): | |
| pass | |
| def OnEnterWindow(self, event): | |
| self.SetHighlighted(True) | |
| self.Refresh() | |
| event.Skip() | |
| def OnLeaveWindow(self, event): | |
| self.SetHighlighted(False) | |
| self.Refresh() | |
| event.Skip() | |
| def SetHighlighted(self, highlight = True): | |
| self.highlighted = highlight | |
| def GetState(self): | |
| if self.highlighted: | |
| state = SB_ITEM_HIGHLIGHTED | |
| else: | |
| state = SB_ITEM_NORMAL | |
| return state | |
| def RenderBackground(self): | |
| rect = self.GetRect() | |
| state = self.GetState() | |
| bkBitmap = wx.EmptyBitmap(rect.width, rect.height) | |
| mdc = wx.MemoryDC() | |
| mdc.SelectObject(bkBitmap) | |
| if state == SB_ITEM_HIGHLIGHTED: | |
| mdc.SetBackground(wx.Brush(wx.YELLOW)) | |
| else: | |
| mdc.SetBackground(wx.Brush(wx.WHITE)) | |
| mdc.Clear() | |
| mdc.SelectObject(wx.NullBitmap) | |
| return bkBitmap | |
| def OnPaint(self, event): | |
| mdc = wx.PaintDC(self) | |
| mdc.DrawBitmap(self.RenderBackground(), 0, 0) | |
| rect = self.GetRect() | |
| font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT) | |
| if self.GetState() == SB_ITEM_HIGHLIGHTED: | |
| font.SetWeight(wx.FONTWEIGHT_BOLD) | |
| mdc.SetFont(font) | |
| wtext, htext = mdc.GetTextExtent(self.text) | |
| x = self.padding | |
| y = (rect.height - htext) / 2 | |
| mdc.DrawText(self.text, x, y) | |
| if __name__ == "__main__": | |
| class TestPanel(wx.Panel): | |
| def __init__(self, parent, size=(500, 500)): | |
| wx.Panel.__init__(self, parent, size=size) | |
| max_elements = 40 | |
| self.box = wx.BoxSizer(wx.VERTICAL) | |
| grid = wx.FlexGridSizer(max_elements, 5) | |
| for t in xrange(max_elements*5): | |
| item = LineItem(self, "test %d" % t, size=(100, 16)) | |
| grid.Add(item, 0, wx.ALL, 0) | |
| self.box.Add(grid, 0, wx.ALL, 0) | |
| self.SetSizer(self.box) | |
| self.Layout() | |
| class Frame(wx.Frame): | |
| def __init__(self, title, size=(500, 650)): | |
| wx.Frame.__init__(self, None, title=title, size=size) | |
| self.statusbar = self.CreateStatusBar() | |
| main_sizer = wx.BoxSizer(wx.VERTICAL) | |
| panel = TestPanel(self, size=size) | |
| main_sizer.Add(panel) | |
| self.SetSizer(main_sizer) | |
| app = wx.App(redirect=False) # Error messages go to popup window | |
| top = Frame("Test Window") | |
| top.Show() | |
| app.MainLoop() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Video of test script on OS X 10.11 (notice lag with highlighting compared to pointer): https://vid.me/hbDl
Video of test script on OS X 10.10 (no / unnoticable lag): https://vid.me/qvjp