Skip to content

Commit

Permalink
Add play, stop and pause methods to Play widget
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Dec 5, 2018
1 parent 1223d41 commit 4f18a61
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ipywidgets/widgets/widget_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,19 @@ class Play(_BoundedInt):
_repeat = Bool(help="Whether the control will repeat in a continous loop.").tag(sync=True)
show_repeat = Bool(True, help="Show the repeat toggle button in the widget.").tag(sync=True)

def _send_action(self, action):
self.send({'action': action})

def play(self):
self._send_action('play')

def stop(self):
self._send_action('stop')

def pause(self):
self._send_action('pause')


class _BoundedIntRange(_IntRange):
max = CInt(100, help="Max value").tag(sync=True)
min = CInt(0, help="Min value").tag(sync=True)
Expand Down
15 changes: 15 additions & 0 deletions packages/controls/src/widget_int.ts
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ class PlayView extends DOMWidgetView {
this.listenTo(this.model, 'change:_playing', this.update_playing);
this.listenTo(this.model, 'change:_repeat', this.update_repeat);
this.listenTo(this.model, 'change:show_repeat', this.update_repeat);
this.listenTo(this.model, 'msg:custom', this.on_custom_message);
this.update_playing();
this.update_repeat();
this.update();
Expand Down Expand Up @@ -898,6 +899,20 @@ class PlayView extends DOMWidgetView {
}
}

on_custom_message(message) {
switch(message.action) {
case 'play':
this.playButton.click();
break;
case 'pause':
this.pauseButton.click();
break;
case 'stop':
this.stopButton.click();
break;
}
}

playButton: HTMLButtonElement;
pauseButton: HTMLButtonElement;
stopButton: HTMLButtonElement;
Expand Down

0 comments on commit 4f18a61

Please sign in to comment.