-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcantest.py
More file actions
440 lines (291 loc) · 14.6 KB
/
cantest.py
File metadata and controls
440 lines (291 loc) · 14.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
from Tkinter import * #GUI library
import tkFont #makes every thing look nice suplys diffrent fonts and such
import sqlite3 #i use this to hold all of the data for the events
import datetime #what do you think
import unidecode #GRRRRRRRRRR
import tkMessageBox # so i can pop error messages up and such
#Giovanni Rescigno : LAB-progaming/clone computers
#date started: 6/20/13
#License: GPL 2.0 (complty open!!!!! have fun)
class mainGui: #the class containg the Gui and handlers
def __init__(self, master):
self.app = Frame(master)
self.app.pack(side = TOP, fill=X)
self.ListFrame = Frame(self.app, width=200)
self.ListFrame.pack(side = LEFT, fill=Y)
self.infoFrame = Frame(self.app, width = 350)
self.infoFrame.pack(side = LEFT, fill=Y)
self.listofdata(self.ListFrame) #fuction that handles the data
self.viewerEvent(self.infoFrame) #fuction that handles the data being displayed
for self.dataoflist in SQLdata.getDataFromSQLITE():
self.data.insert(END, " " + self.dataoflist[1])
def listofdata(self, master):
self.listboxholder = Frame(master)
self.listboxholder.grid(row = 0, column = 0, padx=5)
self.data = Listbox(self.listboxholder, height = 25, width = 25)
self.data.pack(side = LEFT, fill = Y)
self.scroller = Scrollbar(self.listboxholder)
self.scroller.pack(side = LEFT, fill = Y)
self.data.configure(yscrollcommand = self.scroller.set)
self.scroller.configure(command = self.data.yview)
self.data.bind('<<ListboxSelect>>', self.listhandler)
self.buttonBox = Frame(master)
self.buttonBox.grid(row = 1, column = 0, sticky = W)
self.addNewEvent = Button(self.buttonBox, text = "+", command = self.AddButtonPress)
self.addNewEvent.pack(side=LEFT, padx = 2)
self.distroyEvent = Button(self.buttonBox, text = "-", command=self.distoryButtonPress)
self.distroyEvent.pack(side=LEFT)
def viewerEvent(self, master):
self.titleFont = tkFont.Font(family="Helvetica", weight="bold", size=20)# declaration of fonts up here
self.subtitle = tkFont.Font(family="Helvetica", weight="bold", size=14)
self.bodyFont = tkFont.Font(family="Helvetica", weight="normal", size=14)
self.topFrame = Frame(master)
self.topFrame.pack(side = TOP, fill = X, padx = 5, pady = 5)
self.EventName = StringVar()# var holding the Name of the event
self.titleLabel = Label(self.topFrame, font=self.titleFont, textvariable=self.EventName)
self.titleLabel.pack(side = LEFT)
self.CheckVar1 = IntVar()#holds the state of the check box
self.finnished = Checkbutton(self.topFrame, text = "Done", variable = self.CheckVar1,
onvalue = 1, offvalue = 0, command = self.DoneButtonPressed)
self.finnished.pack(side = RIGHT)
self.hr = Frame(master, bg = "black", height = 2, width = 350)
self.hr.pack(fill = X, padx = 3)
self.dateframe = Frame(master)
self.dateframe.pack(fill=X, padx = 5, pady = 10)
self.dateLabel = Label(self.dateframe, text = "Date: ", font = self.subtitle)
self.dateLabel.pack(side = LEFT)
self.dateOfEvent = StringVar()#var holding the date
self.datedata = Label(self.dateframe, textvariable = self.dateOfEvent, font = self.bodyFont)
self.datedata.pack(side = LEFT, padx = 10)
self.timedata = Frame(master)
self.timedata.pack(fill = X, padx = 5, pady = 10)
self.timeLabel = Label(self.timedata, text = "Time: ", font = self.subtitle)
self.timeLabel.pack(side = LEFT)
self.startTimeData = StringVar() #var holding the time an event starts
self.startTime = Label(self.timedata, textvariable = self.startTimeData, font = self.bodyFont)
self.startTime.pack(side = LEFT, padx = 10)
self.endTimeData = StringVar() #var holding the time that event ends
self.endTime = Label(self.timedata, textvariable = self.endTimeData, font = self.bodyFont)
self.endTime.pack(side = LEFT, padx = 10)
self.localdata = Frame(master)
self.localdata.pack(fill = X, padx = 5, pady = 10)
self.localLabel = Label(self.localdata, text = "Location:", font = self.subtitle)
self.localLabel.pack(side = LEFT)
self.location = StringVar() #holds the location of the event (if any)
self.locationData = Label(self.localdata, textvariable = self.location)
self.locationData.pack(side = LEFT, padx = 5)
self.buttonboxinfo = Frame(master)
self.buttonboxinfo.pack(side=BOTTOM, fill = X)
self.editButton = Button(self.buttonboxinfo, text = "Edit", command = self.EditButtonPress)
self.editButton.pack(side = RIGHT)
def entryForm(self, kind):
self.title = StringVar()
self.locationName = StringVar()
self.timeInHours = StringVar()
self.rankOfEvent = StringVar()
self.timeInMinets = StringVar()
self.kind = kind
if (kind == "new"):
self.entryKind = "new event"
else:
self.entryKind = "edit event"
self.indexOfEditedEvent = self.listEvent[0]
self.title.set(self.listEvent[1])
self.locationName.set(self.listEvent[2])
self.amountOfTimeTaken = self.listEvent[5] - self.listEvent[4]
self.amountOfTimeTaken = str(self.amountOfTimeTaken).split(".")
self.timeInHours.set(self.amountOfTimeTaken[0])
self.timeInMinets.set(self.amountOfTimeTaken[1])
self.rankOfEvent.set(int(self.listEvent[6]))
self.eventform = Toplevel()
self.eventform.title(self.entryKind)
self.eventform.geometry("270x165")
self.form = Frame(self.eventform)
self.form.pack(fill=X, padx = 5, pady = 5)
self.labelForTitle = Label(self.form, text = "Title: ")
self.labelForTitle.grid(column = 0, row = 0, pady = 5, sticky = W)
self.EntryForTitle = Entry(self.form, textvariable = self.title)
self.EntryForTitle.grid(column = 1, row = 0)
self.labelForLocation = Label(self.form, text = "Location: ")
self.labelForLocation.grid(column = 0, row = 1, pady = 5, sticky = W)
self.EntryForLocation = Entry(self.form, textvariable = self.locationName)
self.EntryForLocation.grid(column = 1, row = 1)
self.labelForTime = Label(self.form, text = "time taken: ")
self.labelForTime.grid(column = 0, row = 2, pady = 5, sticky = W)
self.timeFrame = Frame(self.form)
self.timeFrame .grid(column = 1, row = 2, sticky = W)
self.timeHours = Entry(self.timeFrame, width = 2, textvariable = self.timeInHours)
self.timeHours.grid(column = 0, row = 0)
self.seporator = Label(self.timeFrame, text = " : ")
self.seporator.grid(column = 1, row = 0)
self.timeMinets = Entry(self.timeFrame, width = 2, textvariable = self.timeInMinets)
self.timeMinets.grid(column = 2, row = 0)
self.labelForRank = Label(self.form, text = "rank: ")
self.labelForRank.grid(column = 0, row = 3, pady = 5, sticky = W)
self.optionRank = OptionMenu(self.form, self.rankOfEvent , "1", "2", "3", "4")
self.optionRank.grid(column = 1, row = 3, sticky = W)
self.submitButton = Button(self.form, text = "submit", command = self.SubmitHandler)
self.submitButton.grid(column = 1, row = 4, sticky = E)
def getBiggestIndex(self):
self.largestIndexList = SQLdata.getDataFromSQLITE()
self.ListOfIndexs = []
for i in self.largestIndexList:
self.ListOfIndexs = self.ListOfIndexs + [int(i[0])]
self.ListOfIndexs.sort()
self.ListOfIndexs.reverse()
return self.ListOfIndexs[0]
##############handlers##############
def listhandler(self, event):
#global self.index
self.lisboxliss = event.widget #find the index of that list box
self.index = int(self.lisboxliss.curselection()[0])
#print self.index
self.listEvent = SQLdata.getDataFromSQLITE()[self.index]
self.EventName.set(self.listEvent[1])#gets the event name form the data base
self.dateOfEvent.set(self.listEvent[3])#gets the dat
self.startTimeData.set(timeing.convertToTime(self.listEvent[4])) #gets the start time and runs it though the time code
self.endTimeData.set(timeing.convertToTime(self.listEvent[5])) #gets the end time and same
self.location.set(self.listEvent[2])#gets the location of the event (you guessed it) from the data base
def distoryButtonPress(self):#the selected event and delelets it
SQLdata.distoryFromData(self.listEvent[0])
def AddButtonPress(self):
self.entryForm("new")
def EditButtonPress(self):
self.entryForm("edit")
def SubmitHandler(self):
self.titleOfThisEvent = self.title.get()
self.LocationOfThisEvent = self.locationName.get()
self.TimeHoursOfThisEvent = self.timeInHours.get()
self.TimeMinetsOfThisEvent = self.timeInMinets.get()
self.rankOfThisEvent = int(self.rankOfEvent.get())
try:#if the number can not be converted in to an int it will throw an error and return
self.TimeHoursOfThisEvent = int(self.TimeHoursOfThisEvent)
self.TimeMinetsOfThisEvent = int(self.TimeMinetsOfThisEvent)
except:
tkMessageBox.showinfo("Error", "Time Value Not a Number!")
return
if self.titleOfThisEvent == "" or self.LocationOfThisEvent == "":#checks to see if the Entrys are empty
tkMessageBox.showinfo("Error", "Text Field Empty!")
return
if self.TimeMinetsOfThisEvent >= 60:
tkMessageBox.showinfo("Error", "only up to 59 minets!")
return
self.endTimeOfThisEvent = self.TimeHoursOfThisEvent + (self.TimeMinetsOfThisEvent / 100.0)#finds the amount of time
#print self.endTimeOfThisEvent
self.listOfNewDataOfNewEvent = [self.titleOfThisEvent, self.LocationOfThisEvent, 0, self.endTimeOfThisEvent, self.rankOfThisEvent]
SQLdata.addFromData(self.listOfNewDataOfNewEvent)
if not(self.kind == "new"):
SQLdata.distoryFromData(self.indexOfEditedEvent)
def DoneButtonPressed(self):
self.timeTakenByEvent = self.listEvent[5] - self.listEvent[4]
self.checksFile = open("checks.txt", "r")#opens file for reading
self.ListOfChecks = self.checksFile.read()
self.checksFile.close()
self.ListOfChecks = self.ListOfChecks.split(", ")
if self.ListOfChecks[0] != str(datetime.date.today()):
self.ListOfChecks[1] = int(self.ListOfChecks[1]) + 1
self.checksFile = open("checks.txt", "w")#opens file for wrihgting
self.ListOfChecks[2] = int(self.ListOfChecks[2]) + self.timeTakenByEvent
self.checksFile.write(str(datetime.date.today()) + ", " + str(int(self.ListOfChecks[1])) + ", " + str(int(self.ListOfChecks[2])))#writes the data to the txt
self.checksFile.close()
SQLdata.distoryFromData(self.listEvent[0])#distorys event that is finnished
class DataReadRight:
def __init__(self):
self.openDatabase()
def getAvrage(self):
self.checksFile = open("checks.txt", "r")
self.ListOfAvrage = self.checksFile.read()
self.ListOfAvrage = self.ListOfAvrage.split(", ")
self.average = int(self.ListOfAvrage[2]) / int(self.ListOfAvrage[1])
self.checksFile.close()
return self.average + 10
def getDataFromSQLITE(self):
self.listofdata = []
for self.rowData in self.EventData.execute("SELECT * FROM events"):
self.indexedrange = len(self.rowData)
self.smallerlist = []
for self.indexofDB in range(self.indexedrange):
self.smallerlist = self.smallerlist + [self.rowData[self.indexofDB]]
self.listofdata = self.listofdata + [self.smallerlist]
return timeing.rankData(self.listofdata, self.getAvrage())
def openDatabase(self):
self.EventData = sqlite3.connect('events.db')#connects to the db file giveing me the ablity to save and request data
self.selecter = self.EventData.cursor()#alows me to qeary the data in the .db file
def distoryFromData(self, index):
self.selecter.execute("DELETE FROM events WHERE indexEvent=" + str(index) + ";")
self.EventData.commit()
self.EventData.close()
self.openDatabase()
Gui.data.delete(0, END)
for self.dataoflist in self.getDataFromSQLITE():
Gui.data.insert(END, " " + self.dataoflist[1])
def addFromData(self, listOfData):
self.newIndex = Gui.getBiggestIndex() + 1
self.selecter.execute("INSERT INTO events VALUES ( '%s','%s','%s','%s','%s','%s','%s');" % ( self.newIndex, listOfData[0],
listOfData[1], "9-9-13", listOfData[2], listOfData[3], listOfData[4]))
self.EventData.commit()
self.EventData.close()
self.openDatabase()
Gui.data.delete(0, END)
for self.dataoflist in self.getDataFromSQLITE():
Gui.data.insert(END, " " + self.dataoflist[1])
class timeing:
def convertToTime(self, oldtime): #converts 24 hour time to 12 hour time with AM or PM
if ((oldtime - int(oldtime)) != 0):
self.minets = int((oldtime - int(oldtime)) *100)
if (self.minets < 0.10):
self.minets = "0" + str(self.minets)
else:
self.minets = str(self.minets)
elif ((oldtime - int(oldtime)) == 0):
self.minets = "00"
self.hours = str(int(oldtime))
if (int(self.hours) < 12 and int(self.hours) != (12 or 24)):
self.hours = str(int(oldtime))
self.fulltime = self.hours + ":" + self.minets + 'am'
elif (int(self.hours) > 12 and int(self.hours) != (12 or 24)):
self.hours = str(int(self.hours) - 12)
self.fulltime = self.hours + ":" + self.minets + 'pm'
elif (int(self.hours) == 12):
self.fulltime = self.hours + ":" + self.minets + "pm"
elif (int(self.hours) == 24):
self.fulltime = str(int(self.hours) - 12) + ":" + self.minets + 'am'
return self.fulltime
def rankData(self, listOfEvents, timeAlocated):
self.rankedlist = sorted(listOfEvents, key = lambda event: event[6])#sorts the events by their 'rank'
self.rankedlist.reverse()#cnages the list form smallest to largest to largest to smallest 'rank'
self.amountOfTime = []#list the corestponds to the list of events but holds the time that is alocated to each event
for i in range(len(self.rankedlist)): #finds the time that is alocated to each event
self.amountOfTime = self.amountOfTime + [self.rankedlist[i][5] - self.rankedlist[i][4]]
self.startTimeOfEvent = 10
self.DayTimeStorage = timeAlocated
self.counter = 0
self.daysInFuture = 0
for self.counter in range(len(self.rankedlist)):
self.fulltime2 = 10
for i in range(self.counter):
self.fulltime2 = self.fulltime2 + self.amountOfTime[i]
print self.fulltime2
if not(self.fulltime2 <= self.DayTimeStorage):
self.startTimeOfEvent = 10
self.daysInFuture = self.daysInFuture + 1
self.fulltime2 = 0
#if self.fulltime <= self.DayTimeStorage:
self.rankedlist[self.counter][4] = self.startTimeOfEvent
self.rankedlist[self.counter][5] = self.startTimeOfEvent + self.amountOfTime[self.counter]
self.startTimeOfEvent = self.rankedlist[self.counter][5]
self.rankedlist[self.counter][3] = self.dateInDays(self.daysInFuture)
self.counter = self.counter + 1
return self.rankedlist
def dateInDays(self, days):
#self.rawymd = str(time.strftime("%Y%m%d"))
#self.dateList = [self.rawymd[0:3], self.rawymd[4:6], self.rawymd[7:]]
return str(datetime.date.today() + datetime.timedelta(days=days))#gives me the date for the amount of days forward "days"
root = Tk()#Tk (GUI library) Object is created
root.title("clone planer") # title is made for the Tk Object
root.geometry("550x455") #the size is created
#other objects are created
timeing = timeing()
SQLdata = DataReadRight()
Gui = mainGui(root)
root.mainloop()#run the GUI in a loop