import ctypes
import datetime
from threading import Timer
from tkinter import *
from tkinter import messagebox
REMIND_MIN = 5 #提醒时间min
TIMEOUT_MIN = 20 #超时时间min
MIN2SEC = 60 #分钟转换秒
MEATING_MAX = 3 #最大会议数量
gtotalnum = 1 #议题总数量
gdisplaytime = 0 #倒计时显示时间
gcurrentmeating = 0 #当前议题编号
gnamelist = [] #各议题名字
gtotaltimelist = [] #各议题的总时间列表
gremindtimelist = [] #各议题的提醒时间列表
gaddflag = False #进入倒计时后又需要添加议题标志
gdisplaycolor = 'green' #倒计时显示颜色
class basedesk(object):
def __init__(self,master):
self.root = master
self.root.config()
self.root.title('Base page')
self.root.geometry('200x200')
page_input_num(self.root)
class page_input_num(object):
def __init__(self, master):
self.master = master
#基准界面initface
self.page_input_num = Frame(self.master)
self.master.geometry("150x70-50+20")
self.master.resizable(0,0) #锁定窗体大小
self.master.wm_title('MeatingTimerV1.0') #设置窗体标题
self.master.wm_attributes('-topmost', 1) #设置窗体置顶
self.master.attributes("-toolwindow", 2) #去掉窗口最大化最小化按钮,只保留关闭
self.label = Label(self.master, text="设置议题数量:")
self.label.grid(row=0, column=0)
self.num = Entry(self.master, width=6) #设置议题数量
self.num.grid(row=0, column=1, padx=5, pady=5)
self.num.insert(0, str(1))
self.button = Button(self.master, text="Start", width=18, command=self.start)
self.button.grid(row=8, column=0, sticky=W, padx=5, pady=5, columnspan=2)
def delete(self):
self.label.destroy()
self.num.destroy()
self.button.destroy()
def start(self):
global gtotalnum
if self.num.get():
if MEATING_MAX < int(self.num.get()):
gtotalnum = MEATING_MAX
else:
gtotalnum = int(self.num.get())
print("设置议题数量:%s" % gtotalnum)
self.delete()
self.page_input_num.destroy()
page_input_info(self.master)
class page_input_info(object):
def __init__(self, master):
global gaddflag
global gtotalnum
global gnamelist
global gtotaltimelist #各议题的总时间列表
global gremindtimelist #各议题的提醒时间列表
self.label1 = []
self.label2 = []
self.label3 = []
self.name = []
self.total = []
self.remind = []
gnamelist.clear()
gtotaltimelist.clear()
gremindtimelist.clear()
self.master = master
self.page_input_info = Frame(self.master)
size = '460x' + str(gtotalnum*27+35) + '-50+20'
self.master.geometry(size)
self.master.resizable(0,0) #锁定窗体大小
self.master.wm_title('MeatingTimerV1.0 - honor ') #设置窗体标题
self.master.wm_attributes('-topmost', 1) #设置窗体置顶
self.master.attributes("-toolwindow", 2) #去掉窗口最大化最小化按钮,只保留关闭
for i in range(gtotalnum):
self.addwindow(i)
if gaddflag:
for i in range(gtotalnum-1):
self.lockwindow(i)
self.btnStart = Button(self.master, text="Start", width=20, command=self.start)
self.btnStart.grid(row=gtotalnum+2, column=0, sticky=E, padx=2, pady=2, columnspan=2)
self.btnExit = Button(self.master, text="Exit", width=20, command=self.exit)
self.btnExit.grid(row=gtotalnum+2, column=2, sticky=W, padx=2, pady=2, columnspan=4)
def collect(self):
global gtotalnum
global gnamelist
global gremindtimelist #各议题的提醒时间列表
global gtotaltimelist #各议题的总时间列表
for i in range(gtotalnum):
if self.name[i].get():
gnamelist.append(str(self.name[i].get()))
if self.total[i].get():
if 0 < int(self.total[i].get()) < 300:
gtotaltimelist.append(int(self.total[i].get()) * MIN2SEC)
else:
self.total[i].delete(0, END)
self.total[i].insert(0, str(TIMEOUT_MIN))
gtotaltimelist.append(TIMEOUT_MIN * MIN2SEC) #默认TIMEOUT_MIN分钟
else:
self.total[i].delete(0, END)
self.total[i].insert(0, str(TIMEOUT_MIN))
gtotaltimelist.append(TIMEOUT_MIN * MIN2SEC) #默认TIMEOUT_MIN分钟
if self.remind[i].get():
if 0 < int(self.remind[i].get()) < 30:
gremindtimelist.append(int(self.remind[i].get()) * MIN2SEC)
else:
self.remind[i].delete(0, END)
self.remind[i].insert(0, str(REMIND_MIN))
gremindtimelist.append(REMIND_MIN * MIN2SEC)
else:
self.remind[i].delete(0, END)
self.remind[i].insert(0, str(REMIND_MIN))
gremindtimelist.append(REMIND_MIN * MIN2SEC)
def addwindow(self, num):
self.label1.append(Label(self.master, text="议题名称:"))#结束前几分钟提醒
self.label2.append(Label(self.master, text="总时间(min):"))#结束前几分钟提醒
self.label3.append(Label(self.master, text="提前提醒(min):"))#结束前几分钟提醒
self.label1[num].grid(row=num, column=0, sticky=W, padx=2, pady=2)
self.label2[num].grid(row=num, column=2, sticky=W, padx=2, pady=2)
self.label3[num].grid(row=num, column=4, sticky=W, padx=2, pady=2)
self.name.append(Entry(self.master, width=20))#会议名称
self.total.append(Entry(self.master, width=4))#设置会议总时间
self.remind.append(Entry(self.master, width=4))#结束前几分钟提醒
self.name[num].grid(row=num, column=1, sticky=W, padx=2, pady=2)
self.total[num].grid(row=num, column=3, sticky=W, padx=2, pady=2)
self.remind[num].grid(row=num, column=5, sticky=W, padx=2, pady=2)
self.name[num].insert(0, str('会议-'+ str(num+1)))
self.total[num].insert(0, str(TIMEOUT_MIN))
self.remind[num].insert(0, str(REMIND_MIN))
def lockwindow(self, num):
self.name[num]['state'] = 'readonly'#会议名称
self.total[num]['state'] = 'readonly'#设置会议总时间
self.remind[num]['state'] = 'readonly'#结束前提醒时间
def delete(self):
global gtotalnum
for i in range(gtotalnum):
self.label1[i].destroy()
self.label2[i].destroy()
self.label3[i].destroy()
self.name[i].destroy()
self.total[i].destroy()
self.remind[i].destroy()
self.btnStart.destroy()
self.btnExit.destroy()
def calculate(self):
global gaddflag
global gdisplaytime
global gtotaltimelist
global gcurrentmeating
if gaddflag:
gaddflag = False
else:
gdisplaytime = gtotaltimelist[gcurrentmeating]
def start(self):
self.collect()
self.calculate()
self.delete()
self.page_input_info.destroy()
page_display(self.master)
def exit(self):
self.page_input_info.destroy()
self.master.quit()
class page_display(object):
def __init__(self, master):
global gnamelist
global gdisplaytime
global gdisplaycolor
global gcurrentmeating
self.master = master
self.countdown = StringVar()
self.countdown.set(0)
color = ['green', 'red']
self.master.geometry("240x50-50+20")
self.master.resizable(0,0) #锁定窗体大小
self.master.wm_title(str(gnamelist[gcurrentmeating])) #设置窗体标题
self.master.wm_attributes('-topmost', 1) #设置窗体置顶
self.page_display = Frame(self.master)
self.display = Label(self.master, textvariable=self.countdown, font=("幼圆", 30, 'bold'), fg=color[bool(0>gdisplaytime)])
self.display.grid(row=0, column=0)#倒计时
self.btnOver = Button(self.master, text="Next", height=2, width=4, command=self.next)
self.btnOver.grid(row=0, column=1, sticky=W, padx=2, pady=2)
self.btnAdd = Button(self.master, text="Add", height=2, width=4, command=self.add)
self.btnAdd.grid(row=0, column=2, sticky=W, padx=2, pady=2)
starttime = datetime.datetime.now().replace(minute=1, second=0, microsecond=0)
self.timer = MyTimer(starttime, 1, self.timing, [1])
self.timer.start()
def delete(self):
self.display.destroy()
self.btnOver.destroy()
self.btnAdd.destroy()
def timing(self, interval):
global gdisplaytime
global gremindtimelist
global gcurrentmeating
color = ['green', 'red']
self.display.config(fg=color[bool(0>gdisplaytime)])
self.countdown.set(str(datetime.timedelta(seconds=abs(gdisplaytime))))
if 0 == gdisplaytime:
self.overBox()
elif gremindtimelist[gcurrentmeating] == gdisplaytime:
self.remindBox()
gdisplaytime -= 1
def remindBox(self):
global gremindtimelist
global gcurrentmeating
time = int(gremindtimelist[gcurrentmeating] / MIN2SEC)
messagebox.showinfo('提醒', '距离议题结束时间还有 %d min' %time)
print('remindProcess')
def overBox(self):
global gnamelist
global gcurrentmeating
messagebox.showwarning('提醒', '议题 #%s# 超时' %gnamelist[gcurrentmeating])
def next(self):
global gtotalnum
global gnamelist
global gdisplaytime
global gcurrentmeating
global gtotaltimelist
if gtotalnum == gcurrentmeating+1:
self.timer.cancel()
messagebox.showwarning('结束', '当前议题为最后一个,点击结束')
self.page_display.destroy()
self.master.quit()
else:
gcurrentmeating += 1
gdisplaytime = gtotaltimelist[gcurrentmeating]
self.master.wm_title(str(gnamelist[gcurrentmeating])) #设置窗体标题
print('meating', gcurrentmeating+1)
def add(self):
global gaddflag
global gtotalnum
gaddflag = True
if gtotalnum < MEATING_MAX:
gtotalnum += 1
self.timer.cancel()
self.delete()
self.page_display.destroy()
page_input_info(self.master)
else:
messagebox.showerror('错误', '超过最大可设置议题数量 #%s# 个' %MEATING_MAX)
#循环调用的定时器类
class MyTimer(object):
def __init__(self, start_time, interval, callback_proc, args=None, kwargs=None):
self.__timer = None
self.__flag = True
self.__start_time = start_time
self.__interval = interval
self.__callback_pro = callback_proc
self.__args = args if args is not None else []
self.__kwargs = kwargs if kwargs is not None else {}
def exec_callback(self, args=None, kwargs=None):
self.__callback_pro(*self.__args, **self.__kwargs)
if self.__flag:
self.__timer = Timer(self.__interval, self.exec_callback)
self.__timer.start()
def start(self):
interval = self.__interval - (datetime.datetime.now().timestamp() - self.__start_time.timestamp())
self.__timer = Timer(interval, self.exec_callback)
self.__timer.start()
def cancel(self):
self.__flag = False
self.__timer.cancel()
def isAdmin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
if __name__ == '__main__':
if isAdmin():
print('管理员权限操作')
root = Tk()
basedesk(root)
root.mainloop()
else:
if sys.version_info[0] == 3:
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)
else:#in python2.x
ctypes.windll.shell32.ShellExecuteW(None, u"runas", unicode(sys.executable), unicode(__file__), None, 1)
初学Python,写出的东西可能大佬们看起来不值一提,没准过段时间我自己回头看这些东西可能也会觉得像一坨垃圾,但至少还能用,记录一下点点滴滴 ?
|