mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	bpo-34548: IDLE: use configured theme colors in TextView (GH-9008)
https://bugs.python.org/issue34548
This commit is contained in:
		
							parent
							
								
									24b447edf2
								
							
						
					
					
						commit
						c87d9f406b
					
				
					 3 changed files with 12 additions and 9 deletions
				
			
		|  | @ -31,11 +31,12 @@ 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. | def color_config(text): | ||||||
|     '''Set color opitons of Text widget. |     """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'. |     # Not automatic because ColorDelegator does not know 'text'. | ||||||
|     theme = idleConf.CurrentTheme() |     theme = idleConf.CurrentTheme() | ||||||
|     normal_colors = idleConf.GetHighlight(theme, 'normal') |     normal_colors = idleConf.GetHighlight(theme, 'normal') | ||||||
|  | @ -50,6 +51,7 @@ def color_config(text):  # Called from htest, Editor, and Turtle Demo. | ||||||
|         inactiveselectbackground=select_colors['background'],  # new in 8.5 |         inactiveselectbackground=select_colors['background'],  # new in 8.5 | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| class ColorDelegator(Delegator): | class ColorDelegator(Delegator): | ||||||
| 
 | 
 | ||||||
|     def __init__(self): |     def __init__(self): | ||||||
|  | @ -285,6 +287,7 @@ def _color_delegator(parent):  # htest # | ||||||
|     d = ColorDelegator() |     d = ColorDelegator() | ||||||
|     p.insertfilter(d) |     p.insertfilter(d) | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||||
|     from unittest import main |     from unittest import main | ||||||
|     main('idlelib.idle_test.test_colorizer', verbosity=2, exit=False) |     main('idlelib.idle_test.test_colorizer', verbosity=2, exit=False) | ||||||
|  |  | ||||||
|  | @ -5,6 +5,8 @@ | ||||||
| from tkinter.ttk import Frame, Scrollbar, Button | from tkinter.ttk import Frame, Scrollbar, Button | ||||||
| from tkinter.messagebox import showerror | from tkinter.messagebox import showerror | ||||||
| 
 | 
 | ||||||
|  | from idlelib.colorizer import color_config | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| class TextFrame(Frame): | class TextFrame(Frame): | ||||||
|     "Display text with scrollbar." |     "Display text with scrollbar." | ||||||
|  | @ -18,12 +20,9 @@ def __init__(self, parent, rawtext): | ||||||
|         super().__init__(parent) |         super().__init__(parent) | ||||||
|         self['relief'] = 'sunken' |         self['relief'] = 'sunken' | ||||||
|         self['height'] = 700 |         self['height'] = 700 | ||||||
|         # TODO: get fg/bg from theme. |  | ||||||
|         self.bg = '#ffffff' |  | ||||||
|         self.fg = '#000000' |  | ||||||
| 
 | 
 | ||||||
|         self.text = text = Text(self, wrap='word', highlightthickness=0, |         self.text = text = Text(self, wrap='word', highlightthickness=0) | ||||||
|                                 fg=self.fg, bg=self.bg) |         color_config(text) | ||||||
|         self.scroll = scroll = Scrollbar(self, orient='vertical', |         self.scroll = scroll = Scrollbar(self, orient='vertical', | ||||||
|                                          takefocus=False, command=text.yview) |                                          takefocus=False, command=text.yview) | ||||||
|         text['yscrollcommand'] = scroll.set |         text['yscrollcommand'] = scroll.set | ||||||
|  |  | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | Use configured color theme for read-only text views. | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Tal Einat
						Tal Einat