source: sasview/src/sas/perspectives/pr/pr_widgets.py @ 61f32d2b

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 61f32d2b was 79492222, checked in by krzywon, 10 years ago

Changed the file and folder names to remove all SANS references.

  • Property mode set to 100644
File size: 7.8 KB
RevLine 
[9ff861b]1
[7116b6e0]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################################################################################
[9ff861b]11
12"""
[7116b6e0]13Text controls for input/output of the main PrView panel
[9ff861b]14"""
15
16import wx
17import os
[75a7ece]18from wx.lib.scrolledpanel import ScrolledPanel
[3ecaa2b]19
20WIDTH = 400
21HEIGHT = 350
22
23
24class DialogPanel(ScrolledPanel):
25    def __init__(self, *args, **kwds):
26        ScrolledPanel.__init__(self, *args, **kwds)
27        self.SetupScrolling()
28       
29       
[9ff861b]30class PrTextCtrl(wx.TextCtrl):
31    """
[7116b6e0]32    Text control for model and fit parameters.
33    Binds the appropriate events for user interactions.
[9ff861b]34    """
35    def __init__(self, *args, **kwds):
36       
37        wx.TextCtrl.__init__(self, *args, **kwds)
38       
[8eeb0b6]39        ## Set to True when the mouse is clicked while the whole string is selected
[a07e72f]40        self.full_selection = False
[8eeb0b6]41        ## Call back for EVT_SET_FOCUS events
42        _on_set_focus_callback = None
[9ff861b]43        # Bind appropriate events
44        self.Bind(wx.EVT_LEFT_UP, self._highlight_text)
[8eeb0b6]45        self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus)
46
47    def _on_set_focus(self, event):
48        """
[7116b6e0]49        Catch when the text control is set in focus to highlight the whole
50        text if necessary
51       
52        :param event: mouse event
53       
[8eeb0b6]54        """
55        event.Skip()
56        self.full_selection = True
[9ff861b]57       
58    def _highlight_text(self, event):
59        """
[7116b6e0]60        Highlight text of a TextCtrl only of no text has be selected
61       
62        :param event: mouse event
63       
[9ff861b]64        """
65        # Make sure the mouse event is available to other listeners
66        event.Skip()
[8eeb0b6]67        control  = event.GetEventObject()
68        if self.full_selection:
69            self.full_selection = False
70            # Check that we have a TextCtrl
71            if issubclass(control.__class__, wx.TextCtrl):
72                # Check whether text has been selected,
73                # if not, select the whole string
74                (start, end) = control.GetSelection()
75                if start==end:
76                    control.SetSelection(-1,-1)
[9ff861b]77
78class OutputTextCtrl(wx.TextCtrl):
79    """
[7116b6e0]80    Text control used to display outputs.
81    No editing allowed. The background is
82    grayed out. User can't select text.
[9ff861b]83    """
84    def __init__(self, *args, **kwds):
[7116b6e0]85        """
86        """
[9ff861b]87        wx.TextCtrl.__init__(self, *args, **kwds)
88        self.SetEditable(False)
89        self.SetBackgroundColour(self.GetParent().GetBackgroundColour())
90       
91        # Bind to mouse event to avoid text highlighting
92        # The event will be skipped once the call-back
93        # is called.
94        self.Bind(wx.EVT_MOUSE_EVENTS, self._click)
95       
96    def _click(self, event):
97        """
[7116b6e0]98        Prevent further handling of the mouse event
99        by not calling Skip().
[9ff861b]100        """ 
101        pass
102       
103
104class DataFileTextCtrl(OutputTextCtrl):
105    """
[7116b6e0]106    Text control used to display only the file name
107    given a full path.
108     
109    :TODO: now that we no longer choose the data file from the panel,
[9ff861b]110        it's no longer necessary to pass around the file path. That code
111        should be refactored away and simplified.
112    """
113    def __init__(self, *args, **kwds):
[7116b6e0]114        """
115        """
[9ff861b]116        OutputTextCtrl.__init__(self, *args, **kwds)
117        self._complete_path = None
118   
119    def SetValue(self, value):
120        """
[7116b6e0]121        Sets the file name given a path
[9ff861b]122        """
123        self._complete_path = str(value)
124        file = os.path.basename(self._complete_path)
125        OutputTextCtrl.SetValue(self, file)
126       
127    def GetValue(self):
128        """
[7116b6e0]129        Return the full path
[9ff861b]130        """
131        return self._complete_path
[75a7ece]132   
[3ecaa2b]133
134           
135           
136def load_error(error=None):
137    """
138    Pop up an error message.
139   
140    :param error: details error message to be displayed
141    """
142    message = "The data file you selected could not be loaded.\n"
143    message += "Make sure the content of your file is properly formatted.\n\n"
144   
145    if error is not None:
146        message += "When contacting the DANSE team, mention the"
147        message += " following:\n%s" % str(error)
148   
149    dial = wx.MessageDialog(None, message, 'Error Loading File',
150                            wx.OK | wx.ICON_EXCLAMATION)
151    dial.ShowModal()   
152
153   
[75a7ece]154class DataDialog(wx.Dialog):
155    """
156    Allow file selection at loading time
157    """
158    def __init__(self, data_list, parent=None, text='', *args, **kwds):
[3ecaa2b]159        kwds['size'] = (WIDTH, HEIGHT)
160        kwds['title'] = "Data Selection"
[75a7ece]161        wx.Dialog.__init__(self, parent, *args, **kwds)
162        self.list_of_ctrl = []
[3ecaa2b]163        self._sizer_main = wx.BoxSizer(wx.VERTICAL)
164        self._sizer_txt = wx.BoxSizer(wx.VERTICAL)
165        self._sizer_button = wx.BoxSizer(wx.HORIZONTAL)
166        self._choice_sizer = wx.GridBagSizer(5, 5)
167        self._panel = DialogPanel(self, style=wx.RAISED_BORDER,
168                               size=(WIDTH-20, HEIGHT/3))
[6813da7d]169       
[3ecaa2b]170        self.__do_layout(data_list, text=text)
[6813da7d]171       
[75a7ece]172       
[3ecaa2b]173    def __do_layout(self, data_list, text=''):
[75a7ece]174        """
175        layout the dialog
176        """
[6813da7d]177        #if not data_list or len(data_list) <= 1:
178        #    return
[75a7ece]179        #add text
180        if text.strip() == "":
181            text = "This Perspective does not allow multiple data !\n"
182            text += "Please select only one Data.\n"
[3ecaa2b]183        text_ctrl = wx.TextCtrl(self, -1, str(text), style=wx.TE_MULTILINE,
184                                size=(-1, HEIGHT/3))
185        text_ctrl.SetEditable(False)
186        self._sizer_txt.Add(text_ctrl , 1, wx.EXPAND|wx.ALL, 10)
[75a7ece]187        iy = 0
188        ix = 0
[3ecaa2b]189        rbox = wx.RadioButton(self._panel, -1, str(data_list[0].name), 
[75a7ece]190                                  (10, 10), style= wx.RB_GROUP)
191        rbox.SetValue(True)
192        self.list_of_ctrl.append((rbox, data_list[0]))
[3ecaa2b]193        self._choice_sizer.Add(rbox, (iy, ix), (1, 1),
[75a7ece]194                         wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
195        for i in range(1, len(data_list)):
196            iy += 1
[3ecaa2b]197            rbox = wx.RadioButton(self._panel, -1, 
198                                  str(data_list[i].name), (10, 10))
[75a7ece]199            rbox.SetValue(False)
200            self.list_of_ctrl.append((rbox, data_list[i]))
[3ecaa2b]201            self._choice_sizer.Add(rbox, (iy, ix),
[75a7ece]202                           (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
[3ecaa2b]203        self._panel.SetSizer(self._choice_sizer)
[75a7ece]204        #add sizer
[3ecaa2b]205        self._sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
[75a7ece]206        button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel")
[3ecaa2b]207        self._sizer_button.Add(button_cancel, 0,
[75a7ece]208                          wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
209        button_OK = wx.Button(self, wx.ID_OK, "Ok")
210        button_OK.SetFocus()
[3ecaa2b]211        self._sizer_button.Add(button_OK, 0,
212                                wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
[75a7ece]213        static_line = wx.StaticLine(self, -1)
214       
[3ecaa2b]215        self._sizer_txt.Add(self._panel, 0, wx.EXPAND|wx.ALL, 5)
216        self._sizer_main.Add(self._sizer_txt, 0, wx.EXPAND|wx.ALL, 5)
217        self._sizer_main.Add(static_line, 0, wx.EXPAND, 0)
218        self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND|wx.ALL, 10)
[6813da7d]219        self.SetSizer(self._sizer_main)
[75a7ece]220       
221    def get_data(self):
222        """
223        return the selected data
224        """
225        for item in self.list_of_ctrl:
226            rbox, data = item
227            if rbox.GetValue():
228                return data
[3ecaa2b]229
[af91b68]230   
231
[3ecaa2b]232 
Note: See TracBrowser for help on using the repository browser.