Maple boss tracker in python - blackmage - 2010-11-21
i'm kind of a newbie programmer and when i can i try to write little scripts to help myself improve. any constructive comments or criticism is welcome. this is my first program using Tkinter and any GUI elements at all
this one is a rather simple time tracker, for bosses. it gives you a list of channels and the time since you last killed the boss. after you kill a boss just type in the channel number you were on and press space. if you want to delete a track, type the channel number in and press 'd'
You have to copy all that text, and create a file with the name you want and the extension ".py"
if you want to adapt this to your own purposes, here's a few notes:
-right now it's made for mushmom tracking so it will give a notice that it's an old track after 1 hour. you can change that on line 106
-if you type in a channel that doesn't exist just press space and it clears the input so you can try again. if you play a server with less than 19 channels you'll probably need to make modifications on lines 27 and line 36, but i havent tested what would happen
-i'm running it in python 2.6
Code: import string
import Tkinter
import time
from Tkinter import *
currentStuff = ''
listOfChannels = [
[1, ""],
[2, ""],
[3, ""],
[4, ""],
[5, ""],
[6, ""],
[7, ""],
[8, ""],
[9, ""],
[10, ""],
[11, ""],
[12, ""],
[13, ""],
[14, ""],
[15, ""],
[16, ""],
[17, ""],
[18, ""],
[19, ""]
]
def storeChannel(input):
try:
#input = raw_input("?")
input = int(input)
if input > 0 and input < 20:
listOfChannels[input-1][1] = '%s' %int(time.time())
print 'woo added a channel time'
tick()
except:
print 'error'
def deleteChannel(input):
try:
input = int(input)
if input > 0 and input < 20:
listOfChannels[input-1][1] = ''
print 'woo deleted a channel time'
tick()
except:
print 'error'
def tick():
global curtime
newtime = time.strftime('%H:%M:%S')
if newtime != curtime:
curtime = newtime
clock.config(text=curtime)
clock.after(3000, tick)
print 'tick is happening'
printAllChannels()
def key(event):
global currentStuff
#print'mee'
#print curtime
if event.char == event.keysym:
try:
typedLetter = int(event.char)
#print typedLetter
currentStuff = '%s' %currentStuff + '%s' %typedLetter
#print currentStuff
except:
print 'poop'
try:
typedLetter = event.char
#print typedLetter
if typedLetter == 'd':
deleteChannel(currentStuff)
currentStuff = ''
except:
print 'double poop' #use this to delete a channel
msg = 'Current Channel Inputted %s' %currentStuff
elif len(event.char) == 1:
msg = 'Punctuation Key %r (%r)' % (event.keysym, event.char)
#print 'space'
storeChannel(currentStuff)
currentStuff = ''
else:
msg = 'Special Key %r' % event.keysym
label1.config(text=msg)
def printAllChannels():
for i in listOfChannels:
howManySecondsOld = 0
howManyMinutesOld = 0
howManyHoursOld = 0
if i[1] != '':
howManySecondsOld = int(time.time() - float(i[1]))
while howManySecondsOld >= 60:
howManyMinutesOld += 1
howManySecondsOld -= 60
while howManyMinutesOld >= 60:
howManyHoursOld += 1
howManyMinutesOld -= 60
if howManySecondsOld == 0 and howManyMinutesOld == 0 and howManyHoursOld == 0:
outputString = '%s' %i[0]
elif howManyHoursOld == 0:
outputString = '%s' %i[0] +' : %sh ' %howManyHoursOld + '%sm ' %howManyMinutesOld +'%ss' %howManySecondsOld
else:
outputString = '%s' %i[0] +' : %sh ' %howManyHoursOld + '%sm ' %howManyMinutesOld +'%ss' %howManySecondsOld + ' *OLD TRACK*'
print outputString
################################################## ^SUBROUTINES^ ###################################################
################# V REAL CODE STARTS HERE V ########################################################################
####################################################################################################################
####################################################################################################################
root = Tk()
curtime = ''
clock = Tkinter.Label(root)
clock.pack()
tick()
print 'woo'
prompt = ' Enter a channel number, than press space to add a channel \n press d to delete'
label1 = Label(root, text=prompt, width=len(prompt), height=8, bg='green')
label1.pack()
root.bind_all('<Key>', key)
root.mainloop()
screenshot, as you can see very simple
Maple boss tracker in python - blackmage - 2010-11-21
If this actually belongs in another forum please move it if you can. it is a useful maple tool that i think others will enjoy, and this rubik's cube forum is not heavily trafficked, but I didn't want to step on any toes.
Also for those of you that don't know how to run this, sorry i am not converting this to an exe, i don't want to do anything to encourage people to download and run black box programs from maple forums. just install python 2.6 and you should be able to run it by double clicking the .py file
|