Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a convenience class to sync traitlet attributes #4901

Merged
merged 8 commits into from Feb 3, 2014

Conversation

jdfreder
Copy link
Member

I'm opening this PR for @jasongrout

Basically this adds an easy way to synchronize two traitlets.

@contextlib.contextmanager
def _busy_updating(self):
self.updating = True
yield
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be

try:
    yield
finally:
    self.updating = False

to protect the state against exceptions.

@jdfreder
Copy link
Member Author

@minrk thanks, changes made

"""
updating = False
def __init__(self, *args):

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably should delete the extra line here.

@jasongrout
Copy link
Member

Thanks for opening this!

@jasongrout
Copy link
Member

Issue #4659 should probably be aware of this PR.

@minrk
Copy link
Member

minrk commented Jan 28, 2014

Yes, the external traitlets effort is going to start over with recent changes after we cut 2.0, and do some cleanup in IPython.config.

@jdfreder
Copy link
Member Author

Thanks for opening this!

Thank you for writing the code :)

@ellisonbg
Copy link
Member

Can you write some simple tests for this in test_traitlets?

@ellisonbg
Copy link
Member

My main question is to the naming of things. Previously, we had used the language "bind" for this type of thing. Do we like "connect" better than "bind"? And being a verb, I think that either of these should be lowercase (even though a class).

@jdfreder
Copy link
Member Author

jdfreder commented Feb 3, 2014

My vote would be for Bind because it's shorter; however, without the capital B I would forget that it was a class and I wouldn't think to construct it.

@ellisonbg
Copy link
Member

But wouldn't just calling it bind(...) construct it?

On Mon, Feb 3, 2014 at 9:13 AM, Jonathan Frederic
notifications@github.comwrote:

My vote would be for Bind because it's shorter; however, without the
capital b I would forget that it was a class and I would never construct
it.

Reply to this email directly or view it on GitHubhttps://github.com//pull/4901#issuecomment-33976627
.

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

return
with self._busy_updating():
for obj,attr in self.objects:
setattr(obj, attr, new)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will re-set the trait on the object that changed it, which means any other callbacks it has registered will fire twice. Do we want to exclude that case in order to avoid this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think you are right - we should figure out how to fix this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! I will use a closure to fix this...

@jdfreder
Copy link
Member Author

jdfreder commented Feb 3, 2014

@takluyver I added the code to prevent double fires and a test to make sure it works as expected.

ellisonbg added a commit that referenced this pull request Feb 3, 2014
Add a convenience class to sync traitlet attributes
@ellisonbg ellisonbg merged commit 7dbba6e into ipython:master Feb 3, 2014
@jasongrout
Copy link
Member

I prefer 'friendly' verbs like 'connect' and 'share' over verbs with slightly negative connotation like 'bind'. For the same reason, I prefer 'interact' over mathematica's name, 'manipulate'.

But I also realize that UI conventions use 'bind' a lot, so I'm -0 on 'bind' and +0 on 'connect' or 'share'.

@jasongrout
Copy link
Member

Looking at http://thesaurus.com/browse/connect, 'consociate' would be an interesting choice. More seriously, though, 'equate', or from http://thesaurus.com/browse/share, 'distribute'.

@takluyver
Copy link
Member

equate is possible, but I don't especially prefer it over bind. I don't think distribute conveys what this is doing well.

@jasongrout
Copy link
Member

A few more from http://thesaurus.com/browse/attach: 'link', 'fasten', 'join', 'attach', 'couple', or further searching: 'lock', 'fuse', 'identify',

@minrk
Copy link
Member

minrk commented Feb 4, 2014

link makes sense to me, but I don't have strong feelings.

@jasongrout
Copy link
Member

I have strong enough feelings about it to submit a PR to change things to 'link', if it would be accepted.

@ellisonbg
Copy link
Member

In general I am in agreement with picking names that don't have negative
connotations: interact is much better than manipulate. But in the case of
bind I think the negative connotations are not so strong that they outweigh
using a simple, clear term that is used everywhere in UI work to mean this
exactly.

On Mon, Feb 3, 2014 at 7:27 PM, Jason Grout notifications@github.comwrote:

I have strong enough feelings about it to submit a PR to change things to
'link', if it would be accepted.

Reply to this email directly or view it on GitHubhttps://github.com//pull/4901#issuecomment-34027543
.

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@jasongrout
Copy link
Member

Yep, so I'm still +0 on something like link and -0 on bind. I'm motivated enough to open a PR if it will be accepted, but not motivated enough to push hard for a change...

@ellisonbg
Copy link
Member

Let's get a read from @minrk @takluyver and @fperez tomorrow on this

On Mon, Feb 3, 2014 at 9:30 PM, Jason Grout notifications@github.comwrote:

Yep, so I'm still +0 on something like link and -0 on bind. I'm motivated
enough to open a PR if it will be accepted, but not motivated enough to
push hard for a change...

Reply to this email directly or view it on GitHubhttps://github.com//pull/4901#issuecomment-34032051
.

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@takluyver
Copy link
Member

No strong feelings between link and bind. Some of the others suggested (distribute, lock) seem clearly wrong, but I don't think those are in serious consideration.

@minrk
Copy link
Member

minrk commented Feb 4, 2014

I still like link. Maybe it's because of their meanings when talking about sockets, but bind/connect indicate asymmetry to me.

@jasongrout
Copy link
Member

@takluyver: I was brainstorming through a thesaurus---not all suggestions are equally appropriate!

+1 to minrk's thinking about being symmetrical.

@ellisonbg
Copy link
Member

I do agree that bind is a bit one way. Probably preferring connect or link.
Share has too many non-technical connotations.

On Tue, Feb 4, 2014 at 11:19 AM, Jason Grout notifications@github.comwrote:

@takluyver https://github.com/takluyver: I was brainstorming through a
thesaurus---not all suggestions are equally appropriate!

+1 to minrk's thinking---that's the other thing I liked about connect or
share: it was symmetrical.

Reply to this email directly or view it on GitHubhttps://github.com//pull/4901#issuecomment-34096040
.

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@ellisonbg
Copy link
Member

And probably prefer connect over link as it is only a verb.

On Tue, Feb 4, 2014 at 1:36 PM, Brian Granger ellisonbg@gmail.com wrote:

I do agree that bind is a bit one way. Probably preferring connect or
link. Share has too many non-technical connotations.

On Tue, Feb 4, 2014 at 11:19 AM, Jason Grout notifications@github.comwrote:

@takluyver https://github.com/takluyver: I was brainstorming through a
thesaurus---not all suggestions are equally appropriate!

+1 to minrk's thinking---that's the other thing I liked about connect or
share: it was symmetrical.

Reply to this email directly or view it on GitHubhttps://github.com//pull/4901#issuecomment-34096040
.

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@jasongrout
Copy link
Member

Though the connect/link function does return an object, which you can then use to break the connection/link later. So link(...) (verb) would return the link object (noun), by which you could later break the connection.

@minrk
Copy link
Member

minrk commented Feb 5, 2014

As @jasongrout points out, bonus points to link for being both a noun and a verb, since it is technically an object. So are we settled on link, then?

@ellisonbg
Copy link
Member

I am reasonably fine with that. I did ping @fperez in an email to see what he thinks. I like his eye for these things, but we can go ahead if there is consensus.

@fperez
Copy link
Member

fperez commented Feb 5, 2014

+1 for link: the symmetry argument is a good one, and from reading the code, I actually think it expresses the behavior best of all the proposed names. Bind is often used either in connect/bind asymmetric situations, or as in bindings (language wrappers). From reading what the code actually does, I find link to be a very natural description.

For example, many UIs for image processing that want to link two attributes to change in sync (such as resizing an image when you want to preserve its aspect ratio), use a little chain link icon to illustrate that:

image

That makes me really like 'link' for this. If @jasongrout is willing to do the PR work, that would be great.

@jasongrout
Copy link
Member

Done. See #5060.

@jdfreder jdfreder deleted the jason_traitlets branch March 10, 2014 18:42
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
Add a convenience class to sync traitlet attributes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants