#!/usr/bin/env python
"""
A Global Time mockup using tool palette widget that show clocks as a group of buttons whose disposition adapts to the size of the window.
Based in the gtk.ToolPalette demo of John Stowers ( https://github.com/GNOME/pygtk/blob/master/examples/pygtk-demo/demos/toolpalette.py ).
The names of the cities were generated with http://www.fantasynamegenerators.com/city-names.php
"""

import pygtk
pygtk.require('2.0')
import gtk
from random import choice
from glob import glob

class GlobalTimeWithToolPalette(gtk.Window):
    def __init__(self, parent=None):
        gtk.Window.__init__(self)
        try:
            self.set_screen(parent.get_screen())
        except AttributeError:
            self.connect('destroy', lambda *w: gtk.main_quit())
        self.set_title("Global Time")
        self.set_icon_name("orage_globaltime")
        self.set_default_size(400,400)

        vb = gtk.VBox()

        self.palette = gtk.ToolPalette()
        self.load_clocks()

        self.sw = gtk.ScrolledWindow()
        self.sw.set_policy (gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
        self.palette.set_style(gtk.TOOLBAR_TEXT)
        self.sw.add(self.palette)
        vb.pack_start(self.sw, True, True)

        self.add(vb)
        self.show_all()

    def load_clocks(self):
        group = gtk.ToolItemGroup("")
        self.palette.add(group)
        times = ["Uwuport", "Blapfast", "Laeyginia", "Oliamdon", "Egegate",
            "Uwester", "Alatock", "Eneeveah", "Ugrustin", "Zuson", "Klusall",
            "Aclaropolis", "Uxiledo", "Teband", "Foblerton", "Hanling",
            "Mauxopolis", "Wromburg", "Aeneuving", "Odramore", "Kento", "Shesa",
            "Khuolore", "Ogrigrario", "Vraodiff", "Clebridge", "Meyford",
            "Ablucaster", "Inoburg", "Tans", "Oshence", "Stranale", "Zhodragos",
            "Edrunpolis", "Zhobert", "Eprofford", "Uuzholens", "Udrocdence",
            "Cragos", "Okans", "Imesa", "Bredrouver", "Bruozholn", "Iviestin",
            "Diton", "Vrofport", "Uveby", "Oreding", "Ovard", "Klago", "Aheaxita",
            "Iteoxta", "Gloulta", "Driucland", "Opratin", "Uruefast", "Aylans",
            "Blouver", "Coetico", "Zauglouver"]
        path_tz = "/usr/share/zoneinfo/"
        timezones = [tz.replace(path_tz, "") for tz in glob(path_tz + "*/*")]
        for i in times:
            b = gtk.ToolButton()
            l = gtk.Label("%s\n%i:00%s" % (i, choice(range(0,24)), choice(["+", "-", ""])))
            l.set_justify(gtk.JUSTIFY_CENTER)
            b.set_tooltip_text("%s\nclick to modify clock" % choice(timezones))
            b.set_is_important(True)
            b.set_label_widget(l)
            group.insert(b,-1)

def main():
    GlobalTimeWithToolPalette()
    gtk.main()

if __name__ == '__main__':
    main()