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

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

working loading data in fitting perspectives

  • 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 load "
56            text += " no more than %s data\n" % str(self._max_data)
57            text += "for adequate plot display size. \n" 
58        text_ctrl = wx.StaticText(self, -1, str(text))
59        self._sizer_txt.Add(text_ctrl)
60        iy = 0
61        ix = 0
62        data_count = 0
63        for i in range(len(data_list)):
64            data_count += 1
65            cb = wx.CheckBox(self._panel, -1, str(data_list[i].name), (10, 10))
66            wx.EVT_CHECKBOX(self, cb.GetId(), self._count_selected_data)
67            if data_count <= MAX_NBR_DATA:
68                cb.SetValue(True)
69            else:
70                cb.SetValue(False)
71            self.list_of_ctrl.append((cb, data_list[i]))
72            self._choice_sizer.Add(cb, (iy, ix),
73                           (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
74            iy += 1
75        self._panel.SetSizer(self._choice_sizer)
76        #add sizer
77        self._sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
78        button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel")
79        self._sizer_button.Add(button_cancel, 0,
80                          wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
81        button_OK = wx.Button(self, wx.ID_OK, "Ok")
82        button_OK.SetFocus()
83        self._sizer_button.Add(button_OK, 0,
84                                wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
85        static_line = wx.StaticLine(self, -1)
86       
87        self._sizer_txt.Add(self._panel, 1, wx.EXPAND|wx.LEFT|wx.RIGHT, 5)
88        self._sizer_main.Add(self._sizer_txt, 1, wx.EXPAND|wx.ALL, 10)
89        self._sizer_main.Add(self._data_text_ctrl, 0, 
90                             wx.EXPAND|wx.LEFT|wx.RIGHT, 10)
91        self._sizer_main.Add(static_line, 0, wx.EXPAND, 0)
92        self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND|wx.ALL, 10)
93        self.SetSizer(self._sizer_main)
94        self.Layout()
95       
96    def get_data(self):
97        """
98        return the selected data
99        """
100        temp = []
101        for item in self.list_of_ctrl:
102            cb, data = item
103            if cb.GetValue():
104                temp.append(data)
105        return temp
106   
107    def _count_selected_data(self, event):
108        """
109        count selected data
110        """
111        if event.GetEventObject().GetValue():
112            self._nb_selected_data += 1
113        else:
114            self._nb_selected_data -= 1
115        select_data_text = " %s Data selected.\n" % str(self._nb_selected_data)
116        self._data_text_ctrl.SetLabel(select_data_text)
117        if self._nb_selected_data <= self._max_data:
118            self._data_text_ctrl.SetForegroundColour('blue')
119        else:
120            self._data_text_ctrl.SetForegroundColour('red')
121       
122       
Note: See TracBrowser for help on using the repository browser.