MCPcopy Create free account
hub / github.com/bpython/bpython / BPythonEdit

Class BPythonEdit

bpython/urwid.py:284–432  ·  view source on GitHub ↗

Customized editor *very* tightly interwoven with URWIDRepl. Changes include: - The edit text supports markup, not just the caption. This works by calling set_edit_markup from the change event as well as whenever markup changes while text does not. - The widget can be made

Source from the content-addressed store, hash-verified

282
283
284class BPythonEdit(urwid.Edit):
285 """Customized editor *very* tightly interwoven with URWIDRepl.
286
287 Changes include:
288
289 - The edit text supports markup, not just the caption.
290 This works by calling set_edit_markup from the change event
291 as well as whenever markup changes while text does not.
292
293 - The widget can be made readonly, which currently just means
294 it is no longer selectable and stops drawing the cursor.
295
296 This is currently a one-way operation, but that is just because
297 I only need and test the readwrite->readonly transition.
298
299 - move_cursor_to_coords is ignored
300 (except for internal calls from keypress or mouse_event).
301
302 - arrow up/down are ignored.
303
304 - an "edit-pos-changed" signal is emitted when edit_pos changes.
305 """
306
307 signals = ["edit-pos-changed"]
308
309 def __init__(self, config, *args, **kwargs):
310 self._bpy_text = ""
311 self._bpy_attr = []
312 self._bpy_selectable = True
313 self._bpy_may_move_cursor = False
314 self.config = config
315 self.tab_length = config.tab_length
316 super().__init__(*args, **kwargs)
317
318 def set_edit_pos(self, pos):
319 super().set_edit_pos(pos)
320 self._emit("edit-pos-changed", self.edit_pos)
321
322 def get_edit_pos(self):
323 return self._edit_pos
324
325 edit_pos = property(get_edit_pos, set_edit_pos)
326
327 def make_readonly(self):
328 self._bpy_selectable = False
329 # This is necessary to prevent the listbox we are in getting
330 # fresh cursor coords of None from get_cursor_coords
331 # immediately after we go readonly and then getting a cached
332 # canvas that still has the cursor set. It spots that
333 # inconsistency and raises.
334 self._invalidate()
335
336 def set_edit_markup(self, markup):
337 """Call this when markup changes but the underlying text does not.
338
339 You should arrange for this to be called from the 'change' signal.
340 """
341 if markup:

Callers 1

promptMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected