#!/usr/bin/env python
"""

Viewer Sync
===========

Contains the functions required for two views to be kept in sync.

## Public Functions

    remove_callback()
        Removes callback from all selected viewers and all viewers linked.

    setup_sync()
        Sets up a viewerSync between a group of Viewer nodes.

    sync_viewers()
        Syncs all the given viewers to the settings on the caller node.

## License

The MIT License (MIT)

iconPanel
Copyright (c) 2011-2014 Philippe Huberdeau and Sean Wallitsch

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

"""

# =============================================================================
# IMPORTS
# =============================================================================

# Standard Imports
from ast import literal_eval

# Nuke Imports
try:
    import nuke
except ImportError:
    pass

# =============================================================================
# GLOBALS
# =============================================================================

# The specific text to display on the viewerSync knob for the listed
# viewer knob.
KNOB_TITLES = {
    'channels': 'channels',
    'cliptest': 'zebra-stripe',
    'downrez': 'proxy settings',
    'format_center': 'format center',
    'gain': 'gain',
    'gamma': 'gamma',
    'masking_mode': 'masking mode',
    'masking_ratio': 'masking ratio',
    'overscan': 'overscan',
    'ignore_pixel_aspect': 'ignore pixel aspect ratio',
    'input_number': 'viewed input',
    'input_process': 'input process on/off',
    'input_process_node': 'input process node',
    'inputs': 'input nodes',
    'rgb_only': 'LUT applies to rgb channels only',
    'roi': 'roi',
    'safe_zone': 'safe zone',
    'show_overscan': 'show overscan',
    'viewerInputOrder': 'input process order',
    'viewerProcess': 'LUT',
    'zoom_lock': 'zoom lock'
}

# These are tooltips for the viewerSync knobs, with the keys being the normal
# knob the viewerSync knob refers to.
KNOB_TOOLTIPS = {
    'channels': 'Sync the layers and alpha channel to display in the viewers. '
                'The "display style" is not synced.',
    'cliptest': 'Sync if zebra-striping is enabled or not between viewers.',
    'downrez': 'Sync the scale down factor for proxy mode. Proxy mode '
               'activation is always synced.',
    'format_center': 'Sync if a crosshair is displayed at the center of the '
                     'viewer window.',
    'gain': 'Sync the gain slider between viewers.',
    'gamma': 'Sync the gamma slider between viewers.',
    'masking_mode': 'Sync the mask style between viewers.',
    'masking_ratio': 'Sync the mask ratio selection between viewers.',
    'overscan': 'Sync the amount of overscan displayed between viewers.',
    'ignore_pixel_aspect': 'If selected all viewers will either show square '
                           'pixels or the pixel aspect ratio denoted by '
                           'the format.',
    'input_number': 'Syncs which input number is being viewed between all '
                    'viewers. This does not mean that all viewers are '
                    'viewing the same nodes, just that all viewers are '
                    'viewing input 1, etc.',