File: directview.py

package info (click to toggle)
ipython 0.13.1-2%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 15,752 kB
  • sloc: python: 69,537; makefile: 355; lisp: 272; sh: 80; objc: 37
file content (68 lines) | stat: -rw-r--r-- 1,851 bytes parent folder | download | duplicates (2)
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
37
38
39
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
"""Widget for interacting with an IPython parallel engine.

Authors:

* Brian Granger
"""

#-----------------------------------------------------------------------------
#  Copyright (C) 2008-2012  The IPython Development Team
#
#  Distributed under the terms of the BSD License.  The full license is in
#  the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------

import os
import uuid

from IPython.core.display import display, Javascript
from IPython.core.displaypub import publish_pretty


#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------


import os, sys
from IPython.core.display import Javascript

from widget import JavascriptWidget


class DirectViewWidget(JavascriptWidget):

    def __init__(self, dv):
        self.dv = dv
        self.targets = self.dv.targets
        super(DirectViewWidget,self).__init__()

    def render(self):
        fname = os.path.join(os.path.dirname(__file__), u'directview.js')
        with open(fname, 'r') as f:
            jscode = f.read()
        data = {
            'widget_var': self.widget_var,
            'targets' : self.encode_json(self.targets)
        }
        jscode = jscode % data
        return jscode

    def execute(self, code, targets='all'):
        if targets == 'all':
            targets = self.targets
        result = self.dv.execute(code,silent=False,block=False,targets=targets)
        result.wait()
        result.display_outputs()


def interact(dv):
    w = DirectViewWidget(dv)
    w.interact()
    return w