These are chat archives for ipython/ipython

9th
Oct 2015
john
@jcoady
Oct 09 2015 00:01
I got this kernel.json file to work
{
"language": "python",
"argv": [
"python",
"-m",
"ipykernel",
"--ipython-dir=C:/Users/Guest/AppData/Roaming/jupyter",
"--profile=dummy",
"-f",
"{connection_file}"
],
"display_name": "Dummy1"
}
The question I have is can I pass an environment variable for the path to APPDATA in the argv parameter "--ipython-dir=C:/Users/Guest/AppData/Roaming/jupyter"
which is a command line argument. Is it possible to pass an environment variable as a command line argument?
Min RK
@minrk
Oct 09 2015 08:43
@jcoady you may want to do it in two steps: 1. write the default kernelspec, 2. modify it. You can do this by writing the default IPython kernelspec to a temp directory, modifying it, and then calling the Juptyer install API with the path to your temp dir.
@SylvainCorlay A roadmap-for-release Issue on the traitlets repo would probably be a useful thing, if you want to start that. I don't feel like I'm in a position to know how close you guys are with all the changes you are planning to make at this point.
One thing that would be really great would be to get it to a point where neither widgets nor bqplot need to modify any private APIs.
Doug Blank
@dsblank
Oct 09 2015 17:00
I could use some help with this question, if anyone has a few minutes: http://stackoverflow.com/questions/33028218/set-an-ipython-widget-value-from-javascript
Jason Grout
@jasongrout
Oct 09 2015 17:09
the model id is what you'd need
Sylvain Corlay
@SylvainCorlay
Oct 09 2015 17:09
@dsblank done,
Jason Grout
@jasongrout
Oct 09 2015 17:09
ah, you must be "Quant"
Sylvain Corlay
@SylvainCorlay
Oct 09 2015 17:10
I know, it is very original
Doug Blank
@dsblank
Oct 09 2015 17:10
Thanks @SylvainCorlay , but I need help on the Javascript side, and I only need one trait. How, in JS, do I set the trait's value?
Jason Grout
@jasongrout
Oct 09 2015 17:11
if you have a handle on the model
model.set(<traitname>, <value>)
model.set('value', 45), for example
Doug Blank
@dsblank
Oct 09 2015 17:11
@jasongrout How to get the model?
Jason Grout
@jasongrout
Oct 09 2015 17:11
query the widget manager
do you know the comm id?
(which, IIRC, is the same as the model id)
Doug Blank
@dsblank
Oct 09 2015 17:12
I can get the comm_id in Python, and generate some JS to send it, if that is the best way.
Jason Grout
@jasongrout
Oct 09 2015 17:12
by the way, this is all fragile and likely to break since it relies on internal details
perhaps better is to write a mouse position "widget"
Doug Blank
@dsblank
Oct 09 2015 17:12
I know, but I need something to work now :)
Even if I write a widget, I don't know how to take code from Javascript and plug into the API
Jason Grout
@jasongrout
Oct 09 2015 17:14
a mouse position widget is much cleaner than what I was going to suggest above, and simpler to reason about
Doug Blank
@dsblank
Oct 09 2015 17:15
Sure, but my mouse data is coming from a click on an SVG... I still will need, in JS, to set the value, right?
Jason Grout
@jasongrout
Oct 09 2015 17:15
Why are you wanting to set the value? To display it?
or to get the value back to python?
Doug Blank
@dsblank
Oct 09 2015 17:16
Get the value back to Python.
Jason Grout
@jasongrout
Oct 09 2015 17:16
how do you generate your svg?
Doug Blank
@dsblank
Oct 09 2015 17:16
calysto.graphics library (that I am writing)
Jason Grout
@jasongrout
Oct 09 2015 17:17
is the svg in the output area of a cell?
Doug Blank
@dsblank
Oct 09 2015 17:17
Yes, in a widget in fact
Jason Grout
@jasongrout
Oct 09 2015 17:17
oh, even better
is the svg already a widget?
Doug Blank
@dsblank
Oct 09 2015 17:17
No, just an HTML widget value
Jason Grout
@jasongrout
Oct 09 2015 17:17
is it being rendered by a widget?
oh
hmmm...
Doug Blank
@dsblank
Oct 09 2015 17:18
I hear you thinking about an SVG widget that would do this automatically?
Jason Grout
@jasongrout
Oct 09 2015 17:18
well, just thinking about how to approach it
one sort of still hacky way to do it is to make a mouse click widget that attaches a click handler to any specific selector
Doug Blank
@dsblank
Oct 09 2015 17:19
I have everything working (of sorts) except the JS setting the trait value
Jason Grout
@jasongrout
Oct 09 2015 17:19
and then just relays the click coordinates back
Doug Blank
@dsblank
Oct 09 2015 17:19
Yep
Jason Grout
@jasongrout
Oct 09 2015 17:20
so a new widget that, when it is rendered, binds a click handler to the specified selector.
then passes the click coordinates back to python whenever the handler is called
Doug Blank
@dsblank
Oct 09 2015 17:20
That would be ideal... put still need the magic to get the model
Sylvain Corlay
@SylvainCorlay
Oct 09 2015 17:21
@dsblank do you have a link to the project?
Doug Blank
@dsblank
Oct 09 2015 17:22
So, no not committed yet... I'm building a GraphWin object that replicates a Python window for John Zelle's "Python Programming" book
But it is pretty simple... just a set of widgets, with a onclick handler for the SVG
Sylvain Corlay
@SylvainCorlay
Oct 09 2015 17:23
ok
cool!
Doug Blank
@dsblank
Oct 09 2015 17:25
If I know the model id, how do I get the JS trait side?
This is sort what I want:
var manager = IPython.WidgetManager._managers[0];
var model = manager.get_model("6aa5635dccac45369608a07d87332ac3");
Sylvain Corlay
@SylvainCorlay
Oct 09 2015 17:28
I think that manager._models is what you want
yes, manager.get_model
var manager = IPython.WidgetManager._managers[0];
var model_prom = manager.get_model("6aa5635dccac45369608a07d87332ac3");
model_prom.then(function(model) {
    model.set('value', 3);
});
Doug Blank
@dsblank
Oct 09 2015 17:32
Ah, that is the magic that I needed, and would never have been able to figure out! Thank you!
I will share this little hack for others; thanks again,... it does indeed work :)
Sylvain Corlay
@SylvainCorlay
Oct 09 2015 17:36
cool
Jason Grout
@jasongrout
Oct 09 2015 17:43
you'll also need to save the changes back to the server
model.save_changes(), I think
be aware that any errors won't be printed then too.
@jdfreder, I have to run and probably won't be on the rest of the day
Sylvain Corlay
@SylvainCorlay
Oct 09 2015 17:45
This message was deleted
Jonathan Frederic
@jdfreder
Oct 09 2015 18:00
ok, ttyl
Sylvain Corlay
@SylvainCorlay
Oct 09 2015 18:53
@dsblank since you work on the octave kernel. Does octave have anything comparable to traitlets which could be used to expose ipywidgets?
Doug Blank
@dsblank
Oct 09 2015 18:55
Perhaps... Octave kernel is built on Metakernel, and that supports many IPython things. The question would be: how do you get octave-level data back and forth?
You can definitely use traitlets in Octave's %%python magic... just tested that.
Steven Silvester
@blink1073
Oct 09 2015 18:59
you could theoretically use JSON to marshal data around for any language that supports it, but Octave (and Matlab) do not provide it out of the box
python-matlab-bridge provides its own JSON library (.m)
Doug Blank
@dsblank
Oct 09 2015 19:00
Hey, @blnk
Hey, @blink1073
You can write out widget output, and read it in in Octave; and vice versa for the python side
Steven Silvester
@blink1073
Oct 09 2015 19:22
write it out how?
Doug Blank
@dsblank
Oct 09 2015 19:25
To a file, in Octave-ese... yes, this would be specific from a traitlet to Octave
@SylvainCorlay Another question: can an executing cell be informed of a traitlet value that changed? The front end widgets update, but running code isn't seeing the new values
Steven Silvester
@blink1073
Oct 09 2015 19:28
you need to add a change handler
Doug Blank
@dsblank
Oct 09 2015 19:29
I have:
i.on_trait_change(lambda *args: print(i.value), "value") but doesn't change when cell is executing
Steven Silvester
@blink1073
Oct 09 2015 19:32
when you set the variable in JS, you also have to call this.touch();, seehttps://github.com/ipython/ipywidgets/blob/master/examples/Custom%20Widget%20-%20Hello%20World.ipynb
Doug Blank
@dsblank
Oct 09 2015 19:35
This is a Python-only issue, but looks like while the cell is executing, it can't update the kernel of the change. Here is code:
from ipywidgets import widgets
i = widgets.IntText()
display(i)
display(i)
i.value = 78
i.on_trait_change(lambda *args: print(i.value), "value")
while i.value == 78:
    time.sleep(1)
    print("In loop:", i.value)
