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

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 f8b79d6 was 9ff861b, checked in by Mathieu Doucet <doucetm@…>, 15 years ago

prview: improved text control look&feel, added scrolled panel, got rid of old code.

  • Property mode set to 100644
File size: 3.0 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        # Bind appropriate events
28        self.Bind(wx.EVT_LEFT_UP, self._highlight_text)
29       
30    def _highlight_text(self, event):
31        """
32            Highlight text of a TextCtrl only of no text has be selected
33            @param event: mouse event
34        """
35        control  = event.GetEventObject()
36        # Check that we have a TextCtrl
37        if issubclass(control.__class__, wx.TextCtrl):
38            # Check whether text has been selected,
39            # if not, select the whole string
40
41            (start, end) = control.GetSelection()
42            if start==end:
43                control.SetSelection(-1,-1)
44               
45        # Make sure the mouse event is available to other listeners
46        event.Skip()
47
48class OutputTextCtrl(wx.TextCtrl):
49    """
50        Text control used to display outputs.
51        No editing allowed. The background is
52        grayed out. User can't select text.
53    """
54    def __init__(self, *args, **kwds):
55        wx.TextCtrl.__init__(self, *args, **kwds)
56        self.SetEditable(False)
57        self.SetBackgroundColour(self.GetParent().GetBackgroundColour())
58       
59        # Bind to mouse event to avoid text highlighting
60        # The event will be skipped once the call-back
61        # is called.
62        self.Bind(wx.EVT_MOUSE_EVENTS, self._click)
63       
64    def _click(self, event):
65        """
66            Prevent further handling of the mouse event
67            by not calling Skip().
68        """ 
69        pass
70       
71
72class DataFileTextCtrl(OutputTextCtrl):
73    """
74        Text control used to display only the file name
75        given a full path.
76         
77        TODO: now that we no longer choose the data file from the panel,
78        it's no longer necessary to pass around the file path. That code
79        should be refactored away and simplified.
80    """
81    def __init__(self, *args, **kwds):
82        OutputTextCtrl.__init__(self, *args, **kwds)
83        self._complete_path = None
84   
85    def SetValue(self, value):
86        """
87            Sets the file name given a path
88        """
89        self._complete_path = str(value)
90        file = os.path.basename(self._complete_path)
91        OutputTextCtrl.SetValue(self, file)
92       
93    def GetValue(self):
94        """
95            Return the full path
96        """
97        return self._complete_path
Note: See TracBrowser for help on using the repository browser.