From 1256c49e24496999a53df0ded55a08afd9aac739 Mon Sep 17 00:00:00 2001 From: Tal Einat Date: Thu, 30 Aug 2018 15:44:53 +0300 Subject: [PATCH 1/5] bpo-34548: IDLE: Make TextView use the configured theme colors --- Lib/idlelib/colorizer.py | 6 ++++-- Lib/idlelib/textview.py | 9 ++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Lib/idlelib/colorizer.py b/Lib/idlelib/colorizer.py index d626d23121df74..85ee4a343cadbd 100644 --- a/Lib/idlelib/colorizer.py +++ b/Lib/idlelib/colorizer.py @@ -32,10 +32,10 @@ def make_pat(): 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. + """Set color options 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') @@ -50,6 +50,7 @@ def color_config(text): # Called from htest, Editor, and Turtle Demo. inactiveselectbackground=select_colors['background'], # new in 8.5 ) + class ColorDelegator(Delegator): def __init__(self): @@ -285,6 +286,7 @@ def _color_delegator(parent): # htest # d = ColorDelegator() p.insertfilter(d) + if __name__ == "__main__": from unittest import main main('idlelib.idle_test.test_colorizer', verbosity=2, exit=False) diff --git a/Lib/idlelib/textview.py b/Lib/idlelib/textview.py index 75b24703b4c357..50830dc90a799d 100644 --- a/Lib/idlelib/textview.py +++ b/Lib/idlelib/textview.py @@ -5,6 +5,8 @@ from tkinter.ttk import Frame, Scrollbar, Button from tkinter.messagebox import showerror +from idlelib.colorizer import color_config + class TextFrame(Frame): "Display text with scrollbar." @@ -18,12 +20,9 @@ def __init__(self, parent, rawtext): super().__init__(parent) self['relief'] = 'sunken' self['height'] = 700 - # TODO: get fg/bg from theme. - self.bg = '#ffffff' - self.fg = '#000000' - self.text = text = Text(self, wrap='word', highlightthickness=0, - fg=self.fg, bg=self.bg) + self.text = text = Text(self, wrap='word', highlightthickness=0) + color_config(self.text) self.scroll = scroll = Scrollbar(self, orient='vertical', takefocus=False, command=text.yview) text['yscrollcommand'] = scroll.set From 68d6454a188b53bef610db821db17c3974a0083f Mon Sep 17 00:00:00 2001 From: Tal Einat Date: Sat, 22 Sep 2018 20:25:32 +0300 Subject: [PATCH 2/5] bpo-34548: add a NEWS entry --- Misc/NEWS.d/next/IDLE/2018-09-22-20-25-07.bpo-34548.7pBzjg.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/IDLE/2018-09-22-20-25-07.bpo-34548.7pBzjg.rst diff --git a/Misc/NEWS.d/next/IDLE/2018-09-22-20-25-07.bpo-34548.7pBzjg.rst b/Misc/NEWS.d/next/IDLE/2018-09-22-20-25-07.bpo-34548.7pBzjg.rst new file mode 100644 index 00000000000000..48cd9fe261e5c4 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2018-09-22-20-25-07.bpo-34548.7pBzjg.rst @@ -0,0 +1 @@ +Make TextView use the text colors from the main IDLE configuration. From 92f39d321f5fb2c5e9e9414949472cdd8200f8b6 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sat, 22 Sep 2018 23:20:17 -0400 Subject: [PATCH 3/5] Minor changes to colorizer, textview, and blurb. --- Lib/idlelib/colorizer.py | 3 ++- Lib/idlelib/textview.py | 2 +- Misc/NEWS.d/next/IDLE/2018-09-22-20-25-07.bpo-34548.7pBzjg.rst | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Lib/idlelib/colorizer.py b/Lib/idlelib/colorizer.py index 85ee4a343cadbd..df03f04888bc19 100644 --- a/Lib/idlelib/colorizer.py +++ b/Lib/idlelib/colorizer.py @@ -31,11 +31,12 @@ def make_pat(): 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. +def color_config(text): """Set color options of Text widget. Should be called whenever ColorDelegator is called. """ + # Called from htest, TextFrame, Editor, and Turtledemo. # Not automatic because ColorDelegator does not know 'text'. theme = idleConf.CurrentTheme() normal_colors = idleConf.GetHighlight(theme, 'normal') diff --git a/Lib/idlelib/textview.py b/Lib/idlelib/textview.py index 50830dc90a799d..464e6ac6b94e31 100644 --- a/Lib/idlelib/textview.py +++ b/Lib/idlelib/textview.py @@ -22,7 +22,7 @@ def __init__(self, parent, rawtext): self['height'] = 700 self.text = text = Text(self, wrap='word', highlightthickness=0) - color_config(self.text) + color_config(text) self.scroll = scroll = Scrollbar(self, orient='vertical', takefocus=False, command=text.yview) text['yscrollcommand'] = scroll.set diff --git a/Misc/NEWS.d/next/IDLE/2018-09-22-20-25-07.bpo-34548.7pBzjg.rst b/Misc/NEWS.d/next/IDLE/2018-09-22-20-25-07.bpo-34548.7pBzjg.rst index 48cd9fe261e5c4..0056f12bac2d45 100644 --- a/Misc/NEWS.d/next/IDLE/2018-09-22-20-25-07.bpo-34548.7pBzjg.rst +++ b/Misc/NEWS.d/next/IDLE/2018-09-22-20-25-07.bpo-34548.7pBzjg.rst @@ -1 +1 @@ -Make TextView use the text colors from the main IDLE configuration. +Use user-selected color theme for read-only text views. From e86927cba2e15c1042d19e0cbc2512bcca97ff2b Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sat, 22 Sep 2018 23:39:00 -0400 Subject: [PATCH 4/5] Tweak color_config docstring. --- Lib/idlelib/colorizer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/idlelib/colorizer.py b/Lib/idlelib/colorizer.py index df03f04888bc19..d4e592b6ebe077 100644 --- a/Lib/idlelib/colorizer.py +++ b/Lib/idlelib/colorizer.py @@ -34,7 +34,7 @@ def make_pat(): def color_config(text): """Set color options of Text widget. - Should be called whenever ColorDelegator is called. + If ColorDelegator is used, this should be called first. """ # Called from htest, TextFrame, Editor, and Turtledemo. # Not automatic because ColorDelegator does not know 'text'. From 9b2831ca2246491d124fd2d9519d32a3be8801b1 Mon Sep 17 00:00:00 2001 From: Tal Einat Date: Sun, 23 Sep 2018 09:18:52 +0300 Subject: [PATCH 5/5] Update 2018-09-22-20-25-07.bpo-34548.7pBzjg.rst --- Misc/NEWS.d/next/IDLE/2018-09-22-20-25-07.bpo-34548.7pBzjg.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/IDLE/2018-09-22-20-25-07.bpo-34548.7pBzjg.rst b/Misc/NEWS.d/next/IDLE/2018-09-22-20-25-07.bpo-34548.7pBzjg.rst index 0056f12bac2d45..237c0c788c2cf3 100644 --- a/Misc/NEWS.d/next/IDLE/2018-09-22-20-25-07.bpo-34548.7pBzjg.rst +++ b/Misc/NEWS.d/next/IDLE/2018-09-22-20-25-07.bpo-34548.7pBzjg.rst @@ -1 +1 @@ -Use user-selected color theme for read-only text views. +Use configured color theme for read-only text views.