#!/usr/bin/python3
import gi, os, sys
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk

# JWM Kit - A set of Graphical Apps to simplify use of JWM (Joe's Window Manager) <https://codeberg.org/JWMKit/JWM_Kit>
# Copyright © 2020-2022 Calvin Kent McNabb <apps.jwmkit@gmail.com>
#
# This file is part of JWM Kit.
#
# JWM Kit is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2,
# as published by the Free Software Foundation.
#
# JWM Kit 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 JWM Kit.  If not, see <https://www.gnu.org/licenses/>.


class Calendar(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="Calendar")
        self.set_decorated(False)
        self.calendar = Gtk.Calendar()
        self.add(self.calendar)


pid = os.getpid()
run_file = "/tmp/jwmkit-calendar.run"
if os.path.isfile(run_file):
    with open(run_file) as f:
        pid = f.read()
    os.remove(run_file)
    os.system("kill -s TERM " + pid)
    sys.exit()
with open(run_file, "w") as f:
    f.write(str(pid))

win = Calendar()
win.set_position(Gtk.WindowPosition.MOUSE)
win.set_resizable(False)
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
os.remove(run_file)
