21
21
import numpy as np
22
22
23
23
24
- __version__ = "1.7.0 "
24
+ __version__ = "1.7.1 "
25
25
26
26
27
27
def string_from_ffi (s ):
@@ -1149,11 +1149,36 @@ def animate(*args, **kwargs):
1149
1149
readout = True ,
1150
1150
)
1151
1151
1152
+ play_widget = widgets .Play (
1153
+ value = 1 ,
1154
+ min = 1 ,
1155
+ max = 1 ,
1156
+ step = 1 ,
1157
+ interval = 500 ,
1158
+ description = "Play animation" ,
1159
+ disabled = False ,
1160
+ )
1161
+
1162
+ speed_widget = widgets .IntSlider (
1163
+ value = 3 ,
1164
+ min = 1 ,
1165
+ max = 20 ,
1166
+ step = 1 ,
1167
+ description = "Speed" ,
1168
+ disabled = False ,
1169
+ continuous_update = True ,
1170
+ readout = True ,
1171
+ )
1172
+
1173
+ widgets .jslink ((play_widget , "value" ), (frame_widget , "value" ))
1174
+ play_and_speed_widget = widgets .HBox ([play_widget , speed_widget ])
1175
+ controls = widgets .VBox ([frame_widget , play_and_speed_widget ])
1176
+
1177
+ controls .layout .visibility = "hidden"
1152
1178
image_widget .layout .visibility = "hidden"
1153
- frame_widget .layout .visibility = "hidden"
1154
1179
waitl_widget = widgets .Label (value = "Generating plots...." )
1155
1180
frame_widget .layout .width = "800px"
1156
- display (image_widget , frame_widget , waitl_widget )
1181
+ display (image_widget , controls , waitl_widget )
1157
1182
1158
1183
# plot all frames to a temporary directory owned by Metview to enure cleanup
1159
1184
tempdirpath = tempfile .mkdtemp (dir = os .environ .get ("METVIEW_TMPDIR" , None ))
@@ -1173,6 +1198,7 @@ def animate(*args, **kwargs):
1173
1198
files = [os .path .join (tempdirpath , f ) for f in sorted (filenames )]
1174
1199
frame_widget .max = len (files )
1175
1200
frame_widget .description = "Frame (" + str (len (files )) + ") :"
1201
+ play_widget .max = len (files )
1176
1202
1177
1203
def plot_frame (frame_index ):
1178
1204
im_file = open (files [frame_index - 1 ], "rb" )
@@ -1186,11 +1212,16 @@ def on_frame_change(change):
1186
1212
plot_frame (1 )
1187
1213
frame_widget .observe (on_frame_change , names = "value" )
1188
1214
1215
+ def on_speed_change (change ):
1216
+ play_widget .interval = 1500 / change ["new" ]
1217
+
1218
+ speed_widget .observe (on_speed_change , names = "value" )
1219
+
1189
1220
# everything is ready now, so hide the 'waiting' label
1190
1221
# and reveal the plot and the frame slider
1191
1222
waitl_widget .layout .visibility = "hidden"
1223
+ controls .layout .visibility = "visible"
1192
1224
image_widget .layout .visibility = "visible"
1193
- frame_widget .layout .visibility = "visible"
1194
1225
1195
1226
1196
1227
# On a test system, importing IPython took approx 0.5 seconds, so to avoid that hit
0 commit comments