From a805eed69ad4b891c8b6b5cc4735ce1d50a815ec Mon Sep 17 00:00:00 2001 From: Mesalu Date: Sun, 16 Jun 2019 18:27:48 -0700 Subject: [PATCH] Attempts to enforce system settings in the demo page panel. Adds a block in the wx.stc.StyledTextCtrl version of DemoPageEditor that will try to match system settings for caret period. Also adds the ability to read a switch off of sys.argv to manually disable cursor blinking. --- demo/Main.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/demo/Main.py b/demo/Main.py index 5469a59b..5facfc09 100644 --- a/demo/Main.py +++ b/demo/Main.py @@ -361,6 +361,37 @@ 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. + """ + 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 + + # attempt to average. + # (wx systemsettings allows on and off time, but scintilla just takes a single period.) + return (onmsec +offmsec) / 2.0 + + except (AttributeError, ValueError): + # Issue where wx.SYS_CARET_ON/OFF_MSEC is unavailable. + # Check + if '--no-caret-blink' in sys.argv: + return 0 + else: + 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 +643,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))