MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _keypress

Method _keypress

lib/matplotlib/widgets.py:1623–1657  ·  view source on GitHub ↗
(self, event)

Source from the content-addressed store, hash-verified

1621
1622 @_call_with_reparented_event
1623 def _keypress(self, event):
1624 if self.ignore(event):
1625 return
1626 if self.capturekeystrokes:
1627 key = event.key
1628 text = self.text
1629 if len(key) == 1:
1630 text = (text[:self.cursor_index] + key +
1631 text[self.cursor_index:])
1632 self.cursor_index += 1
1633 elif key == "right":
1634 if self.cursor_index != len(text):
1635 self.cursor_index += 1
1636 elif key == "left":
1637 if self.cursor_index != 0:
1638 self.cursor_index -= 1
1639 elif key == "home":
1640 self.cursor_index = 0
1641 elif key == "end":
1642 self.cursor_index = len(text)
1643 elif key == "backspace":
1644 if self.cursor_index != 0:
1645 text = (text[:self.cursor_index - 1] +
1646 text[self.cursor_index:])
1647 self.cursor_index -= 1
1648 elif key == "delete":
1649 if self.cursor_index != len(self.text):
1650 text = (text[:self.cursor_index] +
1651 text[self.cursor_index + 1:])
1652 self.text_disp.set_text(text)
1653 self._rendercursor()
1654 if self.eventson:
1655 self._observers.process('change', self.text)
1656 if key in ["enter", "return"]:
1657 self._observers.process('submit', self.text)
1658
1659 def set_val(self, val):
1660 newval = str(val)

Callers

nothing calls this directly

Calls 4

_rendercursorMethod · 0.95
processMethod · 0.80
ignoreMethod · 0.45
set_textMethod · 0.45

Tested by

no test coverage detected