#!/usr/bin/env python3
#
# c2016-2022 by Paul Sherman <psherman2001@gmail.com>      
#									        
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3	
# of the License, or (at your option) any later version.


from tkinter import *
import os, sys, string, subprocess, tkinter.messagebox

cmd="chmod a+x $HOME/.icewm/rc.mail"
rcmd="chmod a-x $HOME/.icewm/rc.mail"
mHome = os.path.expanduser('~')
mPath = mHome + "/.icewm/rc.mail"
if not os.path.exists(mPath):
	os.system('touch ' + mPath)
	
icon0='''\
R0lGODlhGAAYAMZNAAAAAAEBAQICAgMDAwUFBQYGBgkJCQsLCwwMDA8PDxMTExQUFBUVFRYWFhcX
FxsbGxwcHCAgICYmJioqKisrKywsLC8vLzIyMjQ0NEdHR0hISFlZWVpaWmBgYGNjY2lpaWpqamxs
bG5ubnJycnZ2dnp6enx8fISEhIaGho2NjY+Pj5GRkZaWlpmZmZ2dnZ+fn6GhoaWlpaioqKqqqqys
rK2trbCwsLS0tLu7u8DAwMXFxczMzM3NzdHR0dLS0tfX19jY2Nvb29zc3N/f3+Li4uXl5efn5+vr
6+/v7/r6+vz8/P39/f7+/v//////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////yH5
BAEKAH8ALAAAAAAYABgAAAffgH+Cg4SFhoeIiYYBAI2OiosCHDU4KxONkIMCBjhNnk1JHpiQjS2f
nkxKFgCZAApJpz4YSDGspBlNSi5MQA4kTUGjiQAaTUUPHRAhnkLCiAAMSk0/DR5MnjS2jtsFN0yN
MZ5DS55LF6zbjgQ2TBt/AAc7p0wimOkAAzJMH9oDIDk8YlAYlU7AiyYjhN2zRWBbABZNTDwiJKzH
kQrbUjRBsS3RAgQ6jEhodKKJinSG0iXYQSRCiSYtGHUsdE+BjyNNYAi4l/Kegx8zBizseY+ATJ40
Fyp1Jmjp0kxQoyYKBAA7
'''

class App:
	def __init__(self, master):

		frame = Frame(master)

		self.lbl = Label(root, text="Run Email Notification on startup?")
		self.lbl.pack(side=TOP, pady=12)

		self.hi_there = Button(frame, text=" Yes ", fg="navy", command=self.hasta_manana)
		self.hi_there.pack(side=LEFT, padx=10, pady=5)

		self.rboot = Button(frame, text=" No ", command=self.ill_be_back)
		self.rboot.pack(side=LEFT, padx=10, pady=5)
		
		self.button = Button(frame, text="Forget I Asked", fg="red", command=self.forgetIt)
		self.button.pack(side=LEFT, padx=10, pady=5)
		frame.pack()
	
	def forgetIt(self):
		sys.exit()

	def hasta_manana(self):
		os.system(cmd)
		tkinter.messagebox.showinfo("PIM Settings", "\nMail Notification is now set  \nto run on startup...  \n" )
		sys.exit()

	def ill_be_back(self):
		os.system(rcmd)
		tkinter.messagebox.showinfo("PIM Settings", "\nMail Notification is now set  \nNOT to run on startup...  \n" )
		sys.exit()

def callback():
	sys.exit()

root = Tk()
app = App(root)
root.title("Mail Notification Setting")
icon = PhotoImage(master=root, data=icon0)
root.tk.call('wm', 'iconphoto', root._w, icon)
root.protocol("WM_DELETE_WINDOW", callback)
scrX, scrY = root.winfo_screenwidth(), root.winfo_screenheight()
wStart = (scrX - 320) / 2
hStart = (scrY - 90) / 2
root.geometry("%dx%d%+d%+d" % (320, 90, wStart, hStart))
root.mainloop()
