These are chat archives for ipython/ipython

12th
Feb 2015
Scott Sanderson
@ssanderson
Feb 12 2015 00:09
I believe this is the authoritative source on typing distinctions: https://www.destroyallsoftware.com/talks/useing-youre-types-good
:trollface:
Jason Grout
@jasongrout
Feb 12 2015 00:14
@ssanderson - that's great
or... that grates. I'm not sure which :)
everyone knows it but still
Jonathan Frederic
@jdfreder
Feb 12 2015 00:27
@/all it's not the prettiest thing in the world, but here's a multi-cell selection enabled cross-notebook clipboard plugin. I wanted it to help me get ready for a talk so I whipped it up real quick - https://github.com/jdfreder/ipython-crossnotebook .
ctrl-c and ctrl-v (or cmd-c and v for mac users) to copy cells
It works the same way Codemirror and Poster do to interface with the clipboard...
Since the browser doesn't expose a nice clipboard API.
Matthias Bussonnier
@Carreau
Feb 12 2015 00:31
Great !
Jonathan Frederic
@jdfreder
Feb 12 2015 00:31
:P
Matthias Bussonnier
@Carreau
Feb 12 2015 00:31
you should have a look in IPython-contrib, I think jurgen also have a way to (in chrome only) export json top clipboard
and get the json back
Have you investigated localstorage to store things ?
Jonathan Frederic
@jdfreder
Feb 12 2015 00:32
This should be xbrowser
Matthias Bussonnier
@Carreau
Feb 12 2015 00:32
ah, xbrowser is another storry.
Jonathan Frederic
@jdfreder
Feb 12 2015 00:32
No, I wanted to use the clipboard so you could copy and paste to a friend etc...
Watch! :)
[{"metadata":{"collapsed":false,"trusted":false},"cell_type":"code","source":"from IPython.html.widgets import *\nfrom IPython.display import display","execution_count":11,"outputs":[]},{"metadata":{"collapsed":true,"trusted":false},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"collapsed":false,"trusted":false},"cell_type":"code","source":"PaddedTypes = [\n (IntSlider, {'description': 'a'}), \n (IntText, {'description': 'a'}), \n (Text, {'description': 'a'}), \n (Textarea, {'description': 'a'}), \n (Checkbox, {'description': 'a'}), \n (RadioButtons, {'description': 'a', 'values': [1,2,3]}), \n (Select, {'description': 'a', 'values': [1,2,3]}), \n (Dropdown, {'description': 'a', 'values': [1,2,3]}), \n (ToggleButtons, {'description': 'a', 'values': [1,2,3]}), \n (ToggleButton, {'description': 'a'}), \n (Button, {'description': 'a'}),\n]","execution_count":12,"outputs":[]}]
If you have the plugin installed, you could select that and paste it into your notebook.
Better than nothing, right?
Matthias Bussonnier
@Carreau
Feb 12 2015 00:35
I guess :-)
base64 encoded + checksum would be nice too.
and more "escape friendly"
Jonathan Frederic
@jdfreder
Feb 12 2015 00:38
Yeah, or you could use nbconvert to serialize to something human legible.
But I was lazy so I just did cell.toJSON and fromJSON
Matthias Bussonnier
@Carreau
Feb 12 2015 00:40
:-P
I played with yaml-js the other day :-)
Jonathan Frederic
@jdfreder
Feb 12 2015 00:42
cool
I haven't played with that
is the API nice?
Sylvain Corlay
@SylvainCorlay
Feb 12 2015 00:44
yeah, lets drop json and have the entire message spec in yaml
:skull:
mouhaha
@jdfreder for the box-typing, on the js side, rather than having a lookup table type -> traitype module saying where to find the serialiser, we could do something evil. When loading the trait type module, it adds a key to the corresponding object prototype with itself :D
-> no need for a registry
Jonathan Frederic
@jdfreder
Feb 12 2015 00:54
That's a neat idea, although possibly dangerous ,
Sylvain Corlay
@SylvainCorlay
Feb 12 2015 00:55
The key name could be ☠
:)
Petra Chong
@rekcahpassyla
Feb 12 2015 08:57
@jdfreder @takluyver - belated thank yous, I will try those today.
Cedric GESTES
@cgestes
Feb 12 2015 11:03
Guys I'am struggling with what to do, I'am writting an extension where you can dock a cell (and it's output) anywhere on the page.
I would like to be able to save the cell. I can implement a whole system outside the notebook, storing everything in metadata for example. But I think it would be better to store the cells in the notebook directly. would it makes sense to extend the notebook for that kind of usecase. basically it mean having a list of list of cells, instead of just a list of cells. (with some cells that can be hidden).
One other way would be to instanciate a notebook for each dock window, maybe it's better, but in that case I'am not sure about what could happen with save.
this idea is to be able to create GUIs from notebook (a notebook=a GUI).
Sylvain Corlay
@SylvainCorlay
Feb 12 2015 14:12
@ctaf42 it feels like your system moves pretty far away from the linear layout of the notebook, which is a document more than a gui.
Rather than moving cells, you can make a widgets that behaves like a codecell and use the widget persistence API to keep it around.
Cedric GESTES
@cgestes
Feb 12 2015 14:16
@SylvainCorlay yes, it's not possible to do without changing some internals in IPython itself. So for now I'am trying to write my application in html, but connected to an IPython kernel. (ie not using the notebook at all). This will be useful to display widget out of the notebook. (for multiscreen users).
I'll look at the widget persistence API thank you.
Thomas Wiecki
@twiecki
Feb 12 2015 15:00
for some reason shift-tab stopped working for me correctly in the NB. e.g. if I do np.diag(X, <shift-tab>) I get the help for X (which is an ndarray), not for np.diag()
is that intentional?
it's always the last argument, rather than the function
Cedric GESTES
@cgestes
Feb 12 2015 15:26
@jdfreder it seems that I need your iframe patches. I created a webpage containing only one cell. This page create a session, associate it to a running kernel. I can execute code, but when I try to display a widgets created in the real notebook. (the one associated to the kernel I connect to), I get strange message with Promise and Comm.
What was needed to make your patch work? Is that what I need? (I'am still new with the comm inner working)
Cedric GESTES
@cgestes
Feb 12 2015 15:39
it's working with two separate widget and a link between them, but I still get some strange comm message.
Jon Wilson
@jsw-fnal
Feb 12 2015 16:04
Dumb question: there is a little red "@" next to this room in the sidebar. What does this mean?
clicking on it doesn't appear to do anything
Jessica B. Hamrick
@jhamrick
Feb 12 2015 16:06
It means you’ve been @ mentioned, though it also applies when everyone is mentioned at once with ‘all'
It will go away once you’ve read the message that mentions you (or all)
Jon Wilson
@jsw-fnal
Feb 12 2015 17:00
ah, thanks. I thought it would be when I was @ mentioned, but I read through the messages and couldn't find anything. But "all" explains it. Hmm, can I mention myself, @jsw-fnal ?
Cedric GESTES
@cgestes
Feb 12 2015 17:01
pushed an experimental example of the popup window in github.com/ctaf42/ipython-popup
does it make sense to try to integrate popup support in IPython ?
Cedric GESTES
@cgestes
Feb 12 2015 17:11
btw this is an example of a IPython application which is not a notebook. Dont know if that kind of application is wanted. (a webapp connected to a python kernel without notebook), but if that's the case, the code may need some refactoring. (notebook is needed in some places for no reason, the logic to execute code is in notebook/codecell and could benefit from being separated).
Jason Grout
@jasongrout
Feb 12 2015 17:36
@ctaf42 - the sage cell server is another example of a web app that connects to a IPython kernel that is not a notebook: https://sagecell.sagemath.org
Jonathan Frederic
@jdfreder
Feb 12 2015 17:37
@ctaf42 the changes are non-trivial.
Well, some may argue they are trivial, but they are extensive.
Jonathan Frederic
@jdfreder
Feb 12 2015 17:53
@/all supplementary meeting today?
Matthias Bussonnier
@Carreau
Feb 12 2015 17:54
Don't know. Haven't seen things on hackpad.
is there any outstanding points ?
or PR ?
Min RK
@minrk
Feb 12 2015 17:58
Don't think we need one today.
Jonathan Frederic
@jdfreder
Feb 12 2015 20:48
@SylvainCorlay how did you write your dynamic trait function? I was able to do it easily with metaclasses, but I was wondering if you had a better way to do it:
def add_trait(instance, name, trait):
    instance.__class__ = type(instance.__class__.__name__, (instance.__class__,), {name: trait})
    trait.set_default_value(instance)
The student working with @ellisonbg wants to try to do it without metaclasses.
from IPython.utils.traitlets import Int, HasTraits
class A(HasTraits):
    pass
a = A()
b = A()

add_trait(a, 'x', Int(2))
a.x
Out: 2
Sylvain Corlay
@SylvainCorlay
Feb 12 2015 20:51
I' ll have to unearth it.
Jonathan Frederic
@jdfreder
Feb 12 2015 20:51
b.x
error - which is what I want.
So this implementation works
but like I said, just looking for alternatives.
Thanks!
Sylvain Corlay
@SylvainCorlay
Feb 12 2015 20:55
it was last year and was pretty new to traitlets and metaclasses. I first tried with metaclasses and messed up with default values.
Then did something really ugly and verbose that was HasTrait class that holds a single trait type, defined on the fly for each trait type. The fake DynamicHasTrait had a list of those.
...
question in the usecase of widgets, would the addition of a synced trait send a message to the frontend?
Jonathan Frederic
@jdfreder
Feb 12 2015 21:06
No, we'd have to refill the keys list.
Right now it's only filled on construction.
But that shouldn't be hard to do at all.
And then yes, it would work with sync.
Or
Sylvain Corlay
@SylvainCorlay
Feb 12 2015 21:07
then add_trait would need to be a method of HasTrait or Widget
Jonathan Frederic
@jdfreder
Feb 12 2015 21:07
The caller could just add it to .keys itself.
Yes
Sylvain Corlay
@SylvainCorlay
Feb 12 2015 21:08
ok
Jonathan Frederic
@jdfreder
Feb 12 2015 21:08
Well it doesn't have to be
but it would be convenient
because then we could just override it to add the trait name to the keys list
in addition to creating the trait
@SylvainCorlay so using the method above, as-is, no changes, you could use it with a widget like this:
w = Widget()
add_trait(w, 'x', Int())
w.keys.append('x')
w.send_state('x')
Sylvain Corlay
@SylvainCorlay
Feb 12 2015 21:15
Yes, this is really cool
Jonathan Frederic
@jdfreder
Feb 12 2015 21:18
Sorry there's a typo
add_trait(a, 'x', Int())
should be
add_trait(w, 'x', Int())
just fixed it in the block I pasted
thanks
yeah
It should make widget creation from Javascript more like Python. :)
We can define traits from Javascript!
Sylvain Corlay
@SylvainCorlay
Feb 12 2015 21:26
Yeah, somehow, this reminds me of a conversation I had with @jasongrout on having "trait types" on js
Jason Grout
@jasongrout
Feb 12 2015 21:26
we just need a ...
yeah, what @sylvaincorlay said
Sylvain Corlay
@SylvainCorlay
Feb 12 2015 21:26
(regarding serialization)
I got defenestrated and refenestrated multiple times
Jonathan Frederic
@jdfreder
Feb 12 2015 21:35
lol
Sylvain Corlay
@SylvainCorlay
Feb 12 2015 22:00
@jdfreder I really think the box typing remains the most elegant way of doing it.
and as we discussed with Jason this morning, actually, it can handle List(Date) with no overhead
But a List() that happens to only have date (with no trait specified) would have the overhead
Jonathan Frederic
@jdfreder
Feb 12 2015 22:17
@syv
@SylvainCorlay it seems like box typing is what @jasongrout is doing in his PR.
Oh wait
no
I see
he's passing it in the metadata
so he's flattening the hierarchy
hmph
Jonathan Frederic
@jdfreder
Feb 12 2015 22:33
@SylvainCorlay I think I'm still for the box typing. It seems like @jasongrout 's implementation has the same overhead anyways. It wouldn't be too hard to take his PR (which most of the hard work is done for us already) and implement box typing.
Although, I'm still foreseeing trouble with both designs. I think this will be a hard decision to make.
Jonathan Frederic
@jdfreder
Feb 12 2015 22:49
Cool, didn't know there was something in Python like Javascript's .apply until now.
Jason Grout
@jasongrout
Feb 12 2015 23:34
what analogue are you thinking of?
@jdfreder - I'm basically doing two things:
  1. making it possible to specify javascript to_json and from_json functions in the metadata of a traitlet
  2. enabling binary transmission
Jonathan Frederic
@jdfreder
Feb 12 2015 23:36
._im_func
Jason Grout
@jasongrout
Feb 12 2015 23:36
of course, once you have control over the python and the javascript serialization and deserialization, you can implement whatever protocol you want, recurse however you want, etc.
I guess I've used __func__ when poking around a bit. "Changed in version 2.6: For Python 3 forward-compatibility, imfunc is also available as func, and imself as __self."
Jonathan Frederic
@jdfreder
Feb 12 2015 23:38
ahhh
yeah I'm on 2.7 still
I really should make the jump.
Jason Grout
@jasongrout
Feb 12 2015 23:39
uh, it works in 2.6+
Jonathan Frederic
@jdfreder
Feb 12 2015 23:39
Yeah, but so does _im_show and by 50% chance that's what I'm using :P
I made the wrong choice
but if I was using 3, the choice would be made for me