Esempio n. 1
0
	def db_add_cheese(self, event):
		"""
		Handles adding cheese to database

		:return: returns nothing
		"""
		cheese_name = self.area1.get("1.0", 'end-1c').lower().encode('ascii', 'ignore')
		country_name = self.area2.get("1.0", 'end-1c').lower().encode('ascii', 'ignore')
		softness = self.area3.get("1.0", 'end-1c').lower().encode('ascii', 'ignore')

		cheese_to_add = None
		country_to_add = None

		if cheese_name != "":
			cheese_to_add = table_objects.cheese(-1,
				cheese_name, softness)
			db_func.add_cheese_row(self.db, cheese_to_add)
		if country_name != "":
			country_to_add = table_objects.country(-1,
				country_name)
			db_func.add_country_row(self.db, country_to_add)

		if cheese_to_add is not None and country_to_add is not None:
			db_func.connect_cheese_country(self.db,
				cheese_to_add, country_to_add)

		self.clean()

		self.columnconfigure(0, pad = 3, weight = 1)
		self.rowconfigure(0, pad = 3, weight = 1)
		self.rowconfigure(1, pad = 3, weight = 1)

		label = tk.Label(self, text = "Success!",
			font = ("Arial", 20), bg = "white")
		label.grid(row = 0, column = 0)

		back = ttk.Button(self, text = "Back", style = "Slate.TButton")
		back.grid(row = 1, column = 0,
			sticky = tk.N + tk.S + tk.E + tk.W)

		back.bind("<1>", self.main_menu)

		self.pack()
Esempio n. 2
0
    def db_add_cheese(self, event):
        """
		Handles adding cheese to database

		:return: returns nothing
		"""
        cheese_name = self.area1.get("1.0", 'end-1c').lower().encode(
            'ascii', 'ignore')
        country_name = self.area2.get("1.0", 'end-1c').lower().encode(
            'ascii', 'ignore')
        softness = self.area3.get("1.0",
                                  'end-1c').lower().encode('ascii', 'ignore')

        cheese_to_add = None
        country_to_add = None

        if cheese_name != "":
            cheese_to_add = table_objects.cheese(-1, cheese_name, softness)
            db_func.add_cheese_row(self.db, cheese_to_add)
        if country_name != "":
            country_to_add = table_objects.country(-1, country_name)
            db_func.add_country_row(self.db, country_to_add)

        if cheese_to_add is not None and country_to_add is not None:
            db_func.connect_cheese_country(self.db, cheese_to_add,
                                           country_to_add)

        self.clean()

        self.columnconfigure(0, pad=3, weight=1)
        self.rowconfigure(0, pad=3, weight=1)
        self.rowconfigure(1, pad=3, weight=1)

        label = tk.Label(self, text="Success!", font=("Arial", 20), bg="white")
        label.grid(row=0, column=0)

        back = ttk.Button(self, text="Back", style="Slate.TButton")
        back.grid(row=1, column=0, sticky=tk.N + tk.S + tk.E + tk.W)

        back.bind("<1>", self.main_menu)

        self.pack()
