#! /usr/bin/python

#################################################
#  Gnome Calendar 0.1b
#
#  This software is open source and may
#  be used, modified, and redistributed 
#  free of charge...
#  for any non-commercial, non-profit
#  purposes provided these credits are
#  left intact, unedited.  This software 
#  comes with NO warrantee whatsoever, 
#  and the author, cylikon@hotmail.com, 
#  takes NO responsibility for any damages or
#  problems resulting from the use of this 
#  software. 
#
#  This is a Python script and requires you 
#  to have Python 2.2 or better installed.
#
#  Copyright April 2002 (cylikon@hotmail.com)
#  All rights reserved.
#################################################

import sys, os, types, string
from _gtk import *
import GDK, GTK
import time

if __name__ == "__main__" :
    __file__ = sys.argv[0]
HostingDir = os.path.dirname (__file__)

class Context :
    def __init__ (self, tooltips=None, accelgroup=None, imagedirs=None,
    window=None, context=None) :
        if isinstance (context, Context) :
            self._tooltips = context._tooltips
            self._accelgroup = context._accelgroup
            self._imagedirs = context._imagedirs
            self._top = context._top
        else :
            if tooltips is None :
                self._tooltips = gtk_tooltips_new ()
            if accelgroup is None :
                self._accelgroup = gtk_accel_group_new ()
            if imagedirs is None :
                base = HostingDir
                self._imagedirs = [base, os.path.join (base, "pixmaps")]
            if window is None :
                self._top = None
        if tooltips is not None :
            self._tooltips = tooltips
        if accelgroup is not None :
            self._accelgroup = accelgroup
        if type (imagedirs) is types.StringType :
            self._imagedirs = string.split (imagedirs, os.pathsep)
        elif imagedirs is not None :
            self._imagedirs = list (imagedirs)
        if window is not None :
            self._top = window
        self._root = None
    def setTip (self, w, msg) :
        gtk_tooltips_set_tip (self._tooltips, w, msg, None)
    def addAccel (self, w, sigName, keyVal, modVal, flagVal) :
        gtk_widget_add_accelerator (w, sigName, self._accelgroup,
            keyVal, modVal, flagVal)
    def setContainerLabelWithAccel (self, item, text,
    accel=None, mask=0, sig="activate_item") :
        label = gtk_container_children (item)[0]
        key = gtk_label_parse_uline (label, text)
        if accel is None :
            accel = self._accelgroup
            mask = GDK.MOD1_MASK
        gtk_widget_add_accelerator (item, sig, accel, key, mask, 0)
    def findPixmapPath (self, pixName) :
        for i in self._imagedirs :
            pixPath = os.path.join (i, pixName)
            if os.path.exists (pixPath) :
                return pixPath
        raise IOError (None, "pixmap '%s' not found" % pixName)
    def show (self) :
	if self._root is not None :
	    gtk_widget_show_all (self._root)
    def destroy (self) :
	if self._root is not None :
            gtk_widget_destroy (self._root)
    def giveNames (self, nameList) :
        for i in nameList :
            w = getattr (self, i)
            gtk_widget_set_name (w, i)
    controllerClass = None
    def setupController (self) :
        if self.controllerClass is not None :
            ctrl = self.controllerClass ()
            self._controller = ctrl
            self.connect (ctrl)

def gtk_adjustment_set_step_increment (adj, stepInc) :
    # TODO: remove when supported by pygtk
    value = gtk_adjustment_get_value (adj)
    upper = gtk_adjustment_get_upper (adj)
    lower = gtk_adjustment_get_lower (adj)
    pgInc = gtk_adjustment_get_page_increment (adj)
    pgSz = gtk_adjustment_get_page_size (adj)
    gtk_adjustment_set_all (adj, value, upper, lower, stepInc, pgInc, pgSz)

##BEGIN I18N SUPPORT
from locale import setlocale, LC_MESSAGES, LC_ALL
setlocale (LC_ALL, "")

class window1 (Context) :
    def __init__ (self, context=None) :
	Context.__init__ (self, context=context)
	window1 = gtk_window_new (GTK.WINDOW_TOPLEVEL)
	self._root = window1
	if context is None :
	    self._top = window1
	    gtk_widget_realize (window1)
	gtk_window_set_title (window1,"Gnome Calendar")
	gtk_window_set_position (window1, GTK.WIN_POS_NONE)
	gtk_window_add_accel_group (window1, self._accelgroup)
	self.window1 = window1
	calendar1 = gtk_calendar_new ()
	gtk_calendar_display_options (calendar1, (GTK.CALENDAR_SHOW_HEADING | GTK.CALENDAR_SHOW_DAY_NAMES))
        gtk_calendar_select_month(calendar1,time.localtime()[1]-1,time.localtime()[0])
        gtk_calendar_select_day(calendar1,time.localtime()[2])
	self.calendar1 = calendar1
	gtk_container_add (window1, calendar1)
	self.setupController ()
	gtk_widget_show_all (window1)
    def connect (self, listener, extra=None) :
	if extra is None: extra = self

def quit (*args) :
    gtk_main_quit ()

def run () :
    gtk_init ()
    gtk_set_locale ()
    w=window1 ()
    gtk_signal_connect (w.window1, "destroy", quit)
    gtk_main ()

if __name__ == "__main__" :
    run ()
