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
Conversation
@contextlib.contextmanager | ||
def _busy_updating(self): | ||
self.updating = True | ||
yield |
There was a problem hiding this comment.
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.
@minrk thanks, changes made |
""" | ||
updating = False | ||
def __init__(self, *args): | ||
|
There was a problem hiding this comment.
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.
Thanks for opening this! |
Issue #4659 should probably be aware of this PR. |
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. |
Thank you for writing the code :) |
Can you write some simple tests for this in |
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). |
My vote would be for |
But wouldn't just calling it On Mon, Feb 3, 2014 at 9:13 AM, Jonathan Frederic
Brian E. Granger |
return | ||
with self._busy_updating(): | ||
for obj,attr in self.objects: | ||
setattr(obj, attr, new) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
obj1, objN undefined was causing the test to fail.
@takluyver I added the code to prevent double fires and a test to make sure it works as expected. |
Add a convenience class to sync traitlet attributes
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'. |
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'. |
equate is possible, but I don't especially prefer it over bind. I don't think distribute conveys what this is doing well. |
A few more from http://thesaurus.com/browse/attach: 'link', 'fasten', 'join', 'attach', 'couple', or further searching: 'lock', 'fuse', 'identify', |
link makes sense to me, but I don't have strong feelings. |
I have strong enough feelings about it to submit a PR to change things to 'link', if it would be accepted. |
In general I am in agreement with picking names that don't have negative On Mon, Feb 3, 2014 at 7:27 PM, Jason Grout notifications@github.comwrote:
Brian E. Granger |
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... |
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:
Brian E. Granger |
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. |
I still like link. Maybe it's because of their meanings when talking about sockets, but bind/connect indicate asymmetry to me. |
@takluyver: I was brainstorming through a thesaurus---not all suggestions are equally appropriate! +1 to minrk's thinking about being symmetrical. |
I do agree that bind is a bit one way. Probably preferring connect or link. On Tue, Feb 4, 2014 at 11:19 AM, Jason Grout notifications@github.comwrote:
Brian E. Granger |
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:
Brian E. Granger |
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. |
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? |
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. |
+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: That makes me really like 'link' for this. If @jasongrout is willing to do the PR work, that would be great. |
Done. See #5060. |
Add a convenience class to sync traitlet attributes
I'm opening this PR for @jasongrout
Basically this adds an easy way to synchronize two traitlets.