示例#1
0
		def create_new_class(*args):
			#Getting the Textfield
			newclassname = builder.get_object("class_name_text")
			#saving the Name			
			classname = newclassname.get_text()

			#If Classname ist Empty than Error-Message
			if len(classname) == 0:
				messWindow = Tkinter.Tk()
				messWindow.wm_withdraw()
				tkMessageBox.showinfo("Ungültiger Name", "Bitte gültigen Namen eingeben (Keine Sonderzeichen! Bsp. 11_GkInf1)!")
				messWindow.destroy()	
			else:
				#Create new Database-File in "database" if not exists		
				############### THE DEFAULT-PATH COULD BE CHANGE LATER IN A FILE #########
				#
				#
				#
				default_path = "../GradeLi Classes/"
				#
				#
				#
				#########################################################################
				if os.path.isfile(default_path + classname + ".db") == True:		
					messWindow = Tkinter.Tk()
					messWindow.wm_withdraw()
					tkMessageBox.showinfo("Name vergeben", "Name der Klasse ist bereits vergeben. Bitte anderen Namen nutzen oder alte Klasse verschieben.")
					messWindow.destroy()	
					newclasswindow.destroy()
				else:
					#Close Popup-Window
					close_window_newclass()

					#Creating the new Class-Database
					dataop = DataOp()			
					con = dataop.newdatabase(classname)
					dataop.closedatabase(con)

					#Adding Class to Combobox - Sorting after restart
					classesbox = builder.get_object("classes")
					classesbox.append_text(classname)

					#Saving new Classname
					new_class_name = classname

					#Make Loadingbutton Clickable
					loadclass = builder.get_object("loadclass")
					loadclass.set_sensitive(True)

					#Activate always the first Item in the List
					classesbox.set_active(0)

					#Open new Window with new Class-Database
					newmainclass = MainClasses()
					newmainclass.start(new_class_name)
	def start(self, classname, builder, window):

		#Databaseconnection
		dataop = DataOp()
		con = dataop.opendatabase(classname)

		#Get all the Grids :)
		datagrid_buttons = builder.get_object("datagrid_buttons")				
		newviewgrid = builder.get_object("datagrid")

		#Delete a UNit
		def deleteunit(self, id, year, month, day):
			messWindow = Tkinter.Tk()
			messWindow.wm_withdraw()
			result = tkMessageBox.askokcancel("Warnung", "ACHTUNG! Alle Daten der Stunde vom " + str(day) + "." + str(month) + "." + str(year) + " werden UNWIDERRUFLICH gelöscht. Fortfahren?")
			messWindow.destroy()

			#Check for deleting or not
			if result == True:
				#Delete True - Delete the Unit and reload the Grid
				dataop.deleteUnitComplete(con, id)
				fillDataGrid()

		#Save Updatet Information of a Unit
		def saveupdateunit(self, id, updateunitwindow):
			#Get new Title
			date = builder.get_object("unit_date").get_date()		
			title = builder.get_object("unit_title").get_text().decode("utf-8")
			#Saving changes
			
			cur = con.cursor()
			cur.execute("UPDATE units SET year=?, month=?, day=?, title=? WHERE id=?", (date[0], date[1] + 1, date[2], title, id)) 
			con.commit()		

			updateunitwindow.destroy()
			fillDataGrid()

		#Change a unit
		def changeunit(self, id, year, month, day, title):
			builder.add_from_file("gui/NewUnitPopUpdate.glade")
			updateunitwindow = builder.get_object("updateunitwindow")
			
			#Select actual Date in Calender
			date = builder.get_object("unit_date")			
			date.select_month(month - 1, year)
			date.select_day(day)

			titlewidget = builder.get_object("unit_title")
			titlewidget.set_text(title.encode("utf-8"))
			
			#Get Button-Object
			savedata = builder.get_object("updateunit_save")
			savedata.connect("clicked", saveupdateunit, id, updateunitwindow)

			#Show New-Student-Popup
			updateunitwindow.show_all()
				
		#Save new Unit
		def dosaveunit(self, unitwindow):
			#Getting Date and Title
			#Getting Date: Yeahr date[0] month[1] day[2]
			date = builder.get_object("newunit_date").get_date()
			title = builder.get_object("newunit_title").get_text().decode("utf-8")
			
			#Make the Month userfriendly :)
			month = int(date[1]) + 1
			
			#Saving new Unit into Database
			cur = con.cursor()
			
			#Count existing Units in the Datbase
			newid = dataop.getdata(con, "select count(id) from units", None)
			if newid.fetchone()[0] == 0:
				cur.execute("insert into units(id, year, month, day, title) values (0, ?, ?, ?, ?);", (int(date[0]), int(month), int(date[2]), title,))
			else:
				cur.execute("insert into units(id, year, month, day, title) values ((SELECT max(id) FROM units) + 1, ?, ?, ?, ?);", (date[0], int(month), date[2], title,))			
			
			#New Unit-ID: (SELECT max(id) FROM units)
			#Get all Students
			datas_allstu = dataop.getdata(con, "select id from students order by name asc", None)

			#For all Students add UnitStatus-Entry in Database with actual Unit-ID
			newid_stuunit = dataop.getdata(con, "select count(id) from status_stu_unit", None)
			newid_unitid = dataop.getdata(con, "SELECT max(id) FROM units", None)
			
			#New ID's
			unitid = newid_unitid.fetchone()[0]
			unitcount = newid_stuunit.fetchone()[0]			

			for stuall in datas_allstu.fetchall():
				if unitcount == 0:
					cur.execute("insert into status_stu_unit(id, unitid, studentid, status) values (0, ?, ?, 5);", (unitid, int(stuall[0]),))					
					unitcount = unitcount + 1
				else:
					cur.execute("insert into status_stu_unit(id, unitid, studentid, status) values ((SELECT max(id) FROM status_stu_unit) + 1, ?, ?, 5);", (unitid, int(stuall[0]),))					
					
			#Destroy the Add-Unit-Window
			unitwindow.destroy()
			#Reload the Data-Grid _ Units will be load there to
			fillDataGrid()			

		#Updatefunction for Students Unit-Status
		def updateUnitStu(self, studentid, unitid, newstatus, buttongrid):
			#Updating Data in Database
			cur = con.cursor()
			cur.execute("update status_stu_unit set status=? where unitid=? and studentid=?", (newstatus, unitid, studentid,)) 
			con.commit()	

			#Images
			ue_b = Gtk.Image()
			ue_r = Gtk.Image()
			ue_b.set_from_file("icons/quest_black.png")
			ue_r.set_from_file("icons/quest_red.png")

			#OK leaved
			e_b = Gtk.Image()
			e_g = Gtk.Image()
			e_b.set_from_file("icons/ok_black.png")
			e_g.set_from_file("icons/ok_green.png")

			#MIddle good work
			middle_b = Gtk.Image()
			middle_g = Gtk.Image()
			middle_b.set_from_file("icons/middle_black.png")
			middle_g.set_from_file("icons/middle_green.png")

			#One Plus Work
			plus_b = Gtk.Image()
			plus_g = Gtk.Image()
			plus_b.set_from_file("icons/plus_black.png")
			plus_g.set_from_file("icons/plus_green.png")

			#PLusPlus Work
			plusplus_b = Gtk.Image()
			plusplus_g = Gtk.Image()
			plusplus_b.set_from_file("icons/plusplus_black.png")
			plusplus_g.set_from_file("icons/plusplus_green.png")

			#One Minus Work
			minus_b = Gtk.Image()
			minus_g = Gtk.Image()
			minus_b.set_from_file("icons/minus_black.png")
			minus_g.set_from_file("icons/minus_green.png")

			#MinusMinus Work
			minusminus_b = Gtk.Image()
			minusminus_g = Gtk.Image()
			minusminus_b.set_from_file("icons/minusminus_black.png")
			minusminus_g.set_from_file("icons/minusminus_green.png")

			#School-Event
			school_b = Gtk.Image()
			school_g = Gtk.Image()
			school_b.set_from_file("icons/school_black.png")
			school_g.set_from_file("icons/school_green.png")

			#Changings Button-Images to show right color and button
			for button in buttongrid.get_children():				
				if button.get_name() == "ue":
					if newstatus == 0:
						button.set_image(ue_r)	
					else:
						button.set_image(ue_b)			

				if button.get_name() == "e":
					if newstatus == 1:
						button.set_image(e_g)	
					else:
						button.set_image(e_b)			

				if button.get_name() == "school":
					if newstatus == 2:
						button.set_image(school_g)	
					else:
						button.set_image(school_b)	

				if button.get_name() == "minusminus":
					if newstatus == 3:
						button.set_image(minusminus_g)	
					else:
						button.set_image(minusminus_b)				

				if button.get_name() == "minus":
					if newstatus == 4:
						button.set_image(minus_g)	
					else:
						button.set_image(minus_b)					

				if button.get_name() == "mid":
					if newstatus == 5:
						button.set_image(middle_g)	
					else:
						button.set_image(middle_b)		

				if button.get_name() == "plus":
					if newstatus == 6:
						button.set_image(plus_g)	
					else:
						button.set_image(plus_b)	

				if button.get_name() == "plusplus":
					if newstatus == 7:
						button.set_image(plusplus_g)	
					else:
						button.set_image(plusplus_b)			
				
		#Showing the New-Unit-Popup
		def do_addunit(*args):
			builder.add_from_file("gui/NewUnitPop.glade")
			addunitwindow = builder.get_object("addunitwindow")						

			addunitbutton = builder.get_object("addunit_save")
			addunitbutton.connect("clicked", dosaveunit, addunitwindow)
			#Show NewUnit-Popup
			addunitwindow.show_all()

		#Adding all Students to the Grid
		def addingstudents(self, startpoint):
			#Adding Studentsnames - Postname, Prenames, Numbers and Buttons
			data_stu = dataop.getdata(con, "select id, name, prename, mail from students order by 2 asc", None)
			startfield_rows = 1
			#Startfield of Rows
			if startpoint == None:				
				startpoint = 1

			for stu in data_stu.fetchall():
				templabel_numbers = Gtk.Label()
				templabel_postname = Gtk.Label()
				templabel_prename = Gtk.Label()

				templabel_numbers.set_text("     " + str(startfield_rows) + ". ")
				templabel_postname.set_text(stu[1].encode("utf-8") + " ")
				templabel_prename.set_text(stu[2].encode("utf-8") + " ")
				
				#COLOR 0-65535 Gdk.Color(RED, GREEN, BLUE)
				if startfield_rows % 2 != 0:
					templabel_postname.modify_bg(0, Gdk.Color(52000, 52000, 52000))
					templabel_prename.modify_bg(0, Gdk.Color(52000, 52000, 52000))
					templabel_numbers.modify_bg(0, Gdk.Color(52000, 52000, 52000))

				newviewgrid.attach(templabel_numbers, startpoint , startfield_rows + 1, 1, 1)
				newviewgrid.attach(templabel_postname, startpoint + 1 , startfield_rows + 1, 1, 1)
				newviewgrid.attach(templabel_prename, startpoint + 2, startfield_rows + 1, 1, 1)				
				startfield_rows = startfield_rows + 1

		#Loading all Units from Database with Buttons
		def loadingallunits(*args):
			#Adding Units
			datas = dataop.getdata(con, "select id, year, month, day, title from units order by year, month, day asc", None)
			#Startfield of Rows
			startfield_rows = 4
			numb = 1
			for row in datas.fetchall():
				#Adding the Date-Label
				unitbuttonsgrid = Gtk.Grid()
				unitbuttonsgrid_snd = Gtk.Grid()

				#Label
				templabel_date = Gtk.Label()

				#Create a Nice String with max 16 Signs and three points if longer
				title_unit = str(row[4].encode("utf-8"))
				if len(title_unit) > 16:
					title_unit = title_unit[:16] + "..."

				templabel_date.set_markup("<b><big>" + str(row[3]) + "." + str(row[2]) + "." + str(row[1]) + "</big>\n" + title_unit + "</b>")
				templabel_date.set_justify(Gtk.Justification.LEFT)
				unitbuttonsgrid.attach(templabel_date, 2, 1, 1, 1)

				#Buttons
				#ChangeButton
				changebutton = Gtk.Button()
				changebutton.set_name("button_" + str(row[0]))
				image = Gtk.Image()
				image.set_from_file("icons/gear74.png")
				changebutton.set_size_request(10,10)
				changebutton.set_image(image)				
				#Button to Label
				unitbuttonsgrid_snd.attach(changebutton, 2, 1, 1, 1)
				#Add Action to the Button with id from actual student				
				changebutton.connect("clicked", changeunit, row[0], row[1], row[2], row[3], row[4])

				#DeleteButton
				deletebutton = Gtk.Button()
				deletebutton.set_name("delbutton_" + str(row[0]))
				image = Gtk.Image()
				image.set_from_file("icons/cancel19.png")
				deletebutton.set_size_request(10,10)
				deletebutton.set_image(image)				
				#Button to Label
				unitbuttonsgrid_snd.attach(deletebutton, 3, 1, 1, 1)
				#Add Action to the Button with id from actual student
				deletebutton.connect("clicked", deleteunit, row[0], row[1], row[2], row[3])

				#Spacer
				space = Gtk.Label()
				space.set_text("")
				unitbuttonsgrid.attach(space, 1, 1, 1, 1)
				
				unitbuttonsgrid.attach(unitbuttonsgrid_snd, 2, 2, 1, 1)
				
				#Adding all to the Main-Grid
				newviewgrid.attach(unitbuttonsgrid, startfield_rows, 1, 1, 1)
				
				#Adding all Buttons to all Students
				buttoncounter = 2
				data_students = dataop.getdata(con, "select id from students order by name asc", None)				
				for student in data_students.fetchall():
					#Getting Status of the Student
					cur = con.cursor()			
					unitstat_data = cur.execute("select status from status_stu_unit where unitid=? and studentid=?", (int(row[0]), int(student[0]),))
					
					for counter in unitstat_data.fetchall():
						unitstat = counter[0]
						#Images
						ue_b = Gtk.Image()
						ue_r = Gtk.Image()
						ue_b.set_from_file("icons/quest_black.png")
						ue_r.set_from_file("icons/quest_red.png")

						#OK leaved
						e_b = Gtk.Image()
						e_g = Gtk.Image()
						e_b.set_from_file("icons/ok_black.png")
						e_g.set_from_file("icons/ok_green.png")

						#MIddle good work
						middle_b = Gtk.Image()
						middle_g = Gtk.Image()
						middle_b.set_from_file("icons/middle_black.png")
						middle_g.set_from_file("icons/middle_green.png")

						#One Plus Work
						plus_b = Gtk.Image()
						plus_g = Gtk.Image()
						plus_b.set_from_file("icons/plus_black.png")
						plus_g.set_from_file("icons/plus_green.png")

						#PLusPlus Work
						plusplus_b = Gtk.Image()
						plusplus_g = Gtk.Image()
						plusplus_b.set_from_file("icons/plusplus_black.png")
						plusplus_g.set_from_file("icons/plusplus_green.png")

						#One Minus Work
						minus_b = Gtk.Image()
						minus_g = Gtk.Image()
						minus_b.set_from_file("icons/minus_black.png")
						minus_g.set_from_file("icons/minus_green.png")

						#MinusMinus Work
						minusminus_b = Gtk.Image()
						minusminus_g = Gtk.Image()
						minusminus_b.set_from_file("icons/minusminus_black.png")
						minusminus_g.set_from_file("icons/minusminus_green.png")

						#School-Event
						school_b = Gtk.Image()
						school_g = Gtk.Image()
						school_b.set_from_file("icons/school_black.png")
						school_g.set_from_file("icons/school_green.png")
						
						#Creating all Buttons and actions
						#UE-Button
						button_ue = Gtk.Button()	
						button_ue.set_name("ue")			
						button_ue.set_size_request(5,5)
						button_ue.set_image(ue_b) 	
						

						#E-Button
						button_e = Gtk.Button()		
						button_e.set_name("e")		
						button_e.set_size_request(5,5)
						button_e.set_image(e_b)						


						#Middle-Button
						button_middle = Gtk.Button()		
						button_middle.set_name("mid")	
						button_middle.set_size_request(5,5)
						button_middle.set_image(middle_b)						


						#Plus-Button
						button_plus = Gtk.Button()		
						button_plus.set_name("plus")		
						button_plus.set_size_request(5,5)
						button_plus.set_image(plus_b)	

						#PlusPlus-Button
						button_plusplus = Gtk.Button()		
						button_plusplus.set_name("plusplus")		
						button_plusplus.set_size_request(5,5)
						button_plusplus.set_image(plusplus_b)						


						#Minus-Button
						button_minus = Gtk.Button()		
						button_minus.set_name("minus")		
						button_minus.set_size_request(5,5)
						button_minus.set_image(minus_b)	

						#MinusMinus-Button
						button_minusminus = Gtk.Button()		
						button_minusminus.set_name("minusminus")		
						button_minusminus.set_size_request(5,5)
						button_minusminus.set_image(minusminus_b)					


						#School-Button
						button_school = Gtk.Button()	
						button_school.set_name("school")			
						button_school.set_size_request(5,5)
						button_school.set_image(school_b)		


						#Adding Black or Green/Red Images to the Buttons (depends on the Status of the Student for that Unit)
						#	Status
						#	0	- Unknown
						#	1	- Leave OK		
						#	2	- Schoolreason
						#	3	- MinusMinus
						#	4	- Minus
						#	5	- Middle
						#	6	- Plus
						#	7	- PlusPlus
						if unitstat == 0:
							button_ue.set_image(ue_r)			
						elif unitstat == 1:
							button_e.set_image(e_g)	
						elif unitstat == 2:
							button_school.set_image(school_g)	
						elif unitstat == 3:
							button_minusminus.set_image(minusminus_g)					
						elif unitstat == 4:
							button_minus.set_image(minus_g)
						elif unitstat == 5:
							button_middle.set_image(middle_g)
						elif unitstat == 6:
							button_plus.set_image(plus_g)
						elif unitstat == 7:
							button_plusplus.set_image(plusplus_g)	

						#Adding all Buttons
						#Creating the Grid
						buttonsgrid = Gtk.Grid()
						space1 = Gtk.Label()
						space1.set_text("     ")
						buttonsgrid.attach(space1, 5,1,1,1)
						space2 = Gtk.Label()
						space2.set_text(" ")
						buttonsgrid.attach(space2, 1,3,1,1)
						
						buttonsgrid.attach(button_ue, 1,1,1,1)
						buttonsgrid.attach(button_e, 2,1,1,1)						
						buttonsgrid.attach(button_school, 3,1,1,1)

						buttonsgrid.attach(button_minus, 1,2,1,1)
						buttonsgrid.attach(button_middle, 2,2,1,1)
						buttonsgrid.attach(button_plus, 3,2,1,1)

						buttonsgrid.attach(button_minusminus, 4,1,1,1)
						buttonsgrid.attach(button_plusplus, 4,2,1,1)
				
						#Adding all Actions
						button_ue.connect("clicked", updateUnitStu, int(student[0]), int(row[0]), 0, buttonsgrid)
						button_e.connect("clicked", updateUnitStu, int(student[0]), int(row[0]), 1, buttonsgrid)
						button_middle.connect("clicked", updateUnitStu, int(student[0]), int(row[0]), 5, buttonsgrid)
						button_plus.connect("clicked", updateUnitStu, int(student[0]), int(row[0]), 6, buttonsgrid)	
						button_plusplus.connect("clicked", updateUnitStu, int(student[0]), int(row[0]), 7, buttonsgrid)	
						button_minus.connect("clicked", updateUnitStu, int(student[0]), int(row[0]), 4, buttonsgrid)
						button_minusminus.connect("clicked", updateUnitStu, int(student[0]), int(row[0]), 3, buttonsgrid)						
						button_school.connect("clicked", updateUnitStu, int(student[0]), int(row[0]), 2, buttonsgrid)

						con.commit()

						#Check for Grey-Background
						if buttoncounter % 2 == 0:
							buttonsgrid.override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(0.8, 0.8, 0.8))					

						#Adding Students Buttons
						newviewgrid.attach(buttonsgrid, startfield_rows, buttoncounter, 1, 1)

					#Increase Counter to print and save everything
					buttoncounter = buttoncounter + 1

					#Give all Students-Names every Unit wich is mod 4
				if numb % 4 == 0:
					addingstudents(self, startfield_rows + 1)
					startfield_rows = startfield_rows + 5
					numb = numb + 1
				else:
					startfield_rows = startfield_rows + 1					
					numb = numb + 1	



		#Fill the Grid with all Data from the actual database resp. Class		
		def fillDataGrid(*args):
			#Clear the grid
			for child in newviewgrid.get_children():
				newviewgrid.remove(child)

			#Clear the button-grid
			for child in datagrid_buttons.get_children():
				datagrid_buttons.remove(child)

			#Adding Buttons in Top-Area to add Students or import a csv-List (LATER!!)
			addunit = Gtk.Button.new_with_label("Neue Einheit")
			addunit.connect("clicked", do_addunit)
			datagrid_buttons.attach(addunit, 0, 1, 1, 1)
			
			#Loading the Students
			addingstudents(self, None)
			
			#Loading all Units
			loadingallunits()

			#Show the window		
			window.show_all()

		#Fill the Grid for the first time and call this method to reload
		fillDataGrid()