Esempio n. 3
0
    def db_add_recipe(self, event):
        """
		Handles adding recipe to the database		

		:return: returns nothing
		"""
        cheese_name = self.area1.get("1.0", 'end-1c').lower().encode(
            'ascii', 'ignore')
        recipe_name = self.area2.get("1.0", 'end-1c').lower().encode(
            'ascii', 'ignore')
        time = self.area3.get("1.0",
                              'end-1c').lower().encode('ascii', 'ignore')
        instructions = self.area4.get("1.0", 'end-1c').lower().encode(
            'ascii', 'ignore')

        self.columnconfigure(0, pad=3, weight=1)
        self.rowconfigure(0, pad=3, weight=1)
        self.rowconfigure(1, pad=3, weight=1)

        if (cheese_name == "" or recipe_name == ""):
            self.clean()

            label = tk.Label(self,
                             text="Error: A name field was left blank",
                             font=("Arial", 20),
                             bg="white")
            label.grid(row=0, column=0)

            back = ttk.Button(self, text="Back", style="Slate.TButton")
            back.grid(row=1, column=0, sticky=tk.N + tk.S + tk.E + tk.W)

            back.bind("<1>", self.main_menu)
        elif (db_func.row_exists(self.db, cheese_name, "cheeses") is False
              or db_func.row_exists(self.db, recipe_name, "recipes") is True):
            self.clean()

            label = tk.Label(self, text =
             "Error: Cheese doesn't exist in database, "\
             "or recipe already exists",
             font = ("Arial", 16), bg = "white")
            label.grid(row=0, column=0)

            back = ttk.Button(self, text="Back", style="Slate.TButton")
            back.grid(row=1, column=0, sticky=tk.N + tk.S + tk.E + tk.W)

            back.bind("<1>", self.main_menu)
        else:
            cheese_to_add = table_objects.cheese(-1, cheese_name,
                                                 "notimportant")
            db_func.add_cheese_row(self.db, cheese_to_add)

            recipe_to_add = table_objects.recipe(-1, recipe_name, instructions,
                                                 time)
            db_func.add_recipe_row(self.db, recipe_to_add)

            db_func.connect_cheese_recipe(self.db, cheese_to_add,
                                          recipe_to_add)

            self.clean()

            label = tk.Label(self,
                             text="Success!",
                             font=("Arial", 20),
                             bg="white")
            label.grid(row=0, column=0)

            back = ttk.Button(self, text="Back", style="Slate.TButton")
            back.grid(row=1, column=0, sticky=tk.N + tk.S + tk.E + tk.W)

            back.bind("<1>", self.main_menu)

        self.pack()
Esempio n. 4
0
	def db_add_recipe(self, event):
		"""
		Handles adding recipe to the database		

		:return: returns nothing
		"""
		cheese_name = self.area1.get("1.0", 'end-1c').lower().encode('ascii', 'ignore')
		recipe_name = self.area2.get("1.0", 'end-1c').lower().encode('ascii', 'ignore')
		time = self.area3.get("1.0", 'end-1c').lower().encode('ascii', 'ignore')
		instructions = self.area4.get("1.0", 'end-1c').lower().encode('ascii', 'ignore')

		self.columnconfigure(0, pad = 3, weight = 1)
		self.rowconfigure(0, pad = 3, weight = 1)
		self.rowconfigure(1, pad = 3, weight = 1)

		if (cheese_name == "" or recipe_name == ""):
			self.clean()

			label = tk.Label(self, text =
				"Error: A name field was left blank",
				font = ("Arial", 20), bg = "white")
			label.grid(row = 0, column = 0)

			back = ttk.Button(self, text = "Back",
				style = "Slate.TButton")
			back.grid(row = 1, column = 0,
				sticky = tk.N + tk.S + tk.E + tk.W)

			back.bind("<1>", self.main_menu)
		elif (db_func.row_exists(self.db, cheese_name, "cheeses") is False or
			db_func.row_exists(self.db, recipe_name, "recipes") is True):
			self.clean()

			label = tk.Label(self, text = 
				"Error: Cheese doesn't exist in database, "\
				"or recipe already exists",
				font = ("Arial", 16), bg = "white")
			label.grid(row = 0, column = 0)

			back = ttk.Button(self, text = "Back",
				style = "Slate.TButton")
			back.grid(row = 1, column = 0,
				sticky = tk.N + tk.S + tk.E + tk.W)

			back.bind("<1>", self.main_menu)
		else:
			cheese_to_add = table_objects.cheese(-1,
				cheese_name, "notimportant")
			db_func.add_cheese_row(self.db, cheese_to_add)

			recipe_to_add = table_objects.recipe(-1,
				recipe_name, instructions, time)
			db_func.add_recipe_row(self.db,
				recipe_to_add)

			db_func.connect_cheese_recipe(self.db,
				cheese_to_add, recipe_to_add)

			self.clean()

			label = tk.Label(self, text = "Success!",
				font = ("Arial", 20), bg = "white")
			label.grid(row = 0, column = 0)

			back = ttk.Button(self, text = "Back",
				style = "Slate.TButton")
			back.grid(row = 1, column = 0,
				sticky = tk.N + tk.S + tk.E + tk.W)

			back.bind("<1>", self.main_menu)

		self.pack()