These are chat archives for ipython/ipython

8th
Jan 2016
bicubic
@bicubic
Jan 08 2016 12:03
@Discmt you could import the df data into https://saddle.github.io
bicubic
@bicubic
Jan 08 2016 12:09
@minrk I'm just starting to get my head around the extension docs... Is there a mechanism to intercept intended cell output and manipulate it before passing to frontend? E.g. selectively wrap some outputs inside custom html
Min RK
@minrk
Jan 08 2016 12:10
In the Javascript?
bicubic
@bicubic
Jan 08 2016 12:10
in the kernel
Min RK
@minrk
Jan 08 2016 12:10
Hm.
Probably not a super easy way, depending on what custom behavior you want to modify.
bicubic
@bicubic
Jan 08 2016 12:11
contrived use case: I want to capture when a pandas dataframe with some metadata is being rendered, and add some HTML based on that medata. Without messing with the pandas classes
Min RK
@minrk
Jan 08 2016 12:11
You can register custom display formatters without touching the classes
See the for_type bits
So ip.display_formatter.formatters['text/html'].for_type(DataFrame, your_df_func)
bicubic
@bicubic
Jan 08 2016 12:14
ah. Great, thanks
Min RK
@minrk
Jan 08 2016 12:14
In your_df_func, you can call frame._repr_html_() if you want to take the existing format and wrap it in something.
bicubic
@bicubic
Jan 08 2016 12:15
not sure yet if it's enough for the actual use case but a great starting point!
Min RK
@minrk
Jan 08 2016 12:15
return None if your function decides it shouldn't compute the repr, and the next display type will be used.
bicubic
@bicubic
Jan 08 2016 12:15
also, is there documentation regarding how post_run_cell differs from post_execute events?
Min RK
@minrk
Jan 08 2016 12:15
I suppose you could register on object, and it would be called for everything, but that would likely cause some problems.
bicubic
@bicubic
Jan 08 2016 12:16
another contrived use case: I execute a long running task, I want to display a dynamic progress/spinner bar, then remove that and display the result of the long running task
Min RK
@minrk
Jan 08 2016 12:17
Widgets can do that
bicubic
@bicubic
Jan 08 2016 12:17
again, without messing with the code of the long running task
Min RK
@minrk
Jan 08 2016 12:17
Ah. How do you check on progress?
Or do you just mean an indeterminate widget?
bicubic
@bicubic
Jan 08 2016 12:18
lets say there's a function I don't control. I want to display a spinner while its running (i.e. I don't know progress)
Min RK
@minrk
Jan 08 2016 12:18
widgets allow you to close them:
  1. create HTML widget with spinner gif
  2. display(widget)
  3. run job
  4. widget.close()
(I think that should work, I'm not 100% certain about it)
bicubic
@bicubic
Jan 08 2016 12:19
how will this interact with output created during the run job phase? I.e. what if the job calls clear_output?
(this is where I was going with the 'wrap in html' approach, perhaps creating my static html wrapper and inside it the 'job output' div where the job can do whatever it likes including clear_output while the static section remains unchanged)
Min RK
@minrk
Jan 08 2016 12:22
widgets (for better or worse) are not output, so they don't get cleared by clear_output.
bicubic
@bicubic
Jan 08 2016 12:24
okay, thanks a lot. Time to go try this!
bicubic
@bicubic
Jan 08 2016 12:31
wait. display(HTML()) creates a widget?
Min RK
@minrk
Jan 08 2016 12:31
ipywidgets.HTML, not display.HTML
(different thing entirely)
bicubic
@bicubic
Jan 08 2016 12:32
I see, now it makes sense
thanks again :fire:
bicubic
@bicubic
Jan 08 2016 12:39
one more thing, is there documentation or a sequence diagram or something that traces the pipeline between pressing enter to run a cell, and cell output being shown?
Min RK
@minrk
Jan 08 2016 13:02
That's a good idea. No, I don't think so.
All the information is probably out there in the message spec doc, kernel docs, etc., but not a single doc organized that way.
bicubic
@bicubic
Jan 08 2016 13:08
I'll see if I can put one together after I get a decent grasp of it then
Min RK
@minrk
Jan 08 2016 13:09
sounds great, thanks.
Matthew Rattray
@Discmt
Jan 08 2016 15:10
@bicubic I don't see how this can be used to make a dataframe avaliable in javascript. Do you have any examples?
stonebig
@stonebig
Jan 08 2016 17:49

hi, I try to launch a non-blocking_for_ipython process from Ipython notebook and I fail miserably (on Windows). As anyone a tip ?
current try is !start cmd /C python -c "import pyqtgraph.examples; pyqtgraph.examples.run()"

stackoverflow is silent on this: http://stackoverflow.com/questions/34558338/launching-a-dos-command-in-ipython-4-without-blocking-ipython-user-interface

would be nice to have a trick, because of this "run all" feature
msftristew
@msftristew
Jan 08 2016 20:07

Hey, I'm trying to make an IPython wrapper kernel that uses Scala syntax highlighting. This should work with codemirror if I include the clike.js file and set the mimetype to text/x-scala. However, when I make the following additions to the language_info in my kernel class definition:

'mimetype': 'text/x-scala', 'codemirror_mode': {'name':'clike'}

... it doesn't entirely work. I don't get quality Scala syntax highlighting, I just get some simple highlighting on = and integer literals. Anyone have any ideas on what I need to include to take advantage of this codemirror functionality in a wrapper kernel?

Jason Grout
@jasongrout
Jan 08 2016 20:35
Try having 'mimetype': 'text/x-scala', 'codemirror_mode': {'name':'Scala'}
it's a bit confusing
the mode name is 'scala', but it's included in the clike file
Jason Grout
@jasongrout
Jan 08 2016 20:55
so the mode name is scala, but the mode's mode is clike
Sylvain Corlay
@SylvainCorlay
Jan 08 2016 20:56
Rk: the specified mode is only used if the mime type is unknown to codemirror.
Jason Grout
@jasongrout
Jan 08 2016 20:57
yeah, so you can probably also just delete the 'codemirror_mode' key
I don't think that's quite true.
the 'codemirror_mode' overrides the mimetype
but it's redundant in this case because codemirror recognizes that mimetype
msftristew
@msftristew
Jan 08 2016 22:06
Thanks for the help @jasongrout and @SylvainCorlay. I removed the codemirror_mode field and just having name and mimetype set correctly triggered the correct behavior.