示例#3
0
	def start(self, classname, builder, window):

		#Databaseconnection
		dataop = DataOp()
		con = dataop.opendatabase(classname)

		#Button Prev/Next student
		def do_prevstu(self, combobox, maxstu):
			if combobox.get_active() > 0:
				combobox.set_active(combobox.get_active() - 1)	
			else:
				combobox.set_active(maxstu - 1)					

		def do_nextstu(self, combobox, maxstu):
			if combobox.get_active() + 1 != maxstu:
				combobox.set_active(combobox.get_active() + 1)	
			else:
				combobox.set_active(0)					

		#Show actual Student
		def updateview(self, combobox, grid):
			#Clear the Grid
			for child in grid.get_children():
				grid.remove(child)

			tree_iter = combobox.get_active_iter()
			model = combobox.get_model()
			id, name = model[tree_iter][:2]
			#id = StudentId
			#Add Student Name to Grid
			stuname_label = Gtk.Label()
			stuname_label.set_markup("\n<big><b>" + name + "</b></big>")
			grid.attach(stuname_label, 0, 0, 1, 1)

			#Counting all Status-Infos
			#	Status
			#	0	- Unknown
			#	1	- Leave OK		
			#	2	- Schoolreason
			#	3	- MinusMinus
			#	4	- Minus
			#	5	- Middle
			#	6	- Plus
			#	7	- PlusPlus
			#
			unknown = dataop.getdata(con, "select count(status) from status_stu_unit where studentid=? and status=0", id).fetchone()[0]
			leaveok = dataop.getdata(con, "select count(status) from status_stu_unit where studentid=? and status=1", id).fetchone()[0]
			school = dataop.getdata(con, "select count(status) from status_stu_unit where studentid=? and status=2", id).fetchone()[0]
			minusminus = dataop.getdata(con, "select count(status) from status_stu_unit where studentid=? and status=3", id).fetchone()[0]
			minus = dataop.getdata(con, "select count(status) from status_stu_unit where studentid=? and status=4", id).fetchone()[0]
			mid = dataop.getdata(con, "select count(status) from status_stu_unit where studentid=? and status=5", id).fetchone()[0]
			plus = dataop.getdata(con, "select count(status) from status_stu_unit where studentid=? and status=6", id).fetchone()[0]
			plusplus = dataop.getdata(con, "select count(status) from status_stu_unit where studentid=? and status=7", id).fetchone()[0]
			
			statigrid = Gtk.Grid()
			statigrid_allstati = Gtk.Grid()
			status_label = Gtk.Label()
			status_label.set_markup("\n<b><big>Übersicht         </big></b>\n")
			statigrid.attach(status_label, 0, 0, 1, 1)

			#Images			
			ue_r = Gtk.Image()
			ue_r.set_from_file("icons/quest_red.png")			
			lab_ue_count = Gtk.Label()
			lab_ue_count.set_markup(" <big><b>: " + str(unknown) + "</b></big>")
			statigrid_allstati.attach(ue_r, 0, 0, 1, 1)
			statigrid_allstati.attach(lab_ue_count, 1, 0, 1, 1)

			#OK leaved
			e_g = Gtk.Image()
			e_g.set_from_file("icons/ok_green.png")
			e_g_ue_count = Gtk.Label()
			e_g_ue_count.set_markup(" <big><b>: " + str(leaveok) + "</b></big>")
			statigrid_allstati.attach(e_g, 0, 1, 1, 1)
			statigrid_allstati.attach(e_g_ue_count, 1, 1, 1, 1)

			#School-Event
			school_g = Gtk.Image()
			school_g.set_from_file("icons/school_green.png")
			school_g_ue_count = Gtk.Label()
			school_g_ue_count.set_markup(" <big><b>: " + str(school) + "</b></big>")
			statigrid_allstati.attach(school_g, 0, 2, 1, 1)
			statigrid_allstati.attach(school_g_ue_count, 1, 2, 1, 1)

			#MIddle good work
			middle_g = Gtk.Image()
			middle_g.set_from_file("icons/middle_green.png")
			middle_g_ue_count = Gtk.Label()
			middle_g_ue_count.set_markup(" <big><b>: " + str(mid) + "</b></big>")
			statigrid_allstati.attach(middle_g, 0, 3, 1, 1)
			statigrid_allstati.attach(middle_g_ue_count, 1, 3, 1, 1)

			#One Plus Work
			plus_g = Gtk.Image()
			plus_g.set_from_file("icons/plus_green.png")
			plus_g_ue_count = Gtk.Label()
			plus_g_ue_count.set_markup(" <big><b>: " + str(plus) + "</b></big>")
			statigrid_allstati.attach(plus_g, 0, 4, 1, 1)
			statigrid_allstati.attach(plus_g_ue_count, 1, 4, 1, 1)

			#PLusPlus Work
			plusplus_g = Gtk.Image()		
			plusplus_g.set_from_file("icons/plusplus_green.png")
			plusplus_g_ue_count = Gtk.Label()
			plusplus_g_ue_count.set_markup(" <big><b>: " + str(plusplus) + "</b></big>")
			spacer = Gtk.Label("   ")
			statigrid_allstati.attach(spacer, 2, 4, 1, 1)
			statigrid_allstati.attach(plusplus_g, 3, 4, 1, 1)
			statigrid_allstati.attach(plusplus_g_ue_count, 4, 4, 1, 1)


			#One Minus Work
			minus_g = Gtk.Image()
			minus_g.set_from_file("icons/minus_green.png")
			minus_g_ue_count = Gtk.Label()
			minus_g_ue_count.set_markup(" <big><b>: " + str(minus) + "</b></big>")
			statigrid_allstati.attach(minus_g, 0, 5, 1, 1)
			statigrid_allstati.attach(minus_g_ue_count, 1, 5, 1, 1)

			#PLusPlus Work
			minusminus_g = Gtk.Image()
			minusminus_g.set_from_file("icons/minusminus_green.png")
			minusminus_g_ue_count = Gtk.Label()
			minusminus_g_ue_count.set_markup(" <big><b>: " + str(minusminus) + "</b></big>")
			spacer = Gtk.Label("   ")
			statigrid_allstati.attach(spacer, 2, 5, 1, 1)
			statigrid_allstati.attach(minusminus_g, 3, 5, 1, 1)
			statigrid_allstati.attach(minusminus_g_ue_count, 4, 5, 1, 1)

			statigrid.attach(statigrid_allstati, 0, 1, 1, 1)
						
			#Notes to Grid
			notegrid = Gtk.Grid()
			#notegrid_allnotes = Gtk.Grid()
			notegrid_label = Gtk.Label()
			notegrid_label.set_markup("   \n<b><big>Noten        </big></b>\n")
			notegrid.attach(notegrid_label, 0, 0, 1, 1)
			#Calculate the Notes
			cur = con.cursor()
			#Calculating all Downcategories and save them to downcat with the Categorie-ID
			
			#Step One - Getting all Upper Cats
			data_upcats = cur.execute("select id, weight, name from catup order by weight desc")
			rowcounter = 1
			columncounter = 0
			finalnote = []
			for upcats in data_upcats.fetchall():
				#print "Upcat: " + str(upcats[2].encode("utf-8"))
				#print "Weight: " + str(upcats[1])
				#print "ID: " + str(upcats[0])
				uplabel = Gtk.Label()
				uplabel.set_markup("<b><big>" + upcats[2].encode("utf-8") + " (" + str(upcats[1]) + ")</big></b>      ")
				notegrid.attach(uplabel, columncounter, rowcounter, 1, 1)

				rowcounter = rowcounter + 1
				#Step Two: Get all Down-Cats with this Upcat-ID
				data_downcats = cur.execute("select id, weight, name from catdown where upcat=?", (int(upcats[0]), ))
				downcats_notes = []
				for downcats in data_downcats.fetchall():					
					#print "Downcat: " + str(downcats[2].encode("utf-8"))
					#print "Weight: " + str(downcats[1])
					#print "ID: " + str(downcats[0])
					downlabel = Gtk.Label()
					downlabel.set_markup("<b>" + downcats[2].encode("utf-8") + " (" + str(downcats[1]) + ")</b>     ")
					notegrid.attach(downlabel, columncounter, rowcounter, 1, 1)								
					#Step Three: Get all Notes from this DownCat and Upcat from actual Student
					data_notes = cur.execute("select id,weight ,name from notes where upcat=? and downcat=?", (upcats[0], downcats[0]),)
					weight_note = 0
					note_calc = 0
					for notes in data_notes.fetchall():
						#print "Notes: " + str(notes[2].encode("utf-8"))
						#print "Weight: " + str(notes[1])
						#print "ID: " + str(notes[0])
						notes_info = Gtk.Label()
						notes_info.set_markup("<b>" + notes[2].encode("utf-8") + " (" + str(notes[1]) + "):</b>    ")
						notegrid.attach(notes_info, columncounter + 1, rowcounter, 1, 1)																				
						#Step Four: Getting the final note
						try:
							data_stunote = cur.execute("select id, note from notes_student where studentid=? and notesid=? and note!=16.0", (id, notes[0],)).fetchone()[1]						
							#
							#	SPECIAL: All Notes with 16.0 will not be calculatet!!!! Here beware by other Gradesystems!!!
							#
							#
							note_stu_label = Gtk.Label()
							note_stu_label.set_markup("<b>" + str(data_stunote) + "</b>     ")
							notegrid.attach(note_stu_label, columncounter + 2, rowcounter, 1, 1)
							rowcounter = rowcounter + 1															
							weight_note = weight_note + notes[1]
							note_calc = note_calc + data_stunote * notes[1]
						except:
							rowcounter = rowcounter + 1
					
					#Saving all Downcategorie-Notes ID WEIGHT NOTE
					if weight_note > 0:
						downcats_notes.append([downcats[0], downcats[1], round(note_calc / weight_note, 2)])
						note_down = Gtk.Label()
						note_down.set_markup("<b>Gesamt UnKa: " + str(round(note_calc / weight_note, 2)) + "</b>")
						notegrid.attach(note_down, columncounter + 1, rowcounter, 1, 1)
				
					rowcounter = rowcounter + 1	

				#Calculating final Note for Uppercat
				note = 0
				weight = 0
				for finalupcat in downcats_notes:
					note = note + finalupcat[2] * finalupcat[1]
					weight = weight + finalupcat[1]

				#If a Note was calced than save it as Uppercat-Note
				if weight > 0:
					finalnote.append([upcats[1], round(note / weight, 2)])
					note_up = Gtk.Label()
					note_up.set_markup("\n<b>Gesamt ObKa: " + str(round(note / weight, 2)) + "</b>")
					notegrid.attach(note_up, columncounter, rowcounter, 1, 1)
					
				columncounter = columncounter + 3	
				rowcounter = 1

			#Last Notecalc: Final Note of the Student
			finalnotecalc = 0
			weightfinal = 0
			for finalnoteupcat in finalnote:
				finalnotecalc = finalnotecalc + finalnoteupcat[1] * finalnoteupcat[0]
				weightfinal = weightfinal + finalnoteupcat[0]

			#If all Notes are done: Save the final Note of the Student
			if weight > 0:
				studentfinalnote = round(finalnotecalc / weightfinal, 2)
				finallabelnote = Gtk.Label()
				finallabelnote.set_markup("<b><big>Abschlussnote: " + str(studentfinalnote) + "</big></b>")
				
				notegrid.attach(finallabelnote, columncounter + 1, 0, 1, 1)				

			#All Notes to Note-Grid
			#notegrid.attach(notegrid_allnotes, 0, 2, 1, 1)

			#All Grids to Main-Grid
			grid.attach(notegrid, 1, 1, 1, 1)
			grid.attach(statigrid, 0, 1, 1, 1)

			#Reload the Window
			window.show_all()

		#Fill the Grid with all Data from the actual database resp. Class		
		def fillDataGrid(*args):
			
			#Get all the Grids :)
			datagrid_buttons = builder.get_object("datagrid_buttons")				
			newviewgrid = builder.get_object("datagrid")

			#Clear the grid
			for child in newviewgrid.get_children():
				newviewgrid.remove(child)

			#Clear the button-grid
			for child in datagrid_buttons.get_children():
				datagrid_buttons.remove(child)			
			
			#StudentCombobox			
			students = Gtk.ListStore(int, str)			
			datas = dataop.getdata(con, "select id, name, prename from students order by 2 asc", None)
			#Startfield of Rows
			stucounter = 0
			for row in datas.fetchall():
				students.append([row[0], str(row[1].encode("utf-8")) + ", " + str(row[2].encode("utf-8"))])
				stucounter = stucounter + 1
			
			combobox = Gtk.ComboBox.new_with_model_and_entry(students)			
			combobox.set_entry_text_column(1)
			combobox.set_active(0)
			combobox.connect("changed", updateview, combobox, newviewgrid)
			datagrid_buttons.attach(combobox, 1, 1, 1, 1)

			#Adding Next-Button
			prevstu = Gtk.Button.new_with_label("Vorheriger")
			nextstu = Gtk.Button("Nächster")			
			
			nextstu.connect("clicked", do_nextstu, combobox, stucounter)
			prevstu.connect("clicked", do_prevstu, combobox, stucounter)
	
			datagrid_buttons.attach(prevstu, 0, 1, 1, 1)
			datagrid_buttons.attach(nextstu, 2, 1, 1, 1)

			#Update View with first Student in List
			updateview(None, combobox, newviewgrid)
			#Show the window		
			window.show_all()

		#Fill the Grid for the first time and call this method to reload
		fillDataGrid()
	def start(self, classname, builder, window):

		#Databaseconnection
		dataop = DataOp()
		con = dataop.opendatabase(classname)

		#Returns all UpperCat-Notes and the Final-Note as an array
		#Last Entry will be the Finalnote (if there is one :) )		
		def calculateOkFinal(id):
			dataarray = []
			cur = con.cursor()
			#Calculating all Downcategories and save them to downcat with the Categorie-ID
			
			#Step One - Getting all Upper Cats
			data_upcats = cur.execute("select id, weight, name from catup order by weight desc")
			rowcounter = 1
			columncounter = 0
			finalnote = []
			for upcats in data_upcats.fetchall():
				#Step Two: Get all Down-Cats with this Upcat-ID
				data_downcats = cur.execute("select id, weight, name from catdown where upcat=?", (int(upcats[0]), ))
				downcats_notes = []
				for downcats in data_downcats.fetchall():					
					#Step Three: Get all Notes from this DownCat and Upcat from actual Student
					data_notes = cur.execute("select id,weight ,name from notes where upcat=? and downcat=?", (upcats[0], downcats[0]),)
					weight_note = 0
					note_calc = 0
					for notes in data_notes.fetchall():
						#Step Four: Getting the final note
						try:
							data_stunote = cur.execute("select id, note from notes_student where studentid=? and notesid=? and note!=16.0", (id, notes[0],)).fetchone()[1]						
							#
							#	SPECIAL: All Notes with 16.0 will not be calculatet!!!! Here beware by other Gradesystems!!!
							#
							#
							weight_note = weight_note + notes[1]
							note_calc = note_calc + data_stunote * notes[1]
						except:
							rowcounter = rowcounter + 1
					
					#Saving all Downcategorie-Notes ID WEIGHT NOTE
					if weight_note > 0:
						downcats_notes.append([downcats[0], downcats[1], round(note_calc / weight_note, 2)])

				#Calculating final Note for Uppercat
				note = 0
				weight = 0
				for finalupcat in downcats_notes:
					note = note + finalupcat[2] * finalupcat[1]
					weight = weight + finalupcat[1]

				#If a Note was calced than save it as Uppercat-Note
				if weight > 0:
					finalnote.append([upcats[1], round(note / weight, 2)])		
					dataarray.append(round(note / weight, 2))			
				
			#Last Notecalc: Final Note of the Student
			finalnotecalc = 0
			weightfinal = 0
			for finalnoteupcat in finalnote:
				finalnotecalc = finalnotecalc + finalnoteupcat[1] * finalnoteupcat[0]
				weightfinal = weightfinal + finalnoteupcat[0]

			#If all Notes are done: Save the final Note of the Student
			if weight > 0:
				dataarray.append(round(finalnotecalc / weightfinal, 2))		
				
			return dataarray

		#Returns an Array of all counted data
		def gettingCounts(studentid):
			dataarray = []
			unknown = dataarray.append(dataop.getdata(con, "select count(status) from status_stu_unit where studentid=? and status=0", studentid).fetchone()[0])
			leaveok = dataarray.append(dataop.getdata(con, "select count(status) from status_stu_unit where studentid=? and status=1", studentid).fetchone()[0])
			school = dataarray.append(dataop.getdata(con, "select count(status) from status_stu_unit where studentid=? and status=2", studentid).fetchone()[0])
			minusminus = dataarray.append(dataop.getdata(con, "select count(status) from status_stu_unit where studentid=? and status=3", studentid).fetchone()[0])
			minus = dataarray.append(dataop.getdata(con, "select count(status) from status_stu_unit where studentid=? and status=4", studentid).fetchone()[0])
			mid = dataarray.append(dataop.getdata(con, "select count(status) from status_stu_unit where studentid=? and status=5", studentid).fetchone()[0])
			plus = dataarray.append(dataop.getdata(con, "select count(status) from status_stu_unit where studentid=? and status=6", studentid).fetchone()[0])
			plusplus = dataarray.append(dataop.getdata(con, "select count(status) from status_stu_unit where studentid=? and status=7", studentid).fetchone()[0])
			
			return dataarray

		#Fill the Grid with all Data from the actual database resp. Class		
		def fillDataGrid(*args):
			
			#Get all the Grids :)
			datagrid_buttons = builder.get_object("datagrid_buttons")				
			newviewgrid = builder.get_object("datagrid")

			#Clear the grid
			for child in newviewgrid.get_children():
				newviewgrid.remove(child)

			#Clear the button-grid
			for child in datagrid_buttons.get_children():
				datagrid_buttons.remove(child)		

			#Adding Column-Infos
			#Images			
			ue_r = Gtk.Image()
			ue_r.set_from_file("icons/quest_red.png")	
			newviewgrid.attach(ue_r, 4, 0, 1, 1)

			#OK leaved
			e_g = Gtk.Image()
			e_g.set_from_file("icons/ok_green.png")
			newviewgrid.attach(e_g, 6, 0, 1, 1)

			#School-Event
			school_g = Gtk.Image()
			school_g.set_from_file("icons/school_green.png")			
			newviewgrid.attach(school_g, 8, 0, 1, 1)

			#PLusPlus Work
			minusminus_g = Gtk.Image()
			minusminus_g.set_from_file("icons/minusminus_green.png")
			newviewgrid.attach(minusminus_g, 10, 0, 1, 1)

			#One Minus Work
			minus_g = Gtk.Image()
			minus_g.set_from_file("icons/minus_green.png")
			newviewgrid.attach(minus_g, 12, 0, 1, 1)

			#MIddle good work
			middle_g = Gtk.Image()
			middle_g.set_from_file("icons/middle_green.png")
			newviewgrid.attach(middle_g, 14, 0, 1, 1)

			#One Plus Work
			plus_g = Gtk.Image()
			plus_g.set_from_file("icons/plus_green.png")			
			newviewgrid.attach(plus_g, 16, 0, 1, 1)

			#PLusPlus Work
			plusplus_g = Gtk.Image()		
			plusplus_g.set_from_file("icons/plusplus_green.png")
			newviewgrid.attach(plusplus_g, 18, 0, 1, 1)

			
  			#Getting UpCats
  			cur = con.cursor()
  			data_upcats = cur.execute("select short from catup order by weight desc")
  			counter = 0
  			for upcats in data_upcats.fetchall():
  				label_ok = Gtk.Label()
  				label_ok.set_markup("<b>" + upcats[0].encode("utf-8") + "</b>")
  				newviewgrid.attach(label_ok, counter + 20, 0, 1, 1)
  				counter = counter + 2

  			#Label Finalnote
			label_note = Gtk.Label()
			label_note.set_markup("<b>Abschlussnote</b>")
  			newviewgrid.attach(label_note, counter + 22, 0, 1, 1)

			#Adding Spacer
			for i in xrange(3,23 + counter,2):
  				templabel = Gtk.Label("     ")
  				newviewgrid.attach(templabel, i, 0, 1, 1)
			
			#Adding Studentsnames - Postname, Prenames, Numbers and Buttons
			datas = dataop.getdata(con, "select id, name, prename, mail from students order by 2 asc", None)
			#Startfield of Rows
			startfield_rows = 1
			for row in datas.fetchall():
				templabel_numbers = Gtk.Label()
				templabel_postname = Gtk.Label()
				templabel_prename = Gtk.Label()

				templabel_numbers.set_markup("     <b><big>" + str(startfield_rows) + ".</big></b>  ")
				templabel_postname.set_markup("<b><big>" + row[1].encode("utf-8") + "</big></b> ")
				templabel_prename.set_markup("<b><big>" + row[2].encode("utf-8") + "</big></b> ")
				
				#COLOR 0-65535 Gdk.Color(RED, GREEN, BLUE)
				if startfield_rows % 2 != 0:
					templabel_postname.modify_bg(0, Gdk.Color(52000, 52000, 52000))
					templabel_prename.modify_bg(0, Gdk.Color(52000, 52000, 52000))
					templabel_numbers.modify_bg(0, Gdk.Color(52000, 52000, 52000))

				#Getting the Students Notes notes[LAST] = final notes, all before UpperCats
				notes = calculateOkFinal(row[0])
				upcatcount = 0
				cattogo = len(notes) - 1
				for notes_to_label in range(cattogo):
					upcattemp = Gtk.Label(notes[notes_to_label])
					if startfield_rows % 2 != 0:
						upcattemp.modify_bg(0, Gdk.Color(52000, 52000, 52000))
					
					newviewgrid.attach(upcattemp, 20 + upcatcount, startfield_rows, 1, 1)
					upcatcount = upcatcount + 2

				#Adding Final Note
				if cattogo > 0:
					finalnote = Gtk.Label()
					finalnote.set_markup("<b>" + str(notes[cattogo]) + "</b>")
					if startfield_rows % 2 != 0:
						finalnote.modify_bg(0, Gdk.Color(52000, 52000, 52000))

					newviewgrid.attach(finalnote, 22 + upcatcount, startfield_rows, 1, 1)

				#Make the lines grey if 2nd
				if startfield_rows % 2 != 0:
					templabel_postname.modify_bg(0, Gdk.Color(52000, 52000, 52000))
					templabel_prename.modify_bg(0, Gdk.Color(52000, 52000, 52000))
					templabel_numbers.modify_bg(0, Gdk.Color(52000, 52000, 52000))

				#Adding Grey or White Spacers
				for i in xrange(3,23 + counter,2):
	  				templabel = Gtk.Label("     ")
	  				if startfield_rows % 2 != 0:
	  					templabel.modify_bg(0, Gdk.Color(52000, 52000, 52000))	
	  				
	  				newviewgrid.attach(templabel, i, startfield_rows, 1, 1)

	  			#Adding Countet Data
	  			counts = gettingCounts(row[0])
	  			rowspacer = 4
	  			for countet in counts:
	  				templabel = Gtk.Label(str(countet))
	  				if startfield_rows % 2 != 0:
	  					templabel.modify_bg(0, Gdk.Color(52000, 52000, 52000))	
	  				
	  				newviewgrid.attach(templabel, rowspacer, startfield_rows, 1, 1)
	  				rowspacer = rowspacer + 2

				newviewgrid.attach(templabel_postname, 1, startfield_rows, 1, 1)
				newviewgrid.attach(templabel_prename, 2, startfield_rows, 1, 1)
				newviewgrid.attach(templabel_numbers, 0, startfield_rows, 1, 1)
				startfield_rows = startfield_rows + 1

			#Show the window		
			window.show_all()

		#Fill the Grid for the first time and call this method to reload
		fillDataGrid()
	def start(self, classname, builder, window):

		#Databaseconnection
		dataop = DataOp()
		con = dataop.opendatabase(classname)

		######################################################################################
		#
		#
		#
		#				CATEGORIE AREA START
		#	
		######################################################################################

		#Saving new Upper-Categorie
		def savecatup(self, noteupwindow, catmanagewindow):
			#Getting Data from the Window
			name = builder.get_object("name").get_text().decode("utf-8")
			short = builder.get_object("short").get_text().decode("utf-8")
			weight = builder.get_object("weight").get_text().decode("utf-8")

			if len(name) == 0 or len(short) == 0 or len(weight) == 0:
				messWindow = Tkinter.Tk()
				messWindow.wm_withdraw()
				result = tkMessageBox.showinfo("Falsche Daten", "Bitte Daten korrekt eintragen!")
				messWindow.destroy()
			else:
				cur = con.cursor()
				#Count existing Units in the Datbase
				newid = dataop.getdata(con, "select count(id) from catup", None)
				if newid.fetchone()[0] == 0:
					try:
						cur.execute("insert into catup(id, name, short, weight) values (0, ?, ?, ?);", (name, short, int(weight),))
					except:
						messWindow = Tkinter.Tk()
						messWindow.wm_withdraw()
						result = tkMessageBox.showinfo("Falsche Daten", "Bitte bei Gewicht nur ganze Zahlen eingeben!")
						messWindow.destroy()
				else:
					try:
						cur.execute("insert into catup(id, name, short, weight) values ((SELECT max(id) FROM catup) + 1, ?, ?, ?);", (name, short, int(weight),))
					except:
						messWindow = Tkinter.Tk()
						messWindow.wm_withdraw()
						result = tkMessageBox.showinfo("Falsche Daten", "Bitte bei Gewicht nur ganze Zahlen eingeben!")
						messWindow.destroy()

				con.commit()
				noteupwindow.destroy()				

			#Reload the Managewindow
			printupcats(catmanagewindow)
			printdowncats(catmanagewindow)
				
		#Saving new Down-Categorie
		def savecatdown(self, notedownwindow, catmanagewindow):
			#Getting Data from the Window
			name = builder.get_object("name").get_text().decode("utf-8")
			short = builder.get_object("short").get_text().decode("utf-8")
			weight = builder.get_object("weight").get_text().decode("utf-8")
			uppercatid = builder.get_object("comboupcat").get_active_id()
			
			
			if len(name) == 0 or len(short) == 0 or len(weight) == 0:
				messWindow = Tkinter.Tk()
				messWindow.wm_withdraw()
				result = tkMessageBox.showinfo("Falsche Daten", "Bitte Daten korrekt eintragen!")
				messWindow.destroy()
			else:
				cur = con.cursor()
				#Count existing Units in the Datbase
				newid = dataop.getdata(con, "select count(id) from catdown", None)
				if newid.fetchone()[0] == 0:
					try:
						cur.execute("insert into catdown(id, upcat, name, short, weight) values (0, ?, ?, ?, ?);", (int(uppercatid), name, short, int(weight),))
					except:
						messWindow = Tkinter.Tk()
						messWindow.wm_withdraw()
						result = tkMessageBox.showinfo("Falsche Daten", "Bitte bei Gewicht nur ganze Zahlen eingeben oder Oberkategorie anlegen!")
						messWindow.destroy()
				else:
					try:
						cur.execute("insert into catdown(id, upcat, name, short, weight) values ((SELECT max(id) FROM catdown) + 1, ?, ?, ?, ?);", (int(uppercatid), name, short, int(weight),))
					except:
						messWindow = Tkinter.Tk()
						messWindow.wm_withdraw()
						result = tkMessageBox.showinfo("Falsche Daten", "Bitte bei Gewicht nur ganze Zahlen eingeben oder Oberkategorie anlegen!")
						messWindow.destroy()

				con.commit()
				notedownwindow.destroy()				

			#Reload the Managewindow
			printupcats(catmanagewindow)
			printdowncats(catmanagewindow)


		#Showing NOteUpAdd Window to prepare new Upper-Cat
		def addcat_up(self, managewindow):
			builder.add_from_file("gui/NoteUpPop.glade")
			addnoteup = builder.get_object("addnoteup")
						
			#Get Button-Object
			savedata = builder.get_object("addnoteup_save")
			savedata.connect("clicked", savecatup, addnoteup, managewindow)
			#Show New-Student-Popup
			addnoteup.show_all()

		#Showing NOteDownAdd Window to prepare new Down-Cat
		def addcat_down(self, managewindow):
			builder.add_from_file("gui/NoteDownPop.glade")
			addnotedown = builder.get_object("addnotedown")
				
			#Get Button-Object
			savedata = builder.get_object("savenotedown")
			savedata.connect("clicked", savecatdown, addnotedown, managewindow)

			#Loading all Upper-Cats and ad them to a Combo-Box
			uppeercats = builder.get_object("comboupcat")		

			allupcat = dataop.getdata(con, "select id, name from catup order by weight desc", None)
			
			for upcats in allupcat.fetchall():
				uppeercats.append(str(upcats[0]), upcats[1].encode("utf-8"))				

			uppeercats.set_active(0)	

			#Show New-Student-Popup
			addnotedown.show_all()

		#Close the manage-Window
		def closemanagewindow(self, managewindow):
			managewindow.destroy()

		#Updating Changes Catup and reload Grid
		def savechanges_catup(self, catup_changewindow, managewindow, id):
			name = builder.get_object("name").get_text().decode("utf-8")
			short = builder.get_object("short").get_text().decode("utf-8")
			weight = builder.get_object("weight").get_text().decode("utf-8")

			if len(name) == 0 or len(short) == 0 or len(weight) == 0:
				messWindow = Tkinter.Tk()
				messWindow.wm_withdraw()
				result = tkMessageBox.showinfo("Falsche Daten", "Bitte Daten korrekt eintragen!")
				messWindow.destroy()
			else:
				cur = con.cursor()
				#Count existing Units in the Datbase
				try:
					cur.execute("update catup set name=?, short=?, weight=? where id=?", (name, short, int(weight), id,))
				except:
					messWindow = Tkinter.Tk()
					messWindow.wm_withdraw()
					result = tkMessageBox.showinfo("Falsche Daten", "Bitte bei Gewicht nur ganze Zahlen eingeben!")
					messWindow.destroy()

				con.commit()
				catup_changewindow.destroy()
				printupcats(managewindow)
				printdowncats(managewindow)
				fillDataGrid()

		#Updating Changes Catdown and reload Grid
		def savechanges_catdown(self, catdown_changewindow, managewindow, id):
			name = builder.get_object("name").get_text().decode("utf-8")
			short = builder.get_object("short").get_text().decode("utf-8")
			weight = builder.get_object("weight").get_text().decode("utf-8")
			uppercatid = builder.get_object("comboupcat").get_active_id()

			if len(name) == 0 or len(short) == 0 or len(weight) == 0:
				messWindow = Tkinter.Tk()
				messWindow.wm_withdraw()
				result = tkMessageBox.showinfo("Falsche Daten", "Bitte Daten korrekt eintragen!")
				messWindow.destroy()
			else:
				cur = con.cursor()
				#Count existing Units in the Datbase
				try:
					cur.execute("update catdown set name=?, short=?, weight=?, upcat=? where id=?", (name, short, int(weight), uppercatid, id,))
				except:
					messWindow = Tkinter.Tk()
					messWindow.wm_withdraw()
					result = tkMessageBox.showinfo("Falsche Daten", "Bitte bei Gewicht nur ganze Zahlen eingeben!")
					messWindow.destroy()

				con.commit()
				catdown_changewindow.destroy()
				printupcats(managewindow)
				printdowncats(managewindow)
				fillDataGrid()

		#Starting workflow for changing a Upper-Categorie
		def changeupcat(self, id, managewindow, name, short, weight):
			builder.add_from_file("gui/NoteUpPop.glade")
			addnoteupchange = builder.get_object("addnoteup")
						
			builder.get_object("name").set_text(name)
			builder.get_object("short").set_text(short)
			builder.get_object("weight").set_text(str(weight))

			#Get Button-Object
			savedata = builder.get_object("addnoteup_save")
			savedata.connect("clicked", savechanges_catup, addnoteupchange, managewindow, id)
			#Show New-Student-Popup
			addnoteupchange.show_all()

		#WORKFLOW FOR DOWN CATEGORIES
		def changedowncat(self, id, idup, managewindow, name, short, weight):
			builder.add_from_file("gui/NoteDownPop.glade")
			addnotedownchange = builder.get_object("addnotedown")
						
			builder.get_object("name").set_text(name)
			builder.get_object("short").set_text(short)
			builder.get_object("weight").set_text(str(weight))
			#Loading all Upper-Cats and ad them to a Combo-Box
			uppeercats = builder.get_object("comboupcat")		

			allupcat = dataop.getdata(con, "select id, name from catup order by weight desc", None)
			
			for upcats in allupcat.fetchall():
				uppeercats.append(str(upcats[0]), upcats[1].encode("utf-8"))				

			#Select the active Upper-ID
			uppeercats.set_active_id(str(idup))	
			#Get Button-Object
			savedata = builder.get_object("savenotedown")
			savedata.connect("clicked", savechanges_catdown, addnotedownchange, managewindow, id)
			#Show New-Student-Popup
			addnotedownchange.show_all()

		#Delete a Upper Cateogire and all Data wich is connected to (WARNGIN! Deletes Down-Cats and Notes!!! Check dataop.py)
		def delcatup(self, id, managewindow, name):
			messWindow = Tkinter.Tk()
			messWindow.wm_withdraw()
			result = tkMessageBox.askokcancel("Warnung", "ACHTUNG! Alle Daten der Kategorie  " + name + " werden UNWIDERRUFLICH gelöscht. Auch alle Noten und Unterkategorien! Fortfahren?")
			
			#Check for deleting or not
			if result == True:
				#Delete True - Delete the Uppercat and reload the Grid
				dataop.deleteCatUp(con, id)
				messWindow.destroy()
				#Reload Upper-Categories
				printupcats(managewindow)
				printdowncats(managewindow)
			else:
				messWindow.destroy()

		def delcatdown(self, id, managewindow, name):
			messWindow = Tkinter.Tk()
			messWindow.wm_withdraw()
			result = tkMessageBox.askokcancel("Warnung", "ACHTUNG! Alle Daten der Kategorie  " + name + " werden UNWIDERRUFLICH gelöscht. Auch alle Noten! Fortfahren?")
			
			#Check for deleting or not
			if result == True:
				#Delete True - Delete the Uppercat and reload the Grid
				dataop.deleteCatDown(con, id)
				messWindow.destroy()
				#Reload Upper-Categories
				printupcats(managewindow)
				printdowncats(managewindow)				
			else:
				messWindow.destroy()

		#Print all Upper Categories
		def printupcats(managewindow):
			#Adding all Upper Categories
			upgrid = builder.get_object("catup_grid")

			#Clear the UpCatGrid
			for child in upgrid.get_children():
				upgrid.remove(child)

			#Adding all Uppercategories to the Grid
			datas = dataop.getdata(con, "select id, name, short, weight from catup order by weight desc", None)
			
			counter = 1
			for row in datas.fetchall():
				templabel_counter = Gtk.Label()
				templabel_counter.set_markup("<b>" + "  " + str(counter) + ".</b>")
				templabel_name = Gtk.Label()
				templabel_name.set_markup("   <b>" + str(row[1].encode("utf-8")) + "</b>")
				templabel_catshort = Gtk.Label()
				templabel_catshort.set_markup("  <b>" + str(row[2].encode("utf-8")) + "</b>")
				templabel_catweight = Gtk.Label()
				templabel_catweight.set_markup("  <b>" + str(row[3]) + "</b>    ")

				#Buttons to change/delete the Categories
				#ChangeButton
				changebutton = Gtk.Button()
				image = Gtk.Image()
				image.set_from_file("icons/gear74.png")
				changebutton.set_size_request(10,10)
				changebutton.set_image(image)				
				#Button to Label
				upgrid.attach(changebutton, 5, counter, 1, 1)
				#Add Action to the Button with id from actual student				
				changebutton.connect("clicked", changeupcat, row[0], managewindow, str(row[1].encode("utf-8")), str(row[2].encode("utf-8")), row[3])

				#DeleteButton
				deletebutton = Gtk.Button()
				image = Gtk.Image()
				image.set_from_file("icons/cancel19.png")
				deletebutton.set_size_request(10,10)
				deletebutton.set_image(image)				
				#Button to Label
				upgrid.attach(deletebutton, 6, counter, 1, 1)
				#Add Action to the Button with id from actual student
				deletebutton.connect("clicked", delcatup, row[0], managewindow, str(row[1].encode("utf-8")))

				upgrid.attach(templabel_counter, 1, counter, 1, 1)
				upgrid.attach(templabel_name, 2, counter, 1, 1)
				upgrid.attach(templabel_catshort, 3, counter, 1, 1)
				upgrid.attach(templabel_catweight, 4, counter, 1, 1)
				counter = counter + 1
				managewindow.show_all()

		#Print all Upper Categories
		def printdowncats(managewindow):
			#Adding all Upper Categories
			downgrid = builder.get_object("catdown_grid")

			#Clear the UpCatGrid
			for child in downgrid.get_children():
				downgrid.remove(child)

			#Adding all Uppercategories to the Grid
			datas = dataop.getdata(con, "select id, name, short, weight, upcat from catdown order by weight desc", None)
			
			counter = 1
			for row in datas.fetchall():
				#Getting Name of upper Categorie
				uppercatname = dataop.getdata(con, "select name from catup where id=?", row[4]).fetchone()[0]
				templabel_counter = Gtk.Label()
				templabel_counter.set_markup("<b>" + "  " + str(counter) + ".</b>")
				templabel_name = Gtk.Label()
				templabel_name.set_markup("   <b>" + str(row[1].encode("utf-8")) + "</b>")
				templabel_catshort = Gtk.Label()
				templabel_catshort.set_markup("  <b>" + str(row[2].encode("utf-8")) + "</b>")
				templabel_catweight = Gtk.Label()
				templabel_catweight.set_markup("  <b>" + str(row[3]) + "</b>    ")
				templabel_in = Gtk.Label()
				templabel_in.set_markup(" in ")
				templabel_uppercat = Gtk.Label()
				templabel_uppercat.set_markup("<b>" + uppercatname + "</b>    ")

				#Buttons to change/delete the Categories
				#ChangeButton
				changebutton = Gtk.Button()
				image = Gtk.Image()
				image.set_from_file("icons/gear74.png")
				changebutton.set_size_request(10,10)
				changebutton.set_image(image)				
				#Button to Label
				downgrid.attach(changebutton, 7, counter, 1, 1)
				#Add Action to the Button with id from actual student				
				changebutton.connect("clicked", changedowncat, row[0], row[4], managewindow, str(row[1].encode("utf-8")), str(row[2].encode("utf-8")), row[3])

				#DeleteButton
				deletebutton = Gtk.Button()
				image = Gtk.Image()
				image.set_from_file("icons/cancel19.png")
				deletebutton.set_size_request(10,10)
				deletebutton.set_image(image)				
				#Button to Label
				downgrid.attach(deletebutton, 8, counter, 1, 1)
				#Add Action to the Button with id from actual student
				deletebutton.connect("clicked", delcatdown, row[0], managewindow, str(row[1].encode("utf-8")))

				downgrid.attach(templabel_counter, 1, counter, 1, 1)
				downgrid.attach(templabel_name, 2, counter, 1, 1)
				downgrid.attach(templabel_catshort, 3, counter, 1, 1)
				downgrid.attach(templabel_catweight, 4, counter, 1, 1)
				downgrid.attach(templabel_in, 5, counter, 1, 1)
				downgrid.attach(templabel_uppercat, 6, counter, 1, 1)
				counter = counter + 1
				managewindow.show_all()

		#Manage Categories
		def managecat(*args):
			builder.add_from_file("gui/ManageCat.glade")
			managewindow = builder.get_object("windowmanagecat")
						
			#Close-Button
			closewindow = builder.get_object("close_catmanage")
			closewindow.connect("clicked", closemanagewindow, managewindow)

			#New Upper-Cat
			newupcat = builder.get_object("new_upcat")
			newupcat.connect("clicked", addcat_up, managewindow)

			#New Down-Cat
			newdowncat = builder.get_object("new_downcat")
			newdowncat.connect("clicked", addcat_down, managewindow)

			printupcats(managewindow)
			printdowncats(managewindow)
			#Show Categoriemanagewindow
			managewindow.show_all()

		######################################################################################
		#
		#
		#
		#				CATEGORIE AREA END
		#	
		######################################################################################

		######################################################################################
		#
		#
		#
		#				NOTE AREA START
		#	
		######################################################################################

		#Saving a new Note
		def do_savenewnote(self, notewindow):
			#Getting all the Data
			name = builder.get_object("name").get_text().decode("utf-8")
			weight = builder.get_object("weight").get_text()
	
			if len(name) == 0 or len(weight) == 0:
				messWindow = Tkinter.Tk()
				messWindow.wm_withdraw()
				tkMessageBox.showinfo("Falsche Daten", "Bitte korrekte Daten eintragen")
				messWindow.destroy()
			else:
				upcat = builder.get_object("combo_catup").get_active_id()
				downcat = builder.get_object("combo_catdown").get_active_id()
				#Date
				date = builder.get_object("notedate").get_date()			
				year = str(date[0])
				#Make the Month userfriendly :)
				month = str(date[1]+1)
				day = str(date[2])

				#Save Note
				cur = con.cursor()
				#Count existing Notes in the Datbase
				newid = dataop.getdata(con, "select count(id) from notes", None)
				if newid.fetchone()[0] == 0:
					try:						
						cur.execute("insert into notes(id, name, weight, upcat, downcat, year, month, day) values (0, ?, ?, ?, ?, ?, ?, ?);", (name, int(weight), int(upcat), int(downcat), year, month, day))
					except:
						messWindow = Tkinter.Tk()
						messWindow.wm_withdraw()
						result = tkMessageBox.showinfo("Falsche Daten", "Bitte bei Gewicht nur ganze Zahlen eingeben!")
						messWindow.destroy()
				else:
					try:
						cur.execute("insert into notes(id, name, weight, upcat, downcat, year, month, day) values ((SELECT max(id) FROM notes) + 1, ?, ?, ?, ?, ?, ?, ?);", (name, int(weight), int(upcat), int(downcat), year, month, day))
					except:
						messWindow = Tkinter.Tk()
						messWindow.wm_withdraw()
						result = tkMessageBox.showinfo("Falsche Daten", "Bitte bei Gewicht nur ganze Zahlen eingeben!")
						messWindow.destroy()

				con.commit()				
				notewindow.destroy()
				#Fill the new Grid
				fillDataGrid()

		#Updating a Note
		def do_updatenote(self, id, notewindow):
			#Getting all the Data
			name = builder.get_object("name").get_text().decode("utf-8")
			weight = builder.get_object("weight").get_text()
	
			if len(name) == 0 or len(weight) == 0:
				messWindow = Tkinter.Tk()
				messWindow.wm_withdraw()
				tkMessageBox.showinfo("Falsche Daten", "Bitte korrekte Daten eintragen")
				messWindow.destroy()
			else:
				upcat = builder.get_object("combo_catup").get_active_id()
				downcat = builder.get_object("combo_catdown").get_active_id()
				#Date
				date = builder.get_object("notedate").get_date()			
				year = str(date[0])
				#Make the Month userfriendly :)
				month = str(date[1]+1)
				day = str(date[2])

				#Save Note
				cur = con.cursor()
				#Count existing Notes in the Datbase
				cur.execute("update notes set name=?, weight=?, upcat=?, downcat=?, year=?, month=?, day=? where id=?", (name, int(weight), upcat, downcat, year, month, day, id, )) 
				con.commit()				
				notewindow.destroy()
				#Fill the new Grid
				fillDataGrid()

		#Creating the NewNoteWindow
		def addnewnote(*args):
			builder.add_from_file("gui/NewNotePop.glade")
			notewindow = builder.get_object("addnote")
			
			#Loading all Upper-Cats and ad them to a Combo-Box
			uppercats = builder.get_object("combo_catup")		
			allupcat = dataop.getdata(con, "select id, name from catup order by weight desc", None)			
			for upcats in allupcat.fetchall():
				uppercats.append(str(upcats[0]), upcats[1].encode("utf-8"))	
			uppercats.set_active(0)

			#Loading all Down-Cats and ad them to a Combo-Box
			downcats = builder.get_object("combo_catdown")		
			alldowncat = dataop.getdata(con, "select id, name from catdown order by weight desc", None)			
			for downcat in alldowncat.fetchall():
				downcats.append(str(downcat[0]), downcat[1].encode("utf-8"))	
			downcats.set_active(0)

			#Adding Functionality to the Save-Button
			savebutton = builder.get_object("savenote")
			savebutton.connect("clicked", do_savenewnote, notewindow)
			#Show Categoriemanagewindow
			notewindow.show_all()

		#Update a Note
		def updatenote(self, noteid, studentid, notecombobox):
			#Update a Note
			cur = con.cursor()
			#Checking for a Note
			maybenote = cur.execute("select id from notes_student where notesid=? and studentid=?", (noteid, studentid,)).fetchone()

			#Getting new Note
			note = notecombobox.get_active()
				
			#Save a new note or update
			if maybenote == None:
				newid = dataop.getdata(con, "select count(id) from notes_student", None)
				if newid.fetchone()[0] == 0:
					cur.execute("insert into notes_student(id, notesid, studentid, note) values(0, ?, ?,?)", (noteid, studentid, float(note),))
				else:
					cur.execute("insert into notes_student(id, notesid, studentid, note) values((SELECT max(id) FROM notes_student) + 1, ?, ?,?)", (noteid, studentid, float(note),))
			else:
				cur.execute("update notes_student set note=? where notesid=? and studentid=?", (float(note), noteid, studentid,))
				
			con.commit()
			fillDataGrid()			
		
		#Delete a Note
		def deletenote(self, id, mainwindow, name):
			messWindow = Tkinter.Tk()
			messWindow.wm_withdraw()
			result = tkMessageBox.askokcancel("Warnung", "ACHTUNG! Alle Daten der Noten " + str(name) + " werden UNWIDERRUFLICH gelöscht. Fortfahren?")
			messWindow.destroy()

			#Check for deleting or not
			if result == True:
				#Delete True - Delete the Note and reload the Grid
				dataop.deleteNoteComplete(con, id)
				fillDataGrid()

		def changenote(self, mainwindow, id, name, weight, upcat, downcateg, year, month, day):
			builder.add_from_file("gui/NewNotePop.glade")
			notewindow = builder.get_object("addnote")
			name = builder.get_object("name").set_text(name)
			weight = builder.get_object("weight").set_text(str(weight))
			#Loading all Upper-Cats and ad them to a Combo-Box
			uppercats = builder.get_object("combo_catup")		
			allupcat = dataop.getdata(con, "select id, name from catup order by weight desc", None)	
			counter = 0		
			for upcats in allupcat.fetchall():
				uppercats.append(str(upcats[0]), upcats[1].encode("utf-8"))	
				if upcats[0] == upcat:
					uppercats.set_active(counter)
				counter = counter + 1
			
			#Loading all Down-Cats and ad them to a Combo-Box
			downcats = builder.get_object("combo_catdown")		
			alldowncat = dataop.getdata(con, "select id, name from catdown order by weight desc", None)		
			counter = 0	
			for downcat in alldowncat.fetchall():
				downcats.append(str(downcat[0]), downcat[1].encode("utf-8"))	
				if downcat[0] == downcateg:
					downcats.set_active(counter)
				counter = counter + 1
			
			#Date
			date = builder.get_object("notedate")
			date.select_month(int(month) - 1, int(year))
			date.select_day(int(day))

			#Adding Functionality to the Save-Button
			savebutton = builder.get_object("savenote")
			savebutton.connect("clicked", do_updatenote, id, notewindow)
			#Show Categoriemanagewindow
			notewindow.show_all()

		#Loading all Notes
		def loadNotes(datagrid, mainwindow):
			#datas = dataop.getdata(con, "select id, name, weight, upcat, downcat, year, month, day from notes order by year, month, day asc", None)
			datas = dataop.getdata(con, "select id, name, weight, upcat, downcat, year, month, day from notes order by name asc", None)
			rowcount = 4
			notecounter = 0
			for row in datas.fetchall():
				#Getting Names from Categories
				upcat = dataop.getdata(con, "select short, weight from catup where id=?", row[3]).fetchone()
				downcat =  dataop.getdata(con, "select short, weight from catdown where id=?", row[4]).fetchone()
				notegrid = Gtk.Grid()
				notegrid_snd = Gtk.Grid()				
				templabel = Gtk.Label()
				templabel.set_markup("<b><big>" + row[1] + "</big></b>\n<b>Gewicht: " + str(row[2]) + "\n" + row[7] + "."+ row[6] + "."+ row[5] + "\nObKa: " + str(upcat[0]) + " | " + str(upcat[1]) + "\nUnKa: " + str(downcat[0]) + " | " + str(downcat[1]) + "</b>")
				notegrid.attach(templabel, 0, 0, 1, 1)
				
				#Buttons to change/delete the Categories
				#ChangeButton
				changebutton = Gtk.Button()
				image = Gtk.Image()
				image.set_from_file("icons/gear74.png")
				changebutton.set_size_request(10,10)
				changebutton.set_image(image)				
				#Button to Label
				notegrid_snd.attach(changebutton, 0, 0, 1, 1)
				#Add Action to the Button with id from actual student				
				changebutton.connect("clicked", changenote, mainwindow, row[0], str(row[1].encode("utf-8")), row[2],row[3],row[4],row[5],row[6],row[7],)

				#DeleteButton
				deletebutton = Gtk.Button()
				image = Gtk.Image()
				image.set_from_file("icons/cancel19.png")
				deletebutton.set_size_request(10,10)
				deletebutton.set_image(image)				
				#Button to Label
				notegrid_snd.attach(deletebutton, 1, 0, 1, 1)
				#Add Action to the Button with id from actual student
				deletebutton.connect("clicked", deletenote, row[0], mainwindow, str(row[1].encode("utf-8")))

				notegrid.attach(notegrid_snd, 0, 1, 1, 1)
				datagrid.attach(notegrid, rowcount, 0, 1, 1)
				#notes_student (id INT PRIMARY KEY NOT NULL, notesid INT NOT NULL, studentid INT NOT NULL, note DOUBLE NOT NULL)
				data_students = dataop.getdata(con, "select id from students order by name asc", None)				
				studentcounter = 1
				average_note = 0
				#Needed in case that a student as no note 
				corrector = 0
				for student in data_students.fetchall():
					stugrid = Gtk.Grid()
					cur = con.cursor()			
					stunote = cur.execute("select note from notes_student where notesid=? and studentid=?", (int(row[0]), int(student[0]),)).fetchone()
					spacer = Gtk.Label("   ")
					if stunote == None:		
						notecombobox = giv15to0ComboBox()
						stugrid.attach(notecombobox, rowcount, studentcounter, 1, 1)
						stugrid.attach(spacer, rowcount + 1, studentcounter, 1, 1)
						notecombobox.connect("changed", updatenote, int(row[0]), int(student[0]), notecombobox)
					else:

						notecombobox = giv15to0ComboBox()
						notecombobox.set_active(stunote[0])
						#Calculate Average-Note and prevent for adding "na" (16)
						if stunote[0] != 16.0:
							average_note = average_note + stunote[0]
						else:
							corrector = corrector + 1

						stugrid.attach(notecombobox, rowcount, studentcounter, 1, 1)
						stugrid.attach(spacer, rowcount + 1, studentcounter, 1, 1)
						notecombobox.connect("changed", updatenote, int(row[0]), int(student[0]), notecombobox)

					if studentcounter % 2 != 0:
						stugrid.override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(0.8, 0.8, 0.8, 1))				

					datagrid.attach(stugrid, rowcount, studentcounter, 1, 1)	
					studentcounter = studentcounter + 1

				#Adding Average-Note under the Table
				diff = studentcounter - corrector - 1
				average_note = round(average_note / diff, 2)
				average = Gtk.Label("Durchschnitt: " + str(average_note))
				datagrid.attach(average, rowcount, studentcounter + 1, 1, 1)	

				rowcount = rowcount + 2	
				notecounter = notecounter + 1
				#If four Notes reached print all Names of the Students again
				if notecounter % 4 == 0:
					#Adding Studentsnames - Postname, Prenames, Numbers and Buttons
					datas = dataop.getdata(con, "select id, name, prename, mail from students order by 2 asc", None)
					#Startfield of Rows
					startfield_rows = 1
					for row in datas.fetchall():
						templabel_numbers = Gtk.Label()
						templabel_postname = Gtk.Label()
						templabel_prename = Gtk.Label()

						templabel_numbers.set_text("     " + str(startfield_rows) + ". ")
						templabel_postname.set_text(row[1].encode("utf-8") + " ")
						templabel_prename.set_text(row[2].encode("utf-8") + " ")
						
						#COLOR 0-65535 Gdk.Color(RED, GREEN, BLUE)
						if startfield_rows % 2 != 0:
							templabel_postname.modify_bg(0, Gdk.Color(52000, 52000, 52000))
							templabel_prename.modify_bg(0, Gdk.Color(52000, 52000, 52000))
							templabel_numbers.modify_bg(0, Gdk.Color(52000, 52000, 52000))
						datagrid.attach(templabel_postname, rowcount  + 1, startfield_rows, 1, 1)
						datagrid.attach(templabel_prename, rowcount + 2, startfield_rows, 1, 1)
						datagrid.attach(templabel_numbers, rowcount, startfield_rows, 1, 1)
						startfield_rows = startfield_rows + 1		
					rowcount = rowcount + 3
			#Reload the Mainwindow
			mainwindow.show_all()

		#Gives a 0 to 15 Combobox
		def giv15to0ComboBox():			
			notes = Gtk.ListStore(int, str)			
			for note in range(16):
				notes.append([note, str(note)])
			notes.append([17, "na"])
			combobox = Gtk.ComboBox.new_with_model_and_entry(notes)			
			combobox.set_entry_text_column(1)
			return combobox
			
		######################################################################################
		#
		#
		#
		#				NOTE AREA ENDE
		#	
		######################################################################################

		#Fill the Grid with all Data from the actual database resp. Class		
		def fillDataGrid(*args):
			
			#Get all the Grids :)
			datagrid_buttons = builder.get_object("datagrid_buttons")				
			newviewgrid = builder.get_object("datagrid")

			#Clear the grid
			for child in newviewgrid.get_children():
				newviewgrid.remove(child)

			#Clear the button-grid
			for child in datagrid_buttons.get_children():
				datagrid_buttons.remove(child)			
			
			#Adding New Note-Button
			addnote = Gtk.Button.new_with_label("Neue Note")
			addnote.connect("clicked", addnewnote)
			datagrid_buttons.attach(addnote, 0, 1, 1, 1)
	
			#Button for manage Categories			
			kat_down = Gtk.Button("Kategorien verwalten")
			kat_down.connect("clicked", managecat)
			datagrid_buttons.attach(kat_down, 1, 1, 1, 1)

			#Adding Studentsnames - Postname, Prenames, Numbers and Buttons
			datas = dataop.getdata(con, "select id, name, prename, mail from students order by 2 asc", None)
			#Startfield of Rows
			startfield_rows = 1
			for row in datas.fetchall():
				templabel_numbers = Gtk.Label()
				templabel_postname = Gtk.Label()
				templabel_prename = Gtk.Label()

				templabel_numbers.set_text("     " + str(startfield_rows) + ". ")
				templabel_postname.set_text(row[1].encode("utf-8") + " ")
				templabel_prename.set_text(row[2].encode("utf-8") + " ")
				
				#COLOR 0-65535 Gdk.Color(RED, GREEN, BLUE)
				if startfield_rows % 2 != 0:
					templabel_postname.modify_bg(0, Gdk.Color(52000, 52000, 52000))
					templabel_prename.modify_bg(0, Gdk.Color(52000, 52000, 52000))
					templabel_numbers.modify_bg(0, Gdk.Color(52000, 52000, 52000))

				newviewgrid.attach(templabel_postname, 1, startfield_rows, 1, 1)
				newviewgrid.attach(templabel_prename, 2, startfield_rows, 1, 1)
				newviewgrid.attach(templabel_numbers, 0, startfield_rows, 1, 1)
				startfield_rows = startfield_rows + 1

			#Show the window		
			window.show_all()
			loadNotes(newviewgrid, window)			

		#Fill the Grid for the first time and call this method to reload
		fillDataGrid()
