8000 Added a TextBox widget by keflavich · Pull Request #1983 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Added a TextBox widget #1983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 26 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove unused vars
  • Loading branch information
Matt Terry committed Jun 4, 2013
commit e307788de6b9a626f1d3d6b24adfaba1c737d77b
14 changes: 6 additions & 8 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1834,14 +1834,12 @@ def set_text(self, text, redraw=False):
self.redraw()

def _get_text_right(self):
l,b,w,h = self.text.get_window_extent().bounds
r = l+w+2
t = b+h
s = self.text.get_text()
# adjust cursor position for trailing space
numtrail = len(s)-len(s.rstrip())
en = self.ax.get_renderer_cache().points_to_pixels(self.text.get_fontsize())/2.
bbox = self.text.get_window_extent()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This get_window_extent() causes problems on MacOSX. (related to the blitting problems with macosx). You can get around it by calling self.canvas.draw() before get_window_extent(), but that can be laggy. If you check the backend, you can only inflict the lag on macosx users. But then you're putting backend checks into supposedly backend independent widgets.

Any less hacky ideas of how to get the rendered width of a block of text?

l,b,w,h = bbox.bounds

renderer = self.ax.get_renderer_cache()
en = renderer.points_to_pixels(self.text.get_fontsize()) / 2.

r = l + self._cursorpos*np.ceil(en)
r,t = self.ax.transAxes.inverted().transform((r,t))
r,t = self.ax.transAxes.inverted().transform((r,b+h))
return r
0