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.
This commit is contained in:
Mesalu
2019-06-16 18:27:48 -07:00
parent 1e7506600c
commit a805eed69a

View File

@@ -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))