示例#6
0
	def start(self, classname, builder, window):

		#Databaseconnection
		dataop = DataOp()
		con = dataop.opendatabase(classname)

		#Functions for adding, importing and editing students
		def do_addstudent(*args):

			#Function to save a new Student
			def save_new_student(*args):
				name = builder.get_object("student_postname").get_text().decode("utf-8")
				prename = builder.get_object("student_prename").get_text().decode("utf-8")
				mail = builder.get_object("student_mail").get_text().decode("utf-8")
				
				#Checking the data
				if len(name) == 0 or len(prename) == 0:
					messWindow = Tkinter.Tk()
					messWindow.wm_withdraw()
					tkMessageBox.showinfo("Falsche Eingabe", "Bitte mindestens Vorname und Nachname eingeben.")
					messWindow.destroy()	

				#Check of so save new student to database
				else:
					#Insert all Datas
					cur = con.cursor()
					#Count existing Students in the Datbase
					
					newid = dataop.getdata(con, "select count(id) from students", None)
					if newid.fetchone()[0] == 0:
						cur.execute("insert into students(id, name, prename, mail) values (0, ?, ?, ?);", (name, prename, mail,))
					else:
						cur.execute("insert into students(id, name, prename, mail) values ((SELECT max(id) FROM students) + 1, ?, ?, ?);", (name, prename, mail,))		
					con.commit()
					#Destroy Input-Window
					addstudentwindow.destroy()
					#Reload the DataGrid					
					fillDataGrid()

			#Show New-Student-Popup
			builder.add_from_file("gui/NewStudentPop.glade")
			addstudentwindow = builder.get_object("addstudentwindow")
			addstudentwindow.show_all()

			savebutton = builder.get_object("addstudent_save")
			savebutton.connect("clicked", save_new_student)

		#Function to save a new Student
		def save_new_student_csv(postname, prename, mail):
			#Insert all Datas
			cur = con.cursor()
			#Count existing Students in the Datbase
			newid = dataop.getdata(con, "select count(id) from students", None)
			if newid.fetchone()[0] == 0:
				cur.execute("insert into students(id, name, prename, mail) values (0, ?, ?, ?);", (postname, prename, mail,))
			else:
				cur.execute("insert into students(id, name, prename, mail) values ((SELECT max(id) FROM students) + 1, ?, ?, ?);", (postname, prename, mail,))		
			
			con.commit()
			#Reload the DataGrid					
			fillDataGrid()
			
		#Destroy checkwindow
		def quit_checkwindow(self, another, checkwindow):
			checkwindow.destroy()

		#Destroy the CSV-Window
		def abort_savecsv(self, importcsvwin):
			importcsvwin.destroy()

		#Save all new Students
		def savecsv(self, importcsvwin, counter):
			#Getting the Students-Data from the Grid
			grid = builder.get_object("newstudents")
			for newstu in range(counter):
				if newstu > 0:					
					prename = grid.get_child_at(3, newstu).get_text().decode("utf-8")
					postname = grid.get_child_at(5, newstu).get_text().decode("utf-8")
					mail = grid.get_child_at(7, newstu).get_text().decode("utf-8")
					save_new_student_csv(postname, prename, mail)	
			
			#Reload the Grid
			fillDataGrid()
			importcsvwin.destroy()

		#Import a lot of students from a csv-File
		def do_importstudents(*args):
			dialog = Gtk.FileChooserDialog("Klassendatei wählen", None, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
			response = dialog.run()

			if response == -6:
				dialog.destroy()
			elif response == -5:
				#Read CSV-File				
				filename = argv
				filename = str(dialog.get_filename())				
				cr = csv.reader(open(filename,"rb"))

				#Load GUI
				builder.add_from_file("gui/ImportCSV.glade")
				importcsvwin = builder.get_object("importcsv")
				csvgrid = builder.get_object("newstudents")
				
				#Read all Data and prepare Check-Window
				counter = 1
				for row in cr:
					templabel_numb = Gtk.Label(str(counter) + "." )
					templabel_postname = Gtk.Label(str(row[0]))
					templabel_prename = Gtk.Label(str(row[1]))
					templabel_mail = Gtk.Label(str(row[2]))
					
					space1 = Gtk.Label("   ")
					space2 = Gtk.Label("   ")
					space3 = Gtk.Label("   ")

					#If 2nd row --> make it grey :)
					if counter % 2 != 0:
						templabel_numb.modify_bg(0, Gdk.Color(52000, 52000, 52000))
						templabel_postname.modify_bg(0, Gdk.Color(52000, 52000, 52000))
						templabel_prename.modify_bg(0, Gdk.Color(52000, 52000, 52000))
						templabel_mail.modify_bg(0, Gdk.Color(52000, 52000, 52000))
						space1.modify_bg(0, Gdk.Color(52000, 52000, 52000))
						space2.modify_bg(0, Gdk.Color(52000, 52000, 52000))
						space3.modify_bg(0, Gdk.Color(52000, 52000, 52000))
					
					#Attach all Labels to the Grid
					csvgrid.attach(templabel_numb, 1, counter, 1, 1)
					csvgrid.attach(space1, 2, counter, 1, 1)
					csvgrid.attach(templabel_postname, 3, counter, 1, 1)
					csvgrid.attach(space2, 4, counter, 1, 1)
					csvgrid.attach(templabel_prename, 5, counter, 1, 1)
					csvgrid.attach(space3, 6, counter, 1, 1)
					csvgrid.attach(templabel_mail, 7, counter, 1, 1)
					counter = counter + 1
				
				#Adding Button-Functionality
				abort = builder.get_object("abort")
				abort.connect("clicked", abort_savecsv, importcsvwin)

				savecsvbutton = builder.get_object("savecsv")
				savecsvbutton.connect("clicked", savecsv, importcsvwin, counter)

				#Show New-Student-Popup
				importcsvwin.show_all()
		    	dialog.destroy()


		#Save Update Data from Student
		def saveupdatedata(self, id, windowtodestroy):
			name = builder.get_object("student_postname").get_text().decode("utf-8")
			prename = builder.get_object("student_prename").get_text().decode("utf-8")
			mail = builder.get_object("student_mail").get_text().decode("utf-8")
			
			#Checking the data
			if len(name) == 0 or len(prename) == 0:
				messWindow = Tkinter.Tk()
				messWindow.wm_withdraw()
				tkMessageBox.showinfo("Falsche Eingabe", "Bitte mindestens Vorname und Nachname eingeben.")
				messWindow.destroy()	

			#Check of so save new student to database
			else:
				#Update all Datas
				cur = con.cursor()
				cur.execute("UPDATE students SET name=?, prename=?, mail=? WHERE id=?", (name, prename, mail, id)) 
				con.commit()
				#Destroy Input-Window
				windowtodestroy.destroy()
				#Reload the DataGrid					
				fillDataGrid()

		def deletestudent(self, id, prename, postname):
			messWindow = Tkinter.Tk()
			messWindow.wm_withdraw()
			result = tkMessageBox.askokcancel("Warnung", "ACHTUNG! Alle Daten von " + prename.encode("utf-8") + " " + postname.encode("utf-8") + " werden UNWIDERRUFLICH gelöscht. Fortfahren?")
			messWindow.destroy()

			#Check for deleting or not
			if result == True:
				#Delete True - Call main Student-Delete-Funktion and give ID
				dataop.deleteStudentComplete(con, id)
				fillDataGrid()

		#Changes Data from a Student, needs Button and id from a student
		def changedata(self, id, data_post, data_pre, data_mail):
			builder.add_from_file("gui/NewStudentPop.glade")
			addstudentwindow = builder.get_object("addstudentwindow")
			
			#Adding Data into Textfields
			prename = builder.get_object("student_prename")
			postname = builder.get_object("student_postname")
			mail = builder.get_object("student_mail")
			
			prename.set_text(data_pre.encode("utf-8"))		
			postname.set_text(data_post.encode("utf-8"))
			mail.set_text(data_mail.encode("utf-8"))

			#Get Button-Object
			savedata = builder.get_object("addstudent_save")
			savedata.connect("clicked", saveupdatedata, id, addstudentwindow)

			#Show New-Student-Popup
			addstudentwindow.show_all()

		#Fill the Grid with all Data from the actual database resp. Class		
		def fillDataGrid(*args):
			
			#Get all the Grids :)
			datagrid_buttons = builder.get_object("datagrid_buttons")				
			newviewgrid = builder.get_object("datagrid")

			#Clear the grid
			for child in newviewgrid.get_children():
				newviewgrid.remove(child)

			#Clear the button-grid
			for child in datagrid_buttons.get_children():
				datagrid_buttons.remove(child)			
			
			#Adding Buttons in Top-Area to add Students or import a csv-List (LATER!!)
			addstudents = Gtk.Button.new_with_label("Neuer Schüler")
			addstudents.connect("clicked", do_addstudent)
			datagrid_buttons.attach(addstudents, 0, 1, 1, 1)
			
			importstudents = Gtk.Button("Import CSV")
			datagrid_buttons.attach(importstudents, 1, 1, 1, 1)
			importstudents.connect("clicked", do_importstudents)

			#Adding Studentsnames - Postname, Prenames, Numbers and Buttons
			datas = dataop.getdata(con, "select id, name, prename, mail from students order by 2 asc", None)
			#Startfield of Rows
			startfield_rows = 1
			for row in datas.fetchall():
				templabel_numbers = Gtk.Label()
				templabel_postname = Gtk.Label()
				templabel_prename = Gtk.Label()

				templabel_numbers.set_text("     " + str(startfield_rows) + ". ")
				templabel_postname.set_text(row[1].encode("utf-8") + " ")
				templabel_prename.set_text(row[2].encode("utf-8") + " ")
				
				#COLOR 0-65535 Gdk.Color(RED, GREEN, BLUE)
				if startfield_rows % 2 != 0:
					templabel_postname.modify_bg(0, Gdk.Color(52000, 52000, 52000))
					templabel_prename.modify_bg(0, Gdk.Color(52000, 52000, 52000))
					templabel_numbers.modify_bg(0, Gdk.Color(52000, 52000, 52000))

				newviewgrid.attach(templabel_postname, 1, startfield_rows, 1, 1)
				newviewgrid.attach(templabel_prename, 3, startfield_rows, 1, 1)
				newviewgrid.attach(templabel_numbers, 0, startfield_rows, 1, 1)

				#Button to change
				changebutton = Gtk.Button()
				changebutton.set_name("button_" + str(row[0]))
				image = Gtk.Image()
				image.set_from_file("icons/gear74.png")
				changebutton.set_size_request(10,10)
				changebutton.set_image(image)				
				#Button to Label
				newviewgrid.attach(changebutton, 4, startfield_rows, 1, 1)
				#Add Action to the Button with id from actual student
				changebutton.connect("clicked", changedata, row[0], row[1], row[2], row[3])
				
				#Button to delete all Students Data
				deletebutton = Gtk.Button()
				deletebutton.set_name("delete_" + str(row[0]))
				image = Gtk.Image()
				image.set_from_file("icons/cancel19.png")
				deletebutton.set_size_request(10,10)
				deletebutton.set_image(image)				
				#Button to Label
				newviewgrid.attach(deletebutton, 5, startfield_rows, 1, 1)
				#Add Action to the Button with id from actual student
				deletebutton.connect("clicked", deletestudent, row[0], row[1], row[2])

				startfield_rows = startfield_rows + 1

			#Show the window		
			window.show_all()

		#Fill the Grid for the first time and call this method to reload
		fillDataGrid()