source: sasview/src/sas/perspectives/invariant/invariant_widgets.py @ bf6b8d1

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 bf6b8d1 was 78a205a, checked in by Mathieu Doucet <doucetm@…>, 10 years ago

pylint fixes

  • Property mode set to 100644
File size: 6.1 KB
Line 
1################################################################################
2# This software was developed by the University of Tennessee as part of the
3# Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
4# project funded by the US National Science Foundation.
5#
6# See the license text in license.txt
7#
8# copyright 2009, University of Tennessee
9################################################################################
10
11import wx
12from wx.lib.scrolledpanel import ScrolledPanel
13
14WIDTH = 400
15HEIGHT = 350
16
17class DialogPanel(ScrolledPanel):
18    def __init__(self, *args, **kwds):
19        ScrolledPanel.__init__(self, *args, **kwds)
20        self.SetupScrolling()
21
22class InvTextCtrl(wx.TextCtrl):
23    """
24    Text control for model and fit parameters.
25    Binds the appropriate events for user interactions.
26    """
27    def __init__(self, *args, **kwds):
28        wx.TextCtrl.__init__(self, *args, **kwds)
29        # # Set to True when the mouse is clicked while
30        # the whole string is selected
31        self.full_selection = False
32        # # Call back for EVT_SET_FOCUS events
33        _on_set_focus_callback = None
34
35        # Bind appropriate events
36        self.Bind(wx.EVT_LEFT_UP, self._highlight_text)
37        self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus)
38
39    def _on_set_focus(self, event):
40        """
41        Catch when the text control is set in focus to highlight the whole
42        text if necessary
43
44        :param event: mouse event
45        """
46        event.Skip()
47        self.full_selection = True
48
49    def _highlight_text(self, event):
50        """
51        Highlight text of a TextCtrl only of no text has be selected
52
53        :param event: mouse event
54        """
55        # Make sure the mouse event is available to other listeners
56        event.Skip()
57        control = event.GetEventObject()
58        if self.full_selection:
59            self.full_selection = False
60            # Check that we have a TextCtrl
61            if issubclass(control.__class__, wx.TextCtrl):
62                # Check whether text has been selected,
63                # if not, select the whole string
64                (start, end) = control.GetSelection()
65                if start == end:
66                    control.SetSelection(-1, -1)
67
68
69class OutputTextCtrl(wx.TextCtrl):
70    """
71    Text control used to display outputs.
72    No editing allowed. The background is
73    grayed out. User can't select text.
74    """
75    def __init__(self, *args, **kwds):
76        wx.TextCtrl.__init__(self, *args, **kwds)
77        self.SetEditable(False)
78        self.SetBackgroundColour(self.GetParent().GetBackgroundColour())
79
80        # Bind to mouse event to avoid text highlighting
81        # The event will be skipped once the call-back
82        # is called.
83
84        self.Bind(wx.EVT_MOUSE_EVENTS, self._click)
85
86
87    def _click(self, event):
88        """
89        Prevent further handling of the mouse event
90        by not calling Skip().
91        """
92        pass
93
94class DataDialog(wx.Dialog):
95    """
96    Allow file selection at loading time
97    """
98    def __init__(self, data_list, parent=None, text='', *args, **kwds):
99        kwds['size'] = (WIDTH, HEIGHT)
100        kwds['title'] = "Data Selection"
101        wx.Dialog.__init__(self, parent, *args, **kwds)
102        self.list_of_ctrl = []
103        self._sizer_main = wx.BoxSizer(wx.VERTICAL)
104        self._sizer_txt = wx.BoxSizer(wx.VERTICAL)
105        self._sizer_button = wx.BoxSizer(wx.HORIZONTAL)
106        self._choice_sizer = wx.GridBagSizer(5, 5)
107        self._panel = DialogPanel(self, style=wx.RAISED_BORDER,
108                                  size=(WIDTH - 20, HEIGHT / 3))
109        self.SetSizer(self._sizer_main)
110        self.__do_layout(data_list, text=text)
111        self.Layout()
112
113    def __do_layout(self, data_list, text=''):
114        """
115        layout the dialog
116        """
117        # add text
118        if text.strip() == "":
119            text = "This Perspective does not allow multiple data !\n"
120            text += "Please select only one Data.\n"
121        text_ctrl = wx.TextCtrl(self, -1, str(text), style=wx.TE_MULTILINE,
122                                size=(-1, HEIGHT / 3))
123        text_ctrl.SetEditable(False)
124        self._sizer_txt.Add(text_ctrl, 1, wx.EXPAND | wx.ALL, 10)
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, 0, wx.EXPAND | wx.ALL, 5)
154        self._sizer_main.Add(self._sizer_txt, 0, wx.EXPAND | wx.ALL, 5)
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
158    def get_data(self):
159        """
160        return the selected data
161        """
162        for item in self.list_of_ctrl:
163            rbox, data = item
164            if rbox.GetValue():
165                return data
Note: See TracBrowser for help on using the repository browser.