#!/usr/bin/env python
# [SNIPPET_NAME: gtk3 calendar widget with menu]
# [SNIPPET_CATEGORIES: gtk3]
# [SNIPPET_TAGS: widgets, gtk3]
# [SNIPPET_DESCRIPTION: GTK3 calendar example and drop down menu example]
# [SNIPPET_AUTHOR: Oliver Marks ]
# [SNIPPET_LICENSE: GPL]
from gi.repository import Gtk, GLib, GObject


class application_gui:
    """Tutorial 08 menu, calendar widget."""
    count = 0

    def __init__(self):
        #load in our glade interface
        xml = Gtk.Builder()
        xml.add_from_file('tut08.glade')

        #grab our widget using get_object this is the name of the widget from glade, window1 is the default name
        self.window = xml.get_object('window1')
        self.text = xml.get_object('entry1')

        #load our widgets from the glade file
        self.widgets = {}
        self.widgets['calendar'] = xml.get_object('calendar1')
        self.widgets['menushow'] = xml.get_object('menuitem6')
        self.widgets['menuhide'] = xml.get_object('menuitem7')
        self.widgets['menuhello'] = xml.get_object('menuitem8')

        #connect to events, in this instance just quit our application
        self.window.connect('delete_event', Gtk.main_quit)
        self.window.connect('destroy', lambda quit: Gtk.main_quit())
        self.widgets['menushow'].connect('activate', self.showcalendar)
        self.widgets['menuhide'].connect('activate', self.hidecalendar)
        self.widgets['menuhello'].connect('activate', self.hello)
        self.widgets['calendar'].connect('day-selected', self.date_selected)

        #show the window else there is nothing to see :)
        self.window.show()

    def hidecalendar(self, *args):
        self.widgets['calendar'].hide()

    def showcalendar(self, *args):
        self.widgets['calendar'].show()

    def hello(self, *args):
        self.text.set_text('hello world')

    def date_selected(self, *args):
        date = self.widgets['calendar'].get_date()
        self.text.set_text(str(date[2]) + '-'+str(date[1]) + '-' + str(date[0]))

application = application_gui()
Gtk.main()
