mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #27117: Make ColorDelegator htest and turtledemo work with dark theme.
Factor out code for configuring text widget colors to a new function.
This commit is contained in:
parent
58dd7648de
commit
e8a175eaa0
3 changed files with 31 additions and 16 deletions
|
@ -2,6 +2,7 @@ import time
|
||||||
import re
|
import re
|
||||||
import keyword
|
import keyword
|
||||||
import builtins
|
import builtins
|
||||||
|
from tkinter import TkVersion
|
||||||
from idlelib.Delegator import Delegator
|
from idlelib.Delegator import Delegator
|
||||||
from idlelib.configHandler import idleConf
|
from idlelib.configHandler import idleConf
|
||||||
|
|
||||||
|
@ -32,6 +33,28 @@ def make_pat():
|
||||||
prog = re.compile(make_pat(), re.S)
|
prog = re.compile(make_pat(), re.S)
|
||||||
idprog = re.compile(r"\s+(\w+)", 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):
|
class ColorDelegator(Delegator):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -233,6 +256,7 @@ class ColorDelegator(Delegator):
|
||||||
for tag in self.tagdefs:
|
for tag in self.tagdefs:
|
||||||
self.tag_remove(tag, "1.0", "end")
|
self.tag_remove(tag, "1.0", "end")
|
||||||
|
|
||||||
|
|
||||||
def _color_delegator(parent): # htest #
|
def _color_delegator(parent): # htest #
|
||||||
from tkinter import Toplevel, Text
|
from tkinter import Toplevel, Text
|
||||||
from idlelib.Percolator import Percolator
|
from idlelib.Percolator import Percolator
|
||||||
|
@ -247,6 +271,7 @@ def _color_delegator(parent): # htest #
|
||||||
text.insert("insert", source)
|
text.insert("insert", source)
|
||||||
text.focus_set()
|
text.focus_set()
|
||||||
|
|
||||||
|
color_config(text)
|
||||||
p = Percolator(text)
|
p = Percolator(text)
|
||||||
d = ColorDelegator()
|
d = ColorDelegator()
|
||||||
p.insertfilter(d)
|
p.insertfilter(d)
|
||||||
|
|
|
@ -90,7 +90,7 @@ helpDialog = HelpDialog() # singleton instance, no longer used
|
||||||
|
|
||||||
class EditorWindow(object):
|
class EditorWindow(object):
|
||||||
from idlelib.Percolator import Percolator
|
from idlelib.Percolator import Percolator
|
||||||
from idlelib.ColorDelegator import ColorDelegator
|
from idlelib.ColorDelegator import ColorDelegator, color_config
|
||||||
from idlelib.UndoDelegator import UndoDelegator
|
from idlelib.UndoDelegator import UndoDelegator
|
||||||
from idlelib.IOBinding import IOBinding, filesystemencoding, encoding
|
from idlelib.IOBinding import IOBinding, filesystemencoding, encoding
|
||||||
from idlelib import Bindings
|
from idlelib import Bindings
|
||||||
|
@ -742,20 +742,7 @@ class EditorWindow(object):
|
||||||
# Called from self.filename_change_hook and from configDialog.py
|
# Called from self.filename_change_hook and from configDialog.py
|
||||||
self._rmcolorizer()
|
self._rmcolorizer()
|
||||||
self._addcolorizer()
|
self._addcolorizer()
|
||||||
theme = idleConf.CurrentTheme()
|
EditorWindow.color_config(self.text)
|
||||||
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'])
|
|
||||||
|
|
||||||
IDENTCHARS = string.ascii_letters + string.digits + "_"
|
IDENTCHARS = string.ascii_letters + string.digits + "_"
|
||||||
|
|
||||||
|
|
|
@ -89,8 +89,8 @@ import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from tkinter import *
|
from tkinter import *
|
||||||
|
from idlelib.ColorDelegator import ColorDelegator, color_config
|
||||||
from idlelib.Percolator import Percolator
|
from idlelib.Percolator import Percolator
|
||||||
from idlelib.ColorDelegator import ColorDelegator
|
|
||||||
from idlelib.textView import view_text
|
from idlelib.textView import view_text
|
||||||
from turtledemo import __doc__ as about_turtledemo
|
from turtledemo import __doc__ as about_turtledemo
|
||||||
|
|
||||||
|
@ -124,6 +124,8 @@ help_entries = ( # (help_label, help_doc)
|
||||||
('About turtle module', turtle.__doc__),
|
('About turtle module', turtle.__doc__),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DemoWindow(object):
|
class DemoWindow(object):
|
||||||
|
|
||||||
def __init__(self, filename=None):
|
def __init__(self, filename=None):
|
||||||
|
@ -204,6 +206,7 @@ class DemoWindow(object):
|
||||||
self.text_frame = text_frame = Frame(root)
|
self.text_frame = text_frame = Frame(root)
|
||||||
self.text = text = Text(text_frame, name='text', padx=5,
|
self.text = text = Text(text_frame, name='text', padx=5,
|
||||||
wrap='none', width=45)
|
wrap='none', width=45)
|
||||||
|
color_config(text)
|
||||||
|
|
||||||
self.vbar = vbar = Scrollbar(text_frame, name='vbar')
|
self.vbar = vbar = Scrollbar(text_frame, name='vbar')
|
||||||
vbar['command'] = text.yview
|
vbar['command'] = text.yview
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue