source: sasview/calculatorview/perspectives/calculator/calculator_widgets.py @ 83267f9

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 83267f9 was 943cacb, checked in by Jae Cho <jhjcho@…>, 14 years ago

Added callback(textEnter) method on param value changes

  • Property mode set to 100644
File size: 3.2 KB
RevLine 
[378d2eb]1"""
2This software was developed by the University of Tennessee as part of the
3Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
4project funded by the US National Science Foundation.
5
6See the license text in license.txt
7
8copyright 2009, University of Tennessee
9"""
10import wx
[b0ab6cb]11#import os
[378d2eb]12
13class InputTextCtrl(wx.TextCtrl):
14    """
15        Text control for model and fit parameters.
16        Binds the appropriate events for user interactions.
17    """
[943cacb]18    def __init__(self, parent = None, *args, **kwds):
[378d2eb]19       
[943cacb]20        wx.TextCtrl.__init__(self, parent, *args, **kwds)
[378d2eb]21       
[b0ab6cb]22        ## Set to True when the mouse is clicked while the whole
23        #string is selected
24        self.full_selection = False
[378d2eb]25        ## Call back for EVT_SET_FOCUS events
26        _on_set_focus_callback = None
27        # Bind appropriate events
28        self.Bind(wx.EVT_LEFT_UP, self._highlight_text)
29        self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus)
[943cacb]30        self.Bind(wx.EVT_TEXT_ENTER, parent._onparamEnter )
[378d2eb]31
32    def _on_set_focus(self, event):
33        """
34            Catch when the text control is set in focus to highlight the whole
35            text if necessary
36            @param event: mouse event
37        """
38        event.Skip()
39        self.full_selection = True
40       
41    def _highlight_text(self, event):
42        """
43            Highlight text of a TextCtrl only of no text has be selected
44            @param event: mouse event
45        """
46        # Make sure the mouse event is available to other listeners
47        event.Skip()
48        control  = event.GetEventObject()
49        if self.full_selection:
50            self.full_selection = False
51            # Check that we have a TextCtrl
52            if issubclass(control.__class__, wx.TextCtrl):
53                # Check whether text has been selected,
54                # if not, select the whole string
55                (start, end) = control.GetSelection()
[b0ab6cb]56                if start == end:
57                    control.SetSelection(-1, -1)
[378d2eb]58
[b7e0fff]59   
60class InterActiveOutputTextCtrl(wx.TextCtrl):
[378d2eb]61    """
62        Text control used to display outputs.
63        No editing allowed. The background is
64        grayed out. User can't select text.
65    """
66    def __init__(self, *args, **kwds):
67        wx.TextCtrl.__init__(self, *args, **kwds)
68        self.SetEditable(False)
69        self.SetBackgroundColour(self.GetParent().GetBackgroundColour())
70       
[b7e0fff]71class OutputTextCtrl(InterActiveOutputTextCtrl):
72    """
73        Text control used to display outputs.
74        No editing allowed. The background is
75        grayed out. User can't select text.
76    """
77    def __init__(self, *args, **kwds):
78        InterActiveOutputTextCtrl.__init__(self, *args, **kwds)
79        self.SetEditable(False)
80        self.SetBackgroundColour(self.GetParent().GetBackgroundColour())
81       
[378d2eb]82        # Bind to mouse event to avoid text highlighting
83        # The event will be skipped once the call-back
84        # is called.
85        self.Bind(wx.EVT_MOUSE_EVENTS, self._click)
86       
87    def _click(self, event):
88        """
89            Prevent further handling of the mouse event
90            by not calling Skip().
91        """ 
92        pass
[b7e0fff]93
94     
Note: See TracBrowser for help on using the repository browser.