#!/usr/bin/env python
#	Version: 0.1.0
#  	Licence: WTFPL

#    Xrandr gui is free software: you can redistribute it and/or modify
#    it under the terms of WTF Public License This program is distributed
#    in the hope that it will be useful, but WITHOUT ANY WARRANTY.
#    You have been warned!

################################################################################
# Configuration Section Begins Here                                            #
################################################################################

c = dict(
    # The title to be shown on the pop-up and the icon tooltip.
    title = "Xrandr GUI",

    # Icon to use in the system tray and pop-up.
    icon = "/usr/share/pixmaps/xrandr-applet.svg",
    
    # Frequency none.
    interval = 0,

    # code that indicates applet checks.
    check = "1",

    # Command to run notification
    gui = "/usr/bin/xrandr-gui",
)

import gtk
import gobject

import commands
import subprocess
from time import time
import os.path
import sys

def do_show():
    """Show applet"""
    subprocess.call(c['gui'], shell=True)


def onClick(widget):
    """Event handler for the tray icon being clicked."""
    widget.set_visible(False)
    gobject.timeout_add(1, do_show)

tray = gtk.StatusIcon()
tray.set_from_file(c['icon'])
tray.set_tooltip(c['title'])
tray.set_visible(False)
tray.connect('activate', onClick)

next_check = int(time()) + c['interval']
def main_loop():
    global next_check
    if int(time()) >= next_check:
        status = commands.getoutput(c['check'])
        if status != "0":
           tray.set_visible(True)
        elif tray.get_visible() == True and status == "0":
           tray.set_visible(False)
        next_check = int(time()) + c['interval']

    gobject.timeout_add(1000, main_loop)

gobject.timeout_add(1000, main_loop)
try:
    for n in range(0):
        print n
	sys.stdout.flush()
except:
     pass
gtk.main()

