wohlganger | 58fc71c | 2017-09-10 16:19:47 -0500 | [diff] [blame] | 1 | """codecontext - display the block context above the edit window |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 2 | |
Kurt B. Kaiser | 0a13579 | 2005-10-03 19:26:03 +0000 | [diff] [blame] | 3 | Once code has scrolled off the top of a window, it can be difficult to |
| 4 | determine which block you are in. This extension implements a pane at the top |
| 5 | of each IDLE edit window which provides block structure hints. These hints are |
| 6 | the lines which contain the block opening keywords, e.g. 'if', for the |
Cheryl Sabella | 29996a1 | 2018-06-01 19:23:00 -0400 | [diff] [blame] | 7 | enclosing block. The number of hint lines is determined by the maxlines |
Terry Jan Reedy | 6fa5bdc | 2016-05-28 13:22:31 -0400 | [diff] [blame] | 8 | variable in the codecontext section of config-extensions.def. Lines which do |
Kurt B. Kaiser | 0a13579 | 2005-10-03 19:26:03 +0000 | [diff] [blame] | 9 | not open blocks are not shown in the context hints pane. |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 10 | |
| 11 | """ |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 12 | import re |
Kurt B. Kaiser | 3536a5c | 2007-12-12 17:22:06 +0000 | [diff] [blame] | 13 | from sys import maxsize as INFINITY |
Terry Jan Reedy | bfbaa6b | 2016-08-31 00:50:55 -0400 | [diff] [blame] | 14 | |
| 15 | import tkinter |
| 16 | from tkinter.constants import TOP, LEFT, X, W, SUNKEN |
| 17 | |
Terry Jan Reedy | 6fa5bdc | 2016-05-28 13:22:31 -0400 | [diff] [blame] | 18 | from idlelib.config import idleConf |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 19 | |
Terry Jan Reedy | 049882e | 2014-12-11 05:33:36 -0500 | [diff] [blame] | 20 | BLOCKOPENERS = {"class", "def", "elif", "else", "except", "finally", "for", |
Terry Jan Reedy | d89ca94 | 2018-05-17 20:38:41 -0400 | [diff] [blame] | 21 | "if", "try", "while", "with", "async"} |
Kurt B. Kaiser | d00587a | 2004-04-24 03:08:13 +0000 | [diff] [blame] | 22 | UPDATEINTERVAL = 100 # millisec |
Cheryl Sabella | de65162 | 2018-06-01 21:45:54 -0400 | [diff] [blame] | 23 | CONFIGUPDATEINTERVAL = 1000 # millisec |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 24 | |
Cheryl Sabella | 654038d | 2018-05-19 15:34:03 -0400 | [diff] [blame] | 25 | |
Cheryl Sabella | 8506016 | 2018-05-23 22:18:15 -0400 | [diff] [blame] | 26 | def get_spaces_firstword(codeline, c=re.compile(r"^(\s*)(\w*)")): |
| 27 | "Extract the beginning whitespace and first word from codeline." |
| 28 | return c.match(codeline).groups() |
| 29 | |
| 30 | |
| 31 | def get_line_info(codeline): |
| 32 | """Return tuple of (line indent value, codeline, block start keyword). |
| 33 | |
| 34 | The indentation of empty lines (or comment lines) is INFINITY. |
| 35 | If the line does not start a block, the keyword value is False. |
| 36 | """ |
| 37 | spaces, firstword = get_spaces_firstword(codeline) |
| 38 | indent = len(spaces) |
| 39 | if len(codeline) == indent or codeline[indent] == '#': |
| 40 | indent = INFINITY |
| 41 | opener = firstword in BLOCKOPENERS and firstword |
| 42 | return indent, codeline, opener |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 43 | |
wohlganger | 58fc71c | 2017-09-10 16:19:47 -0500 | [diff] [blame] | 44 | |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 45 | class CodeContext: |
Cheryl Sabella | 654038d | 2018-05-19 15:34:03 -0400 | [diff] [blame] | 46 | "Display block context above the edit window." |
| 47 | |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 48 | def __init__(self, editwin): |
Cheryl Sabella | 654038d | 2018-05-19 15:34:03 -0400 | [diff] [blame] | 49 | """Initialize settings for context block. |
| 50 | |
| 51 | editwin is the Editor window for the context block. |
| 52 | self.text is the editor window text widget. |
| 53 | self.textfont is the editor window font. |
| 54 | |
Cheryl Sabella | b609e68 | 2018-06-04 11:58:44 -0400 | [diff] [blame] | 55 | self.context displays the code context text above the editor text. |
Cheryl Sabella | 8506016 | 2018-05-23 22:18:15 -0400 | [diff] [blame] | 56 | Initially None, it is toggled via <<toggle-code-context>>. |
Cheryl Sabella | 654038d | 2018-05-19 15:34:03 -0400 | [diff] [blame] | 57 | self.topvisible is the number of the top text line displayed. |
| 58 | self.info is a list of (line number, indent level, line text, |
| 59 | block keyword) tuples for the block structure above topvisible. |
Cheryl Sabella | 8506016 | 2018-05-23 22:18:15 -0400 | [diff] [blame] | 60 | self.info[0] is initialized with a 'dummy' line which |
| 61 | starts the toplevel 'block' of the module. |
Cheryl Sabella | 654038d | 2018-05-19 15:34:03 -0400 | [diff] [blame] | 62 | |
| 63 | self.t1 and self.t2 are two timer events on the editor text widget to |
Cheryl Sabella | 8506016 | 2018-05-23 22:18:15 -0400 | [diff] [blame] | 64 | monitor for changes to the context text or editor font. |
Cheryl Sabella | 654038d | 2018-05-19 15:34:03 -0400 | [diff] [blame] | 65 | """ |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 66 | self.editwin = editwin |
| 67 | self.text = editwin.text |
| 68 | self.textfont = self.text["font"] |
Cheryl Sabella | de65162 | 2018-06-01 21:45:54 -0400 | [diff] [blame] | 69 | self.contextcolors = CodeContext.colors |
Cheryl Sabella | b609e68 | 2018-06-04 11:58:44 -0400 | [diff] [blame] | 70 | self.context = None |
Kurt B. Kaiser | 0a13579 | 2005-10-03 19:26:03 +0000 | [diff] [blame] | 71 | self.topvisible = 1 |
Cheryl Sabella | 654038d | 2018-05-19 15:34:03 -0400 | [diff] [blame] | 72 | self.info = [(0, -1, "", False)] |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 73 | # Start two update cycles, one for context lines, one for font changes. |
Terry Jan Reedy | a6bb313 | 2017-09-17 00:56:56 -0400 | [diff] [blame] | 74 | self.t1 = self.text.after(UPDATEINTERVAL, self.timer_event) |
Cheryl Sabella | de65162 | 2018-06-01 21:45:54 -0400 | [diff] [blame] | 75 | self.t2 = self.text.after(CONFIGUPDATEINTERVAL, self.config_timer_event) |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 76 | |
wohlganger | 58fc71c | 2017-09-10 16:19:47 -0500 | [diff] [blame] | 77 | @classmethod |
| 78 | def reload(cls): |
Cheryl Sabella | 654038d | 2018-05-19 15:34:03 -0400 | [diff] [blame] | 79 | "Load class variables from config." |
wohlganger | 58fc71c | 2017-09-10 16:19:47 -0500 | [diff] [blame] | 80 | cls.context_depth = idleConf.GetOption("extensions", "CodeContext", |
Cheryl Sabella | 29996a1 | 2018-06-01 19:23:00 -0400 | [diff] [blame] | 81 | "maxlines", type="int", default=15) |
Cheryl Sabella | de65162 | 2018-06-01 21:45:54 -0400 | [diff] [blame] | 82 | cls.colors = idleConf.GetHighlight(idleConf.CurrentTheme(), 'context') |
Terry Jan Reedy | a6bb313 | 2017-09-17 00:56:56 -0400 | [diff] [blame] | 83 | |
| 84 | def __del__(self): |
Cheryl Sabella | 654038d | 2018-05-19 15:34:03 -0400 | [diff] [blame] | 85 | "Cancel scheduled events." |
Terry Jan Reedy | a6bb313 | 2017-09-17 00:56:56 -0400 | [diff] [blame] | 86 | try: |
| 87 | self.text.after_cancel(self.t1) |
| 88 | self.text.after_cancel(self.t2) |
| 89 | except: |
| 90 | pass |
wohlganger | 58fc71c | 2017-09-10 16:19:47 -0500 | [diff] [blame] | 91 | |
Kurt B. Kaiser | d00587a | 2004-04-24 03:08:13 +0000 | [diff] [blame] | 92 | def toggle_code_context_event(self, event=None): |
Cheryl Sabella | 654038d | 2018-05-19 15:34:03 -0400 | [diff] [blame] | 93 | """Toggle code context display. |
| 94 | |
Cheryl Sabella | b609e68 | 2018-06-04 11:58:44 -0400 | [diff] [blame] | 95 | If self.context doesn't exist, create it to match the size of the editor |
Cheryl Sabella | 654038d | 2018-05-19 15:34:03 -0400 | [diff] [blame] | 96 | window text (toggle on). If it does exist, destroy it (toggle off). |
| 97 | Return 'break' to complete the processing of the binding. |
| 98 | """ |
Cheryl Sabella | b609e68 | 2018-06-04 11:58:44 -0400 | [diff] [blame] | 99 | if not self.context: |
Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 100 | # Calculate the border width and horizontal padding required to |
| 101 | # align the context with the text in the main Text widget. |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 102 | # |
Serhiy Storchaka | 645058d | 2015-05-06 14:00:04 +0300 | [diff] [blame] | 103 | # All values are passed through getint(), since some |
Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 104 | # values may be pixel objects, which can't simply be added to ints. |
| 105 | widgets = self.editwin.text, self.editwin.text_frame |
Cheryl Sabella | 8506016 | 2018-05-23 22:18:15 -0400 | [diff] [blame] | 106 | # Calculate the required horizontal padding and border width. |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 107 | padx = 0 |
Cheryl Sabella | 8506016 | 2018-05-23 22:18:15 -0400 | [diff] [blame] | 108 | border = 0 |
Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 109 | for widget in widgets: |
Serhiy Storchaka | 645058d | 2015-05-06 14:00:04 +0300 | [diff] [blame] | 110 | padx += widget.tk.getint(widget.pack_info()['padx']) |
| 111 | padx += widget.tk.getint(widget.cget('padx')) |
Serhiy Storchaka | 645058d | 2015-05-06 14:00:04 +0300 | [diff] [blame] | 112 | border += widget.tk.getint(widget.cget('border')) |
Cheryl Sabella | b609e68 | 2018-06-04 11:58:44 -0400 | [diff] [blame] | 113 | self.context = tkinter.Text( |
| 114 | self.editwin.top, font=self.textfont, |
Cheryl Sabella | de65162 | 2018-06-01 21:45:54 -0400 | [diff] [blame] | 115 | bg=self.contextcolors['background'], |
| 116 | fg=self.contextcolors['foreground'], |
Cheryl Sabella | b609e68 | 2018-06-04 11:58:44 -0400 | [diff] [blame] | 117 | height=1, |
Cheryl Sabella | 8506016 | 2018-05-23 22:18:15 -0400 | [diff] [blame] | 118 | width=1, # Don't request more than we get. |
Cheryl Sabella | b609e68 | 2018-06-04 11:58:44 -0400 | [diff] [blame] | 119 | padx=padx, border=border, relief=SUNKEN, state='disabled') |
Cheryl Sabella | 041272b | 2018-06-08 01:21:15 -0400 | [diff] [blame] | 120 | self.context.bind('<ButtonRelease-1>', self.jumptoline) |
Cheryl Sabella | b609e68 | 2018-06-04 11:58:44 -0400 | [diff] [blame] | 121 | # Pack the context widget before and above the text_frame widget, |
Cheryl Sabella | 8506016 | 2018-05-23 22:18:15 -0400 | [diff] [blame] | 122 | # thus ensuring that it will appear directly above text_frame. |
Cheryl Sabella | b609e68 | 2018-06-04 11:58:44 -0400 | [diff] [blame] | 123 | self.context.pack(side=TOP, fill=X, expand=False, |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 124 | before=self.editwin.text_frame) |
Kurt B. Kaiser | d00587a | 2004-04-24 03:08:13 +0000 | [diff] [blame] | 125 | else: |
Cheryl Sabella | b609e68 | 2018-06-04 11:58:44 -0400 | [diff] [blame] | 126 | self.context.destroy() |
| 127 | self.context = None |
Serhiy Storchaka | 213ce12 | 2017-06-27 07:02:32 +0300 | [diff] [blame] | 128 | return "break" |
Kurt B. Kaiser | d00587a | 2004-04-24 03:08:13 +0000 | [diff] [blame] | 129 | |
Kurt B. Kaiser | 0a13579 | 2005-10-03 19:26:03 +0000 | [diff] [blame] | 130 | def get_context(self, new_topvisible, stopline=1, stopindent=0): |
Cheryl Sabella | 654038d | 2018-05-19 15:34:03 -0400 | [diff] [blame] | 131 | """Return a list of block line tuples and the 'last' indent. |
Kurt B. Kaiser | 0a13579 | 2005-10-03 19:26:03 +0000 | [diff] [blame] | 132 | |
Cheryl Sabella | 654038d | 2018-05-19 15:34:03 -0400 | [diff] [blame] | 133 | The tuple fields are (linenum, indent, text, opener). |
| 134 | The list represents header lines from new_topvisible back to |
| 135 | stopline with successively shorter indents > stopindent. |
| 136 | The list is returned ordered by line number. |
| 137 | Last indent returned is the smallest indent observed. |
Kurt B. Kaiser | 7491022 | 2005-10-02 23:36:46 +0000 | [diff] [blame] | 138 | """ |
Kurt B. Kaiser | 0a13579 | 2005-10-03 19:26:03 +0000 | [diff] [blame] | 139 | assert stopline > 0 |
Kurt B. Kaiser | 7491022 | 2005-10-02 23:36:46 +0000 | [diff] [blame] | 140 | lines = [] |
Cheryl Sabella | 8506016 | 2018-05-23 22:18:15 -0400 | [diff] [blame] | 141 | # The indentation level we are currently in. |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 142 | lastindent = INFINITY |
| 143 | # For a line to be interesting, it must begin with a block opening |
| 144 | # keyword, and have less indentation than lastindent. |
Guido van Rossum | 805365e | 2007-05-07 22:24:25 +0000 | [diff] [blame] | 145 | for linenum in range(new_topvisible, stopline-1, -1): |
Cheryl Sabella | 8506016 | 2018-05-23 22:18:15 -0400 | [diff] [blame] | 146 | codeline = self.text.get(f'{linenum}.0', f'{linenum}.end') |
| 147 | indent, text, opener = get_line_info(codeline) |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 148 | if indent < lastindent: |
| 149 | lastindent = indent |
Kurt B. Kaiser | e3636e0 | 2004-04-26 22:26:04 +0000 | [diff] [blame] | 150 | if opener in ("else", "elif"): |
Cheryl Sabella | 8506016 | 2018-05-23 22:18:15 -0400 | [diff] [blame] | 151 | # Also show the if statement. |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 152 | lastindent += 1 |
Kurt B. Kaiser | 0a13579 | 2005-10-03 19:26:03 +0000 | [diff] [blame] | 153 | if opener and linenum < new_topvisible and indent >= stopindent: |
| 154 | lines.append((linenum, indent, text, opener)) |
Kurt B. Kaiser | 7491022 | 2005-10-02 23:36:46 +0000 | [diff] [blame] | 155 | if lastindent <= stopindent: |
| 156 | break |
| 157 | lines.reverse() |
| 158 | return lines, lastindent |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 159 | |
Kurt B. Kaiser | 0a13579 | 2005-10-03 19:26:03 +0000 | [diff] [blame] | 160 | def update_code_context(self): |
| 161 | """Update context information and lines visible in the context pane. |
| 162 | |
Cheryl Sabella | 654038d | 2018-05-19 15:34:03 -0400 | [diff] [blame] | 163 | No update is done if the text hasn't been scrolled. If the text |
| 164 | was scrolled, the lines that should be shown in the context will |
Cheryl Sabella | b609e68 | 2018-06-04 11:58:44 -0400 | [diff] [blame] | 165 | be retrieved and the context area will be updated with the code, |
| 166 | up to the number of maxlines. |
Kurt B. Kaiser | 7491022 | 2005-10-02 23:36:46 +0000 | [diff] [blame] | 167 | """ |
Kurt B. Kaiser | 0a13579 | 2005-10-03 19:26:03 +0000 | [diff] [blame] | 168 | new_topvisible = int(self.text.index("@0,0").split('.')[0]) |
Cheryl Sabella | 8506016 | 2018-05-23 22:18:15 -0400 | [diff] [blame] | 169 | if self.topvisible == new_topvisible: # Haven't scrolled. |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 170 | return |
Cheryl Sabella | 8506016 | 2018-05-23 22:18:15 -0400 | [diff] [blame] | 171 | if self.topvisible < new_topvisible: # Scroll down. |
Kurt B. Kaiser | 0a13579 | 2005-10-03 19:26:03 +0000 | [diff] [blame] | 172 | lines, lastindent = self.get_context(new_topvisible, |
| 173 | self.topvisible) |
Cheryl Sabella | 8506016 | 2018-05-23 22:18:15 -0400 | [diff] [blame] | 174 | # Retain only context info applicable to the region |
| 175 | # between topvisible and new_topvisible. |
Kurt B. Kaiser | 7491022 | 2005-10-02 23:36:46 +0000 | [diff] [blame] | 176 | while self.info[-1][1] >= lastindent: |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 177 | del self.info[-1] |
Cheryl Sabella | 8506016 | 2018-05-23 22:18:15 -0400 | [diff] [blame] | 178 | else: # self.topvisible > new_topvisible: # Scroll up. |
Kurt B. Kaiser | 7491022 | 2005-10-02 23:36:46 +0000 | [diff] [blame] | 179 | stopindent = self.info[-1][1] + 1 |
Cheryl Sabella | 8506016 | 2018-05-23 22:18:15 -0400 | [diff] [blame] | 180 | # Retain only context info associated |
| 181 | # with lines above new_topvisible. |
Kurt B. Kaiser | 0a13579 | 2005-10-03 19:26:03 +0000 | [diff] [blame] | 182 | while self.info[-1][0] >= new_topvisible: |
Kurt B. Kaiser | 7491022 | 2005-10-02 23:36:46 +0000 | [diff] [blame] | 183 | stopindent = self.info[-1][1] |
| 184 | del self.info[-1] |
Kurt B. Kaiser | 0a13579 | 2005-10-03 19:26:03 +0000 | [diff] [blame] | 185 | lines, lastindent = self.get_context(new_topvisible, |
| 186 | self.info[-1][0]+1, |
| 187 | stopindent) |
| 188 | self.info.extend(lines) |
| 189 | self.topvisible = new_topvisible |
Cheryl Sabella | 29996a1 | 2018-06-01 19:23:00 -0400 | [diff] [blame] | 190 | # Last context_depth context lines. |
| 191 | context_strings = [x[2] for x in self.info[-self.context_depth:]] |
| 192 | showfirst = 0 if context_strings[0] else 1 |
Cheryl Sabella | b609e68 | 2018-06-04 11:58:44 -0400 | [diff] [blame] | 193 | # Update widget. |
| 194 | self.context['height'] = len(context_strings) - showfirst |
| 195 | self.context['state'] = 'normal' |
| 196 | self.context.delete('1.0', 'end') |
| 197 | self.context.insert('end', '\n'.join(context_strings[showfirst:])) |
| 198 | self.context['state'] = 'disabled' |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 199 | |
Cheryl Sabella | 041272b | 2018-06-08 01:21:15 -0400 | [diff] [blame] | 200 | def jumptoline(self, event=None): |
| 201 | "Show clicked context line at top of editor." |
| 202 | lines = len(self.info) |
| 203 | if lines == 1: # No context lines are showing. |
| 204 | newtop = 1 |
| 205 | else: |
| 206 | # Line number clicked. |
| 207 | contextline = int(float(self.context.index('insert'))) |
| 208 | # Lines not displayed due to maxlines. |
| 209 | offset = max(1, lines - self.context_depth) - 1 |
| 210 | newtop = self.info[offset + contextline][0] |
| 211 | self.text.yview(f'{newtop}.0') |
| 212 | self.update_code_context() |
| 213 | |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 214 | def timer_event(self): |
Cheryl Sabella | 654038d | 2018-05-19 15:34:03 -0400 | [diff] [blame] | 215 | "Event on editor text widget triggered every UPDATEINTERVAL ms." |
Cheryl Sabella | b609e68 | 2018-06-04 11:58:44 -0400 | [diff] [blame] | 216 | if self.context: |
Kurt B. Kaiser | 0a13579 | 2005-10-03 19:26:03 +0000 | [diff] [blame] | 217 | self.update_code_context() |
Terry Jan Reedy | a6bb313 | 2017-09-17 00:56:56 -0400 | [diff] [blame] | 218 | self.t1 = self.text.after(UPDATEINTERVAL, self.timer_event) |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 219 | |
Cheryl Sabella | de65162 | 2018-06-01 21:45:54 -0400 | [diff] [blame] | 220 | def config_timer_event(self): |
| 221 | "Event on editor text widget triggered every CONFIGUPDATEINTERVAL ms." |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 222 | newtextfont = self.text["font"] |
Cheryl Sabella | b609e68 | 2018-06-04 11:58:44 -0400 | [diff] [blame] | 223 | if (self.context and (newtextfont != self.textfont or |
Cheryl Sabella | de65162 | 2018-06-01 21:45:54 -0400 | [diff] [blame] | 224 | CodeContext.colors != self.contextcolors)): |
Kurt B. Kaiser | 54d1a3b | 2004-04-21 20:06:26 +0000 | [diff] [blame] | 225 | self.textfont = newtextfont |
Cheryl Sabella | de65162 | 2018-06-01 21:45:54 -0400 | [diff] [blame] | 226 | self.contextcolors = CodeContext.colors |
Cheryl Sabella | b609e68 | 2018-06-04 11:58:44 -0400 | [diff] [blame] | 227 | self.context["font"] = self.textfont |
| 228 | self.context['background'] = self.contextcolors['background'] |
| 229 | self.context['foreground'] = self.contextcolors['foreground'] |
Cheryl Sabella | de65162 | 2018-06-01 21:45:54 -0400 | [diff] [blame] | 230 | self.t2 = self.text.after(CONFIGUPDATEINTERVAL, self.config_timer_event) |
wohlganger | 58fc71c | 2017-09-10 16:19:47 -0500 | [diff] [blame] | 231 | |
| 232 | |
| 233 | CodeContext.reload() |
Cheryl Sabella | 654038d | 2018-05-19 15:34:03 -0400 | [diff] [blame] | 234 | |
| 235 | |
Terry Jan Reedy | 4d92158 | 2018-06-19 19:12:52 -0400 | [diff] [blame] | 236 | if __name__ == "__main__": |
| 237 | from unittest import main |
| 238 | main('idlelib.idle_test.test_codecontext', verbosity=2, exit=False) |
| 239 | |
| 240 | # Add htest. |