source: sasview/src/sas/perspectives/fitting/fitting_widgets.py @ d26dea0

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 d26dea0 was 2f4b430, checked in by Doucet, Mathieu <doucetm@…>, 10 years ago

Take care of white spaces (pylint)

  • Property mode set to 100644
File size: 7.5 KB
Line 
1
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################################################################################
11import wx
12from wx.lib.scrolledpanel import ScrolledPanel
13
14MAX_NBR_DATA = 4
15WIDTH = 430
16HEIGHT = 350
17
18
19class DialogPanel(ScrolledPanel):
20    def __init__(self, *args, **kwds):
21        ScrolledPanel.__init__(self, *args, **kwds)
22        self.SetupScrolling()
23
24
25class BatchDataDialog(wx.Dialog):
26    """
27    The current design of Batch  fit allows only of type of data in the data
28    set. This allows the user to make a quick selection of the type of data
29    to use in fit tab.
30    """
31    def __init__(self, parent=None, *args, **kwds):
32        wx.Dialog.__init__(self, parent, *args, **kwds)
33        self.SetSize((WIDTH, HEIGHT))
34        self.data_1d_selected = None
35        self.data_2d_selected = None
36        self._do_layout()
37
38    def _do_layout(self):
39        """
40        Draw the content of the current dialog window
41        """
42        vbox = wx.BoxSizer(wx.VERTICAL)
43        box_description = wx.StaticBox(self, -1, str("Hint"))
44        hint_sizer = wx.StaticBoxSizer(box_description, wx.VERTICAL)
45        selection_sizer = wx.GridBagSizer(5, 5)
46        button_sizer = wx.BoxSizer(wx.HORIZONTAL)
47        self.data_1d_selected = wx.RadioButton(self, -1, 'Data1D',
48                                                style=wx.RB_GROUP)
49        self.data_2d_selected = wx.RadioButton(self, -1, 'Data2D')
50        self.data_1d_selected.SetValue(True)
51        self.data_2d_selected.SetValue(False)
52        button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel")
53        button_OK = wx.Button(self, wx.ID_OK, "Ok")
54        button_OK.SetFocus()
55        hint = "Selected Data set contains both 1D and 2D Data.\n"
56        hint += "Please select on type of analysis before proceeding.\n"
57        hint_sizer.Add(wx.StaticText(self, -1, hint))
58        #draw area containing radio buttons
59        ix = 0
60        iy = 0
61        selection_sizer.Add(self.data_1d_selected, (iy, ix),
62                           (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
63        iy += 1
64        selection_sizer.Add(self.data_2d_selected, (iy, ix),
65                           (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
66        #contruction the sizer contaning button
67        button_sizer.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
68        button_sizer.Add(button_cancel, 0,
69                         wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10)
70        button_sizer.Add(button_OK, 0,
71                                wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10)
72        vbox.Add(hint_sizer, 0, wx.EXPAND | wx.ALL, 10)
73        vbox.Add(selection_sizer, 0, wx.TOP | wx.BOTTOM, 10)
74        vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0)
75        vbox.Add(button_sizer, 0, wx.TOP | wx.BOTTOM, 10)
76        self.SetSizer(vbox)
77        self.Layout()
78
79    def get_data(self):
80        """
81        return 1 if  user requested Data1D , 2 if user requested Data2D
82        """
83        if self.data_1d_selected.GetValue():
84            return 1
85        else:
86            return 2
87
88
89class DataDialog(wx.Dialog):
90    """
91    Allow file selection at loading time
92    """
93    def __init__(self, data_list, parent=None, text='',
94                 nb_data=MAX_NBR_DATA, *args, **kwds):
95        wx.Dialog.__init__(self, parent, *args, **kwds)
96        self.SetTitle("Data Selection")
97        self._max_data = nb_data
98        self._nb_selected_data = nb_data
99
100        self.SetSize((WIDTH, HEIGHT))
101        self.list_of_ctrl = []
102        if not data_list:
103            return
104        select_data_text = " %s Data selected.\n" % str(self._nb_selected_data)
105        self._data_text_ctrl = wx.StaticText(self, -1, str(select_data_text))
106
107        self._data_text_ctrl.SetForegroundColour('blue')
108        self._sizer_main = wx.BoxSizer(wx.VERTICAL)
109        self._sizer_txt = wx.BoxSizer(wx.VERTICAL)
110        self._sizer_button = wx.BoxSizer(wx.HORIZONTAL)
111        self._choice_sizer = wx.GridBagSizer(5, 5)
112        self._panel = DialogPanel(self, style=wx.RAISED_BORDER,
113                               size=(WIDTH - 20, HEIGHT / 3))
114        self.__do_layout(data_list, text=text)
115
116    def __do_layout(self, data_list, text=''):
117        """
118        layout the dialog
119        """
120        if not data_list or len(data_list) <= 1:
121            return
122        #add text
123        if text.strip() == "":
124            text = "Fitting: We recommend that you selected"
125            text += " no more than '%s' data\n" % str(self._max_data)
126            text += "for adequate plot display size. \n"
127            text += "unchecked data won't be send to fitting . \n"
128        text_ctrl = wx.StaticText(self, -1, str(text))
129        self._sizer_txt.Add(text_ctrl)
130        iy = 0
131        ix = 0
132        data_count = 0
133        for i in range(len(data_list)):
134            data_count += 1
135            cb = wx.CheckBox(self._panel, -1, str(data_list[i].name), (10, 10))
136            wx.EVT_CHECKBOX(self, cb.GetId(), self._count_selected_data)
137            if data_count <= MAX_NBR_DATA:
138                cb.SetValue(True)
139            else:
140                cb.SetValue(False)
141            self.list_of_ctrl.append((cb, data_list[i]))
142            self._choice_sizer.Add(cb, (iy, ix),
143                           (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
144            iy += 1
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        self._sizer_txt.Add(self._panel, 0, wx.EXPAND | wx.ALL, 10)
157        self._sizer_main.Add(self._sizer_txt, 0, wx.EXPAND | wx.ALL, 10)
158        self._sizer_main.Add(self._data_text_ctrl, 0, wx.EXPAND | wx.ALL, 10)
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        self.SetSizer(self._sizer_main)
162        self.Layout()
163
164    def get_data(self):
165        """
166        return the selected data
167        """
168        temp = []
169        for item in self.list_of_ctrl:
170            cb, data = item
171            if cb.GetValue():
172                temp.append(data)
173        return temp
174
175    def _count_selected_data(self, event):
176        """
177        count selected data
178        """
179        if event.GetEventObject().GetValue():
180            self._nb_selected_data += 1
181        else:
182            self._nb_selected_data -= 1
183        select_data_text = " %s Data selected.\n" % str(self._nb_selected_data)
184        self._data_text_ctrl.SetLabel(select_data_text)
185        if self._nb_selected_data <= self._max_data:
186            self._data_text_ctrl.SetForegroundColour('blue')
187        else:
188            self._data_text_ctrl.SetForegroundColour('red')
Note: See TracBrowser for help on using the repository browser.