# -*- coding: cp1252 -*- # # # (gpl)Peter Schwede # This is going to be the new sequel of Downcounter 2 # # TODO-list (german): # 1. Lautstärkeprogrammierung # 2. ShutDown befehle # Standard-Strings abspeichern, ändern,.. # # # includes import os from Tkinter import * from tkFont import * import tkFileDialog as fd import time as t import datetime as dt # Build the Mainwindow MainWindow = Tk() # Standard (original) strings MainWindowTitle = "DownCounter 3" TimeFormatString = StringVar(MainWindow) TimeFormatString.set("%H:%M:%S") XRadiobuttonString = StringVar(MainWindow) XRadiobuttonString.set("x") XEntryString = StringVar(MainWindow) XEntryString.set(t.strftime(TimeFormatString.get(),t.localtime(t.time()+5*60))) XTRadiobuttonSting = StringVar(MainWindow) XTRadiobuttonSting.set("x+t") XTEntryString = StringVar(MainWindow) XTEntryString.set(t.strftime(TimeFormatString.get(),t.gmtime(5*60))) OkButtonString = StringVar(MainWindow) OkButtonString.set("Ok") OpenFileCheckbuttonString = StringVar(MainWindow) OpenFileCheckbuttonString.set("Open File") DisplayLabelString = StringVar(MainWindow) DisplayLabelString.set("--:--:--") ProcessBarBGString = StringVar(MainWindow) ProcessBarBGString.set("#000000") ProcessBarWidth = IntVar(MainWindow) ProcessBarWidth.set(100) ProcessBarHeight = IntVar(MainWindow) ProcessBarHeight.set(33) ProcessBarBarFillString = StringVar(MainWindow) ProcessBarBarFillString.set("#0080ff") ProcessBarPercent = DoubleVar(MainWindow) AbortButtonString = StringVar(MainWindow) AbortButtonString.set("Cancel") ShutDownRadiobuttonString = StringVar(MainWindow) ShutDownRadiobuttonString.set("Shut Down") TimeFrameString = StringVar(MainWindow) TimeFrameString.set("Time") EventFrameString = StringVar(MainWindow) EventFrameString.set("Event") DisplayFrameString = StringVar(MainWindow) DisplayFrameString.set("Display") DisplayLabelFont = Font(family="Arial", size=25) OpenFileEntryString = StringVar(MainWindow) OpenFileEntryString.set("\"\"") CloseWindowCheckbuttonString = StringVar(MainWindow) CloseWindowCheckbuttonString.set("Close Window") TimeSetting = BooleanVar(MainWindow) CloseWindowSetting = BooleanVar(MainWindow) ShutDownSetting = BooleanVar(MainWindow) MainWindow.title(MainWindowTitle) EndTime = t.struct_time TimeGone = t.struct_time TimeSpan = t.struct_time Runner = 0 # functions for better usage performance (unimportant) # switch some radiobuttons' True value to selected Entry def XEntryEvent(event): XRadiobutton.select() def XTEntryEvent(event): XTRadiobutton.select() def OpenFileEntryFocusInEvent(event): OpenFileRadiobutton.select() def OpenFileDialog(): OpenFileEntryString.set("\""+fd.askopenfilename()+"\"") # make a frame for the time config TimeFrame = LabelFrame(MainWindow, text=TimeFrameString.get(), relief=GROOVE) TimeFrame.grid(row=0, column=0, sticky=W+E+N+S) # add a Radiobutton "x" and an entry to the TimeFrame XRadiobutton = Radiobutton(TimeFrame, text=XRadiobuttonString.get(), variable=TimeSetting, value=True) XRadiobutton.select() XRadiobutton.grid(row=0, column=0, sticky=W) XEntry = Entry(TimeFrame, textvariable=XEntryString) XEntry.grid(row=1, column=0, sticky=W, padx=5) XEntry.bind("", XEntryEvent) # add a Radiobutton "t+x" and an entry to the TimeFrame XTRadiobutton = Radiobutton(TimeFrame, text=XTRadiobuttonSting.get(), variable=TimeSetting, value=False) XTRadiobutton.grid(row=2, column=0, sticky=W) XTEntry = Entry(TimeFrame, textvariable=XTEntryString) XTEntry.grid(row=3, column=0, sticky=W, padx=5) XTEntry.bind("", XTEntryEvent) # make a frame for the event config EventFrame = LabelFrame(MainWindow, text=EventFrameString.get(), relief=GROOVE) EventFrame.grid(row=0, column=1, sticky=W+E+N+S) # add a Checkbutton for "Close Window" CloseWindowCheckbutton = Checkbutton(EventFrame, text=CloseWindowCheckbuttonString.get(), variable=CloseWindowSetting) CloseWindowCheckbutton.grid(row=2, sticky=W+E+N+S) CloseWindowCheckbutton.select() # add a ShutDown Checkbutton ShutDownRadiobutton = Radiobutton(EventFrame, text=ShutDownRadiobuttonString.get(), variable=ShutDownSetting, value=1) ShutDownRadiobutton.grid(row=3, sticky=W) # make a frame for the display DisplayFrame = LabelFrame(MainWindow, text=DisplayFrameString.get(), relief=GROOVE) DisplayFrame.grid(row=1, columnspan=2, sticky=N+S+E+W) # add a big Label for the left time, processbar DisplayLabel = Label(DisplayFrame, text=DisplayLabelString.get()) DisplayLabel.grid(row=0, rowspan=2, sticky=W+E+S+N) DisplayLabel["font"] = DisplayLabelFont # make the Processbar ProcessBar = Canvas(DisplayFrame, height=ProcessBarHeight.get(), width=ProcessBarWidth.get(), bg=ProcessBarBGString.get(), bd=0) ProcessBar.grid(row=0, column=1, sticky=W+E+S+N) #create the visible bar ProcessBar.create_rectangle(0, 0, 0, ProcessBarHeight.get(), fill=ProcessBarBarFillString.get(), width=0, tag="bar") # functions for functionality ;) (important) def CancelCountDown(): global Runner MainWindow.after_cancel(Runner) if(CloseWindowSetting.get()==True): MainWindow.quit() else: DisplayLabel["text"] = "--:--:--" MainWindow.title(MainWindowTitle) ProcessBar.coords("bar", 1, 1, 0, ProcessBarHeight.get()) def updateCountdown(): global EndTime global TimeGone global TimeSpan global ProcessBarPercent global Runner tmp = EndTime - TimeGone DisplayLabel["text"] = tmp MainWindow.title(str(tmp) + " - DownCounter 3") TimeGone += dt.timedelta(days=0, hours=0, minutes=0, seconds=1) ProcessBarPercent.set(ProcessBarWidth.get()*(tmp.days*24*60*60.0 + tmp.seconds)/(TimeSpan.days*24*60*60.0 + TimeSpan.seconds)) ProcessBar.coords("bar", 1, 1, ProcessBarWidth.get()-ProcessBarPercent.get(), ProcessBarHeight.get()) Runner = MainWindow.after(1000, updateCountdown) if(dt.datetime.now() > EndTime): os.system(OpenFileEntryString.get()) CancelCountDown() def setEndTime(): global EndTime global TimeGone global TimeSpan global TimeSetting global OkButton global Runner try: MainWindow.after_cancel(Runner) finally: tmp2 = dt.datetime.now() tmp2 -= tmp2.microsecond*dt.timedelta(0,0,1) if(TimeSetting.get()==True): # EndTime = Eingabe = x tmp = t.strptime(XEntryString.get(),TimeFormatString.get()) EndTime = dt.datetime(year=tmp2.year, month=tmp2.month, day=tmp2.day, hour=tmp.tm_hour, minute=tmp.tm_min, second=tmp.tm_sec) else: # EndTime = Aktuelle Zeit + Eingabe = x+t tmp = t.strptime(XTEntryString.get(),TimeFormatString.get()) EndTime = tmp2 + dt.timedelta(days=tmp.tm_mday-1, hours=tmp.tm_hour, minutes=tmp.tm_min, seconds=tmp.tm_sec) TimeGone = tmp2 TimeSpan = EndTime - TimeGone dt.datetime.now() # print EndTime updateCountdown() #the rest which needs the functions: (buttons, etc) # add the OkButton for starting the countdown OkButton = Button(TimeFrame, text=OkButtonString.get(), width=4, default=ACTIVE, command=setEndTime) OkButton.grid(column=1, row=0, rowspan=4, sticky=W+E+N+S, padx=5, pady=5) # add a Radiobutton for "Open File" and an Entry OpenFileRadiobutton = Radiobutton(EventFrame, text=OpenFileCheckbuttonString.get(), variable=ShutDownSetting, value=0, command=OpenFileDialog) OpenFileRadiobutton.grid(row=0, sticky=W) OpenFileEntry = Entry(EventFrame, textvariable=OpenFileEntryString) OpenFileEntry.grid(row=1, sticky=W, padx=5) OpenFileEntry.bind("", OpenFileEntryFocusInEvent) # add the Abortbutton AbortButton = Button(DisplayFrame, text=AbortButtonString.get(), command=CancelCountDown) AbortButton.grid(row=1, column=1, sticky=W+E) # Run the MainLoop! MainWindow.mainloop()