#!/usr/bin/python
# Polish News Module ver. 3.x
# INSTALLER
import os
import sys

#Autodetect the resolution, thanks to Adam Geitgey!
havexwi = os.system("which xwininfo 2>&1 > /dev/null")
os.system("rm -f $HOME/.superkaramba/PNM3.rc")

if (havexwi == 0): pass
else: print "\nCan't find xwininfo in your path."

fp = os.popen("xwininfo -root -stats")
output = fp.read()
output = output.splitlines()
i = 0
print "Your screen resolution is: "
for x in output:
        param = x.split()
        if (len(param) > 1):
                if param[0].find("Width:") != -1:
                        print "X = " + str(param[1])
                        resX = int(param[1])
                if param[0].find("Height:") != -1:
                        print "Y = " + str(param[1])
                        resY = int(param[1])

theme = "# Main \"window\"\n"
theme += "KARAMBA X=" + str(resX-465) + " Y=40 W=465 H=430 INTERVAL=1000000 LOCKED=TRUE\n"
theme += "# Backgrouns and handle\n"
theme += "IMAGE X=0 Y=160 PATH=\"pics/handle.png\" NAME=\"handle\" #W=27 H=112\n"
theme += "IMAGE X=23 Y=19 PATH=\"pics/calendar_small.png\" NAME=\"small\" #W=56 #H=393 #Button bg\n"
theme += "IMAGE X=75 Y=19 PATH=\"pics/calendar.png\" NAME=\"bg\" #W=390 H=393 #Main bg\n"
theme += "# Arrows and reload\n"
theme += "IMAGE X=29 Y=0 PATH=\"pics/uparrow-panel.png\" NAME=\"up_panel\" #W=41 H=25\n"
theme += "IMAGE X=29 Y=403 PATH=\"pics/downarrow-panel.png\" NAME=\"down_panel\" #W=41 H=25\n"
theme += "IMAGE X=425 Y=318 PATH=\"pics/uparrow-inside.png\" NAME=\"up_news\" #W=22 H=22\n"
theme += "IMAGE X=425 Y=372 PATH=\"pics/downarrow-inside.png\" NAME=\"down_news\" #W=22 H=22\n"
theme += "IMAGE X=421 Y=341 PATH=\"pics/reload.png\" NAME=\"reload\" #W=22 H=22\n"

theme_file = open(sys.path[0] + '/PNM3.theme', 'w')
theme_file.write(theme)
theme_file.close()
