#!/usr/bin/python

import sys
import os
import subprocess
from optparse import OptionParser

#currently hardcoded
#panel_id=0
#launcher_position=0
#icon_autohide="changes-prevent"
#icon_alwaysvisible="changes-allow"



def main():
	if len(sys.argv) != 5:
		print "Propper Use: Panel ID number, Launcher Position Number, Autohide Icon Name, Always Visible Icon Name"
		sys.exit()
	panel_id=sys.argv[1]
	launcher_position=sys.argv[2]
	icon_autohide=sys.argv[3]
	icon_alwaysvisible=sys.argv[4]
	
	def change_icon(icon_name):
		launcher_id = subprocess.check_output(["/usr/bin/xfconf-query","-c","xfce4-panel","-p","/panels/panel-"+panel_id+"/plugin-ids"]).splitlines()[2+int(launcher_position)]
		desktop_file = subprocess.check_output(["/usr/bin/xfconf-query","-c","xfce4-panel","-p",("/plugins/plugin-"+launcher_id+"/items")]).splitlines()[2]
		subprocess.call([ "desktop-file-edit", "--set-key=Icon","--set-value="+icon_name, os.getenv("HOME")+"/.config/xfce4/panel/launcher-"+launcher_id+"/"+desktop_file ])

	if subprocess.check_output(["/usr/bin/xfconf-query","-c","xfce4-panel","-p","/panels/panel-"+panel_id+"/autohide"]).splitlines()[0] == "true" :
		change_icon(icon_autohide)
		subprocess.call(["xfconf-query", "-c", "xfce4-panel", "-p", "/panels/panel-"+panel_id+"/autohide","-s","false"])
	else:
		change_icon(icon_alwaysvisible)
		subprocess.call(["xfconf-query", "-c", "xfce4-panel", "-p", "/panels/panel-"+panel_id+"/autohide","-s","true"])



if __name__ == "__main__":
	main()

