IWidget.py 3.29 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
#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

37
from MDANSE.GUI import PUBLISHER
38 39

class IWidget(wx.Panel):
40 41
        
    _registry = "widget"
42 43 44 45 46 47 48 49 50 51 52

    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
                                                        
53
        self._label = self._configurator.label
54 55 56 57 58
                        
        self.initialize()
                        
        self.build_panel()
        
59 60
        self.Bind(wx.EVT_WINDOW_DESTROY,self.OnDestroy)
        
61
        PUBLISHER.subscribe(self._set_data, 'msg_set_data')
62 63 64 65 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
                        
    @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)
97 98
        
        self._widgetPanel.GrandParent.Refresh()
99 100 101 102 103 104 105 106
                
    def get_value(self):
        
        return self.get_widget_value()

    def set_data(self,datakey):
        pass

107
    def _set_data(self,message):
108
                
109
        plugin = message
110 111 112 113
        if not plugin.is_parent(self):
            return
        
        self.set_data(plugin.datakey)
114 115 116

    def OnDestroy(self,event):
                
117
        PUBLISHER.unsubscribe(self._set_data, 'msg_set_data')
118
        event.Skip()