source: sasview/calculatorview/perspectives/calculator/calculator_widgets.py @ 1c779b6

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 1c779b6 was b7e0fff, checked in by Gervaise Alina <gervyh@…>, 14 years ago

enable copy and paste of slit length textcrtl

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