source: sasview/prview/perspectives/pr/pr_widgets.py @ d84a90c

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 d84a90c was 8eeb0b6, checked in by Mathieu Doucet <doucetm@…>, 15 years ago

prview: fix highlighting for prview text controls

  • Property mode set to 100644
File size: 3.6 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"""
10
11"""
12    Text controls for input/output of the main PrView panel
13"""
14
15import wx
16import os
17
18class PrTextCtrl(wx.TextCtrl):
19    """
20        Text control for model and fit parameters.
21        Binds the appropriate events for user interactions.
22    """
23    def __init__(self, *args, **kwds):
24       
25        wx.TextCtrl.__init__(self, *args, **kwds)
26       
27        ## Set to True when the mouse is clicked while the whole string is selected
28        full_selection = False
29        ## Call back for EVT_SET_FOCUS events
30        _on_set_focus_callback = None
31        # Bind appropriate events
32        self.Bind(wx.EVT_LEFT_UP, self._highlight_text)
33        self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus)
34
35    def _on_set_focus(self, event):
36        """
37            Catch when the text control is set in focus to highlight the whole
38            text if necessary
39            @param event: mouse event
40        """
41        event.Skip()
42        self.full_selection = True
43       
44    def _highlight_text(self, event):
45        """
46            Highlight text of a TextCtrl only of no text has be selected
47            @param event: mouse event
48        """
49        # Make sure the mouse event is available to other listeners
50        event.Skip()
51        control  = event.GetEventObject()
52        if self.full_selection:
53            self.full_selection = False
54            # Check that we have a TextCtrl
55            if issubclass(control.__class__, wx.TextCtrl):
56                # Check whether text has been selected,
57                # if not, select the whole string
58                (start, end) = control.GetSelection()
59                if start==end:
60                    control.SetSelection(-1,-1)
61
62class OutputTextCtrl(wx.TextCtrl):
63    """
64        Text control used to display outputs.
65        No editing allowed. The background is
66        grayed out. User can't select text.
67    """
68    def __init__(self, *args, **kwds):
69        wx.TextCtrl.__init__(self, *args, **kwds)
70        self.SetEditable(False)
71        self.SetBackgroundColour(self.GetParent().GetBackgroundColour())
72       
73        # Bind to mouse event to avoid text highlighting
74        # The event will be skipped once the call-back
75        # is called.
76        self.Bind(wx.EVT_MOUSE_EVENTS, self._click)
77       
78    def _click(self, event):
79        """
80            Prevent further handling of the mouse event
81            by not calling Skip().
82        """ 
83        pass
84       
85
86class DataFileTextCtrl(OutputTextCtrl):
87    """
88        Text control used to display only the file name
89        given a full path.
90         
91        TODO: now that we no longer choose the data file from the panel,
92        it's no longer necessary to pass around the file path. That code
93        should be refactored away and simplified.
94    """
95    def __init__(self, *args, **kwds):
96        OutputTextCtrl.__init__(self, *args, **kwds)
97        self._complete_path = None
98   
99    def SetValue(self, value):
100        """
101            Sets the file name given a path
102        """
103        self._complete_path = str(value)
104        file = os.path.basename(self._complete_path)
105        OutputTextCtrl.SetValue(self, file)
106       
107    def GetValue(self):
108        """
109            Return the full path
110        """
111        return self._complete_path
Note: See TracBrowser for help on using the repository browser.