Ignore:
Timestamp:
Jul 25, 2009 6:58:31 PM (15 years ago)
Author:
Mathieu Doucet <doucetm@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
812b901
Parents:
e2da832
Message:

sansview: fixed mouse interaction with text control for partial string selection.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sansview/perspectives/fitting/basepage.py

    r646c97a r6f2c919  
    116116        self.set_layout() 
    117117        
     118    class ModelTextCtrl(wx.TextCtrl): 
     119        """ 
     120            Text control for model and fit parameters. 
     121            Binds the appropriate events for user interactions. 
     122            Default callback methods can be overwritten on initialization 
     123             
     124            @param kill_focus_callback: callback method for EVT_KILL_FOCUS event 
     125            @param set_focus_callback:  callback method for EVT_SET_FOCUS event 
     126            @param mouse_up_callback:   callback method for EVT_LEFT_UP event 
     127            @param text_enter_callback: callback method for EVT_TEXT_ENTER event 
     128        """ 
     129        def __init__(self, parent, id=-1, value=wx.EmptyString, pos=wx.DefaultPosition,  
     130                     size=wx.DefaultSize, style=0, validator=wx.DefaultValidator, name=wx.TextCtrlNameStr, 
     131                     kill_focus_callback = None, set_focus_callback  = None, 
     132                     mouse_up_callback   = None, text_enter_callback = None): 
     133             
     134            wx.TextCtrl.__init__(self, parent, id, value, pos, size, style, validator, name) 
     135             
     136            # Bind appropriate events 
     137            self.Bind(wx.EVT_SET_FOCUS,  parent.onSetFocus \ 
     138                      if set_focus_callback is None else set_focus_callback) 
     139            self.Bind(wx.EVT_KILL_FOCUS, parent._onparamEnter \ 
     140                      if kill_focus_callback is None else kill_focus_callback) 
     141            self.Bind(wx.EVT_TEXT_ENTER, parent._onparamEnter \ 
     142                      if text_enter_callback is None else text_enter_callback) 
     143            self.Bind(wx.EVT_LEFT_UP,    parent._highlight_text \ 
     144                      if mouse_up_callback is None else mouse_up_callback) 
    118145        
    119146    def onContextMenu(self, event):  
     
    455482                    item[4].Hide() 
    456483        self.Layout() 
    457         # Get a handle to the TextCtrl 
    458         widget = evt.GetEventObject() 
    459         # Select the whole control, after this event resolves 
    460         wx.CallAfter(widget.SetSelection, -1,-1) 
    461484        return 
    462485     
     486    def _highlight_text(self, event): 
     487        """ 
     488            Highlight text of a TextCtrl only of no text has be selected 
     489            @param event: mouse event 
     490        """ 
     491        control  = event.GetEventObject() 
     492        # Check that we have a TextCtrl 
     493        if issubclass(control.__class__, wx.TextCtrl): 
     494            # Check whether text has been selected,  
     495            # if not, select the whole string 
     496 
     497            (start, end) = control.GetSelection() 
     498            if start==end: 
     499                control.SetSelection(-1,-1) 
     500                 
     501        # Make sure the mouse event is available to other listeners 
     502        event.Skip() 
    463503     
    464504    def read_file(self, path): 
     
    14911531    def _set_range_sizer(self, title, object1=None,object=None): 
    14921532        """ 
    1493             Fill the  
     1533            TODO: object1 and object are NOT proper parameter names. 
     1534            Please clean up your code. 
    14941535        """ 
    14951536        self.sizer5.Clear(True) 
     
    14971538        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
    14981539        #-------------------------------------------------------------- 
    1499         self.qmin    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 
     1540        self.qmin    = BasicPage.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20)) 
    15001541        self.qmin.SetValue(str(self.qmin_x)) 
    15011542        self.qmin.SetToolTipString("Minimun value of Q in linear scale.") 
    1502         self.qmin.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) 
    1503         self.qmin.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 
    1504         self.qmin.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) 
    15051543      
    1506         self.qmax    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 
     1544        self.qmax    = BasicPage.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20)) 
    15071545        self.qmax.SetValue(str(self.qmax_x)) 
    15081546        self.qmax.SetToolTipString("Maximum value of Q in linear scale.") 
    1509         self.qmax.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) 
    1510         self.qmax.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 
    1511         self.qmax.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) 
    15121547      
    15131548        sizer_horizontal=wx.BoxSizer(wx.HORIZONTAL) 
Note: See TracChangeset for help on using the changeset viewer.