#------------------------------------------------------------------------------
# Copyright (c) 2015, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
""" An which demonstrates a declarive function override.

This example demonstrates how to use the `=>` operator to override a
declarative function defined with the @d_func decorator.

<< autodoc-me >>
"""
from __future__ import print_function
from enaml.core.declarative import d_func
from enaml.widgets.api import Window, PushButton, Container


class MySpecialPushButton(PushButton):
    """ A push button which has something to say.

    """
    @d_func
    def say_something(self, name):
        msg = 'Hi, {}'
        print(msg.format(name))


enamldef Main(Window):
    attr name1 = 'John'
    attr name2 = 'Jane'
    Container:
        MySpecialPushButton:
            text = 'Say Hi'
            clicked :: self.say_something(name1)
        MySpecialPushButton:
            text = 'Say Hello'
            clicked :: self.say_something(name2)
            say_something => (name):
                print('Hello, '+ name)
