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

Method bind_events

Lib/idlelib/sidebar.py:138–262  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

136 return 'break'
137
138 def bind_events(self):
139 self.text['yscrollcommand'] = self.redirect_yscroll_event
140
141 # Ensure focus is always redirected to the main editor text widget.
142 self.main_widget.bind('<FocusIn>', self.redirect_focusin_event)
143
144 # Redirect mouse scrolling to the main editor text widget.
145 #
146 # Note that without this, scrolling with the mouse only scrolls
147 # the line numbers.
148 self.main_widget.bind('<MouseWheel>', self.redirect_mousewheel_event)
149
150 # Redirect mouse button events to the main editor text widget,
151 # except for the left mouse button (1).
152 #
153 # Note: X-11 sends Button-4 and Button-5 events for the scroll wheel.
154 def bind_mouse_event(event_name, target_event_name):
155 handler = functools.partial(self.redirect_mousebutton_event,
156 event_name=target_event_name)
157 self.main_widget.bind(event_name, handler)
158
159 for button in [2, 3, 4, 5]:
160 for event_name in (f'<Button-{button}>',
161 f'<ButtonRelease-{button}>',
162 f'<B{button}-Motion>',
163 ):
164 bind_mouse_event(event_name, target_event_name=event_name)
165
166 # Convert double- and triple-click events to normal click events,
167 # since event_generate() doesn't allow generating such events.
168 for event_name in (f'<Double-Button-{button}>',
169 f'<Triple-Button-{button}>',
170 ):
171 bind_mouse_event(event_name,
172 target_event_name=f'<Button-{button}>')
173
174 # start_line is set upon <Button-1> to allow selecting a range of rows
175 # by dragging. It is cleared upon <ButtonRelease-1>.
176 start_line = None
177
178 # last_y is initially set upon <B1-Leave> and is continuously updated
179 # upon <B1-Motion>, until <B1-Enter> or the mouse button is released.
180 # It is used in text_auto_scroll(), which is called repeatedly and
181 # does have a mouse event available.
182 last_y = None
183
184 # auto_scrolling_after_id is set whenever text_auto_scroll is
185 # scheduled via .after(). It is used to stop the auto-scrolling
186 # upon <B1-Enter>, as well as to avoid scheduling the function several
187 # times in parallel.
188 auto_scrolling_after_id = None
189
190 def drag_update_selection_and_insert_mark(y_coord):
191 """Helper function for drag and selection event handlers."""
192 lineno = get_lineno(self.text, f"@0,{y_coord}")
193 a, b = sorted([start_line, lineno])
194 self.text.tag_remove("sel", "1.0", "end")
195 self.text.tag_add("sel", f"{a}.0", f"{b+1}.0")

Callers 2

__init__Method · 0.95
bind_eventsMethod · 0.45

Calls 1

bindMethod · 0.45

Tested by

no test coverage detected