source: sasview/invariantview/src/sans/perspectives/invariant/invariant_widgets.py @ 8182fbb

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 8182fbb was 6813da7d, checked in by Jae Cho <jhjcho@…>, 13 years ago

dialog fixes

  • Property mode set to 100644
File size: 6.2 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 = 350
20
21class DialogPanel(ScrolledPanel):
22    def __init__(self, *args, **kwds):
23        ScrolledPanel.__init__(self, *args, **kwds)
24        self.SetupScrolling()
25       
26class InvTextCtrl(wx.TextCtrl):
27    """
28    Text control for model and fit parameters.
29    Binds the appropriate events for user interactions.
30    """
31    def __init__(self, *args, **kwds):
32        wx.TextCtrl.__init__(self, *args, **kwds)
33        ## Set to True when the mouse is clicked while
34        #the whole string is selected
35        self.full_selection = False
36        ## Call back for EVT_SET_FOCUS events
37        _on_set_focus_callback = None
38
39        # Bind appropriate events
40        self.Bind(wx.EVT_LEFT_UP, self._highlight_text)
41        self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus)
42       
43    def _on_set_focus(self, event):
44        """
45        Catch when the text control is set in focus to highlight the whole
46        text if necessary
47       
48        :param event: mouse event
49        """
50        event.Skip()
51        self.full_selection = True
52       
53    def _highlight_text(self, event):
54        """
55        Highlight text of a TextCtrl only of no text has be selected
56       
57        :param event: mouse event
58        """
59        # Make sure the mouse event is available to other listeners
60        event.Skip()
61        control  = event.GetEventObject()
62        if self.full_selection:
63            self.full_selection = False
64            # Check that we have a TextCtrl
65            if issubclass(control.__class__, wx.TextCtrl):
66                # Check whether text has been selected,
67                # if not, select the whole string
68                (start, end) = control.GetSelection()
69                if start == end:
70                    control.SetSelection(-1, -1)
71           
72
73class OutputTextCtrl(wx.TextCtrl):
74    """
75    Text control used to display outputs.
76    No editing allowed. The background is
77    grayed out. User can't select text.
78    """
79    def __init__(self, *args, **kwds):
80        wx.TextCtrl.__init__(self, *args, **kwds)
81        self.SetEditable(False)
82        self.SetBackgroundColour(self.GetParent().GetBackgroundColour())
83       
84        # Bind to mouse event to avoid text highlighting
85        # The event will be skipped once the call-back
86        # is called.
87       
88        self.Bind(wx.EVT_MOUSE_EVENTS, self._click)
89
90       
91    def _click(self, event):
92        """
93        Prevent further handling of the mouse event
94        by not calling Skip().
95        """ 
96        pass
97   
98class DataDialog(wx.Dialog):
99    """
100    Allow file selection at loading time
101    """
102    def __init__(self, data_list, parent=None, text='', *args, **kwds):
103        kwds['size'] = (WIDTH, HEIGHT)
104        kwds['title'] = "Data Selection"
105        wx.Dialog.__init__(self, parent, *args, **kwds)
106        self.list_of_ctrl = []
107        self._sizer_main = wx.BoxSizer(wx.VERTICAL)
108        self._sizer_txt = wx.BoxSizer(wx.VERTICAL)
109        self._sizer_button = wx.BoxSizer(wx.HORIZONTAL)
110        self._choice_sizer = wx.GridBagSizer(5, 5)
111        self._panel = DialogPanel(self, style=wx.RAISED_BORDER,
112                               size=(WIDTH-20, HEIGHT/3))
113        self.SetSizer(self._sizer_main)
114        self.__do_layout(data_list, text=text)
115        self.Layout()
116       
117    def __do_layout(self, data_list, text=''):
118        """
119        layout the dialog
120        """
121        #add text
122        if text.strip() == "":
123            text = "This Perspective does not allow multiple data !\n"
124            text += "Please select only one Data.\n"
125        text_ctrl = wx.TextCtrl(self, -1, str(text), style=wx.TE_MULTILINE,
126                                size=(-1, HEIGHT/3))
127        text_ctrl.SetEditable(False)
128        self._sizer_txt.Add(text_ctrl , 1, wx.EXPAND|wx.ALL, 10)
129        iy = 0
130        ix = 0
131        rbox = wx.RadioButton(self._panel, -1, str(data_list[0].name), 
132                                  (10, 10), style= wx.RB_GROUP)
133        rbox.SetValue(True)
134        self.list_of_ctrl.append((rbox, data_list[0]))
135        self._choice_sizer.Add(rbox, (iy, ix), (1, 1),
136                         wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
137        for i in range(1, len(data_list)):
138            iy += 1
139            rbox = wx.RadioButton(self._panel, -1, 
140                                  str(data_list[i].name), (10, 10))
141            rbox.SetValue(False)
142            self.list_of_ctrl.append((rbox, data_list[i]))
143            self._choice_sizer.Add(rbox, (iy, ix),
144                           (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
145        self._panel.SetSizer(self._choice_sizer)
146        #add sizer
147        self._sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
148        button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel")
149        self._sizer_button.Add(button_cancel, 0,
150                          wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
151        button_OK = wx.Button(self, wx.ID_OK, "Ok")
152        button_OK.SetFocus()
153        self._sizer_button.Add(button_OK, 0,
154                                wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
155        static_line = wx.StaticLine(self, -1)
156       
157        self._sizer_txt.Add(self._panel, 0, wx.EXPAND|wx.ALL, 5)
158        self._sizer_main.Add(self._sizer_txt, 0, wx.EXPAND|wx.ALL, 5)
159        self._sizer_main.Add(static_line, 0, wx.EXPAND, 0)
160        self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND|wx.ALL, 10)
161       
162       
163    def get_data(self):
164        """
165        return the selected data
166        """
167        for item in self.list_of_ctrl:
168            rbox, data = item
169            if rbox.GetValue():
170                return data
171
172   
173
174 
Note: See TracBrowser for help on using the repository browser.