(self, x)
| 850 | self._notify_submit_observers() |
| 851 | |
| 852 | def position_cursor(self, x): |
| 853 | # now, we have to figure out where the cursor goes. |
| 854 | # approximate it based on assuming all characters the same length |
| 855 | if len(self.text) == 0: |
| 856 | self.cursor_index = 0 |
| 857 | else: |
| 858 | bb = self.text_disp.get_window_extent() |
| 859 | |
| 860 | trans = self.ax.transData |
| 861 | inv = self.ax.transData.inverted() |
| 862 | bb = trans.transform(inv.transform(bb)) |
| 863 | |
| 864 | text_start = bb[0, 0] |
| 865 | text_end = bb[1, 0] |
| 866 | |
| 867 | ratio = (x - text_start) / (text_end - text_start) |
| 868 | |
| 869 | if ratio < 0: |
| 870 | ratio = 0 |
| 871 | if ratio > 1: |
| 872 | ratio = 1 |
| 873 | |
| 874 | self.cursor_index = int(len(self.text) * ratio) |
| 875 | |
| 876 | self._rendercursor() |
| 877 | |
| 878 | def _click(self, event): |
| 879 | if self.ignore(event): |
no test coverage detected