MCPcopy Index your code
hub / github.com/python/cpython / toggle_code_context_event

Method toggle_code_context_event

Lib/idlelib/codecontext.py:93–147  ·  view source on GitHub ↗

Toggle code context display. If self.context doesn't exist, create it to match the size of the editor window text (toggle on). If it does exist, destroy it (toggle off). Return 'break' to complete the processing of the binding.

(self, event=None)

Source from the content-addressed store, hash-verified

91 self.t1 = None
92
93 def toggle_code_context_event(self, event=None):
94 """Toggle code context display.
95
96 If self.context doesn't exist, create it to match the size of the editor
97 window text (toggle on). If it does exist, destroy it (toggle off).
98 Return 'break' to complete the processing of the binding.
99 """
100 if self.context is None:
101 # Calculate the border width and horizontal padding required to
102 # align the context with the text in the main Text widget.
103 #
104 # All values are passed through getint(), since some
105 # values may be pixel objects, which can't simply be added to ints.
106 widgets = self.editwin.text, self.editwin.text_frame
107 # Calculate the required horizontal padding and border width.
108 padx = 0
109 border = 0
110 for widget in widgets:
111 info = (widget.grid_info()
112 if widget is self.editwin.text
113 else widget.pack_info())
114 padx += widget.tk.getint(info['padx'])
115 padx += widget.tk.getint(widget.cget('padx'))
116 border += widget.tk.getint(widget.cget('border'))
117 context = self.context = Text(
118 self.editwin.text_frame,
119 height=1,
120 width=1, # Don't request more than we get.
121 highlightthickness=0,
122 padx=padx, border=border, relief=SUNKEN, state='disabled')
123 self.update_font()
124 self.update_highlight_colors()
125 context.bind('<ButtonRelease-1>', self.jumptoline)
126 # Get the current context and initiate the recurring update event.
127 self.timer_event()
128 # Grid the context widget above the text widget.
129 context.grid(row=0, column=1, sticky=NSEW)
130
131 line_number_colors = idleConf.GetHighlight(idleConf.CurrentTheme(),
132 'linenumber')
133 self.cell00 = Frame(self.editwin.text_frame,
134 bg=line_number_colors['background'])
135 self.cell00.grid(row=0, column=0, sticky=NSEW)
136 menu_status = 'Hide'
137 else:
138 self.context.destroy()
139 self.context = None
140 self.cell00.destroy()
141 self.cell00 = None
142 self.text.after_cancel(self.t1)
143 self._reset()
144 menu_status = 'Show'
145 self.editwin.update_menu_label(menu='options', index='*ode*ontext',
146 label=f'{menu_status} Code Context')
147 return "break"
148
149 def get_context(self, new_topvisible, stopline=1, stopindent=0):
150 """Return a list of block line tuples and the 'last' indent.

Callers 5

test_jumptolineMethod · 0.80
test_timer_eventMethod · 0.80
test_fontMethod · 0.80
test_highlight_colorsMethod · 0.80

Calls 15

update_fontMethod · 0.95
timer_eventMethod · 0.95
_resetMethod · 0.95
TextClass · 0.90
FrameClass · 0.90
grid_infoMethod · 0.80
pack_infoMethod · 0.80
GetHighlightMethod · 0.80
CurrentThemeMethod · 0.80
after_cancelMethod · 0.80
getintMethod · 0.45

Tested by 5

test_jumptolineMethod · 0.64
test_timer_eventMethod · 0.64
test_fontMethod · 0.64
test_highlight_colorsMethod · 0.64