Steven Silvester
@blink1073
Oct 09 2015 19:44
if you take out the sleep-loop, does the handler fire?
Doug Blank
@dsblank
Oct 09 2015 19:56
No. This must be a known limitation.... maybe I can write specific code to allow messages coming to kernel to be processed?
Steven Silvester
@blink1073
Oct 09 2015 20:00
it works without the busy-loop if you take out the second call to display(), FWIW
Doug Blank
@dsblank
Oct 09 2015 20:02
You removed the whole while part?
Steven Silvester
@blink1073
Oct 09 2015 20:02
yes
Doug Blank
@dsblank
Oct 09 2015 20:03
Well, then the cell isn't executing. So, yes that will work :)
Steven Silvester
@blink1073
Oct 09 2015 20:03
ha, yeah
Doug Blank
@dsblank
Oct 09 2015 20:05
Anyone know if there is a way to pump the comm messages during a loop?
Sylvain Corlay
@SylvainCorlay
Oct 09 2015 20:16
@dsblank no, you cannot do that
a non-idle kernel blocks the processing of the comm messages
what are you trying to do exactly?
Doug Blank
@dsblank
Oct 09 2015 20:17
Ok, is there a work around... manually process the comm messages? Otherwise my mouse handling widget can't work.
getMouse() waits for user to click on SVG
Sylvain Corlay
@SylvainCorlay
Oct 09 2015 20:18
Why do you need a running loop in the backend?
The javascript has its own evenloop
Doug Blank
@dsblank
Oct 09 2015 20:19
I'm replicating someone else's API... getMouse() should wait for click
Sylvain Corlay
@SylvainCorlay
Oct 09 2015 20:19
on the Python side?
Doug Blank
@dsblank
Oct 09 2015 20:19
Yes
Sylvain Corlay
@SylvainCorlay
Oct 09 2015 20:20
well, I don't think it is the right way to do it here. Since you already have the js event loop running, you should not need to do something like this in the backend.
Doug Blank
@dsblank
Oct 09 2015 20:20
How could I do this?
Sylvain Corlay
@SylvainCorlay
Oct 09 2015 20:23
in your example, you should not need the while loop.
Doug Blank
@dsblank
Oct 09 2015 20:24
I can't return until the user has clicked
Maybe I won't be able to replicate this API...
Sylvain Corlay
@SylvainCorlay
Oct 09 2015 20:31
well, if you want a blocking API, you can probably create such a loop...
Hey, does anyone know how to create custom section titles in sphinx documentation?
I am working on API docs for bqplot, and we have a pattern in mark attributes, (attributes vs data attributes) hence I need to create these sections types.