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
RevLine 
[518d35d]1
2
[d7a39e5]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
[518d35d]15import wx
[cacbd7d]16from wx.lib.scrolledpanel import ScrolledPanel
[518d35d]17
[cacbd7d]18WIDTH = 400
[9cec2dd]19HEIGHT = 350
20
21class DialogPanel(ScrolledPanel):
22    def __init__(self, *args, **kwds):
23        ScrolledPanel.__init__(self, *args, **kwds)
24        self.SetupScrolling()
[cacbd7d]25       
[518d35d]26class InvTextCtrl(wx.TextCtrl):
27    """
[d7a39e5]28    Text control for model and fit parameters.
29    Binds the appropriate events for user interactions.
[518d35d]30    """
31    def __init__(self, *args, **kwds):
32        wx.TextCtrl.__init__(self, *args, **kwds)
[4a2b054]33        ## Set to True when the mouse is clicked while
34        #the whole string is selected
[4e1c362]35        self.full_selection = False
[518d35d]36        ## Call back for EVT_SET_FOCUS events
37        _on_set_focus_callback = None
[4e1c362]38
[518d35d]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)
[4e1c362]42       
[518d35d]43    def _on_set_focus(self, event):
44        """
[d7a39e5]45        Catch when the text control is set in focus to highlight the whole
46        text if necessary
47       
48        :param event: mouse event
[518d35d]49        """
50        event.Skip()
51        self.full_selection = True
52       
53    def _highlight_text(self, event):
54        """
[d7a39e5]55        Highlight text of a TextCtrl only of no text has be selected
56       
57        :param event: mouse event
[518d35d]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()
[4a2b054]69                if start == end:
70                    control.SetSelection(-1, -1)
[4e1c362]71           
[518d35d]72
73class OutputTextCtrl(wx.TextCtrl):
74    """
[d7a39e5]75    Text control used to display outputs.
76    No editing allowed. The background is
77    grayed out. User can't select text.
[518d35d]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.
[4e1c362]87       
[518d35d]88        self.Bind(wx.EVT_MOUSE_EVENTS, self._click)
[4e1c362]89
[518d35d]90       
91    def _click(self, event):
92        """
[d7a39e5]93        Prevent further handling of the mouse event
94        by not calling Skip().
[518d35d]95        """ 
96        pass
[4e1c362]97   
[cacbd7d]98class DataDialog(wx.Dialog):
99    """
100    Allow file selection at loading time
101    """
102    def __init__(self, data_list, parent=None, text='', *args, **kwds):
[9cec2dd]103        kwds['size'] = (WIDTH, HEIGHT)
104        kwds['title'] = "Data Selection"
[cacbd7d]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)
[9cec2dd]111        self._panel = DialogPanel(self, style=wx.RAISED_BORDER,
112                               size=(WIDTH-20, HEIGHT/3))
113        self.SetSizer(self._sizer_main)
[cacbd7d]114        self.__do_layout(data_list, text=text)
[9cec2dd]115        self.Layout()
[cacbd7d]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"
[9cec2dd]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)
[cacbd7d]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       
[9cec2dd]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)
[cacbd7d]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)
[9cec2dd]161       
[cacbd7d]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
[4e1c362]172   
173
[518d35d]174 
Note: See TracBrowser for help on using the repository browser.