mirror of
https://github.com/python/cpython.git
synced 2025-08-28 04:35:02 +00:00
bpo-31493: Fix code context update and font update timers. (#3622)
Canceling timers prevents a warning message when test_idle completes. (This is the minimum fix needed before upcoming releases.)
This commit is contained in:
parent
f361897069
commit
a6bb313c70
2 changed files with 29 additions and 26 deletions
|
@ -22,15 +22,14 @@ BLOCKOPENERS = {"class", "def", "elif", "else", "except", "finally", "for",
|
||||||
UPDATEINTERVAL = 100 # millisec
|
UPDATEINTERVAL = 100 # millisec
|
||||||
FONTUPDATEINTERVAL = 1000 # millisec
|
FONTUPDATEINTERVAL = 1000 # millisec
|
||||||
|
|
||||||
getspacesfirstword =\
|
def getspacesfirstword(s, c=re.compile(r"^(\s*)(\w*)")):
|
||||||
lambda s, c=re.compile(r"^(\s*)(\w*)"): c.match(s).groups()
|
return c.match(s).groups()
|
||||||
|
|
||||||
|
|
||||||
class CodeContext:
|
class CodeContext:
|
||||||
bgcolor = idleConf.GetOption("extensions", "CodeContext",
|
bgcolor = "LightGray"
|
||||||
"bgcolor", type="str", default="LightGray")
|
fgcolor = "Black"
|
||||||
fgcolor = idleConf.GetOption("extensions", "CodeContext",
|
|
||||||
"fgcolor", type="str", default="Black")
|
|
||||||
def __init__(self, editwin):
|
def __init__(self, editwin):
|
||||||
self.editwin = editwin
|
self.editwin = editwin
|
||||||
self.text = editwin.text
|
self.text = editwin.text
|
||||||
|
@ -43,19 +42,25 @@ class CodeContext:
|
||||||
# starts the toplevel 'block' of the module.
|
# starts the toplevel 'block' of the module.
|
||||||
self.info = [(0, -1, "", False)]
|
self.info = [(0, -1, "", False)]
|
||||||
self.topvisible = 1
|
self.topvisible = 1
|
||||||
self.reload()
|
|
||||||
# Start two update cycles, one for context lines, one for font changes.
|
# Start two update cycles, one for context lines, one for font changes.
|
||||||
self.text.after(UPDATEINTERVAL, self.timer_event)
|
self.t1 = self.text.after(UPDATEINTERVAL, self.timer_event)
|
||||||
self.text.after(FONTUPDATEINTERVAL, self.font_timer_event)
|
self.t2 = self.text.after(FONTUPDATEINTERVAL, self.font_timer_event)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def reload(cls):
|
def reload(cls):
|
||||||
cls.context_depth = idleConf.GetOption("extensions", "CodeContext",
|
cls.context_depth = idleConf.GetOption("extensions", "CodeContext",
|
||||||
"numlines", type="int", default=3)
|
"numlines", type="int", default=3)
|
||||||
cls.bgcolor = idleConf.GetOption("extensions", "CodeContext",
|
## cls.bgcolor = idleConf.GetOption("extensions", "CodeContext",
|
||||||
"bgcolor", type="str", default="LightGray")
|
## "bgcolor", type="str", default="LightGray")
|
||||||
cls.fgcolor = idleConf.GetOption("extensions", "CodeContext",
|
## cls.fgcolor = idleConf.GetOption("extensions", "CodeContext",
|
||||||
"fgcolor", type="str", default="Black")
|
## "fgcolor", type="str", default="Black")
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
try:
|
||||||
|
self.text.after_cancel(self.t1)
|
||||||
|
self.text.after_cancel(self.t2)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def toggle_code_context_event(self, event=None):
|
def toggle_code_context_event(self, event=None):
|
||||||
if not self.label:
|
if not self.label:
|
||||||
|
@ -74,14 +79,12 @@ class CodeContext:
|
||||||
border = 0
|
border = 0
|
||||||
for widget in widgets:
|
for widget in widgets:
|
||||||
border += widget.tk.getint(widget.cget('border'))
|
border += widget.tk.getint(widget.cget('border'))
|
||||||
self.label = tkinter.Label(self.editwin.top,
|
self.label = tkinter.Label(
|
||||||
text="\n" * (self.context_depth - 1),
|
self.editwin.top, text="\n" * (self.context_depth - 1),
|
||||||
anchor=W, justify=LEFT,
|
anchor=W, justify=LEFT, font=self.textfont,
|
||||||
font=self.textfont,
|
|
||||||
bg=self.bgcolor, fg=self.fgcolor,
|
bg=self.bgcolor, fg=self.fgcolor,
|
||||||
width=1, #don't request more than we get
|
width=1, #don't request more than we get
|
||||||
padx=padx, border=border,
|
padx=padx, border=border, relief=SUNKEN)
|
||||||
relief=SUNKEN)
|
|
||||||
# Pack the label widget before and above the text_frame widget,
|
# Pack the label widget before and above the text_frame widget,
|
||||||
# thus ensuring that it will appear directly above text_frame
|
# thus ensuring that it will appear directly above text_frame
|
||||||
self.label.pack(side=TOP, fill=X, expand=False,
|
self.label.pack(side=TOP, fill=X, expand=False,
|
||||||
|
@ -89,9 +92,6 @@ class CodeContext:
|
||||||
else:
|
else:
|
||||||
self.label.destroy()
|
self.label.destroy()
|
||||||
self.label = None
|
self.label = None
|
||||||
idleConf.SetOption("main", "Theme", "contexton",
|
|
||||||
str(self.label is not None))
|
|
||||||
idleConf.SaveUserCfgFiles()
|
|
||||||
return "break"
|
return "break"
|
||||||
|
|
||||||
def get_line_info(self, linenum):
|
def get_line_info(self, linenum):
|
||||||
|
@ -172,14 +172,14 @@ class CodeContext:
|
||||||
def timer_event(self):
|
def timer_event(self):
|
||||||
if self.label:
|
if self.label:
|
||||||
self.update_code_context()
|
self.update_code_context()
|
||||||
self.text.after(UPDATEINTERVAL, self.timer_event)
|
self.t1 = self.text.after(UPDATEINTERVAL, self.timer_event)
|
||||||
|
|
||||||
def font_timer_event(self):
|
def font_timer_event(self):
|
||||||
newtextfont = self.text["font"]
|
newtextfont = self.text["font"]
|
||||||
if self.label and newtextfont != self.textfont:
|
if self.label and newtextfont != self.textfont:
|
||||||
self.textfont = newtextfont
|
self.textfont = newtextfont
|
||||||
self.label["font"] = self.textfont
|
self.label["font"] = self.textfont
|
||||||
self.text.after(FONTUPDATEINTERVAL, self.font_timer_event)
|
self.t2 = self.text.after(FONTUPDATEINTERVAL, self.font_timer_event)
|
||||||
|
|
||||||
|
|
||||||
CodeContext.reload()
|
CodeContext.reload()
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
IDLE code context -- fix code update and font update timers.
|
||||||
|
|
||||||
|
Canceling timers prevents a warning message when test_idle completes.
|
Loading…
Add table
Add a link
Reference in a new issue