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

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 f994d7cd 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
RevLine 
[c26a64b]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)
[f32d144]5#project funded by the US National Science Foundation.
[c26a64b]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
[657490af]15WIDTH = 430
16HEIGHT = 350
[c26a64b]17
[f32d144]18
[657490af]19class DialogPanel(ScrolledPanel):
20    def __init__(self, *args, **kwds):
21        ScrolledPanel.__init__(self, *args, **kwds)
22        self.SetupScrolling()
[2f4b430]23
24
[3f36675]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    """
[f32d144]31    def __init__(self, parent=None, *args, **kwds):
[3f36675]32        wx.Dialog.__init__(self, parent, *args, **kwds)
[657490af]33        self.SetSize((WIDTH, HEIGHT))
[3f36675]34        self.data_1d_selected = None
35        self.data_2d_selected = None
36        self._do_layout()
[2f4b430]37
[3f36675]38    def _do_layout(self):
39        """
40        Draw the content of the current dialog window
41        """
42        vbox = wx.BoxSizer(wx.VERTICAL)
[f32d144]43        box_description = wx.StaticBox(self, -1, str("Hint"))
[3f36675]44        hint_sizer = wx.StaticBoxSizer(box_description, wx.VERTICAL)
[2f4b430]45        selection_sizer = wx.GridBagSizer(5, 5)
[3f36675]46        button_sizer = wx.BoxSizer(wx.HORIZONTAL)
47        self.data_1d_selected = wx.RadioButton(self, -1, 'Data1D',
48                                                style=wx.RB_GROUP)
[f32d144]49        self.data_2d_selected = wx.RadioButton(self, -1, 'Data2D')
[3f36675]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),
[2f4b430]62                           (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
[3f36675]63        iy += 1
64        selection_sizer.Add(self.data_2d_selected, (iy, ix),
[2f4b430]65                           (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
[3f36675]66        #contruction the sizer contaning button
[2f4b430]67        button_sizer.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
[3f36675]68        button_sizer.Add(button_cancel, 0,
[2f4b430]69                         wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10)
[3f36675]70        button_sizer.Add(button_OK, 0,
[2f4b430]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)
[3f36675]76        self.SetSizer(vbox)
[657490af]77        self.Layout()
[2f4b430]78
[3f36675]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
[c26a64b]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
[2f4b430]99
[c26a64b]100        self.SetSize((WIDTH, HEIGHT))
101        self.list_of_ctrl = []
102        if not data_list:
[f32d144]103            return
[c26a64b]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))
[2f4b430]106
[c26a64b]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)
[657490af]112        self._panel = DialogPanel(self, style=wx.RAISED_BORDER,
[2f4b430]113                               size=(WIDTH - 20, HEIGHT / 3))
[c26a64b]114        self.__do_layout(data_list, text=text)
[2f4b430]115
[c26a64b]116    def __do_layout(self, data_list, text=''):
117        """
118        layout the dialog
119        """
120        if not data_list or len(data_list) <= 1:
[f32d144]121            return
[c26a64b]122        #add text
123        if text.strip() == "":
[cfcb7207]124            text = "Fitting: We recommend that you selected"
125            text += " no more than '%s' data\n" % str(self._max_data)
[f32d144]126            text += "for adequate plot display size. \n"
127            text += "unchecked data won't be send to fitting . \n"
[c26a64b]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),
[2f4b430]143                           (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
[c26a64b]144            iy += 1
145        self._panel.SetSizer(self._choice_sizer)
146        #add sizer
[2f4b430]147        self._sizer_button.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
[c26a64b]148        button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel")
149        self._sizer_button.Add(button_cancel, 0,
[2f4b430]150                          wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10)
[c26a64b]151        button_OK = wx.Button(self, wx.ID_OK, "Ok")
152        button_OK.SetFocus()
153        self._sizer_button.Add(button_OK, 0,
[2f4b430]154                                wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10)
[c26a64b]155        static_line = wx.StaticLine(self, -1)
[2f4b430]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)
[c26a64b]159        self._sizer_main.Add(static_line, 0, wx.EXPAND, 0)
[2f4b430]160        self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND | wx.ALL, 10)
[c26a64b]161        self.SetSizer(self._sizer_main)
162        self.Layout()
[2f4b430]163
[c26a64b]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
[2f4b430]174
[c26a64b]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:
[f32d144]188            self._data_text_ctrl.SetForegroundColour('red')
Note: See TracBrowser for help on using the repository browser.