Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- import tkinter
- from tkinter import *
- import time
- def graph(file):
- f = open(file , "r")
- if f.mode == 'r':
- contents =f.read()
- f1 = contents.split('\n')
- gold=0
- time = 0
- goldList=[]
- times=[]
- title=0
- for x in f1:
- if time>60:
- break
- xSplit = x.split(' ')
- if len(xSplit) != 1:
- gold+= int(xSplit[0])
- goldList.append(gold)
- timeConversion = xSplit[1].split(":")
- timeM = int(timeConversion[0])
- timeS = int(timeConversion[1])
- timemS = int(timeConversion[2])
- t1 = (timeM*60 + timeS + float(timemS))
- time += round(t1,2)
- times.append(time)
- else:
- title = xSplit[0]
- plt.plot(times,goldList,label=title)
- plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3,
- ncol=2, mode="expand", borderaxespad=0.)
- class StopWatch(Frame):
- """ Implements a stop watch frame widget. """
- def __init__(self, parent=None, **kw):
- Frame.__init__(self, parent, kw)
- self._start = 0.0
- self._elapsedtime = 0.0
- self._running = 0
- self.timestr = StringVar()
- #self.lapstr = StringVar()
- self.e = 0
- self.m = 0
- self.makeWidgets()
- self.laps = []
- self.lapmod2 = 0
- self.today = time.strftime("%d %b %Y %H-%M-%S", time.localtime())
- def makeWidgets(self):
- """ Make the time label. """
- l1 = Label(self, text='----Farm Name----')
- l1.pack(fill=X, expand=NO, pady=1, padx=2)
- self.e = Entry(self)
- self.e.pack(pady=2, padx=2)
- j1 = Label(self, text='----Split Value----')
- j1.pack(fill=X, expand=NO, pady=1, padx=2)
- self.p = Entry(self)
- self.p.pack(pady=2, padx=2)
- l = Label(self, textvariable=self.timestr)
- self._setTime(self._elapsedtime)
- l.pack(fill=X, expand=NO, pady=3, padx=2)
- l2 = Label(self, text='----Splits----')
- l2.pack(fill=X, expand=NO, pady=4, padx=2)
- scrollbar = Scrollbar(self, orient=VERTICAL)
- self.m = Listbox(self,selectmode=EXTENDED, height = 5,
- yscrollcommand=scrollbar.set)
- self.m.pack(side=LEFT, fill=BOTH, expand=1, pady=5, padx=2)
- scrollbar.config(command=self.m.yview)
- scrollbar.pack(side=RIGHT, fill=Y)
- def _update(self):
- """ Update the label with elapsed time. """
- self._elapsedtime = time.time() - self._start
- self._setTime(self._elapsedtime)
- self._timer = self.after(50, self._update)
- def _setTime(self, elap):
- """ Set the time string to Minutes:Seconds:Hundreths """
- minutes = int(elap/60)
- seconds = int(elap - minutes*60.0)
- hseconds = int((elap - minutes*60.0 - seconds)*100)
- self.timestr.set('%02d:%02d:%02d' % (minutes, seconds, hseconds))
- def _setLapTime(self, elap):
- """ Set the time string to Minutes:Seconds:Hundreths """
- minutes = int(elap/60)
- seconds = int(elap - minutes*60.0)
- hseconds = int((elap - minutes*60.0 - seconds)*100)
- return '%02d:%02d:%02d' % (minutes, seconds, hseconds)
- def Start(self):
- """ Start the stopwatch, ignore if running. """
- if not self._running:
- self._start = time.time() - self._elapsedtime
- self._update()
- self._running = 1
- def Stop(self):
- """ Stop the stopwatch, ignore if stopped. """
- if self._running:
- self.after_cancel(self._timer)
- self._elapsedtime = time.time() - self._start
- self._setTime(self._elapsedtime)
- self._running = 0
- def Reset(self):
- """ Reset the stopwatch. """
- self._start = time.time()
- self._elapsedtime = 0.0
- self.laps = []
- self._setTime(self._elapsedtime)
- def Lap(self):
- '''Makes a lap, only if started'''
- tempo = self._elapsedtime - self.lapmod2
- if self._running:
- self.laps.append(self._setLapTime(tempo))
- self.m.insert(END, self.laps[-1])
- self.m.yview_moveto(1)
- self.lapmod2 = self._elapsedtime
- def GravaCSV(self):
- '''Pega nome do cronometro e cria arquivo para guardar as laps'''
- arquivo = str(self.e.get()) + ' - '
- inventoryValue = str(self.p.get())
- with open('Routes/' + str(self.e.get()) + '.txt', 'wb') as lapfile:
- lapfile.write(bytes(str(self.e.get()) + '\n', 'utf-8'))
- for lap in self.laps:
- lapfile.write((bytes(inventoryValue + ' ' + str(lap) + '\n', 'utf-8')))
- graph('Routes/' + str(self.e.get()) + '.txt')
- plt.show()
- def main():
- root = Tk()
- root.wm_attributes("-topmost", 1) #always on top - might do a button for it
- sw = StopWatch(root)
- sw.pack(side=TOP)
- Button(root, text='Split', command=sw.Lap).pack(side=LEFT)
- Button(root, text='Start', command=sw.Start).pack(side=LEFT)
- Button(root, text='Stop', command=sw.Stop).pack(side=LEFT)
- #Button(root, text='Reset', command=sw.Reset).pack(side=LEFT)
- Button(root, text='Save', command=sw.GravaCSV).pack(side=LEFT)
- Button(root, text='Quit', command=root.quit).pack(side=LEFT)
- root.mainloop()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement