source: sasview/sansview/perspectives/fitting/fitting_widgets.py @ ce180bd

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 ce180bd was cfcb7207, checked in by Gervaise Alina <gervyh@…>, 14 years ago

add hint for loading multiple data

  • Property mode set to 100644
File size: 4.7 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################################################################################
11
12
13import wx
14from wx.lib.scrolledpanel import ScrolledPanel
15
16WIDTH = 400
17HEIGHT = 300
18MAX_NBR_DATA = 4
19
20class DataDialog(wx.Dialog):
21    """
22    Allow file selection at loading time
23    """
24    def __init__(self, data_list, parent=None, text='',
25                 nb_data=MAX_NBR_DATA, *args, **kwds):
26        wx.Dialog.__init__(self, parent, *args, **kwds)
27        self.SetTitle("Data Selection")
28        self._max_data = nb_data
29        self._nb_selected_data = nb_data
30       
31        self.SetSize((WIDTH, HEIGHT))
32        self.list_of_ctrl = []
33        if not data_list:
34            return 
35        select_data_text = " %s Data selected.\n" % str(self._nb_selected_data)
36        self._data_text_ctrl = wx.StaticText(self, -1, str(select_data_text))
37        self._data_text_ctrl.SetForegroundColour('blue')
38        self._sizer_main = wx.BoxSizer(wx.VERTICAL)
39        self._sizer_txt = wx.BoxSizer(wx.VERTICAL)
40        self._sizer_button = wx.BoxSizer(wx.HORIZONTAL)
41        self._choice_sizer = wx.GridBagSizer(5, 5)
42        self._panel = ScrolledPanel(self, style=wx.RAISED_BORDER,
43                               size=(WIDTH-20, HEIGHT-50))
44        self._panel.SetupScrolling()
45        self.__do_layout(data_list, text=text)
46       
47    def __do_layout(self, data_list, text=''):
48        """
49        layout the dialog
50        """
51        if not data_list or len(data_list) <= 1:
52            return 
53        #add text
54        if text.strip() == "":
55            text = "Fitting: We recommend that you selected"
56            text += " no more than '%s' data\n" % str(self._max_data)
57            text += "for adequate plot display size. \n" 
58            text += "unchecked data won't be send to fitting . \n" 
59        text_ctrl = wx.StaticText(self, -1, str(text))
60        self._sizer_txt.Add(text_ctrl)
61        iy = 0
62        ix = 0
63        data_count = 0
64        for i in range(len(data_list)):
65            data_count += 1
66            cb = wx.CheckBox(self._panel, -1, str(data_list[i].name), (10, 10))
67            wx.EVT_CHECKBOX(self, cb.GetId(), self._count_selected_data)
68            if data_count <= MAX_NBR_DATA:
69                cb.SetValue(True)
70            else:
71                cb.SetValue(False)
72            self.list_of_ctrl.append((cb, data_list[i]))
73            self._choice_sizer.Add(cb, (iy, ix),
74                           (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
75            iy += 1
76        self._panel.SetSizer(self._choice_sizer)
77        #add sizer
78        self._sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
79        button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel")
80        self._sizer_button.Add(button_cancel, 0,
81                          wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
82        button_OK = wx.Button(self, wx.ID_OK, "Ok")
83        button_OK.SetFocus()
84        self._sizer_button.Add(button_OK, 0,
85                                wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
86        static_line = wx.StaticLine(self, -1)
87       
88        self._sizer_txt.Add(self._panel, 1, wx.EXPAND|wx.LEFT|wx.RIGHT, 5)
89        self._sizer_main.Add(self._sizer_txt, 1, wx.EXPAND|wx.ALL, 10)
90        self._sizer_main.Add(self._data_text_ctrl, 0, 
91                             wx.EXPAND|wx.LEFT|wx.RIGHT, 10)
92        self._sizer_main.Add(static_line, 0, wx.EXPAND, 0)
93        self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND|wx.ALL, 10)
94        self.SetSizer(self._sizer_main)
95        self.Layout()
96       
97    def get_data(self):
98        """
99        return the selected data
100        """
101        temp = []
102        for item in self.list_of_ctrl:
103            cb, data = item
104            if cb.GetValue():
105                temp.append(data)
106        return temp
107   
108    def _count_selected_data(self, event):
109        """
110        count selected data
111        """
112        if event.GetEventObject().GetValue():
113            self._nb_selected_data += 1
114        else:
115            self._nb_selected_data -= 1
116        select_data_text = " %s Data selected.\n" % str(self._nb_selected_data)
117        self._data_text_ctrl.SetLabel(select_data_text)
118        if self._nb_selected_data <= self._max_data:
119            self._data_text_ctrl.SetForegroundColour('blue')
120        else:
121            self._data_text_ctrl.SetForegroundColour('red')
122       
123       
Note: See TracBrowser for help on using the repository browser.