@@ -717,7 +717,7 @@ def __init__(self, ax, label, initial='',
717
717
self .connect_event ('key_press_event' , self ._keypress )
718
718
self .connect_event ('resize_event' , self ._resize )
719
719
ax .set_navigate (False )
720
- ax .set_axis_bgcolor (color )
720
+ ax .set_facecolor (color )
721
721
ax .set_xticks ([])
722
722
ax .set_yticks ([])
723
723
self .color = color
@@ -817,18 +817,14 @@ def begin_typing(self, x):
817
817
for key in self .params_to_disable :
818
818
self .reset_params [key ] = rcParams [key ]
819
819
rcParams [key ] = []
820
- #now, we have to figure out where the cursor goes.
821
- #approximate it based on assuming all characters the same length
822
- self .cursor_index = len (self .text )
823
- self ._rendercursor ()
824
820
825
821
def stop_typing (self ):
826
822
notifysubmit = False
827
823
# because _notify_submit_users might throw an error in the
828
824
# user's code, we only want to call it once we've already done
829
825
# our cleanup.
830
826
if self .capturekeystrokes :
831
- #since the user is no longer typing,
827
+ #since the user is no longer typing,
832
828
#reactivate the standard command keys
833
829
for key in self .params_to_disable :
834
830
rcParams [key ] = self .reset_params [key ]
@@ -839,6 +835,31 @@ def stop_typing(self):
839
835
if notifysubmit :
840
836
self ._notify_submit_observers ()
841
837
838
+ def position_cursor (self , x ):
839
+ #now, we have to figure out where the cursor goes.
840
+ #approximate it based on assuming all characters the same length
841
+ if len (self .text ) == 0 :
842
+ self .cursor_index = 0
843
+ else :
844
+ bb = self .text_disp .get_window_extent ()
845
+
846
+ trans = self .ax .transData
847
+ inv = self .ax .transData .inverted ()
848
+ bb = trans .transform (inv .transform (bb ))
849
+
850
+ text_start = bb [0 , 0 ]
851
+ text_end = bb [1 , 0 ]
852
+
853
+ ratio = (x - text_start ) / (text_end - text_start )
854
+
855
+ if ratio < 0 :
856
+ ratio = 0
857
+ if ratio > 1 :
858
+ ratio = 1
859
+
860
+ self .cursor_index = int (len (self .text ) * ratio )
861
+
862
+ self ._rendercursor ()
842
863
843
864
def _click (self , event ):
844
865
if self .ignore (event ):
@@ -852,6 +873,7 @@ def _click(self, event):
852
873
event .canvas .grab_mouse (self .ax )
853
874
if not (self .capturekeystrokes ):
854
875
self .begin_typing (event .x )
876
+ self .position_cursor (event .x )
855
877
856
878
def _resize (self , event ):
857
879
self .stop_typing ()
@@ -864,7 +886,7 @@ def _motion(self, event):
864
886
else :
865
887
c = self .color
866
888
if c != self ._lastcolor :
867
- self .ax .set_axis_bgcolor (c )
889
+ self .ax .set_facecolor (c )
868
890
self ._lastcolor = c
869
891
if self .drawon :
870
892
self .ax .figure .canvas .draw ()
0 commit comments