source: sasview/invariantview/perspectives/invariant/invariant_widgets.py @ 8cd029b

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 8cd029b was cacbd7d, checked in by Gervaise Alina <gervyh@…>, 14 years ago

work on loading multplie data to invariant panel

  • Property mode set to 100644
File size: 6.1 KB
Line 
1
2
3
4################################################################################
5#This software was developed by the University of Tennessee as part of the
6#Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
7#project funded by the US National Science Foundation.
8#
9#See the license text in license.txt
10#
11#copyright 2009, University of Tennessee
12################################################################################
13
14
15import wx
16from wx.lib.scrolledpanel import ScrolledPanel
17
18WIDTH = 400
19HEIGHT = 200
20       
21class InvTextCtrl(wx.TextCtrl):
22    """
23    Text control for model and fit parameters.
24    Binds the appropriate events for user interactions.
25    """
26    def __init__(self, *args, **kwds):
27        wx.TextCtrl.__init__(self, *args, **kwds)
28        ## Set to True when the mouse is clicked while
29        #the whole string is selected
30        self.full_selection = False
31        ## Call back for EVT_SET_FOCUS events
32        _on_set_focus_callback = None
33
34        # Bind appropriate events
35        self.Bind(wx.EVT_LEFT_UP, self._highlight_text)
36        self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus)
37       
38    def _on_set_focus(self, event):
39        """
40        Catch when the text control is set in focus to highlight the whole
41        text if necessary
42       
43        :param event: mouse event
44        """
45        event.Skip()
46        self.full_selection = True
47       
48    def _highlight_text(self, event):
49        """
50        Highlight text of a TextCtrl only of no text has be selected
51       
52        :param event: mouse event
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           
67
68class OutputTextCtrl(wx.TextCtrl):
69    """
70    Text control used to display outputs.
71    No editing allowed. The background is
72    grayed out. User can't select text.
73    """
74    def __init__(self, *args, **kwds):
75        wx.TextCtrl.__init__(self, *args, **kwds)
76        self.SetEditable(False)
77        self.SetBackgroundColour(self.GetParent().GetBackgroundColour())
78       
79        # Bind to mouse event to avoid text highlighting
80        # The event will be skipped once the call-back
81        # is called.
82       
83        self.Bind(wx.EVT_MOUSE_EVENTS, self._click)
84
85       
86    def _click(self, event):
87        """
88        Prevent further handling of the mouse event
89        by not calling Skip().
90        """ 
91        pass
92   
93class DataDialog(wx.Dialog):
94    """
95    Allow file selection at loading time
96    """
97    def __init__(self, data_list, parent=None, text='', *args, **kwds):
98        wx.Dialog.__init__(self, parent, *args, **kwds)
99        self.SetTitle("Data Selection")
100        self.SetSize((WIDTH, HEIGHT))
101        self.list_of_ctrl = []
102        if not data_list:
103            return 
104        self._sizer_main = wx.BoxSizer(wx.VERTICAL)
105        self._sizer_txt = wx.BoxSizer(wx.VERTICAL)
106        self._sizer_button = wx.BoxSizer(wx.HORIZONTAL)
107        self._choice_sizer = wx.GridBagSizer(5, 5)
108        self._panel = ScrolledPanel(self, style=wx.RAISED_BORDER,
109                               size=(WIDTH-20, HEIGHT-50))
110        self._panel.SetupScrolling()
111        self.__do_layout(data_list, text=text)
112       
113    def __do_layout(self, data_list, text=''):
114        """
115        layout the dialog
116        """
117        if not data_list or len(data_list) <= 1:
118            return 
119        #add text
120        if text.strip() == "":
121            text = "This Perspective does not allow multiple data !\n"
122            text += "Please select only one Data.\n"
123        text_ctrl = wx.StaticText(self, -1, str(text))
124        self._sizer_txt.Add(text_ctrl)
125        iy = 0
126        ix = 0
127        rbox = wx.RadioButton(self._panel, -1, str(data_list[0].name), 
128                                  (10, 10), style= wx.RB_GROUP)
129        rbox.SetValue(True)
130        self.list_of_ctrl.append((rbox, data_list[0]))
131        self._choice_sizer.Add(rbox, (iy, ix), (1, 1),
132                         wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
133        for i in range(1, len(data_list)):
134            iy += 1
135            rbox = wx.RadioButton(self._panel, -1, 
136                                  str(data_list[i].name), (10, 10))
137            rbox.SetValue(False)
138            self.list_of_ctrl.append((rbox, data_list[i]))
139            self._choice_sizer.Add(rbox, (iy, ix),
140                           (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
141        self._panel.SetSizer(self._choice_sizer)
142        #add sizer
143        self._sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
144        button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel")
145        self._sizer_button.Add(button_cancel, 0,
146                          wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
147        button_OK = wx.Button(self, wx.ID_OK, "Ok")
148        button_OK.SetFocus()
149        self._sizer_button.Add(button_OK, 0,
150                                wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
151        static_line = wx.StaticLine(self, -1)
152       
153        self._sizer_txt.Add(self._panel, 1, wx.EXPAND|wx.LEFT|wx.RIGHT, 5)
154        self._sizer_main.Add(self._sizer_txt, 1, wx.EXPAND|wx.ALL, 10)
155        self._sizer_main.Add(static_line, 0, wx.EXPAND, 0)
156        self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND|wx.ALL, 10)
157        self.SetSizer(self._sizer_main)
158        self.Layout()
159       
160    def get_data(self):
161        """
162        return the selected data
163        """
164        for item in self.list_of_ctrl:
165            rbox, data = item
166            if rbox.GetValue():
167                return data
168
169   
170
171 
Note: See TracBrowser for help on using the repository browser.