FramesWidget.py 3.41 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
#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

30
:author: Eric C. Pellegrini
31
32
33
34
35
36
'''

import wx
import wx.lib.intctrl as wxintctrl

from MDANSE.App.GUI import DATA_CONTROLLER
37
from MDANSE.App.GUI.Framework.Widgets.IWidget import IWidget
38
        
39
class FramesWidget(IWidget):
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
        
    type = "frames"
    
    def add_widgets(self):

        sizer = wx.BoxSizer(wx.HORIZONTAL)

        gbSizer = wx.GridBagSizer(5,5)
        
        firstLabel = wx.StaticText(self._widgetPanel, wx.ID_ANY, label="First frame")
        self._first = wxintctrl.IntCtrl(self._widgetPanel, wx.ID_ANY, limited=True, allow_none=False)

        labelLabel = wx.StaticText(self._widgetPanel, wx.ID_ANY, label="Last frame")
        self._last = wxintctrl.IntCtrl(self._widgetPanel, wx.ID_ANY, limited=True, allow_none=False)

        stepLabel = wx.StaticText(self._widgetPanel, wx.ID_ANY, label="Frame step")
        self._step = wxintctrl.IntCtrl(self._widgetPanel, wx.ID_ANY, limited=True, allow_none=False)

        gbSizer.Add(firstLabel, (0,0), flag=wx.ALIGN_CENTER_VERTICAL)
        gbSizer.Add(labelLabel, (0,3), flag=wx.ALIGN_CENTER_VERTICAL)
        gbSizer.Add(stepLabel,  (0,6), flag=wx.ALIGN_CENTER_VERTICAL)

        gbSizer.Add(self._first, (0,1), flag=wx.EXPAND)
        gbSizer.Add(self._last,  (0,4), flag=wx.EXPAND)
        gbSizer.Add(self._step,  (0,7), flag=wx.EXPAND)

        gbSizer.AddGrowableCol(1)
        gbSizer.AddGrowableCol(4)
        gbSizer.AddGrowableCol(7)

        sizer.Add(gbSizer, 1, wx.ALL|wx.EXPAND, 5)

        return sizer

    def get_widget_value(self):
        
        val = (self._first.GetValue(), self._last.GetValue(), self._step.GetValue())
        
        return val
    
80
    def set_data(self, datakey):
81
        
82
        self._trajectory = DATA_CONTROLLER[datakey]
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
        
        nFrames = len(self._trajectory.data) - 1
                
        self._first.SetMin(0)
        self._first.SetMax(nFrames-1)
        self._first.SetValue(0)

        self._last.SetMin(1)
        self._last.SetMax(nFrames)
        self._last.SetValue(nFrames)

        self._step.SetMin(1)
        self._step.SetMax(nFrames)
        self._step.SetValue(1)
        
    @property
    def time(self):
        
        f, l, s = self.get_value()
        
        time = self._trajectory.data.time[f:l:s]
        
        return time