source: sasview/calculatorview/perspectives/calculator/calculator_widgets.py @ 44148f0

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 44148f0 was b0ab6cb, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working with pylint

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