8000 Text box widget, take over of PR5375 by fariza · Pull Request #6988 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
10000

Text box widget, take over of PR5375 #6988

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

Merged
merged 9 commits into from
Sep 3, 2016
Merged
Prev Previous commit
Next Next commit
TextBox: Added set_val method for convenient scripted setting and upd…
…ating.
  • Loading branch information
smithsp authored and fariza committed Aug 29, 2016
commit 1c86e82d7e75be233ed480af8fdfaff89bd169f5
22 changes: 18 additions & 4 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ def __init__(self, ax, label, initial='',
self.connect_event('key_press_event', self._keypress)
self.connect_event('resize_event', self._resize)
ax.set_navigate(False)
ax.set_facecolor(color)
ax.set_axis_bgcolor(color)
ax.set_xticks([])
ax.set_yticks([])
self.color = color
Expand Down Expand Up @@ -804,11 +804,25 @@ def _keypress(self, event):
self.text_disp.remove()
self.text_disp = self._make_text_disp(self.text)
self._rendercursor()
for cid, func in six.iteritems(self.change_observers):
func(self.text)
self._notify_change_observers()
if key == "enter":
self._notify_submit_observers()

def set_val(self,val):
newval = str(val)
if self.text==newval:
return
self.text = newval
self.text_disp.remove()
self.text_disp = self._make_text_disp(self.text)
self._rendercursor()
self._notify_change_observers()
self._notify_submit_observers()

def _notify_change_observers(self):
for cid, func in six.iteritems(self.change_observers):
func(self.text)

def begin_typing(self, x):
self.capturekeystrokes = True
#disable command keys so that the user can type without
Expand Down Expand Up @@ -887,7 +901,7 @@ def _motion(self, event):
else:
c = self.color
if c != self._lastcolor:
self.ax.set_facecolor(c)
self.ax.set_axis_bgcolor(c)
self._lastcolor = c
if self.drawon:
self.ax.figure.canvas.draw()
Expand Down
0