2222UPDATEINTERVAL = 100 # millisec
2323FONTUPDATEINTERVAL = 1000 # millisec
2424
25- getspacesfirstword = \
26- lambda s , c = re . compile ( r"^(\s*)(\w*)" ): c .match (s ).groups ()
25+ def getspacesfirstword ( s , c = re . compile ( r"^(\s*)(\w*)" )):
26+ return c .match (s ).groups ()
2727
2828
2929class CodeContext :
30- bgcolor = idleConf .GetOption ("extensions" , "CodeContext" ,
31- "bgcolor" , type = "str" , default = "LightGray" )
32- fgcolor = idleConf .GetOption ("extensions" , "CodeContext" ,
33- "fgcolor" , type = "str" , default = "Black" )
30+ bgcolor = "LightGray"
31+ fgcolor = "Black"
32+
3433 def __init__ (self , editwin ):
3534 self .editwin = editwin
3635 self .text = editwin .text
@@ -43,19 +42,25 @@ def __init__(self, editwin):
4342 # starts the toplevel 'block' of the module.
4443 self .info = [(0 , - 1 , "" , False )]
4544 self .topvisible = 1
46- self .reload ()
4745 # Start two update cycles, one for context lines, one for font changes.
48- self .text .after (UPDATEINTERVAL , self .timer_event )
49- self .text .after (FONTUPDATEINTERVAL , self .font_timer_event )
46+ self .t1 = self . text .after (UPDATEINTERVAL , self .timer_event )
47+ self .t2 = self . text .after (FONTUPDATEINTERVAL , self .font_timer_event )
5048
5149 @classmethod
5250 def reload (cls ):
5351 cls .context_depth = idleConf .GetOption ("extensions" , "CodeContext" ,
5452 "numlines" , type = "int" , default = 3 )
55- cls .bgcolor = idleConf .GetOption ("extensions" , "CodeContext" ,
56- "bgcolor" , type = "str" , default = "LightGray" )
57- cls .fgcolor = idleConf .GetOption ("extensions" , "CodeContext" ,
58- "fgcolor" , type = "str" , default = "Black" )
53+ ## cls.bgcolor = idleConf.GetOption("extensions", "CodeContext",
54+ ## "bgcolor", type="str", default="LightGray")
55+ ## cls.fgcolor = idleConf.GetOption("extensions", "CodeContext",
56+ ## "fgcolor", type="str", default="Black")
57+
58+ def __del__ (self ):
59+ try :
60+ self .text .after_cancel (self .t1 )
61+ self .text .after_cancel (self .t2 )
62+ except :
63+ pass
5964
6065 def toggle_code_context_event (self , event = None ):
6166 if not self .label :
@@ -74,24 +79,19 @@ def toggle_code_context_event(self, event=None):
7479 border = 0
7580 for widget in widgets :
7681 border += widget .tk .getint (widget .cget ('border' ))
77- self .label = tkinter .Label (self .editwin .top ,
78- text = "\n " * (self .context_depth - 1 ),
79- anchor = W , justify = LEFT ,
80- font = self .textfont ,
81- bg = self .bgcolor , fg = self .fgcolor ,
82- width = 1 , #don't request more than we get
83- padx = padx , border = border ,
84- relief = SUNKEN )
82+ self .label = tkinter .Label (
83+ self .editwin .top , text = "\n " * (self .context_depth - 1 ),
84+ anchor = W , justify = LEFT , font = self .textfont ,
85+ bg = self .bgcolor , fg = self .fgcolor ,
86+ width = 1 , #don't request more than we get
87+ padx = padx , border = border , relief = SUNKEN )
8588 # Pack the label widget before and above the text_frame widget,
8689 # thus ensuring that it will appear directly above text_frame
8790 self .label .pack (side = TOP , fill = X , expand = False ,
8891 before = self .editwin .text_frame )
8992 else :
9093 self .label .destroy ()
9194 self .label = None
92- idleConf .SetOption ("main" , "Theme" , "contexton" ,
93- str (self .label is not None ))
94- idleConf .SaveUserCfgFiles ()
9595 return "break"
9696
9797 def get_line_info (self , linenum ):
@@ -172,14 +172,14 @@ def update_code_context(self):
172172 def timer_event (self ):
173173 if self .label :
174174 self .update_code_context ()
175- self .text .after (UPDATEINTERVAL , self .timer_event )
175+ self .t1 = self . text .after (UPDATEINTERVAL , self .timer_event )
176176
177177 def font_timer_event (self ):
178178 newtextfont = self .text ["font" ]
179179 if self .label and newtextfont != self .textfont :
180180 self .textfont = newtextfont
181181 self .label ["font" ] = self .textfont
182- self .text .after (FONTUPDATEINTERVAL , self .font_timer_event )
182+ self .t2 = self . text .after (FONTUPDATEINTERVAL , self .font_timer_event )
183183
184184
185185CodeContext .reload ()
0 commit comments