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

Rename Callback to Handler #298

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

mottosso
Copy link
Member

@mottosso mottosso commented Oct 10, 2016

This PR implements on, and renames all references to callback to handler.

Full backwards compatibility is preserved


Example

Technically, on is simply an alias for register_handler, previously known ad register_callback.

from pyblish import api, util

def on_published(context):
  print("Published!")

api.on("published", on_published)

util.publish()
# Published!

Explicit Support for Graphical User Interfaces.

In addition, this PR implements "weak references" for all event handlers.

This shouldn't have much effect on your day to day use of Pyblish, but will make a difference in a few small corner cases.

For example, consider this.

count = {"#": 0}

class MyObject(object):
    def __init__(self):
        pyblish.api.on("mySignal", self.on_mysignal)

    def on_mysignal(self):
        count["#"] += 1

obj = MyObject()
pyblish.api.emit("mySignal")
assert_equals(count["#"], 1)

del(obj)
pyblish.api.emit("mySignal")
assert_equals(count["#"], 1)

As you would expect, once the object is deleted, the handler stops being called. Prior to this PR however, count["#"] equalled 2.

In practice, this could cause issues when you build a GUI around signals, and register methods within your GUI and then create a new instance of this GUI.

The second instance would reconnect to these signals, leaving the old methods in place, resulting in two calls per method. For each instance of your GUI, the calls would stack up, and off you go.

This PR enables you to build user interfaces that harness the signals produces throughout Pyblish, without worrying about these difficult-to-debug problems.

@mottosso
Copy link
Member Author

mottosso commented Oct 10, 2016

This fails on Python 3.3. :( Investigating..

@mottosso mottosso changed the title Implement #293 Rename Callback to Handler Jul 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant