bpo-33679: IDLE: Re-enable color configuration for code context (GH-7… · python/cpython@dd851d6 (original) (raw)

`@@ -20,7 +20,7 @@

`

20

20

`BLOCKOPENERS = {"class", "def", "elif", "else", "except", "finally", "for",

`

21

21

`"if", "try", "while", "with", "async"}

`

22

22

`UPDATEINTERVAL = 100 # millisec

`

23

``

`-

FONTUPDATEINTERVAL = 1000 # millisec

`

``

23

`+

CONFIGUPDATEINTERVAL = 1000 # millisec

`

24

24

``

25

25

``

26

26

`def get_spaces_firstword(codeline, c=re.compile(r"^(\s*)(\w*)")):

`

`@@ -45,9 +45,6 @@ def get_line_info(codeline):

`

45

45

`class CodeContext:

`

46

46

`"Display block context above the edit window."

`

47

47

``

48

``

`-

bgcolor = "LightGray"

`

49

``

`-

fgcolor = "Black"

`

50

``

-

51

48

`def init(self, editwin):

`

52

49

`"""Initialize settings for context block.

`

53

50

``

`@@ -69,22 +66,20 @@ def init(self, editwin):

`

69

66

`self.editwin = editwin

`

70

67

`self.text = editwin.text

`

71

68

`self.textfont = self.text["font"]

`

``

69

`+

self.contextcolors = CodeContext.colors

`

72

70

`self.label = None

`

73

71

`self.topvisible = 1

`

74

72

`self.info = [(0, -1, "", False)]

`

75

73

`# Start two update cycles, one for context lines, one for font changes.

`

76

74

`self.t1 = self.text.after(UPDATEINTERVAL, self.timer_event)

`

77

``

`-

self.t2 = self.text.after(FONTUPDATEINTERVAL, self.font_timer_event)

`

``

75

`+

self.t2 = self.text.after(CONFIGUPDATEINTERVAL, self.config_timer_event)

`

78

76

``

79

77

`@classmethod

`

80

78

`def reload(cls):

`

81

79

`"Load class variables from config."

`

82

80

`cls.context_depth = idleConf.GetOption("extensions", "CodeContext",

`

83

81

`"maxlines", type="int", default=15)

`

84

``

`-

cls.bgcolor = idleConf.GetOption("extensions", "CodeContext",

`

85

``

`-

"bgcolor", type="str", default="LightGray")

`

86

``

`-

cls.fgcolor = idleConf.GetOption("extensions", "CodeContext",

`

87

``

`-

"fgcolor", type="str", default="Black")

`

``

82

`+

cls.colors = idleConf.GetHighlight(idleConf.CurrentTheme(), 'context')

`

88

83

``

89

84

`def del(self):

`

90

85

`"Cancel scheduled events."

`

`@@ -118,7 +113,8 @@ def toggle_code_context_event(self, event=None):

`

118

113

`self.label = tkinter.Label(

`

119

114

`self.editwin.top, text="",

`

120

115

`anchor=W, justify=LEFT, font=self.textfont,

`

121

``

`-

bg=self.bgcolor, fg=self.fgcolor,

`

``

116

`+

bg=self.contextcolors['background'],

`

``

117

`+

fg=self.contextcolors['foreground'],

`

122

118

`width=1, # Don't request more than we get.

`

123

119

`padx=padx, border=border, relief=SUNKEN)

`

124

120

`# Pack the label widget before and above the text_frame widget,

`

`@@ -202,13 +198,17 @@ def timer_event(self):

`

202

198

`self.update_code_context()

`

203

199

`self.t1 = self.text.after(UPDATEINTERVAL, self.timer_event)

`

204

200

``

205

``

`-

def font_timer_event(self):

`

206

``

`-

"Event on editor text widget triggered every FONTUPDATEINTERVAL ms."

`

``

201

`+

def config_timer_event(self):

`

``

202

`+

"Event on editor text widget triggered every CONFIGUPDATEINTERVAL ms."

`

207

203

`newtextfont = self.text["font"]

`

208

``

`-

if self.label and newtextfont != self.textfont:

`

``

204

`+

if (self.label and (newtextfont != self.textfont or

`

``

205

`+

CodeContext.colors != self.contextcolors)):

`

209

206

`self.textfont = newtextfont

`

``

207

`+

self.contextcolors = CodeContext.colors

`

210

208

`self.label["font"] = self.textfont

`

211

``

`-

self.t2 = self.text.after(FONTUPDATEINTERVAL, self.font_timer_event)

`

``

209

`+

self.label['background'] = self.contextcolors['background']

`

``

210

`+

self.label['foreground'] = self.contextcolors['foreground']

`

``

211

`+

self.t2 = self.text.after(CONFIGUPDATEINTERVAL, self.config_timer_event)

`

212

212

``

213

213

``

214

214

`CodeContext.reload()

`