AnimationPlugin.py 7.07 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 Apr 14, 2015

:author: Eric C. Pellegrini
'''

import wx
import wx.aui as wxaui


37
from MDANSE.GUI import PUBLISHER
38
from MDANSE.GUI.Icons import ICONS
39
from MDANSE.GUI.Plugins.ComponentPlugin import ComponentPlugin
40
41
42
43
44
45
46

class AnimationPlugin(ComponentPlugin):
    
    type = "animation"
    
    label = "Animation"
    
47
    ancestor = ["molecular_viewer"]
48
49
50
51
52
53
54
55
56
57
58
59
        
    def __init__(self, parent, *args, **kwargs):
        
        ComponentPlugin.__init__(self, parent, size=(-1,50), *args, **kwargs)
                    
    def build_panel(self):   
 
        panel = wx.Panel(self, wx.ID_ANY, size=self.GetSize())
 
        controlSizer = wx.BoxSizer(wx.HORIZONTAL)

        firstButton = wx.BitmapButton(panel, wx.ID_ANY, ICONS["first",32,32])
60
        self.startStop = wx.BitmapButton(panel, wx.ID_ANY, ICONS["play",32,32])
61
62
        lastButton = wx.BitmapButton(panel, wx.ID_ANY, ICONS["last",32,32])
        self.frameSlider = wx.Slider(panel,id=wx.ID_ANY, value=0, minValue=0, maxValue=1, style=wx.SL_HORIZONTAL)
63
        self.frameSlider.SetRange(0,self._parent.n_frames-1)            
64
65
66
67
68
69
70
71
72
        self.frameEntry = wx.TextCtrl(panel,id=wx.ID_ANY,value="0", size=(60,20), style= wx.SL_HORIZONTAL|wx.TE_PROCESS_ENTER)        
        speedBitmap = wx.StaticBitmap(panel,-1, ICONS["clock",42,42])
        self.speedSlider = wx.Slider(panel,id=wx.ID_ANY,value=0,minValue=0,maxValue=1,style=wx.SL_HORIZONTAL)
        self.speedSlider.SetRange(0,self._parent.max_laps)
        speed = self._parent.max_laps - self._parent.timer_interval
        self.speedSlider.SetValue(speed)
        self.speedEntry = wx.TextCtrl(panel,id=wx.ID_ANY,value=str(speed), size=(60,20), style= wx.SL_HORIZONTAL|wx.TE_PROCESS_ENTER)

        controlSizer.Add(firstButton, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL,5)
73
        controlSizer.Add(self.startStop, 0,  wx.ALIGN_CENTER_VERTICAL)
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
        controlSizer.Add(lastButton, 0, wx.ALIGN_CENTER_VERTICAL)
        controlSizer.Add((5, -1), 0, wx.ALIGN_RIGHT)

        controlSizer.Add(self.frameSlider, 3, wx.ALIGN_CENTER_VERTICAL)
        controlSizer.Add(self.frameEntry, 0, wx.ALIGN_CENTER_VERTICAL)
        controlSizer.Add((5, -1), 0, wx.ALIGN_RIGHT)

        controlSizer.Add(speedBitmap, 0 , wx.ALIGN_CENTER_VERTICAL) 
        controlSizer.Add((5, -1), 0, wx.ALIGN_RIGHT)

        controlSizer.Add(self.speedSlider, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL) 
        controlSizer.Add(self.speedEntry, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL,5) 
                
        panel.SetSizer(controlSizer)
        controlSizer.Fit(panel)        
        panel.Layout()
                
        self._mgr.AddPane(panel, wxaui.AuiPaneInfo().Center().Dock().CaptionVisible(False).CloseButton(False).MinSize(self.GetSize()))

        self._mgr.Update()

        self.Bind(wx.EVT_SCROLL, self.on_frame_sliding, self.frameSlider)
        self.Bind(wx.EVT_TEXT_ENTER, self.on_set_frame, self.frameEntry)
        
        self.Bind(wx.EVT_SLIDER, self.on_change_frame_rate, self.speedSlider)
        self.Bind(wx.EVT_TEXT_ENTER, self.on_set_speed, self.speedEntry)
        
101
        self.Bind(wx.EVT_BUTTON, self.on_start_stop_animation, self.startStop)
102
103
104
        self.Bind(wx.EVT_BUTTON, self.on_goto_first_frame, firstButton)
        self.Bind(wx.EVT_BUTTON, self.on_goto_last_frame, lastButton)
                
105
106
107
        PUBLISHER.subscribe(self.msg_update_animation_icon, 'msg_animate_trajectory')
        PUBLISHER.subscribe(self.msg_set_trajectory, 'msg_set_trajectory')
        PUBLISHER.subscribe(self.msg_timer, 'msg_timer')
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
                
    def plug(self):
        self._parent._mgr.GetPane(self).LeftDockable(False).RightDockable(False).Dock().Bottom().CloseButton(True)
        
        self._parent._mgr.Update()        

    def on_change_frame_rate(self, event=None):

        laps = self.speedSlider.GetValue()
        
        self._parent.change_frame_rate(laps)
        
        self.speedEntry.SetValue(str(self.speedSlider.GetValue()))        

    def on_frame_sliding(self, event=None):
        
        frame = self.frameSlider.GetValue()
        
        self._parent.set_frame(frame)
        
        frame = self._parent.current_frame
        
        self.frameEntry.SetValue(str(frame))
        self.frameSlider.SetValue(frame)
        
    def on_goto_first_frame(self, event=None):
        
        self._parent.goto_first_frame()

        self.frameEntry.SetValue(str(0))
        self.frameSlider.SetValue(0)

    def on_goto_last_frame(self, event=None):

        self._parent.goto_last_frame()

        self.frameEntry.SetValue(str(self._parent.n_frames-1))
        self.frameSlider.SetValue(self._parent.n_frames-1)

    def on_set_speed(self, event=None):

        self.speedSlider.SetValue(int(self.speedEntry.GetValue()))        
        self._parent.change_frame_rate()
                
152
    def msg_timer(self, message):
153
        
154
        plugin = message.data
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
        if not plugin.is_parent(self):
            return
        
        frame = plugin.current_frame
        
        self.frameEntry.SetValue(str(frame))
        self.frameSlider.SetValue(int(frame))
        
    def on_set_frame(self, event=None):
        
        frame = int(self.frameEntry.GetValue())
        
        self._parent.set_configuration(frame)
        
        self.frameSlider.SetValue(frame)
        
    def on_start_stop_animation(self, event=None):
        
        self._parent.start_stop_animation()

175
    def msg_update_animation_icon(self, message):
176
 
177
        plugin = message.data
178
179
180
181
        if not plugin.is_parent(self):
            return
                 
        if plugin.animation_loop:
182
            self.startStop.SetBitmapLabel(ICONS["pause",32,32])
183
        else:
184
185
            self.startStop.SetBitmapLabel(ICONS["play",32,32])

186
187
188
    def msg_set_trajectory(self, message):
        
        plugin = message.data
189
190
191
192
        if not plugin.is_parent(self):
            return
 
        self.frameSlider.SetRange(0,self._parent.n_frames-1)