bpo-34548: IDLE: use configured theme colors in TextView (GH-9008) · python/cpython@c87d9f4

3 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -31,11 +31,12 @@ def make_pat():

3131

prog = re.compile(make_pat(), re.S)

3232

idprog = re.compile(r"\s+(\w+)", re.S)

3333
34-

def color_config(text): # Called from htest, Editor, and Turtle Demo.

35-

'''Set color opitons of Text widget.

34+

def color_config(text):

35+

"""Set color options of Text widget.

3636
37-

Should be called whenever ColorDelegator is called.

38-

'''

37+

If ColorDelegator is used, this should be called first.

38+

"""

39+

# Called from htest, TextFrame, Editor, and Turtledemo.

3940

# Not automatic because ColorDelegator does not know 'text'.

4041

theme = idleConf.CurrentTheme()

4142

normal_colors = idleConf.GetHighlight(theme, 'normal')

@@ -50,6 +51,7 @@ def color_config(text): # Called from htest, Editor, and Turtle Demo.

5051

inactiveselectbackground=select_colors['background'], # new in 8.5

5152

)

5253
54+
5355

class ColorDelegator(Delegator):

5456
5557

def __init__(self):

@@ -285,6 +287,7 @@ def _color_delegator(parent): # htest #

285287

d = ColorDelegator()

286288

p.insertfilter(d)

287289
290+
288291

if __name__ == "__main__":

289292

from unittest import main

290293

main('idlelib.idle_test.test_colorizer', verbosity=2, exit=False)

Original file line numberDiff line numberDiff line change

@@ -5,6 +5,8 @@

55

from tkinter.ttk import Frame, Scrollbar, Button

66

from tkinter.messagebox import showerror

77
8+

from idlelib.colorizer import color_config

9+
810
911

class TextFrame(Frame):

1012

"Display text with scrollbar."

@@ -18,12 +20,9 @@ def __init__(self, parent, rawtext):

1820

super().__init__(parent)

1921

self['relief'] = 'sunken'

2022

self['height'] = 700

21-

# TODO: get fg/bg from theme.

22-

self.bg = '#ffffff'

23-

self.fg = '#000000'

2423
25-

self.text = text = Text(self, wrap='word', highlightthickness=0,

26-

fg=self.fg, bg=self.bg)

24+

self.text = text = Text(self, wrap='word', highlightthickness=0)

25+

color_config(text)

2726

self.scroll = scroll = Scrollbar(self, orient='vertical',

2827

takefocus=False, command=text.yview)

2928

text['yscrollcommand'] = scroll.set

Original file line numberDiff line numberDiff line change

@@ -0,0 +1 @@

1+

Use configured color theme for read-only text views.