def test_closet(): ''' tests the Closet class ''' closet_one = Closet([ SuitJacket('Tweed', 1, 2), SuitJacket('Tuxedo', 0), SuitJacket('Tuxedo', 2, 2) ]) closet_two = Closet( [SuitJacket('Blazer', 1), SuitJacket('Pinstriped', 0, 3)]) closet_three = Closet([]) closets = [closet_one, closet_two, closet_three] test_get_jackets_of_type(closets) test_add_jacket() test_get_jackets_by_style(closets)
def add_closet(self): length = input('length: ') breadth = input('breadth: ') height = input('height: ') max_capacity = input('max_capacity: ') items = input('items: ') self.closet = Closet(length, breadth,height, max_capacity, items)
def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.controller = controller self.closet = Closet() self.closet.load() self.tops = self.closet.tops self.bottoms = self.closet.bottoms self.shoes = self.closet.shoes self.colordict = dict() self.outfits = list() tk.Label(self, text="Calculated Outfits", font=controller.titleFont, justify=tk.CENTER).place(anchor=tk.N, relx=0.5, rely=0.01) BackButton = tk.Button( self, text="Back", font=controller.bodyFont, command=lambda: controller.show_frame("HomeFrame")) BackButton.place(anchor=tk.NE, relx=0.07, rely=0.04) mainSb = tk.Scrollbar(self) mainSb.pack(side=tk.RIGHT, fill="y", padx=(0, 345), pady=243) self.lbox = tk.Listbox(self, font=controller.bodyFont, yscrollcommand=mainSb.set, width=50, justify=tk.CENTER, selectmode=tk.SINGLE) self.lbox.place(anchor=tk.CENTER, relx=0.5, rely=0.5) mainSb.config(command=self.lbox.yview) tk.Button(self, text="Outfit Info", font=controller.bodyFont, command=lambda: self.Selected()).place(anchor=tk.NE, relx=0.9, rely=0.9)
def test_add_jacket(): ''' tests the add_jacket function of the Closet class ''' closet = Closet([SuitJacket('Blazer', 1), SuitJacket('Pinstriped', 0, 3)]) closet.add_jacket(SuitJacket('Sporting', 0, 2)) assert len(closet.get_jackets_of_type('Sporting')) == 1 assert closet.get_jackets_of_type('Sporting')[0].get_style_score() == 2
class OutfitFrame(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.controller = controller self.closet = Closet() self.closet.load() self.tops = self.closet.tops self.bottoms = self.closet.bottoms self.shoes = self.closet.shoes self.colordict = dict() self.outfits = list() tk.Label(self, text="Calculated Outfits", font=controller.titleFont, justify=tk.CENTER).place(anchor=tk.N, relx=0.5, rely=0.01) BackButton = tk.Button( self, text="Back", font=controller.bodyFont, command=lambda: controller.show_frame("HomeFrame")) BackButton.place(anchor=tk.NE, relx=0.07, rely=0.04) mainSb = tk.Scrollbar(self) mainSb.pack(side=tk.RIGHT, fill="y", padx=(0, 345), pady=243) self.lbox = tk.Listbox(self, font=controller.bodyFont, yscrollcommand=mainSb.set, width=50, justify=tk.CENTER, selectmode=tk.SINGLE) self.lbox.place(anchor=tk.CENTER, relx=0.5, rely=0.5) mainSb.config(command=self.lbox.yview) tk.Button(self, text="Outfit Info", font=controller.bodyFont, command=lambda: self.Selected()).place(anchor=tk.NE, relx=0.9, rely=0.9) def Selected(self): if all(self.lbox.curselection()) or not self.outfits: tk.messagebox.showerror("Error", "No Outfit Selected") return def StrToTuple(self, myStr): tup = tuple() for token in myStr.split(","): tup = tup + (int(token), ) return tup def GetBottomThatMatches(self, listOfColors): listOfBottoms = list() for col in listOfColors: for bottom in self.bottoms: bottomCol = bottom.colors[0].replace(',', '') if str(bottomCol) == str(col): listOfBottoms.append(bottom) return listOfBottoms def initialize(self): self.lbox.delete(0, tk.END) self.outfits = list() print("Cleared List") self.colordict = colors.initializeColors() for shirt in self.tops: sColor = shirt.colors[0] sColor = tuple(self.StrToTuple(sColor)) Bottoms = self.GetBottomThatMatches(self.colordict[sColor]) if Bottoms: for bottom in Bottoms: self.outfits.append( str(shirt.getName()) + " AND " + str(bottom.getName()) + " AND Converse White Shoes") if not self.outfits: self.lbox.insert(tk.END, "No Outfits Found") print("FOUND NONE") for outfit in self.outfits: self.lbox.insert(tk.END, outfit)
def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.controller = controller self.closet = Closet() self.closet.load() self.tops = self.closet.tops self.bottoms = self.closet.bottoms self.shoes = self.closet.shoes titleCanvas = tk.Canvas(self) titleCanvas.pack(anchor=tk.NE, expand=True, fill="x") titleText = tk.Label(titleCanvas, text="Your Closet", font=controller.titleFont) titleText.pack(anchor=tk.N, side=tk.TOP, pady=15) BackButton = tk.Button( titleCanvas, text="Back", font=controller.bodyFont, command=lambda: controller.show_frame("HomeFrame")) BackButton.pack(anchor=tk.NE, side=tk.LEFT, padx=15) topsListCanvas = tk.Canvas(self) topsListCanvas.place(anchor=tk.CENTER, relx=0.25, rely=0.35) bottomsListCanvas = tk.Canvas(self) bottomsListCanvas.place(anchor=tk.CENTER, relx=0.5, rely=0.35) shoesListCanvas = tk.Canvas(self) shoesListCanvas.place(anchor=tk.CENTER, relx=0.75, rely=0.35) topsSb = tk.Scrollbar(topsListCanvas) topsSb.pack(side=tk.RIGHT, fill="y", pady=(30, 0)) bottomsSb = tk.Scrollbar(bottomsListCanvas) bottomsSb.pack(side=tk.RIGHT, fill="y", pady=(30, 0)) shoesSb = tk.Scrollbar(shoesListCanvas) shoesSb.pack(side=tk.RIGHT, fill="y", pady=(30, 0)) self.topsList = tk.Listbox(topsListCanvas, font=controller.bodyFont, yscrollcommand=topsSb.set, width=30) self.bottomsList = tk.Listbox(bottomsListCanvas, font=controller.bodyFont, yscrollcommand=bottomsSb.set, width=30) self.shoesList = tk.Listbox(shoesListCanvas, font=controller.bodyFont, yscrollcommand=shoesSb.set, width=30) topsSb.config(command=self.topsList.yview) bottomsSb.config(command=self.bottomsList.yview) shoesSb.config(command=self.shoesList.yview) tk.Label(topsListCanvas, text="Tops", font=controller.titleFont).pack(anchor=tk.N, side=tk.TOP) tk.Label(bottomsListCanvas, text="Bottoms", font=controller.titleFont).pack(anchor=tk.N, side=tk.TOP) tk.Label(shoesListCanvas, text="Shoes", font=controller.titleFont).pack(anchor=tk.N, side=tk.TOP) self.topsList.pack(anchor=tk.N, side=tk.TOP, pady="5") self.bottomsList.pack(anchor=tk.N, side=tk.TOP, pady="5") self.shoesList.pack(anchor=tk.N, side=tk.TOP, pady="5") self.initialize()
from closet import Closet cl = Closet() cl.start_program()