Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7961826

Browse files
HastingsGreerfariza
authored andcommitted
added adjustable padding between label and text box
1 parent f7001c1 commit 7961826

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/matplotlib/widgets.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ class TextBox(AxesWidget):
656656
"""
657657

658658
def __init__(self, ax, label, initial='',
659-
color='.95', hovercolor='1'):
659+
color='.95', hovercolor='1', label_pad=.01):
660660
"""
661661
Parameters
662662
----------
@@ -675,6 +675,9 @@ def __init__(self, ax, label, initial='',
675675
676676
hovercolor : color
677677
The color of the box when the mouse is over it
678+
679+
label_pad : float
680+
the distance between the label and the right side of the textbox
678681
"""
679682
AxesWidget.__init__(self, ax)
680683

@@ -686,7 +689,7 @@ def __init__(self, ax, label, initial='',
686689
self.params_to_disable += [key]
687690

688691
self.text = initial
689-
self.label = ax.text(-0.01, 0.5, label,
692+
self.label = ax.text(-label_pad, 0.5, label,
690693
verticalalignment='center',
691694
horizontalalignment='right',
692695
transform=ax.transAxes)
@@ -805,7 +808,7 @@ def _keypress(self, event):
805808
func(self.text)
806809
if key == "enter":
807810
self._notify_submit_observers()
808-
811+
809812
def begin_typing(self, x):
810813
self.capturekeystrokes = True
811814
#disable command keys so that the user can type without
@@ -816,10 +819,9 @@ def begin_typing(self, x):
816819
rcParams[key] = []
817820
#now, we have to figure out where the cursor goes.
818821
#approximate it based on assuming all characters the same length
819-
print(x)
820822
self.cursor_index = len(self.text)
821823
self._rendercursor()
822-
824+
823825
def stop_typing(self):
824826
notifysubmit = False
825827
# because _notify_submit_users might throw an error in the
@@ -837,7 +839,7 @@ def stop_typing(self):
837839
if notifysubmit:
838840
self._notify_submit_observers()
839841

840-
842+
841843
def _click(self, event):
842844
if self.ignore(event):
843845
return
@@ -850,10 +852,10 @@ def _click(self, event):
850852
event.canvas.grab_mouse(self.ax)
851853
if not(self.capturekeystrokes):
852854
self.begin_typing(event.x)
853-
855+
854856
def _resize(self, event):
855857
self.stop_typing()
856-
858+
857859
def _motion(self, event):
858860
if self.ignore(event):
859861
return

0 commit comments

Comments
 (0)