IWidget.py 3.37 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#MDANSE : Molecular Dynamics Analysis for Neutron Scattering Experiments
#------------------------------------------------------------------------------------------
#Copyright (C)
#2015- Eric C. Pellegrini Institut Laue-Langevin
#BP 156
#6, rue Jules Horowitz
#38042 Grenoble Cedex 9
#France
#pellegrini[at]ill.fr
#goret[at]ill.fr
#aoun[at]ill.fr
#
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU Lesser General Public
#License as published by the Free Software Foundation; either
#version 2.1 of the License, or (at your option) any later version.
#
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

''' 
Created on Mar 30, 2015

:author: Eric C. Pellegrini
'''

import abc
        
import wx

from MDANSE import REGISTRY
38
39

from MDANSE.GUI import PUBLISHER
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

class IWidget(wx.Panel):
    
    __metaclass__ = REGISTRY
    
    type = "widget"

    def __init__(self, parent, name, configurator, *args, **kwargs):
        
        wx.Panel.__init__(self, parent, wx.ID_ANY, *args, **kwargs)

        self._parent = parent
        
        self._name = name
                                
        self._configurator = configurator
                                                        
57
        self._label = ' '.join(name.capitalize().split('_'))
58
59
60
61
62
                        
        self.initialize()
                        
        self.build_panel()
        
63
64
        self.Bind(wx.EVT_WINDOW_DESTROY,self.OnDestroy)
        
65
        PUBLISHER.subscribe(self._set_data, 'msg_set_data')
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
                        
    @property
    def label(self):
        return self._label

    @property
    def name(self):
        return self._name

    def initialize(self):
        pass

    @abc.abstractmethod
    def get_widget_value(self):
        pass
                
    @abc.abstractmethod
    def add_widgets(self):
        pass
    
    def build_panel(self):        

        self._staticBox = wx.StaticBox(self, wx.ID_ANY, label=self.label)

        self._staticBoxSizer = wx.StaticBoxSizer(self._staticBox, wx.VERTICAL)
                
        self._widgetPanel = wx.Panel(self, wx.ID_ANY)

        self._widgetPanelSizer = self.add_widgets()
        
        self._widgetPanel.SetSizer(self._widgetPanelSizer)
        
        self._staticBoxSizer.Add(self._widgetPanel, 1, wx.ALL|wx.EXPAND, 0)
        
        self.SetSizer(self._staticBoxSizer)
101
102
        
        self._widgetPanel.GrandParent.Refresh()
103
104
105
106
107
108
109
110
                
    def get_value(self):
        
        return self.get_widget_value()

    def set_data(self,datakey):
        pass

111
    def _set_data(self,message):
112
                
113
        plugin = message.data
114
115
116
117
        if not plugin.is_parent(self):
            return
        
        self.set_data(plugin.datakey)
118
119
120

    def OnDestroy(self,event):
                
121
        PUBLISHER.unsubscribe(self._set_data, 'msg_set_data')
122
        event.Skip()