ConfigurationPanel.py 1.88 KB
Newer Older
1
2
3
4
5
6
import wx

from MDANSE import REGISTRY

class ConfigurationPanel(wx.Panel):
    
7
    def __init__(self, parent, configurable):
8
9
10
        
        wx.Panel.__init__(self, parent, wx.ID_ANY)
        
11
        self._configurable = configurable
12
13
14
15
16
17
18
19
20
        
        self._widgets = {}
        
        self.build_panel()
        
    def build_panel(self):
        
        self.panelSizer = wx.BoxSizer(wx.VERTICAL)

21
        configuration = self._configurable.build_configuration()
22

23
24
25
26
27
        for cfgName in self._configurable.settings.keys():
            
            widget = configuration[cfgName].widget
                        
            widgetClass = REGISTRY["widget"][widget]
28
                        
29
            self._widgets[cfgName] = widgetClass(self, cfgName, configuration[cfgName])
30
            
31
            self.panelSizer.Add(self._widgets[cfgName], 0, wx.ALL|wx.EXPAND, 5)
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
                  
        self.SetSizer(self.panelSizer)
                                   
        self.Layout()

        self.Fit()
                    
    @property
    def widgets(self):
        return self._widgets
                 
    def get_value(self):
        
        return dict([(k,v.get_value()) for k,v in self._widgets.items()])
    
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#     def validate(self):
# 
#         for w in self._widgets.values():
#             w.SetBackgroundColour(wx.NullColour)
#             w.Refresh()
#              
#         try:
#             self._configurable.parameters = self.get_value()
#         except ConfiguratorError as e:
#             d = wx.MessageDialog(self, str(e), style=wx.ICON_ERROR|wx.STAY_ON_TOP|wx.CENTRE)
#             d.ShowModal()
#             w = self._widgets[e.configurator.name]
#             w.SetBackgroundColour("Pink")
#             w.Refresh()
#             w.SetFocus()
#             return False
#         else:
#             return True