#
#   Python GUI - Dialogs - Generic
#

from Properties import overridable_property
from Windows import Window

class Dialog(Window):

    default_button = overridable_property('default_button',
        "Button to be activated by the default key.")
    
    cancel_button = overridable_property('cancel_button',
        "Button to be activated by the cancel key.")
    
    _default_button = None
    _cancel_button = None

    def __init__(self, title = "", style = 'nonmodal_dialog', 
            closable = 0, zoomable = 0, resizable = 0, **kwds):
        Window.__init__(self, title = title, style = style, 
            closable = closable, zoomable = zoomable, resizable = resizable,
            **kwds)
    
    def get_default_button(self):
        return self._default_button
    
    def set_default_button(self, button):
        self._default_button = button
        if button:
            button.style = 'default'
    
    def get_cancel_button(self):
        return self._cancel_button
    
    def set_cancel_button(self, button):
        self._cancel_button = button
        if button:
            button.style = 'cancel'

    def key_down(self, event):
        print "GDialog.key_down:", repr(event.char) ###
        c = event.char
        if c in self._default_keys:
            button = self.default_button
        elif c in self._cancel_keys:
            button = self.cancel_button
        else:
            button = None
        if button:
            button.activate()
        else:
            self.pass_to_next_handler('key_down', event)
