source: sasview/prview/perspectives/pr/pr_widgets.py @ 64bda1e

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 64bda1e was 7116b6e0, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working on documentation

  • Property mode set to 100644
File size: 3.8 KB
Line 
1
2################################################################################
3#This software was developed by the University of Tennessee as part of the
4#Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
5#project funded by the US National Science Foundation.
6#
7#See the license text in license.txt
8#
9#copyright 2009, University of Tennessee
10################################################################################
11
12"""
13Text controls for input/output of the main PrView panel
14"""
15
16import wx
17import os
18
19class PrTextCtrl(wx.TextCtrl):
20    """
21    Text control for model and fit parameters.
22    Binds the appropriate events for user interactions.
23    """
24    def __init__(self, *args, **kwds):
25       
26        wx.TextCtrl.__init__(self, *args, **kwds)
27       
28        ## Set to True when the mouse is clicked while the whole string is selected
29        full_selection = False
30        ## Call back for EVT_SET_FOCUS events
31        _on_set_focus_callback = None
32        # Bind appropriate events
33        self.Bind(wx.EVT_LEFT_UP, self._highlight_text)
34        self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus)
35
36    def _on_set_focus(self, event):
37        """
38        Catch when the text control is set in focus to highlight the whole
39        text if necessary
40       
41        :param event: mouse event
42       
43        """
44        event.Skip()
45        self.full_selection = True
46       
47    def _highlight_text(self, event):
48        """
49        Highlight text of a TextCtrl only of no text has be selected
50       
51        :param event: mouse event
52       
53        """
54        # Make sure the mouse event is available to other listeners
55        event.Skip()
56        control  = event.GetEventObject()
57        if self.full_selection:
58            self.full_selection = False
59            # Check that we have a TextCtrl
60            if issubclass(control.__class__, wx.TextCtrl):
61                # Check whether text has been selected,
62                # if not, select the whole string
63                (start, end) = control.GetSelection()
64                if start==end:
65                    control.SetSelection(-1,-1)
66
67class OutputTextCtrl(wx.TextCtrl):
68    """
69    Text control used to display outputs.
70    No editing allowed. The background is
71    grayed out. User can't select text.
72    """
73    def __init__(self, *args, **kwds):
74        """
75        """
76        wx.TextCtrl.__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
93class DataFileTextCtrl(OutputTextCtrl):
94    """
95    Text control used to display only the file name
96    given a full path.
97     
98    :TODO: now that we no longer choose the data file from the panel,
99        it's no longer necessary to pass around the file path. That code
100        should be refactored away and simplified.
101    """
102    def __init__(self, *args, **kwds):
103        """
104        """
105        OutputTextCtrl.__init__(self, *args, **kwds)
106        self._complete_path = None
107   
108    def SetValue(self, value):
109        """
110        Sets the file name given a path
111        """
112        self._complete_path = str(value)
113        file = os.path.basename(self._complete_path)
114        OutputTextCtrl.SetValue(self, file)
115       
116    def GetValue(self):
117        """
118        Return the full path
119        """
120        return self._complete_path
Note: See TracBrowser for help on using the repository browser.