-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Added a TextBox widget #1983
Changes from 1 commit
487c15a
557adaa
4110887
82e3f9b
8ed729b
19fd160
dc4b04c
32d9bb0
dc8ef76
003c931
e77e5e5
952e122
e307788
a83b096
c11973c
1a2a1aa
5239d7e
f523505
42b8489
d80083b
4b963a5
aba387a
a1e0207
a81e0b8
8f753d0
b382ceb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1672,8 +1672,8 @@ def __init__(self, ax, s='', enter_callback=None, **text_kwargs): | |
activate the cursor. | ||
|
||
*WARNING* Activating a textbox will remove all other key-press | ||
bindings! They'll be stored in FloatTextBox.old_callbacks and restored | ||
when FloatTextBox.end_text_entry() is called. | ||
bindings! They'll be stored in TextBox.old_callbacks and restored | ||
when TextBox.end_text_entry() is called. | ||
|
||
The default widget assumes only numerical data and will not | ||
allow text entry besides numerical characters and ('e','-','.') | ||
|
@@ -1684,15 +1684,15 @@ def __init__(self, ax, s='', enter_callback=None, **text_kwargs): | |
The parent axes for the widget | ||
|
||
*s* : str | ||
The initial text of the FloatTextBox. Should be able to be coerced | ||
The initial text of the TextBox. Should be able to be coerced | ||
to a float. | ||
|
||
*enter_callback* : function | ||
A function of one argument that will be called with | ||
FloatTextBox.value passed in as the only argument when enter is | ||
A function of one argument that will be called with | ||
TextBox.value passed in as the only argument when enter is | ||
pressed | ||
|
||
*text_kwargs* : | ||
*text_kwargs* : | ||
Additional keywork arguments are passed on to self.ax.text() | ||
""" | ||
AxesWidget.__init__(self, ax) | ||
|
@@ -1701,8 +1701,8 @@ def __init__(self, ax, s='', enter_callback=None, **text_kwargs): | |
self.ax.set_xticks([]) | ||
|
||
self.value = float(s) | ||
self.text = self.ax.text(0.025, 0.2, s, transform=self.ax.transAxes, | ||
**text_kwargs) | ||
self.text = self.ax.text(0.025, 0.2, s, | ||
transform=self.ax.transAxes, **text_kwargs) | ||
|
||
self.enter_callback = enter_callback | ||
self._cid = None | ||
|
@@ -1719,8 +1719,10 @@ def cursor(self): | |
# solve some of the problems associated | ||
if self._cursor is None: | ||
r = self._get_text_right() # needs a renderer | ||
self._cursor, = self.ax.plot([r,r], [0.2, 0.8], | ||
transform=self.ax.transAxes) | ||
self._cursor = self.ax.plot([r, r], | ||
[0.2, 0.8], | ||
transform=self.ax.transAxes, | ||
)[0] | ||
self._cursor.set_visible(False) | ||
return self._cursor | ||
|
||
|
@@ -1745,7 +1747,8 @@ def begin_text_entry(self): | |
for k in keypress_cbs.keys(): | ||
self.old_callbacks[k] = keypress_cbs.pop(k) | ||
|
||
self._cid = self.canvas.mpl_connect('key_press_event', self.keypress) | ||
self._cid = self.canvas.mpl_connect('key_press_event', | ||
self.keypress) | ||
self.cursor.set_visible(True) | ||
self.redraw() | ||
|
||
|
@@ -1816,7 +1819,7 @@ def keypress(self, event): | |
self.set_text(newt, redraw=True) | ||
|
||
r = self._get_text_right() | ||
self.cursor.set_xdata([r,r]) | ||
self.cursor.set_xdata([r, r]) | ||
self.redraw() | ||
|
||
def set_text(self, text, redraw=False): | ||
|
@@ -1836,11 +1839,11 @@ def set_text(self, text, redraw=False): | |
|
||
def _get_text_right(self): | ||
bbox = self.text.get_window_extent() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This Any less hacky ideas of how to get the rendered width of a block of text? |
||
l,b,w,h = bbox.bounds | ||
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,b+h)) | ||
r = l + self._cursorpos * np.ceil(en) | ||
r, t = self.ax.transAxes.inverted().transform((r, b + h)) | ||
return r |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I'm not familiar with the numpydoc format but we should conform to that for the sake of consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in my branch.