Ejemplo n.º 1
0
 def snap_click(self, b=None):
     w = self.widget
     cy = self.cy
     json = self.to_json_value()
     snap = js_proxy.ProxyWidget()
     self.configure_widget(snap, layout="preset", descriptor=json)
     snap.embed(True, await=["cytoscape"])
Ejemplo n.º 2
0
 def __init__(self, target):
     self.target = target
     w = self.widget = js_proxy.ProxyWidget()
     e = self.element = w.element()
     # Create JS/python parallel mapping for finding elements.
     self.displays = {}
     self.expanded = {}
     w(e._set("DISPLAYS", {}))
     self.displays_reference = e.DISPLAYS
     self.jQuery = w.window().jQuery
     self.display_object(None, target, expanded=True, top=True)
Ejemplo n.º 3
0
 def __init__(self, width=500, height=500, autoRotate=False, center=(0,0,0), offset=100):
     init()
     w = self.w = js_proxy.ProxyWidget()
     element = self.element = w.element()
     window = self.window = w.window()
     THREE = self.THREE = window.THREE
     self.center = center
     self.offset = offset
     self.autoRotate = autoRotate
     scene = self.scene = w.save_new("scene", THREE.Scene, [])
     renderer = self.renderer = w.save_new("renderer", THREE.WebGLRenderer, [])
     w(renderer.setSize(width, height))
     w(renderer.setClearColor( 0xffffff, 1))
     w(element.append(renderer.domElement))
Ejemplo n.º 4
0
 def canvas(self, width=None, height=None, entropy=True):
     """
     Make a jsproxy canvas widget which draws the motif using sequence_motif.js.
     """
     from jp_gene_viz import js_proxy
     js_proxy.load_javascript_support()
     w = js_proxy.ProxyWidget()
     elt = w.element()
     return self.add_canvas(w,
                            elt,
                            width=width,
                            height=height,
                            entropy=entropy,
                            x=5,
                            y=5)
Ejemplo n.º 5
0
def explore_directory(directory):
    from jp_gene_viz import js_proxy
    from IPython.display import display, HTML
    js_proxy.load_javascript_support()
    load_highcharts = """
    <script src="https://code.highcharts.com/highcharts.js"></script>
    """
    display(HTML(load_highcharts))
    widget = js_proxy.ProxyWidget()
    elt = widget.element()
    # create a chart element look up table
    #widget(elt._set("PieCharts", {}))
    # attach a pie chart for directory
    chart = DirectoryPieChart(directory, widget, elt)
    widget.flush()
    display(widget)
    return widget
Ejemplo n.º 6
0
    def __init__(self,
                 message="Choose file",
                 root=".",
                 files=True,
                 folders=False,
                 upload=False,
                 dialog=True,
                 width=500,
                 *args,
                 **kwargs):
        """
        FileChooser constructor.

        Parameters
        ----------
        message : str 
            Message near the top of the widget as a prompt.
        root : str
            The root path for the top folder to display.
        files : bool
            Make non-folders selectable iff true.
        folders : bool
            Show folders iff true.
        upload : bool
            Enable file upload iff true.
        dialog : bool
            Show in a jQueryUI dialog iff true, else inline.
        width : int
            Width of widget in pixels.
        """
        super(FileChooser, self).__init__(*args, **kwargs)
        js_context.load_if_not_loaded(["simple_upload_button.js"])
        js_context.load_if_not_loaded(["server_file_chooser.js"])
        self.root = root
        self.upload = upload
        self.files = files
        self.folders = folders
        self.dialog = dialog
        self.message = message
        self.width = width
        self.widget = js_proxy.ProxyWidget()
        self.layout([self.root])
Ejemplo n.º 7
0
def test_plot(with_box=False, with_rotator=True):
    from IPython import display
    import math
    sp = ScatterPlot3D()
    points1 = [(400 + math.sin(i * 2), math.cos(i * 3) * 1.5,
                math.sin(i * 0.5)) for i in range(150)]
    sp.add_series("star", 0xff0000, points1)
    points2 = [(401 + math.sin(i), math.cos(i * 2), math.sin(i * 1.5) * 1.7)
               for i in range(150)]
    sp.add_series("openCube", 0xffff00, points2)
    w = js_proxy.ProxyWidget()
    window = w.window()
    element = w.element()
    THREE = window.THREE
    new = w.save_new
    scene = new("scene", THREE.Scene, [])
    camera = new("camera", THREE.PerspectiveCamera, [75, 1.0, 1, 10000])
    w(camera.position._set("z", 500))
    # plot the scatter points
    sp.plot(300, w, scene, 10)
    if with_box:
        geometry = new("geometry", THREE.BoxGeometry, [200, 200, 200])
        #geometry = new("geometry", THREE.TetrahedronGeometry, [])
        material = new("material", THREE.MeshBasicMaterial, [{
            "color": 0xff00ee,
            "wireframe": True
        }])
        mesh = new("mesh", THREE.Mesh, [geometry, material])
        w(scene.add(mesh))
    renderer = new("renderer", THREE.WebGLRenderer, [])
    w(renderer.setSize(800, 800))
    w(element.append(renderer.domElement))
    do_render = w(renderer.render(scene, camera))
    if with_rotator:
        gamma = xyz_dict(0, 0, 1)
        delta = xyz_dict(1, 0, 0)
        radius = 300
        w(THREE.rotator(gamma, delta, radius, camera, renderer, scene))
    json_sent = w.flush()
    display.display(w)
    return w
Ejemplo n.º 8
0
 def __init__(self, *args, **kwargs):
     super(Diagram, self).__init__(*args, **kwargs)
     initialize()
     mx = self.max_angle * 2
     d = self.diagram = js_proxy.ProxyWidget()
     xy = self.xy_slider = widgets.FloatSlider(description="XY rotation",
                                               min=-mx,
                                               max=mx)
     xz = self.xy_slider = widgets.FloatSlider(description="XZ rotation",
                                               min=-mx,
                                               max=mx)
     yz = self.xy_slider = widgets.FloatSlider(description="YZ rotation",
                                               min=-mx,
                                               max=mx)
     traitlets.link((self, "xy_rotation"), (xy, "value"))
     traitlets.link((self, "xz_rotation"), (xz, "value"))
     traitlets.link((self, "yz_rotation"), (yz, "value"))
     self.on_trait_change(self.draw_diagram, "xy_rotation")
     self.on_trait_change(self.draw_diagram, "xz_rotation")
     self.on_trait_change(self.draw_diagram, "yz_rotation")
     self.assembly = widgets.VBox(children=[xy, xz, yz, d])
Ejemplo n.º 9
0
 def __init__(self, dataset, *args, **kwargs):
     super(Nearest, self).__init__(*args, **kwargs)
     initialize()
     self.dataset = dataset
     feature_names = list(dataset.feature_names)
     self.x_name = feature_names[0]
     self.y_name = feature_names[1]
     self.z_name = feature_names[2]
     sc = self.scatter_plot = js_proxy.ProxyWidget()
     xd = self.x_dropdown = widgets.Dropdown(
         options=list(feature_names), value=self.x_name)
     yd = self.y_dropdown = widgets.Dropdown(
         options=list(feature_names), value=self.y_name)
     zd = self.z_dropdown = widgets.Dropdown(
         options=list(feature_names), value=self.z_name)
     bc = self.border_checkbox = widgets.Checkbox(description="border", value=True)
     tc = self.training_checkbox = widgets.Checkbox(description="training", value=True)
     tstc = self.test_checkbox = widgets.Checkbox(description="test", value=True)
     ns = self.n_slider = widgets.IntSlider(value=self.n_neighbors, min=1, max=20,
         description="neighbors", width="50px")
     ss = self.n_slider = widgets.FloatSlider(value=self.n_neighbors, min=0.2, max=0.5,
         description="test size", width="50px", step=0.1)
     traitlets.directional_link((ss, "value"), (self, "test_size"))
     traitlets.directional_link((xd, "value"), (self, "x_name"))
     traitlets.directional_link((yd, "value"), (self, "y_name"))
     traitlets.directional_link((zd, "value"), (self, "z_name"))
     traitlets.directional_link((bc, "value"), (self, "show_borders"))
     traitlets.directional_link((ns, "value"), (self, "n_neighbors"))
     traitlets.directional_link((tc, "value"), (self, "show_training"))
     traitlets.directional_link((tstc, "value"), (self, "show_test"))
     xd.on_trait_change(self.redraw, "value")
     ss.on_trait_change(self.redraw, "value")
     yd.on_trait_change(self.redraw, "value")
     zd.on_trait_change(self.redraw, "value")
     bc.on_trait_change(self.redraw, "value")
     tc.on_trait_change(self.redraw, "value")
     tstc.on_trait_change(self.redraw, "value")
     ns.on_trait_change(self.redraw, "value")
     controls = widgets.VBox(children=[xd, yd, zd, bc, tc, tstc, ns, ss])
     self.assembly = widgets.HBox(children=[controls, sc])
Ejemplo n.º 10
0
 def __init__(self,
              viewBox="0 0 500 500",
              dimension=SIDE_DEFAULT,
              *pargs,
              **kwargs):
     super(HTML5CanvasProxy, self).__init__(*pargs, **kwargs)
     self.viewBox = viewBox
     self.svg_width = dimension
     self.svg_height = dimension
     self.on_trait_change(self.change_dimensions, "svg_width")
     self.on_trait_change(self.change_dimensions, "svg_height")
     self.on_trait_change(self.start_watch_event, "watch_event")
     self.on_trait_change(self.stop_watch_event, "unwatch_event")
     self.font = "Arial"  # default
     self.font_size = 10
     self.font_style = ""
     self.font_weight = "normal"
     self.operations = []
     self.assignments = {}
     w = self.widget = js_proxy.ProxyWidget()
     self.element = w.element()
     self.empty()
Ejemplo n.º 11
0
def decrypt_widget():
    import time
    import threading
    from jp_gene_viz import js_proxy
    js_proxy.load_javascript_support()
    # wait for the js to compile...
    time.sleep(0.5)
    from IPython.display import display
    d = js_proxy.ProxyWidget()
    elt = d.element()
    #display(d)
    window = d.window()
    jQuery = window.jQuery
    d(elt.width("400px").height("100px"))
    d(
        elt.html(
            """<input type="password" id="pw000"/> <input id="b000" type="button" value="decrypt files"/> """
        ))

    def click_handler(id, args):
        print "click"
        t = threading.Timer(0.1, extract)
        t.start()

    def extract():
        print "extracting password..."
        print d.send(jQuery("#pw000").val(), pw_callback)

    def pw_callback(arg):
        print "... password extracted"
        password = arg[0]
        # print("pw="+repr(password))
        decrypt(password)

    callback = d.callback(click_handler, None)
    d(jQuery("#b000").click(callback))
    d.flush()
    #display(d)
    return d
 def show(self):
     ls = self.label_selection = self.label_selector()
     sd = self.spot_display = self.display_spot_canvas()
     #detail = self.detail_display = self.display_spot_canvas(width=2*self.radius, height=2*self.radius)
     im_detail = self.image_detail = js_proxy.ProxyWidget()
     #self.assembly = self.label_selection # testing only
     info = self.info_area = widgets.Textarea(description="status")
     filename = self.file_name_text = widgets.Text(
         value=self.annotation_path)
     savebutton = self.save_button = widgets.Button(description="save")
     savebutton.on_click(self.save_click)
     restorebutton = self.restore_button = widgets.Button(
         description="restore")
     restorebutton.on_click(self.restore_click)
     nearbybutton = self.nearby_button = widgets.Button(
         description="x: nearby")
     nearbybutton.on_click(self.nearby_click)
     file_save_widgets = [filename, savebutton, restorebutton]
     if self.spots_href is not None:
         spots_checkbox = self.spots_checkbox = widgets.Checkbox(
             description="spots")
         file_save_widgets.append(spots_checkbox)
         spots_checkbox.on_trait_change(self.redraw, "value")
     file_save_widgets.append(nearbybutton)
     file_save = widgets.HBox(children=file_save_widgets)
     work_area = widgets.HBox(children=[sd.target, ls, im_detail])
     self.assembly = widgets.VBox(children=[work_area, file_save, info])
     #self.assembly = widgets.HBox(children=[ls])
     display(self.assembly)
     self.configure_label_selector()
     self.configure_image_detail()
     self.add_key_bindings()
     self.label_selection.flush()
     if os.path.exists(self.annotation_path):
         self.restore_click()
     else:
         self.draw_spots()
 def __init__(self, data=None, slide_columns=8):
     self.row_size = slide_columns
     if data is None:
         data = Data()
     self.data = data
     slides = data.slides
     slide_displays = []
     slide_name_to_controller = {}
     slide_controllers = []
     slide_rows = int(len(slides) / slide_columns)
     if slide_rows * slide_columns < len(slides):
         slide_rows += 1
     self.slide_margin = margin = 5
     row_size = 2*margin + slide_rows * (data.slide_height + margin)
     col_size = 2*margin + (slide_columns) * (data.slide_width + margin)
     slides_width = 2 * self.big_width
     #slide_drawing = cartesian_svg.doodle(-1, -1, col_size+1, row_size+1, slides_width, margin=2)
     #print "rows, cols", slide_rows, slide_columns
     #print "slides dimensions", len(slides), col_size, row_size, "html width", slides_width
     slide_drawing = canvas_doodle(-1, -1, col_size+1, row_size+1, slides_width, margin=2)
     self.slide_drawing = slide_drawing
     #slide_drawing.enable_events("click", self.slide_drawing_click)
     count = 0
     for slide_name in slides:
         count += 1
         #if count > 30:
         #    break
         controller = Slide(slide_name, data, slide_drawing)
         slide_controllers.append(controller)
         assert slide_name not in slide_name_to_controller
         slide_name_to_controller[slide_name] = controller
     self.slide_controllers = slide_controllers
     controller_rows = []
     available_controllers = list(slide_controllers)
     while available_controllers:
         row_list = available_controllers[:self.row_size]
         available_controllers = available_controllers[self.row_size:]
         controller_rows.append(row_list)
     self.controller_rows = controller_rows
     self.slide_name_to_controller = slide_name_to_controller
     #tsne_drawing = cartesian_svg.doodle(-TSNE_RADIUS-1, -TSNE_RADIUS-1, TSNE_RADIUS+1, TSNE_RADIUS+1, self.big_width, margin=4)
     tsne_drawing = canvas_doodle(-TSNE_RADIUS-1, -TSNE_RADIUS-1, TSNE_RADIUS+1, TSNE_RADIUS+1, self.big_width, margin=4)
     self.tsne_drawing = tsne_drawing
     #tsne_events = "click mouseover mouseout"
     #tsne_events = "click"
     #print "enabling tsne events", tsne_events
     #tsne_drawing.enable_events(tsne_events, self.tsne_event_callback)
     #big_slide_drawing = cartesian_svg.doodle(-1, -1, data.slide_width+1, data.slide_height+1, self.big_width, margin=4)
     big_slide_drawing = canvas_doodle(-1, -1, data.slide_width+1, data.slide_height+1, self.big_width, margin=4)
     self.big_slide_drawing = big_slide_drawing
     # make dialog
     w = js_proxy.ProxyWidget()
     e = w.element()
     w(e.html("Temporary content for dialog").dialog())
     w(e.dialog("close"))
     w.flush()
     self.dialog = w
     big_assembly = widgets.HBox(children=[tsne_drawing.target.widget, big_slide_drawing.target.widget])
     self.assembly = widgets.VBox(children=[big_assembly, slide_drawing.target.widget, self.dialog])
     self.tsne_controller = TSNE(data, tsne_drawing)
     self.slide_controller_rows = slide_controllers
     self.chosen_slide = slides[0]
     self.chosen_indicator = None
     self.events_enabled = False
     self.reset_bookkeeping()
 def label_selector(self):
     w = js_proxy.ProxyWidget()
     return w
Ejemplo n.º 15
0
 def configure_widget(self, w=None, layout="cose", descriptor=None):
     if w is None:
         self.widget = js_proxy.ProxyWidget()
         w = self.widget
     element = w.element()
     w(element.empty())
     # set up an event callback helper
     w.save_function(
         "event_cb", ["callback"], """
         //debugger;
         return function(evt) {
             //debugger;
             var cyTarget = evt.cyTarget;
             if (cyTarget && cyTarget.data) {
                 var result = evt.cyTarget.data();
                 if (result) {
                     result.type = evt.type;
                     result.shiftKey = evt.originalEvent.shiftKey;
                     result.isNode = cyTarget.isNode();
                     result.isEdge = cyTarget.isEdge();
                     return callback(result);
                 }
             }
             return callback({});
         }
     """)
     self.element = element = w.element()
     window = w.window()
     cytoscape = window.cytoscape
     jQuery = window.jQuery
     w(
         element._set(
             "target",
             jQuery("<div></div>").height("600px").width("800px").
             #html("cytoscape target div").
             appendTo(element)))
     #nodes = [{"data": {"id": "n", "label": "cytoscape"}}]
     if descriptor is None:
         nodes = []
         edges = []
         elements = {"nodes": nodes, "edges": edges}
         descriptor = {
             "container": element.target._get(0),
             "style": STYLE,
             "elements": elements,
             "layout": {
                 "name": layout,
                 "padding": 5
             }
         }
     else:
         descriptor = copy.deepcopy(descriptor)
         descriptor["container"] = element.target._get(0)
         descriptor["layout"]["name"] = layout
     w(element._set("cy_container", cytoscape(descriptor)))
     w(element.height("600px").width("800px"))
     self.cy = cy = element.cy_container
     clickcallback = element.event_cb(
         w.callback(self.clickhandler, data="click", level=3))
     self.getter = cy._get("$")
     # only add events in live mode
     if w == self.widget:
         w(cy.on('click', clickcallback))
     return w