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