#!/usr/bin/env python # coding: utf-8 # In[21]: import ipywidgets as widgets # Loads the Widget framework. from IPython.core.magics.namespace import NamespaceMagics # Used to query namespace. # For this example, hide these names, just to avoid polluting the namespace further get_ipython().user_ns_hidden['widgets'] = widgets get_ipython().user_ns_hidden['NamespaceMagics'] = NamespaceMagics # In[22]: class VariableInspectorWindow(object): instance = None def __init__(self, ipython): """Public constructor.""" if VariableInspectorWindow.instance is not None: raise Exception("""Only one instance of the Variable Inspector can exist at a time. Call close() on the active instance before creating a new instance. If you have lost the handle to the active instance, you can re-obtain it via `VariableInspectorWindow.instance`.""") VariableInspectorWindow.instance = self self.closed = False self.namespace = NamespaceMagics() self.namespace.shell = ipython.kernel.shell self._box = widgets.Box() self._box._dom_classes = ['inspector'] self._box.background_color = '#fff' self._box.border_color = '#ccc' self._box.border_width = 1 self._box.border_radius = 5 self._modal_body = widgets.VBox() self._modal_body.overflow_y = 'scroll' self._modal_body_label = widgets.HTML(value = 'Not hooked') self._modal_body.children = [self._modal_body_label] self._box.children = [ self._modal_body, ] self._ipython = ipython self._ipython.events.register('post_run_cell', self._fill) def close(self): """Close and remove hooks.""" if not self.closed: self._ipython.events.unregister('post_run_cell', self._fill) self._box.close() self.closed = True VariableInspectorWindow.instance = None def _fill(self): """Fill self with variable information.""" values = self.namespace.who_ls() self._modal_body_label.value = '
NameTypeValue
' + \ '
'.join(['{0}{1}{2}'.format(v, type(eval(v)).__name__, str(eval(v))) for v in values]) + \ '
' def _ipython_display_(self): """Called when display() or pyout is used to display the Variable Inspector.""" self._box._ipython_display_() # In[23]: #inspector.close() # In[24]: inspector = VariableInspectorWindow(get_ipython()) inspector # In[10]: get_ipython().run_cell_magic('javascript', '', "$('div.inspector')\n .detach()\n .prependTo($('body'))\n .css({\n 'z-index': 999, \n position: 'fixed',\n 'box-shadow': '5px 5px 12px -3px black',\n opacity: 0.9\n })\n .draggable();\n") # In[4]: a=3 # In[11]: b=4 # In[12]: s=5 # In[13]: get_ipython().system('pip install git+https://github.com/takluyver/mobilechelonian.git') # In[25]: from mobilechelonian import Turtle t = Turtle() t.speed(5) colours=["red","blue","yellow","brown","black","purple","green"] t.penup(); t.left(90); t.forward(200);t.right(90);t.pendown() for i in range (0,18): t.pencolor(colours[i%7]) t.right(20) t.forward(50) t.right(180) t.home() # In[20]: t=Turtle() t.forward(100) t.right(90) t.forward(100) # In[ ]: