[Python-checkins] cpython: Issue #27117: Make colorizer htest and turtledemo work with dark theme.

terry.reedy python-checkins at python.org
Sun May 29 01:42:23 EDT 2016


https://hg.python.org/cpython/rev/c95864a37ee2
changeset: 101556:c95864a37ee2
user: Terry Jan Reedy <tjreedy at udel.edu>
date: Sun May 29 01:40:22 2016 -0400
summary:
 Issue #27117: Make colorizer htest and turtledemo work with dark theme.
Factor out code for configuring text widget colors to a new function.
files:
 Lib/idlelib/colorizer.py | 25 +++++++++++++++++++++++++
 Lib/idlelib/editor.py | 17 ++---------------
 Lib/turtledemo/__main__.py | 5 ++++-
 3 files changed, 31 insertions(+), 16 deletions(-)
diff --git a/Lib/idlelib/colorizer.py b/Lib/idlelib/colorizer.py
--- a/Lib/idlelib/colorizer.py
+++ b/Lib/idlelib/colorizer.py
@@ -2,6 +2,7 @@
 import re
 import keyword
 import builtins
+from tkinter import TkVersion
 from idlelib.delegator import Delegator
 from idlelib.config import idleConf
 
@@ -32,6 +33,28 @@
 prog = re.compile(make_pat(), re.S)
 idprog = re.compile(r"\s+(\w+)", re.S)
 
+def color_config(text): # Called from htest, Editor, and Turtle Demo.
+ '''Set color opitons of Text widget.
+
+ Should be called whenever ColorDelegator is called.
+ '''
+ # Not automatic because ColorDelegator does not know 'text'.
+ theme = idleConf.CurrentTheme()
+ normal_colors = idleConf.GetHighlight(theme, 'normal')
+ cursor_color = idleConf.GetHighlight(theme, 'cursor', fgBg='fg')
+ select_colors = idleConf.GetHighlight(theme, 'hilite')
+ text.config(
+ foreground=normal_colors['foreground'],
+ background=normal_colors['background'],
+ insertbackground=cursor_color,
+ selectforeground=select_colors['foreground'],
+ selectbackground=select_colors['background'],
+ )
+ if TkVersion >= 8.5:
+ text.config(
+ inactiveselectbackground=select_colors['background'])
+
+
 class ColorDelegator(Delegator):
 
 def __init__(self):
@@ -233,6 +256,7 @@
 for tag in self.tagdefs:
 self.tag_remove(tag, "1.0", "end")
 
+
 def _color_delegator(parent): # htest #
 from tkinter import Toplevel, Text
 from idlelib.percolator import Percolator
@@ -247,6 +271,7 @@
 text.insert("insert", source)
 text.focus_set()
 
+ color_config(text)
 p = Percolator(text)
 d = ColorDelegator()
 p.insertfilter(d)
diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py
--- a/Lib/idlelib/editor.py
+++ b/Lib/idlelib/editor.py
@@ -90,7 +90,7 @@
 
 class EditorWindow(object):
 from idlelib.percolator import Percolator
- from idlelib.colorizer import ColorDelegator
+ from idlelib.colorizer import ColorDelegator, color_config
 from idlelib.undo import UndoDelegator
 from idlelib.iomenu import IOBinding, filesystemencoding, encoding
 from idlelib import mainmenu
@@ -742,20 +742,7 @@
 # Called from self.filename_change_hook and from configdialog.py
 self._rmcolorizer()
 self._addcolorizer()
- theme = idleConf.CurrentTheme()
- normal_colors = idleConf.GetHighlight(theme, 'normal')
- cursor_color = idleConf.GetHighlight(theme, 'cursor', fgBg='fg')
- select_colors = idleConf.GetHighlight(theme, 'hilite')
- self.text.config(
- foreground=normal_colors['foreground'],
- background=normal_colors['background'],
- insertbackground=cursor_color,
- selectforeground=select_colors['foreground'],
- selectbackground=select_colors['background'],
- )
- if TkVersion >= 8.5:
- self.text.config(
- inactiveselectbackground=select_colors['background'])
+ EditorWindow.color_config(self.text)
 
 IDENTCHARS = string.ascii_letters + string.digits + "_"
 
diff --git a/Lib/turtledemo/__main__.py b/Lib/turtledemo/__main__.py
--- a/Lib/turtledemo/__main__.py
+++ b/Lib/turtledemo/__main__.py
@@ -89,8 +89,8 @@
 import os
 
 from tkinter import *
+from idlelib.colorizer import ColorDelegator, color_config
 from idlelib.percolator import Percolator
-from idlelib.colorizer import ColorDelegator
 from idlelib.textview import view_text
 from turtledemo import __doc__ as about_turtledemo
 
@@ -123,6 +123,8 @@
 ('About turtle module', turtle.__doc__),
 )
 
+
+
 class DemoWindow(object):
 
 def __init__(self, filename=None):
@@ -203,6 +205,7 @@
 self.text_frame = text_frame = Frame(root)
 self.text = text = Text(text_frame, name='text', padx=5,
 wrap='none', width=45)
+ color_config(text)
 
 self.vbar = vbar = Scrollbar(text_frame, name='vbar')
 vbar['command'] = text.yview
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /