diff --git a/demo/Main.py b/demo/Main.py index 4cfebae7..20715f92 100644 --- a/demo/Main.py +++ b/demo/Main.py @@ -361,6 +361,36 @@ def FindImages(text, widgetName): return winAppearance +def GetCaretPeriod(win = None): + """ + Attempts to identify the correct caret blinkrate to use in the Demo Code panel. + + :pram wx.Window win: a window to pass to wx.SystemSettings.GetMetric. + + :return: a value in milliseconds that indicates the proper period. + :rtype: int + + :raises: ValueError if unable to resolve a proper caret blink rate. + """ + if '--no-caret-blink' in sys.argv: + return 0 + + try: + onmsec = wx.SystemSettings.GetMetric(wx.SYS_CARET_ON_MSEC, win) + offmsec = wx.SystemSettings.GetMetric(wx.SYS_CARET_OFF_MSEC, win) + + # check values aren't -1 + if -1 in (onmsec, offmsec): + raise ValueError("Unable to determine caret blink rate.") + + # attempt to average. + # (wx systemsettings allows on and off time, but scintilla just takes a single period.) + return (onmsec + offmsec) / 2.0 + + except AttributeError: + # Issue where wx.SYS_CARET_ON/OFF_MSEC is unavailable. + raise ValueError("Unable to determine caret blink rate.") + #--------------------------------------------------------------------------- # Set up a thread that will scan the wxWidgets docs for window styles, # events and widgets screenshots @@ -612,6 +642,12 @@ try: # Selection background self.SetSelBackground(1, '#66CCFF') + # Attempt to set caret blink rate. + try: + self.SetCaretPeriod(GetCaretPeriod(self)) + except ValueError: + pass + self.SetSelBackground(True, wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT)) self.SetSelForeground(True, wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT))