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

Fix KeyError when calling pyblish_qml.show() more than once #365

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions pyblish_qml/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def install(modal):

use_threaded_wrapper = not modal

install_callbacks()
install_host(use_threaded_wrapper)

_state["installed"] = True
Expand Down Expand Up @@ -103,8 +102,12 @@ def show(parent=None,
# getting all plugins on pyblish_qml.show().
targets = ["default"] + pyblish.api.registered_targets()

# Install event handlers.
install_callbacks()

# Automatically install if not already installed.
install(modal)
if not _state.get("installed"):
install(modal)

show_settings = settings.to_dict()
show_settings['autoPublish'] = auto_publish
Expand Down Expand Up @@ -186,13 +189,22 @@ def quit(proxy):


def install_callbacks():
uninstall_callbacks()

pyblish.api.register_callback("instanceToggled", _toggle_instance)
pyblish.api.register_callback("pluginToggled", _toggle_plugin)


def uninstall_callbacks():
pyblish.api.deregister_callback("instanceToggled", _toggle_instance)
pyblish.api.deregister_callback("pluginToggled", _toggle_plugin)
registered_callbacks = pyblish.api.registered_callbacks()
instance_toggled_callbacks = registered_callbacks.get("instanceToggled", [])
plugin_toggled_callbacks = registered_callbacks.get("pluginToggled", [])

if _toggle_instance in instance_toggled_callbacks:
pyblish.api.deregister_callback("instanceToggled", _toggle_instance)

if _toggle_plugin in plugin_toggled_callbacks:
pyblish.api.deregister_callback("pluginToggled", _toggle_plugin)


def _toggle_instance(instance, new_value, old_value):
Expand Down