# Copyright (c) 2001 LOGILAB S.A. (Paris, FRANCE).
# http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA  02111-1307
# USA.

"""
DialogWindow is a functional dialog window, similar to GnomeDialog
"""

__revision__ = "$Id: DialogWindow.py,v 1.7 2001/10/09 16:06:35 alf Exp $"

from gtk import *
from narval.gui import unicode_to_gtk
import sys 

if sys.platform == 'win32':
    def update_gui():
        for i in range(10):
            mainiteration()
else:
    def update_gui():
        while events_pending():
            mainiteration()


class DialogWindow(GtkWindow):
    """
    Parent class is GtkWindow,
    three defaults buttons are available (OK, Apply, Cancel)
    """

    def __init__(self,title):
        GtkWindow.__init__(self,WINDOW_DIALOG,title)
        self.set_position(WIN_POS_CENTER)

        # a vbox for window
        vbox = GtkVBox()
        self.add(vbox)

        # a frame
        frame = GtkFrame()
        vbox.pack_start(frame)
        vbox.show()

        # vbox
        self._vbox = GtkVBox()
        self._vbox.show()
        self._vbox.set_spacing(5)
        self._vbox.set_border_width(4)
        frame.add(self._vbox)
        frame.set_border_width(4)
        frame.show_all()

        # button box
        hbbox = GtkHButtonBox()
        hbbox.show()
        vbox.pack_end(hbbox,expand=FALSE)
        hbbox.set_layout_default(BUTTONBOX_SPREAD)
        hbbox.set_border_width(4)

        # some useful button
        self.ok_button = GtkButton(unicode_to_gtk(_("OK")))
        hbbox.pack_start(self.ok_button)
        self.apply_button = GtkButton(unicode_to_gtk(_("Apply")))
        hbbox.pack_start(self.apply_button)
        self.cancel_button = GtkButton(unicode_to_gtk(_("Cancel")))
        hbbox.pack_start(self.cancel_button)

    def append_dialog(self,dialog,expand=TRUE):
        self._vbox.pack_start(dialog,expand)
        dialog.show_all()

        
    
    
