class ProductFavorite(): def __init__( self, container=None, displayer=None, session=None ): """ 'container' (Obj ): instance of Container. 'displayer' (obj ): instance of Displayer. 'session,' (obj ): instance of Session. 'grid' (Obj ): instance of Grid. 'f_container' (Frame): container frame. 'm_frame' (Frame): master frame of view. 'name' (str ): name of view. 'json_script' (dict ): json dict of script. 'width' (int ): view width. 'height' (int ): view height. 'padx' (int ): view 'pady' (int ): view 'bg' (str ): view bg. """ # Instances self.container = container self.displayer = displayer self.session = session self.grid = None # Frames self.f_container = self.container.f_container self.m_frame = None # Informations self.name = None # Script self.json_script = None # Style Sheet self.width = self.container.width self.height = self.container.height self.padx = 0 self.pady = 0 self.bg = "#ffffff" # Tk control variables self.var_product_id = IntVar() # Widgets row 0 self.var_paging_label = StringVar() self.w_paging_txt = None self.w_paging_previous = None self.w_paging_next = None # Widgets row 1 & 2 self.w_img_products = [] self.w_product_names = [] self.w_product_radios = [] # Widgets row 3 self.w_submit_button = None self.favorites = [] self.favorites_count = 0 # Paging self.page = 0 self.pages = 0 self.p_start = None self.p_stop = None self.favorites = None # Fill status self.fill_status = False # Previous View in **kwargs self.previous_view = None # -- Displayer initialisation -- # self.construct() def construct(self, **kwargs): """ Construt view. to not fill the view during initialization. 'grid' (obj): Instance of Grid. 'm_frame' (Frame): Tkinter master frame of view. """ # 1. Create new grid in page container. self.grid = Grid( frame=self.f_container, width=self.width, height=self.height, padx=self.padx, pady=self.pady, bg=self.bg ) # 2. Get view frame for displayer function self.m_frame = self.grid.master_frame # 3. Construct the view rows self.row_0(action="construct") self.row_1(action="construct") self.row_2(action="construct") self.row_3(action="construct") def fill(self, **kwargs): """ Fill the view rows. 'json_script' (dict): texts for view. 'name' (str): view name. """ for key, value in kwargs.items(): if key == "view": self.previous_view = value # 1. Get the script. self.json_script = self.session.get_script( package_name="product", file_name="favorite" ) # 2. Save name of view for displayer. self.name = self.json_script.get("view_name") self.favorites = self.session.dbmanager.db_user_prod.read( user_id=self.session.user_id ) # Count products self.favorites_count = len(self.favorites) self.page = 0 self.pages = int(self.favorites_count / 6) self.paging_favorites = self.favorites[0:6] # 3. Refresh rows. if self.fill_status is True: self.row_0(action="refresh") self.row_1(action="refresh") self.row_2(action="refresh") self.row_3(action="refresh") # 4. Fill the view rows. self.row_0(action="fill") self.row_1(action="fill") self.row_2(action="fill") self.row_3(action="fill") self.fill_status = True if len(self.favorites) == 0: self.display_empty() return 0 def paging(self, p_action=None): """ 'current_page' (int ): Nunber of current page. 'action' (str ): Next or Previous 'elements_per_page' (int ): Number of element per page. 'list_start' (int ): 'list_stop' (int ): 'list' (list): List to cut. """ # Paging if p_action == "next": self.page = self.page + 1 elif p_action == "previous": self.page = self.page - 1 self.p_start = int( self.page * 6 ) self.p_stop = int( self.p_start + 6 ) self.paging_favorites = self.favorites[self.p_start:self.p_stop] self.row_0(action="refresh") self.row_1(action="refresh") self.row_2(action="refresh") self.row_1(action="fill") self.row_2(action="fill") def paging_next(self): """ Paging. """ test = self.page + 1 if test <= self.pages: self.paging( p_action="next" ) def paging_prev(self): """ Paging. """ test = self.page - 1 if test >= 0: self.paging( p_action="previous" ) def display_previous(self): """ Display previous view. """ self.displayer.display( c_view="product_favorite", f_view=self.previous_view ) def display_product_sheet(self): """ Display product sheet. """ self.product_id = self.var_product_id.get() self.displayer.display( c_view="product_favorite", f_view="product_sheet", product_id=self.product_id ) def display_empty(self): """ Display product sheet. """ self.displayer.display( c_view="product_favorite", f_view="empty", page="search_engine" ) def row_0(self, action=None): """ Name : PAGING cols : 0 """ if action == "construct": # -- CREATE ROW -- # self.grid.row( width=self.width, height=40, padx=self.padx, pady=self.pady, bg="#E3E9ED" ) self.grid.column( span=9, row=0, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=1, row=0, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=2, row=0, width=None, height=None, padx=None, pady=None, bg=None ) elif action == "fill": # Get script txt = self.json_script.get("row_0") # -- COLUMN 1/3 : EMPTY -- # if self.w_paging_txt is None: self.var_paging_label.set( "{} {} / {}".format( txt.get("paging_label"), self.page, self.pages ) ) self.w_paging_txt = Label( self.grid.col_frames[0][0], anchor="w", pady=5, padx=5, textvariable=self.var_paging_label, bg="#E3E9ED", fg="#000000", font="Helvetica 10 bold" ) self.w_paging_txt.pack(fill='both', expand=True) # -- COLUMN 2/3 : PAGING BUTTON -- # if self.w_paging_previous is None: self.w_paging_previous = Button( self.grid.col_frames[0][2], text=txt.get("paging_prev"), fg="#ffffff", bg="#6B7379", activeforeground="#ffffff", activebackground="#6B7379", command=self.paging_prev ) self.w_paging_previous.pack(side="left", expand=True) # -- COLUMN 2/3 : PAGING BUTTON -- # if self.w_paging_next is None: self.w_paging_next = Button( self.grid.col_frames[0][2], text=txt.get("paging_next"), fg="#ffffff", bg="#1D262D", activeforeground="#ffffff", activebackground="#1D262D", command=self.paging_next ) self.w_paging_next.pack(side="right", expand=True) elif action == "refresh": # Get script txt = self.json_script.get("row_0") self.var_paging_label.set( "{} {} / {}".format( txt.get("paging_label"), self.page, self.pages ) ) def row_1(self, action=None): """ Name : PRODUCT 0 - 3 cols : 1 """ if action == "construct": # -- CREATE ROW -- # self.grid.row( width=self.width, height=270, padx=self.padx, pady=self.pady, bg="#ffffff" ) # -- CREATE COLS -- # self.grid.column( span=4, row=1, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=4, row=1, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=4, row=1, width=None, height=None, padx=None, pady=None, bg=None ) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_1") count = 0 for product in self.paging_favorites[0:3]: # -- COLUMN 1 : PRODUCT IMAGE -- # if product.get("product_img_url") == "empty": img = Image.open( "frontend/images/views/search/no_image.png" ) else: req = requests.get(product.get("product_img_url")) img = Image.open(BytesIO(req.content)) img_resize = img.resize((125, 160), Image.ANTIALIAS) tk_img_product = ImageTk.PhotoImage(img_resize) self.w_img_product = Label( self.grid.col_frames[1][count], image=tk_img_product, bg="#ffffff" ) self.w_img_product.image = tk_img_product self.w_img_product.pack(expand=True) # -- COLUMN 1 : PRODUCT NAME -- # self.w_product_name = Label( self.grid.col_frames[1][count], text="{}".format(product.get("product_name")), anchor="n", bg="#ffffff", font="Helvetica 10 bold" ) self.w_product_name.pack(expand=True) # -- COLUMN 1 : PRODUCT RADIO -- # self.w_product_radio = Radiobutton( self.grid.col_frames[1][count], variable=self.var_product_id, value=product.get("product_id"), bg="#ffffff" ) self.w_product_radio.pack(fill="x", expand=True) # For UX DESIGN if count == 0: self.w_product_radio.select() self.w_img_products.append( self.w_img_product ) self.w_product_names.append( self.w_product_name ) self.w_product_radios.append( self.w_product_radio ) count += 1 elif action == "refresh": if len(self.w_img_products) != 0: for w_img_product in self.w_img_products: w_img_product.pack_forget() if len(self.w_product_names) != 0: for w_product_name in self.w_product_names: w_product_name.pack_forget() if len(self.w_product_radios) != 0: for w_product_radio in self.w_product_radios: w_product_radio.pack_forget() self.w_img_products = [] self.w_product_names = [] self.w_product_radios = [] def row_2(self, action=None): """ Name : PRODUCT 3 - 6 cols : 1 """ if action == "construct": # -- CREATE ROW -- # self.grid.row( width=self.width, height=270, padx=self.padx, pady=self.pady, bg="#ffffff" ) # -- CREATE COLS -- # self.grid.column( span=4, row=2, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=4, row=2, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=4, row=2, width=None, height=None, padx=None, pady=None, bg=None ) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_2") count = 0 for product in self.paging_favorites[3:6]: # -- COLUMN 1 : PRODUCT IMAGE -- # if product.get("product_img_url") == "empty": img = Image.open( "frontend/images/views/search/no_image.png" ) else: req = requests.get(product.get("product_img_url")) img = Image.open(BytesIO(req.content)) img_resize = img.resize((125, 160), Image.ANTIALIAS) tk_img_product = ImageTk.PhotoImage(img_resize) self.w_img_product = Label( self.grid.col_frames[2][count], image=tk_img_product, bg="#ffffff" ) self.w_img_product.image = tk_img_product self.w_img_product.pack(expand=True) # -- COLUMN 1 : PRODUCT NAME -- # self.w_product_name = Label( self.grid.col_frames[2][count], text="{}".format(product.get("product_name")), anchor="n", bg="#ffffff", font="Helvetica 10 bold" ) self.w_product_name.pack(expand=True) # -- COLUMN 1 : PRODUCT RADIO -- # self.w_product_radio = Radiobutton( self.grid.col_frames[2][count], variable=self.var_product_id, value=product.get("product_id"), bg="#ffffff" ) self.w_product_radio.pack(fill="x", expand=True) self.w_img_products.append( self.w_img_product ) self.w_product_names.append( self.w_product_name ) self.w_product_radios.append( self.w_product_radio ) count += 1 elif action == "refresh": if len(self.w_img_products) != 0: for w_img_product in self.w_img_products: w_img_product.pack_forget() if len(self.w_product_names) != 0: for w_product_name in self.w_product_names: w_product_name.pack_forget() if len(self.w_product_radios) != 0: for w_product_radio in self.w_product_radios: w_product_radio.pack_forget() self.w_img_products = [] self.w_product_names = [] self.w_product_radios = [] def row_3(self, action=None): """ Name : SUBMIT BUTTON cols : 3 """ if action == "construct": # -- CREATE ROW -- # self.grid.row( width=self.width, height=50, padx=self.padx, pady=self.pady, bg="#ffffff" ) # -- CREATE COLS -- # self.grid.column( span=4, row=3, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=4, row=3, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=4, row=3, width=None, height=None, padx=None, pady=None, bg=None ) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_3") # -- COLUMN 1 : SUBMIT BUTTON -- # self.w_submit_button = Button( self.grid.col_frames[3][1], text=txt.get("submit_button"), fg="#ffffff", bg="#7A57EC", activeforeground="#ffffff", activebackground="#845EFF", command=self.display_product_sheet ) self.w_submit_button.pack(side=BOTTOM, fill=X) elif action == "refresh": self.w_submit_button.pack_forget() self.w_submit_button = None
class SearchEngine(): def __init__(self, container=None, displayer=None, session=None): """ 'container' (Obj ): instance of Container. 'displayer' (obj ): instance of Displayer. 'session,' (obj ): instance of Session. 'grid' (Obj ): instance of Grid. 'f_container' (Frame): container frame. 'm_frame' (Frame): master frame of view. 'name' (str ): name of view. 'json_script' (dict ): json dict of script. 'width' (int ): view width. 'height' (int ): view height. 'padx' (int ): view 'pady' (int ): view 'bg' (str ): view bg. """ # Instances self.container = container self.displayer = displayer self.session = session self.grid = None # Frames self.f_container = self.container.f_container self.m_frame = None # Informations self.name = None # Script self.json_script = None # Style Sheet self.width = self.container.width self.height = self.container.height self.padx = 0 self.pady = 0 self.bg = "#ffffff" # Tk control variables self.var_product_name = StringVar() # Widgets row 0 self.canvas = None self.search_entry = None self.search_button = None # Widgets row 1 self.w_products_img = None self.w_products_button = None self.w_nutriscore_imgs = [] self.w_nutriscore_buttons = [] self.nutriscores = [{ "nutriscore_a": "#038141", "nutriscore_b": "#85bb2f", "nutriscore_c": "#fecb02", "nutriscore_d": "#ee8100", "nutriscore_e": "#e63e11" }] self.nutri_funcs = [{ "nutriscore_a": self.display_products_a, "nutriscore_b": self.display_products_b, "nutriscore_c": self.display_products_c, "nutriscore_d": self.display_products_d, "nutriscore_e": self.display_products_e }] self.products_count = [] # Fill status self.fill_status = False # Previous View in **kwargs self.previous_view = None # -- Displayer initialisation -- # self.construct() def construct(self, **kwargs): """ Construt view. to not fill the view during initialization. 'grid' (obj): Instance of Grid. 'm_frame' (Frame): Tkinter master frame of view. """ # 1. Create new grid in page container. self.grid = Grid(frame=self.f_container, width=self.width, height=self.height, padx=self.padx, pady=self.pady, bg=self.bg) # 2. Get view frame for displayer function self.m_frame = self.grid.master_frame # 3. Construct the view rows self.row_0(action="construct") self.row_1(action="construct") def fill(self, **kwargs): """ Fill the view rows. 'json_script' (dict): texts for view. 'name' (str): view name. """ for key, value in kwargs.items(): if key == "view": self.previous_view = value # 1. Get products products = self.session.dbmanager.db_product.count(action="*") self.products_count.append(products) nutriscores = ["a", "b", "c", "d", "e"] for nutriscore in nutriscores: products = self.session.dbmanager.db_product.count( action="nutriscore", param=nutriscore) self.products_count.append(products) # 1. Get the script. self.json_script = self.session.get_script(package_name="search", file_name="engine") # 2. Save name of view for displayer. self.name = self.json_script.get("view_name") # 3. Refresh rows. if self.fill_status is True: self.row_0(action="refresh") self.row_1(action="refresh") # 4. Fill the view rows. self.row_0(action="fill") self.row_1(action="fill") self.fill_status = True def display_previous(self): """ Display previous view. """ self.displayer.display(c_view="search_engine", f_view=self.previous_view) def display_products_all(self): """ Display view search_result. Package "SEARCH" """ self.displayer.display(c_view="search_engine", f_view="search_result") def display_products_a(self): """ Display view search_result. Package "SEARCH" """ self.displayer.display(c_view="search_engine", f_view="search_result", search_action="nutriscore", search_value="a") def display_products_b(self): """ Display view search_result. Package "SEARCH" """ self.displayer.display(c_view="search_engine", f_view="search_result", search_action="nutriscore", search_value="b") def display_products_c(self): """ Display view search_result. Package "SEARCH" """ self.displayer.display(c_view="search_engine", f_view="search_result", search_action="nutriscore", search_value="c") def display_products_d(self): """ Display view search_result. Package "SEARCH" """ self.displayer.display(c_view="search_engine", f_view="search_result", search_action="nutriscore", search_value="d") def display_products_e(self): """ Display view search_result. Package "SEARCH" """ self.displayer.display(c_view="search_engine", f_view="search_result", search_action="nutriscore", search_value="e") def display_research(self): """ Display view search_result. Package "SEARCH" """ self.product_name = self.var_product_name.get() self.displayer.display(c_view="search_engine", f_view="search_result", search_action="key", search_value=self.product_name) def row_0(self, action=None): """ Name : TITLE cols : 1 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=500, padx=0, pady=0, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=12, row=0, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_0") if self.canvas is None: img = Image.open("frontend/images/views/search/background.jpg") imgResize = img.resize((640, 500), Image.ANTIALIAS) imgTkinter = ImageTk.PhotoImage(imgResize) self.canvas = Canvas(self.grid.col_frames[0][0], width=self.width, height=500, highlightthickness=0) self.canvas.pack(expand=True, fill="both") self.canvas.create_image(0, 0, image=imgTkinter, anchor="nw") self.canvas.image = imgTkinter self.canvas.create_text(100, 100, text=txt.get("view_title"), anchor='nw', fill="#ffffff", font="Helvetica 20 bold") self.canvas.create_text(100, 135, text=txt.get("view_subtitle"), anchor='nw', fill="#ffffff", font="Helvetica 12 bold") self.search_entry = Entry(self.canvas, textvariable=self.var_product_name, borderwidth=0) self.search_entry.place(x=100, y=170, height=50, width=350) self.search_button = Button(self.canvas, text="Rechercher", fg="#ffffff", bg="#7A57EC", activeforeground="#ffffff", activebackground="#845EFF", borderwidth=0, command=self.display_research) self.search_button.place(x=450, y=170, height=50, width=100) elif action == "refresh": """ Refresh this row. """ self.canvas.delete("all") self.canvas.pack_forget() self.search_entry.delete(0, 1000) self.search_entry.place_forget() self.search_button.place_forget() self.canvas = None self.search_entry = None self.search_button = None def row_1(self, action=None): """ Name : NUTRISCORES cols : 6 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=150, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_1") if self.w_products_img is None: img = Image.open("frontend/images/views/search/products.png") imgResize = img.resize((80, 70), Image.ANTIALIAS) imgTkinter = ImageTk.PhotoImage(imgResize) self.w_products_img = Label(self.grid.col_frames[1][0], image=imgTkinter, borderwidth=5, bg="#ffffff") self.w_products_img.image = imgTkinter self.w_products_img.pack(fill="both", expand=True) if self.w_products_button is None: self.w_products_button = Button( self.grid.col_frames[1][0], text="{} \n products".format(self.products_count[0]), fg="#000000", bg="#ffffff", highlightbackground="#ffffff", activeforeground="#000000", activebackground="#ededed", borderwidth=0, font="Helvetica 10 bold", command=self.display_products_all) self.w_products_button.pack(fill="both") nutri_count = 1 for nutriscore in self.nutriscores: for key, value in nutriscore.items(): img = Image.open( "frontend/images/nutriscores/{}.png".format(key)) imgResize = img.resize((90, 50), Image.ANTIALIAS) imgTkinter = ImageTk.PhotoImage(imgResize) w_nutriscore_img = Label( self.grid.col_frames[1][nutri_count], image=imgTkinter, borderwidth=15, bg=value) w_nutriscore_img.image = imgTkinter w_nutriscore_img.pack(fill="both", expand=True) w_nutriscore_button = Button( self.grid.col_frames[1][nutri_count], text="{} \n products".format( self.products_count[nutri_count]), fg="#ffffff", bg=value, highlightbackground=value, activeforeground="#000000", activebackground="#ededed", borderwidth=0, font="Helvetica 10 bold", command=self.nutri_funcs[0].get(key)) w_nutriscore_button.pack(fill="both") self.w_nutriscore_imgs.append(w_nutriscore_img) self.w_nutriscore_buttons.append(w_nutriscore_button) nutri_count += 1 elif action == "refresh": """ Refresh this row. """ if len(self.w_nutriscore_imgs) > 0: for w_nutriscore_img in self.w_nutriscore_imgs: w_nutriscore_img.pack_forget() if len(self.w_nutriscore_buttons) > 0: for w_nutriscore_button in self.w_nutriscore_buttons: w_nutriscore_button.pack_forget() self.w_products_img.pack_forget() self.w_products_button.pack_forget() self.w_products_img = None self.w_products_button = None self.w_nutriscore_imgs = [] self.w_nutriscore_buttons = []
class Error404(): def __init__(self, container=None, displayer=None, session=None): """ 'container' (Obj ): instance of Container. 'displayer' (obj ): instance of Displayer. 'session,' (obj ): instance of Session. 'grid' (Obj ): instance of Grid. 'f_container' (Frame): container frame. 'm_frame' (Frame): master frame of view. 'name' (str ): name of view. 'json_script' (dict ): json dict of script. 'width' (int ): view width. 'height' (int ): view height. 'padx' (int ): view 'pady' (int ): view 'bg' (str ): view bg. """ # Instances self.container = container self.displayer = displayer self.session = session self.grid = None # Frames self.f_container = self.container.f_container self.m_frame = None # Informations self.name = None # Script self.json_script = None # Style Sheet self.width = self.container.width self.height = self.container.height self.padx = 0 self.pady = 0 self.bg = "#ffffff" # Tk control variables # Widgets row 0 self.w_error404_img = None self.w_error404_button = None self.page_to_display = None # Fill status self.fill_status = False # Previous View in **kwargs self.previous_view = None # -- Displayer initialisation -- # self.construct() def construct(self, **kwargs): """ Construt view. to not fill the view during initialization. 'grid' (obj): Instance of Grid. 'm_frame' (Frame): Tkinter master frame of view. """ # 1. Create new grid in page container. self.grid = Grid(frame=self.f_container, width=self.width, height=self.height, padx=self.padx, pady=self.pady, bg=self.bg) # 2. Get view frame for displayer function self.m_frame = self.grid.master_frame # 3. Construct the view rows self.row_0(action="construct") def fill(self, **kwargs): """ Fill the view rows. 'json_script' (dict): texts for view. 'name' (str): view name. """ for key, value in kwargs.items(): if key == "view": self.previous_view = value elif key == "page": self.page_to_display = value # 1. Get the script. self.json_script = self.session.get_script(package_name="others", file_name="error404") # 2. Save name of view for displayer. self.name = self.json_script.get("view_name") # 3. Refresh rows. if self.fill_status is True: self.row_0(action="refresh") # 3. Fill the view rows. self.row_0(action="fill") self.fill_status = True def display_page(self): """ Display previous view. """ self.displayer.display(c_view="error_404", f_view=self.page_to_display) def row_0(self, action=None): """ Name : ERROR cols : 0 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=500, padx=self.padx, pady=self.pady, bg="#ffffff") self.grid.column(span=2, row=0, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=8, row=0, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=0, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get script txt = self.json_script.get("row_0") # -- COLUMN 1/3 : EMPTY -- # # -- COLUMN 2/3 : ERROR 404 IMG -- # if self.w_error404_img is None: img = Image.open("frontend/images/views/search/error_404.png") imgResize = img.resize((300, 300), Image.ANTIALIAS) imgTkinter = ImageTk.PhotoImage(imgResize) self.w_error404_img = Label(self.grid.col_frames[0][1], image=imgTkinter, borderwidth=5, bg="#ffffff") self.w_error404_img.image = imgTkinter self.w_error404_img.pack(fill="both", expand=True) # -- COLUMN 3/3 : ERROR 404 IMG -- # if self.w_error404_button is None: self.w_error404_button = Button(self.grid.col_frames[0][1], text=txt.get("error_button"), fg="#ffffff", bg="#6B7379", activeforeground="#ffffff", activebackground="#6B7379", command=self.display_page) self.w_error404_button.pack(expand=True) elif action == "refresh": self.w_error404_img.pack_forget() self.w_error404_button.pack_forget() self.w_error404_img = None self.w_error404_button = None
class UserWelcome(): def __init__(self, container=None, displayer=None, session=None): """ 'container' (Obj ): instance of Container. 'displayer' (obj ): instance of Displayer. 'session,' (obj ): instance of Session. 'grid' (Obj ): instance of Grid. 'f_container' (Frame): container frame. 'm_frame' (Frame): master frame of view. 'name' (str ): name of view. 'json_script' (dict ): json dict of script. 'width' (int ): view width. 'height' (int ): view height. 'padx' (int ): view 'pady' (int ): view 'bg' (str ): view bg. """ # Instances self.container = container self.displayer = displayer self.session = session self.grid = None # Frames self.f_container = self.container.f_container self.m_frame = None # Informations self.name = None # Script self.json_script = None # Style Sheet self.width = self.container.width self.height = self.container.height self.padx = 0 self.pady = 0 self.bg = "#ffffff" # Tk control variables self.var_user_id = IntVar() self.w_avatars_fill = False # For fill this view self.users = None # Widgets row 0 self.w_title = None # widgets row 1 self.w_avatar_icons = [] self.w_avatar_names = [] self.w_user_radios = [] self.w_subscribe_buttons = [] # Widgets row 2 self.w_avatar_button = None # Fill status self.fill_status = False # Previous View in **kwargs self.previous_view = None # -- Displayer initialisation -- # self.construct() def construct(self, **kwargs): """ Construt view. to not fill the view during initialization. 'grid' (obj): Instance of Grid. 'm_frame' (Frame): Tkinter master frame of view. """ # 1. Create new grid in page container. self.grid = Grid(frame=self.f_container, width=self.width, height=self.height, padx=self.padx, pady=self.pady, bg=self.bg) # 2. Get view frame for displayer function self.m_frame = self.grid.master_frame # 3. Construct the view rows self.row_0(action="construct") self.row_1(action="construct") self.row_2(action="construct") def fill(self, **kwargs): """ Fill the view rows. 'json_script' (dict): texts for view. 'name' (str): view name. """ for key, value in kwargs.items(): if key == "view": self.previous_view = value # 1. Get the script. self.json_script = self.session.get_script(package_name="user", file_name="welcome") # 2. Save name of view for displayer. self.name = self.json_script.get("view_name") # 3. Get users self.users = self.session.dbmanager.db_user.read(action="*") if self.w_avatars_fill is True: self.row_1(action="refresh") # 3. Refresh rows. if self.fill_status is True: self.row_0(action="refresh") self.row_1(action="refresh") self.row_2(action="refresh") # 4. Fill the view rows. self.row_0(action="fill") self.row_1(action="fill") self.row_2(action="fill") self.fill_status = True def display_previous(self): """ Display previous view. """ self.displayer.display(c_view="user_welcome", f_view=self.previous_view) def display_create_user(self): """ Display view user_form. Package "USER" """ self.displayer.display( c_view="user_welcome", f_view="user_form", ) def display_home(self): """ Display view user_form. Package "USER" """ if len(self.users) != 0: self.session.user_id = self.var_user_id.get() self.displayer.display(c_view="user_welcome", f_view="home") else: self.display_create_user() def row_0(self, action=None): """ Name : TITLE cols : 1 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=150, padx=0, pady=0, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=12, row=0, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_0") # -- COLUMN 1/1 : TITLE -- # if self.w_title is None: self.w_title = Label(self.grid.col_frames[0][0], padx=5, text=txt.get("view_title"), bg="#ffffff", fg="#000000", font="Helvetica 12 bold") self.w_title.pack(fill="both", expand=True) elif action == "refresh": self.w_title.pack_forget() self.w_title = None def row_1(self, action=None): """ Name : USERS cols : 1 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=150, padx=0, pady=0, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": if self.w_avatars_fill is not True: # Get texts for this row txt = self.json_script.get("row_1") user_counter = 0 free_space = 0 while user_counter != len(self.users): user = self.users[user_counter] # -- COLUMN 1 : USER AVATAR IMAGE -- # img = Image.open("frontend/images/avatars/{}.png".format( user.get("user_avatar_name"))) img_resize = img.resize((75, 75), Image.ANTIALIAS) img_tkinter = ImageTk.PhotoImage(img_resize) w_avatar_icon = Label( self.grid.col_frames[1][user_counter], image=img_tkinter, borderwidth=0, bg="#ffffff") w_avatar_icon.image = img_tkinter w_avatar_icon.pack(fill='both', expand=True) # -- COLUMN 1 : USER AVATAR NAME -- # w_avatar_name = Label( self.grid.col_frames[1][user_counter], text="{}".format(user.get("user_name")), anchor="n", bg="#ffffff", pady=10, ) w_avatar_name.pack(fill='both', expand=True) # -- COLUMN 1 : USER AVATAR RADIO -- # w_user_radio = Radiobutton( self.grid.col_frames[1][user_counter], variable=self.var_user_id, value=user.get("user_id"), bg="#ffffff") w_user_radio.pack(fill='both', expand=True) if user_counter == 0: w_user_radio.select() self.w_avatar_icons.append(w_avatar_icon) self.w_avatar_names.append(w_avatar_name) self.w_user_radios.append(w_user_radio) user_counter += 1 free_space = 6 - user_counter free_counter = 0 while free_counter != free_space: # -- COLUMN 1 : USER AVATAR IMAGE -- # img = Image.open( "frontend/images/avatars/empty.png").convert("RGBA") img_resize = img.resize((75, 75), Image.ANTIALIAS) img_tkinter = ImageTk.PhotoImage(img_resize) w_avatar_icon = Label( self.grid.col_frames[1][user_counter], image=img_tkinter, bg="#ffffff") w_avatar_icon.image = img_tkinter w_avatar_icon.pack(fill="both", expand=True) # -- COLUMN 1 : USER AVATAR NAME -- # w_avatar_name = Label( self.grid.col_frames[1][user_counter], text=txt.get("user_empty"), anchor="n", bg="#ffffff", pady=10, ) w_avatar_name.pack(fill='both', expand=True) # -- COLUMN 1 : FREE USER SUBSCRIBE BUTTON -- # w_subscribe_button = Button( self.grid.col_frames[1][user_counter], text=txt.get("user_empty_button"), borderwidth=0, font="Helvetica 8 bold", bg="#7dd2f0", fg="#ffffff", activebackground="#71bdd8", activeforeground="#ffffff", command=self.display_create_user) w_subscribe_button.pack(fill='both', expand=True) self.w_avatar_icons.append(w_avatar_icon) self.w_avatar_names.append(w_avatar_name) self.w_subscribe_buttons.append(w_subscribe_button) user_counter += 1 free_counter += 1 self.w_avatars_fill = True elif action == "refresh": """ Refresh this row. """ for w_avatar_icon in self.w_avatar_icons: w_avatar_icon.pack_forget() for w_avatar_name in self.w_avatar_names: w_avatar_name.pack_forget() for w_user_radio in self.w_user_radios: w_user_radio.pack_forget() for w_subscribe_button in self.w_subscribe_buttons: w_subscribe_button.pack_forget() self.w_subscribe_buttons = [] self.w_avatar_icons = [] self.w_avatar_names = [] self.w_user_radios = [] self.w_avatars_fill = False def row_2(self, action=None): """ Name : SUBMIT BUTTON cols : 3 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=225, padx=0, pady=0, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=4, row=2, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=4, row=2, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=4, row=2, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_2") if self.w_avatar_button is None: # -- COLUMN 1 : AVATAR BUTTON -- # self.w_avatar_button = Button(self.grid.col_frames[2][1], text=txt.get("submit_button"), fg="#ffffff", bg="#7A57EC", activeforeground="#ffffff", activebackground="#845EFF", command=self.display_home) self.w_avatar_button.pack(fill="x", side="bottom", expand=True) elif action == "refresh": """ Refresh this row. """ self.w_avatar_button.pack_forget() self.w_avatar_button = None
class Home(): def __init__( self, container=None, displayer=None, session=None ): """ 'container' (Obj ): instance of Container. 'displayer' (obj ): instance of Displayer. 'session,' (obj ): instance of Session. 'grid' (Obj ): instance of Grid. 'f_container' (Frame): container frame. 'm_frame' (Frame): master frame of view. 'name' (str ): name of view. 'json_script' (dict ): json dict of script. 'width' (int ): view width. 'height' (int ): view height. 'padx' (int ): view 'pady' (int ): view 'bg' (str ): view bg. """ # Instances self.container = container self.displayer = displayer self.session = session self.grid = None # Frames self.f_container = self.container.f_container self.m_frame = None # Informations self.name = None # Script self.json_script = None # Style Sheet self.width = self.container.width self.height = self.container.height self.padx = 0 self.pady = 0 self.bg = "#ffffff" # Tk control variables # Widgets row 0 self.canvas = None # Widgets row 1 self.w_search_label = None self.w_search_button = None # Widgets row 2 self.w_favorite_label = None self.w_favorite_button = None # Widgets row 3 self.w_settings_label = None self.w_settings_button = None # Widgets row 4 self.w_user_label = None self.w_user_button = None # Fill status self.fill_status = False # Previous View in **kwargs self.previous_view = None # -- Displayer initialisation -- # self.construct() def construct(self, **kwargs): """ Construt view. to not fill the view during initialization. 'grid' (obj): Instance of Grid. 'm_frame' (Frame): Tkinter master frame of view. """ # 1. Create new grid in page container. self.grid = Grid( frame=self.f_container, width=self.width, height=self.height, padx=self.padx, pady=self.pady, bg=self.bg ) # 2. Get view frame for displayer function self.m_frame = self.grid.master_frame # 3. Construct the view rows self.row_0(action="construct") self.row_1(action="construct") self.row_2(action="construct") self.row_3(action="construct") self.row_4(action="construct") def fill(self, **kwargs): """ Fill the view rows. 'json_script' (dict): texts for view. 'name' (str): view name. """ # 1. Get the script. self.json_script = self.session.get_script( package_name="others", file_name="home" ) # 2. Save name of view for displayer. self.name = self.json_script.get("view_name") # 3. Refresh rows. if self.fill_status is True: self.row_0(action="refresh") self.row_1(action="refresh") self.row_2(action="refresh") self.row_3(action="refresh") self.row_4(action="refresh") # 4. Fill the view rows. self.row_0(action="fill") self.row_1(action="fill") self.row_2(action="fill") self.row_3(action="fill") self.row_4(action="fill") self.fill_status = True def display_previous(self): """ Display previous view. """ self.displayer.display( c_view="home", f_view=self.previous_view ) def display_search_engine(self): """ Display view "search_engine". Package "SEARCH". """ self.displayer.display( c_view="home", f_view="search_engine" ) def display_product_favorite(self): """ Display view "product_favorite". Package "SEARCH". """ self.displayer.display( c_view="home", f_view="product_favorite" ) def display_settings(self): """ Display view "settings". Package "OTHERS". """ self.displayer.display( c_view="home", f_view="settings" ) def display_user_profil(self): """ Display view "user_profil". Package "USER". """ self.displayer.display( c_view="home", f_view="user_profil" ) def row_0(self, action=None): """ Name : TITLE cols : 1 """ if action == "construct": # -- CREATE ROW -- # self.grid.row( width=self.width, height=250, padx=self.padx, pady=self.pady, bg="#ffffff" ) # -- CREATE COLS -- # self.grid.column( span=12, row=0, width=None, height=None, padx=None, pady=None, bg=None ) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_0") if self.canvas is None: img = Image.open( "frontend/images/views/home/background.jpg" ) imgResize = img.resize((640, 500), Image.ANTIALIAS) imgTkinter = ImageTk.PhotoImage(imgResize) self.canvas = Canvas( self.grid.col_frames[0][0], width=self.width, height=250, highlightthickness=0 ) self.canvas.pack(expand=True, fill="both") self.canvas.create_image(0, 0, image=imgTkinter, anchor="nw") self.canvas.image = imgTkinter self.canvas.create_text( 120, 100, text=txt.get("view_title"), anchor='nw', fill="#ffffff", font="Helvetica 20 bold" ) elif action == "refresh": """ Refresh this row. """ self.canvas.delete("all") self.canvas.pack_forget() self.canvas = None def row_1(self, action=None): """ Name : SEARCH cols : 4 """ if action == "construct": # -- CREATE ROW -- # self.grid.row( width=self.width, height=100, padx=self.padx, pady=self.pady, bg="#84dbff" ) # -- CREATE COLS -- # self.grid.column( span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=6, row=1, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=3, row=1, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=1, row=1, width=None, height=None, padx=None, pady=None, bg=None ) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_1") if self.w_search_label is None: # -- COLUMN 1 : IMAGE SEARCH -- # img = Image.open("frontend/images/views/home/search.png") img_resize = img.resize((70, 70), Image.ANTIALIAS) search_img = ImageTk.PhotoImage(img_resize) self.w_search_label = Label( self.grid.col_frames[1][0], image=search_img, bg="#84dbff" ) self.w_search_label.image = search_img self.w_search_label.pack(fill="both", expand=True) if self.w_search_button is None: # -- COLUMN 2 : SEARCH BUTTON -- # self.w_search_button = Button( self.grid.col_frames[1][2], text=txt.get("button"), fg="#000000", bg="#ededed", activeforeground="#000000", activebackground="#ffffff", borderwidth=0, command=self.display_search_engine ) self.w_search_button.pack(fill="x", expand=True) elif action == "refresh": """ Refresh this row. """ self.w_search_label.pack_forget() self.w_search_button.pack_forget() self.w_search_label = None self.w_search_button = None def row_2(self, action=None): """ Name : FAVORITE PRODUCT cols : 4 """ if action == "construct": # -- CREATE ROW -- # self.grid.row( width=self.width, height=100, padx=self.padx, pady=self.pady, bg="#26b16b" ) # -- CREATE COLS -- # self.grid.column( span=2, row=2, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=6, row=2, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=3, row=2, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=1, row=2, width=None, height=None, padx=None, pady=None, bg=None ) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_2") if self.w_favorite_label is None: # -- COLUMN 1 : IMAGE FAVORITE -- # img = Image.open("frontend/images/views/home/favorite.png") img_resize = img.resize((70, 70), Image.ANTIALIAS) favorite_img = ImageTk.PhotoImage(img_resize) self.w_favorite_label = Label( self.grid.col_frames[2][0], image=favorite_img, bg="#26b16b" ) self.w_favorite_label.image = favorite_img self.w_favorite_label.pack(fill="both", expand=True) if self.w_favorite_button is None: # -- COLUMN 2 : SEARCH BUTTON -- # self.w_favorite_button = Button( self.grid.col_frames[2][2], text=txt.get("button"), fg="#000000", bg="#ededed", activeforeground="#000000", activebackground="#ffffff", borderwidth=0, command=self.display_product_favorite ) self.w_favorite_button.pack(fill="x", expand=True) elif action == "refresh": self.w_favorite_label.pack_forget() self.w_favorite_button.pack_forget() self.w_favorite_label = None self.w_favorite_button = None def row_3(self, action=None): """ Name : UPDATE cols : 4 """ if action == "construct": # -- CREATE ROW -- # self.grid.row( width=self.width, height=100, padx=self.padx, pady=self.pady, bg="#ffe399" ) # -- CREATE COLS -- # self.grid.column( span=2, row=3, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=6, row=3, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=3, row=3, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=1, row=3, width=None, height=None, padx=None, pady=None, bg=None ) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_3") if self.w_settings_label is None: # -- COLUMN 1 : SETTINGS IMAGE -- # img = Image.open("frontend/images/views/home/settings.png") img_resize = img.resize((70, 70), Image.ANTIALIAS) settings_img = ImageTk.PhotoImage(img_resize) self.w_settings_label = Label( self.grid.col_frames[3][0], image=settings_img, bg="#ffe399" ) self.w_settings_label.image = settings_img self.w_settings_label.pack(fill="both", expand=True) if self.w_settings_button is None: # -- COLUMN 2 : SETTINGS BUTTON -- # self.w_settings_button = Button( self.grid.col_frames[3][2], text=txt.get("button"), fg="#000000", bg="#ededed", activeforeground="#000000", activebackground="#ffffff", borderwidth=0, command=self.display_settings ) self.w_settings_button.pack(fill="x", expand=True) elif action == "refresh": self.w_settings_label.pack_forget() self.w_settings_button.pack_forget() self.w_settings_label = None self.w_settings_button = None def row_4(self, action=None): """ Name : USER PROFIL cols : 4 """ if action == "construct": # -- CREATE ROW -- # self.grid.row( width=self.width, height=100, padx=self.padx, pady=self.pady, bg="#ff4347" ) # -- CREATE COLS -- # self.grid.column( span=2, row=4, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=6, row=4, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=3, row=4, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=1, row=4, width=None, height=None, padx=None, pady=None, bg=None ) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_4") if self.w_user_label is None: # -- COLUMN 1 : IMAGE USER -- # img = Image.open("frontend/images/views/home/user.png") img_resize = img.resize((70, 70), Image.ANTIALIAS) user_img = ImageTk.PhotoImage(img_resize) self.w_user_label = Label( self.grid.col_frames[4][0], image=user_img, bg="#ff4347" ) self.w_user_label.image = user_img self.w_user_label.pack(fill="both", expand=True) if self.w_user_button is None: # -- COLUMN 2 : USER BUTTON -- # self.w_user_button = Button( self.grid.col_frames[4][2], text=txt.get("button"), fg="#000000", bg="#ededed", activeforeground="#000000", activebackground="#ffffff", anchor="w", borderwidth=0, command=self.display_user_profil ) self.w_user_button.pack(fill="x", expand=True) elif action == "refresh": self.w_user_label.pack_forget() self.w_user_button.pack_forget() self.w_user_label = None self.w_user_button = None
class SearchCategories(): def __init__(self, container=None, displayer=None, session=None): """ 'container' (Obj ): instance of Container. 'displayer' (obj ): instance of Displayer. 'session,' (obj ): instance of Session. 'grid' (Obj ): instance of Grid. 'f_container' (Frame): container frame. 'm_frame' (Frame): master frame of view. 'name' (str ): name of view. 'json_script' (dict ): json dict of script. 'width' (int ): view width. 'height' (int ): view height. 'padx' (int ): view 'pady' (int ): view 'bg' (str ): view bg. """ # Instances self.container = container self.displayer = displayer self.session = session self.grid = None # Frames self.f_container = self.container.f_container self.m_frame = None # Informations self.name = None # Script self.json_script = None # Style Sheet self.width = self.container.width self.height = self.container.height self.padx = 0 self.pady = 0 self.bg = "#ffffff" # Tk control variables self.var_category = IntVar() # Widgets row 0 self.var_paging_label = StringVar() self.w_paging_txt = None self.w_paging_previous = None self.w_paging_next = None # Row 1 self.w_language_flags = [] self.w_category_names = [] self.w_category_products = [] self.w_category_radios = [] # Row 2 self.w_previous_button = None self.w_submit_button = None # Paging self.page = 0 self.pages = 0 self.p_start = None self.p_stop = None self.paging_categories = None # Fill status self.fill_status = False # Previous View in **kwargs self.previous_view = None # -- Displayer initialisation -- # self.construct() def construct(self, **kwargs): """ Construt view. to not fill the view during initialization. 'grid' (obj): Instance of Grid. 'm_frame' (Frame): Tkinter master frame of view. """ # 1. Create new grid in page container. self.grid = Grid(frame=self.f_container, width=self.width, height=self.height, padx=self.padx, pady=self.pady, bg=self.bg) # 2. Get view frame for displayer function self.m_frame = self.grid.master_frame # 3. Construct the view rows self.row_0(action="construct") self.row_1(action="construct") self.row_2(action="construct") def fill(self, **kwargs): """ Fill the view rows. 'json_script' (dict): texts for view. 'name' (str): view name. """ for key, value in kwargs.items(): if key == "view": self.previous_view = value # 1. Get the script. self.json_script = self.session.get_script(package_name="search", file_name="categories") # 2. Save name of view for displayer. self.name = self.json_script.get("view_name") self.categories = self.session.dbmanager.db_category.read(action="*") # Count categories self.categories_count = len(self.categories) self.page = 0 self.pages = int(self.categories_count / 15) self.paging_categories = self.categories[0:15] # 3. Refresh rows. if self.fill_status is True: self.row_0(action="refresh") self.row_1(action="refresh") self.row_2(action="refresh") # 4. Fill the view rows. self.row_0(action="fill") self.row_1(action="fill") self.row_2(action="fill") self.fill_status = True if self.categories_count == 0: self.display_empty() return 1 def paging(self, p_action=None): """ 'current_page' (int ): Nunber of current page. 'action' (str ): Next or Previous 'elements_per_page' (int ): Number of element per page. 'list_start' (int ): 'list_stop' (int ): 'list' (list): List to cut. """ # Paging if p_action == "next": self.page = self.page + 1 elif p_action == "previous": self.page = self.page - 1 self.p_start = int(self.page * 15) self.p_stop = int(self.p_start + 15) self.paging_categories = self.categories[self.p_start:self.p_stop] self.row_0(action="refresh") self.row_1(action="refresh") self.row_2(action="refresh") self.row_1(action="fill") self.row_2(action="fill") def paging_next(self): """ Paging. """ test = self.page + 1 if test <= self.pages: self.paging(p_action="next") def paging_prev(self): """ Paging. """ test = self.page - 1 if test >= 0: self.paging(p_action="previous") def display_previous(self): """ Display previous view. """ self.displayer.display(c_view="search_categories", f_view=self.previous_view) def display_search_result(self): """ Display search result. """ category_id = self.var_category.get() self.displayer.display(c_view="search_categories", f_view="search_result", search_action="cat_id", search_value=category_id) def display_empty(self): """ Display search result. """ self.displayer.display(c_view="search_categories", f_view="empty", page="categories") def row_0(self, action=None): """ Name : PAGING cols : 0 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=40, padx=self.padx, pady=self.pady, bg="#E3E9ED") self.grid.column(span=9, row=0, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=1, row=0, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=0, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get script txt = self.json_script.get("row_0") # -- COLUMN 1/3 : EMPTY -- # if self.w_paging_txt is None: self.var_paging_label.set("{} {} / {}".format( txt.get("paging_label"), self.page, self.pages)) self.w_paging_txt = Label(self.grid.col_frames[0][0], anchor="w", pady=5, padx=5, textvariable=self.var_paging_label, bg="#E3E9ED", fg="#000000", font="Helvetica 10 bold") self.w_paging_txt.pack(fill='both', expand=True) # -- COLUMN 2/3 : PAGING BUTTON -- # if self.w_paging_previous is None: self.w_paging_previous = Button(self.grid.col_frames[0][2], text=txt.get("paging_prev"), fg="#ffffff", bg="#6B7379", activeforeground="#ffffff", activebackground="#6B7379", command=self.paging_prev) self.w_paging_previous.pack(side="left", expand=True) # -- COLUMN 2/3 : PAGING BUTTON -- # if self.w_paging_next is None: self.w_paging_next = Button(self.grid.col_frames[0][2], text=txt.get("paging_next"), fg="#ffffff", bg="#1D262D", activeforeground="#ffffff", activebackground="#1D262D", command=self.paging_next) self.w_paging_next.pack(side="right", expand=True) elif action == "refresh": # Get script txt = self.json_script.get("row_0") self.var_paging_label.set("{} {} / {}".format( txt.get("paging_label"), self.page, self.pages)) def row_1(self, action=None): """ Name : CATEGORIES cols : 3 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=500, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=5, bg=None) self.grid.column(span=6, row=1, width=None, height=None, padx=None, pady=5, bg=None) self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=5, bg=None) self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=5, bg=None) elif action == "fill": # Get script txt = self.json_script.get("row_1") count = 0 for category in self.paging_categories[0:15]: """# -- COLUMN 1/5 : CATEGORY LANGUAGE -- # img = Image.open( "v2/frontend/resources/images/flags/{}.png" .format(category["language"]) ) imgResize = img.resize((20, 20), Image.ANTIALIAS) imgTkinter = ImageTk.PhotoImage(imgResize) w_language_flag = Label( self.grid.col_frames[2][0], image=imgTkinter, borderwidth=0, bg="#ffffff" ) w_language_flag.image = imgTkinter w_language_flag.pack(fill='both', expand=True)""" w_category_name = Label(self.grid.col_frames[1][1], anchor="w", pady=0, text=category["category_name"], bg="#ffffff", fg="#000000", font="Helvetica 10 bold") w_category_name.pack(fill='both', expand=True) w_category_product = Label(self.grid.col_frames[1][2], pady=0, text=category["category_products"], bg="#ffffff", fg="#000000", font="Helvetica 10 bold") w_category_product.pack(fill='both', expand=True) w_category_radio = Radiobutton(self.grid.col_frames[1][3], variable=self.var_category, value=category["category_id"], bg="#ffffff") w_category_radio.pack(fill='both', expand=True) # For UX DESIGN if count == 0: w_category_radio.select() count += 1 # self.w_language_flags.append(w_language_flag) self.w_category_names.append(w_category_name) self.w_category_products.append(w_category_product) self.w_category_radios.append(w_category_radio) elif action == "refresh": if len(self.w_language_flags) != 0: for tk_widget in self.w_language_flags: tk_widget.pack_forget() if len(self.w_category_names) != 0: for tk_widget in self.w_category_names: tk_widget.pack_forget() if len(self.w_category_products) != 0: for tk_widget in self.w_category_products: tk_widget.pack_forget() if len(self.w_category_radios) != 0: for tk_widget in self.w_category_radios: tk_widget.pack_forget() def row_2(self, action=None): """ Name : SUBMIT BUTTON cols : 4 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=60, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=2, row=2, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=4, row=2, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=4, row=2, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=2, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": txt = self.json_script.get("row_2") # -- COLUMN 1/4 : EMPTY -- # # -- COLUMN 2/4 : SUBMIT BUTTON -- # if self.w_previous_button is None: self.w_previous_button = Button( self.grid.col_frames[2][1], text=txt.get("previous_button"), fg="#ffffff", bg="#7A57EC", activeforeground="#ffffff", activebackground="#845EFF", command=self.display_previous) self.w_previous_button.pack(side=BOTTOM, fill=X) # -- COLUMN 3/4 : SUBMIT BUTTON -- # if self.w_submit_button is None: self.w_submit_button = Button( self.grid.col_frames[2][2], text=txt.get("submit_button"), fg="#ffffff", bg="#7A57EC", activeforeground="#ffffff", activebackground="#845EFF", command=self.display_search_result) self.w_submit_button.pack(side=BOTTOM, fill=X) # -- COLUMN 3/3 : EMPTY -- # elif action == "refresh": pass
class UserAvatars(): def __init__(self, container=None, displayer=None, session=None): """ 'container' (obj ): instance of Container. 'displayer' (obj ): instance of Displayer. 'session,' (obj ): instance of Session. 'grid' (obj ): instance of Grid. 'f_container' (Frame): container frame. 'm_frame' (Frame): master frame of view. 'name' (str ): name of view. 'json_script' (dict ): json dict of script. 'width' (int ): view width. 'height' (int ): view height. 'padx' (int ): view 'pady' (int ): view 'bg' (str ): view bg. """ # Instances self.container = container self.displayer = displayer self.session = session self.grid = None # Frames self.f_container = self.container.f_container self.m_frame = None # Informations self.name = None # Script self.json_script = None # Style Sheet self.width = self.container.width self.height = self.container.height self.padx = 0 self.pady = 0 self.bg = "#ffffff" # Tk control variables self.var_avatar = StringVar() self.avatars = [ "artist", "astronaut", "clown", "nurse", "police", "reporter", "santa", "scientist", "sheriff", "worker", "cashier", "doctor", "fireman" ] self.avatar_name = "" self.w_avatar_fill = False # Widgets row 0 self.w_title = None # widgets row 1 & 2 self.w_img_avatars = [] self.w_avatar_names = [] self.w_avatar_radios = [] # Widgets row 3 self.w_previous_button = None self.w_submit_button = None # Fill status self.fill_status = False # Previous View in **kwargs self.previous_view = None # -- Displayer initialisation -- # self.construct() def construct(self, **kwargs): """ Construt view. to not fill the view during initialization. 'grid' (obj): Instance of Grid. 'm_frame' (Frame): Tkinter master frame of view. """ # 1. Create new grid in page container. self.grid = Grid(frame=self.f_container, width=self.width, height=self.height, padx=self.padx, pady=self.pady, bg=self.bg) # 2. Get view frame for displayer function self.m_frame = self.grid.master_frame # 3. Construct the view rows self.row_0(action="construct") self.row_1(action="construct") self.row_2(action="construct") self.row_3(action="construct") def fill(self, **kwargs): """ Fill the view rows. 'json_script' (dict): texts for view. 'name' (str): view name. """ for key, value in kwargs.items(): if key == "view": self.previous_view = value # 1. Get the script. self.json_script = self.session.get_script(package_name="user", file_name="avatars") # 2. Save name of view for displayer. self.name = self.json_script.get("view_name") # 3. Refresh rows. if self.fill_status is True: self.row_0(action="refresh") self.row_1(action="refresh") self.row_2(action="refresh") self.row_3(action="refresh") # 3. Fill the view rows. self.row_0(action="fill") self.row_1(action="fill") self.row_2(action="fill") self.row_3(action="fill") self.fill_status = True def display_previous(self): """ Display previous view. """ self.avatar_name = self.var_avatar.get() self.displayer.display(c_view="user_avatars", f_view=self.previous_view, avatar_name=self.avatar_name) def row_0(self, action=None): """ Name : TITLE cols : 1 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=150, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=12, row=0, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_0") # -- COLUMN 1/1 : TITLE -- # if self.w_title is None: self.w_title = Label(self.grid.col_frames[0][0], text=txt.get("view_title"), bg="#ffffff", fg="#000000", font="Helvetica 12 bold") self.w_title.pack(fill="both", expand=True) elif action == "refresh": pass def row_1(self, action=None): """ Name : AVATAR LIST 0 -6 cols : 6 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=150, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": if self.w_avatar_fill is not True: # -- COLUMN 1/1 : TITLE -- # count = 0 for avatar in self.avatars[0:6]: # -- COLUMN 1 : AVATAR IMAGE -- # img = Image.open( "frontend/images/avatars/{}.png".format(avatar)) img_resize = img.resize((50, 50), Image.ANTIALIAS) img_tkinter = ImageTk.PhotoImage(img_resize) w_img_avatar = Label(self.grid.col_frames[1][count], image=img_tkinter, borderwidth=0, bg="#ffffff") w_img_avatar.image = img_tkinter w_img_avatar.pack(fill='both', expand=True) # -- COLUMN 1 : AVATAR NAME -- # w_avatar_name = Label(self.grid.col_frames[1][count], text=avatar, bg="#ffffff") w_avatar_name.pack() # -- COLUMN 1 : AVATAR RADIO -- # w_avatar_radio = Radiobutton( self.grid.col_frames[1][count], variable=self.var_avatar, value=avatar, bg="#ffffff") w_avatar_radio.pack() if count == 0: w_avatar_radio.select() self.w_img_avatars.append(w_img_avatar) self.w_avatar_names.append(w_avatar_name) self.w_avatar_radios.append(w_avatar_radio) count += 1 elif action == "refresh": pass def row_2(self, action=None): """ Name : AVATAR LIST 6 - 12 cols : 6 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=150, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=2, row=2, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=2, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=2, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=2, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=2, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=2, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": if self.w_avatar_fill is not True: # -- COLUMN 1/1 : TITLE -- # count = 0 for avatar in self.avatars[6:12]: # -- COLUMN 1 : AVATAR IMAGE -- # img = Image.open( "frontend/images/avatars/{}.png".format(avatar)) img_resize = img.resize((50, 50), Image.ANTIALIAS) img_tkinter = ImageTk.PhotoImage(img_resize) w_img_avatar = Label(self.grid.col_frames[2][count], image=img_tkinter, borderwidth=0, bg="#ffffff") w_img_avatar.image = img_tkinter w_img_avatar.pack(fill='both', expand=True) # -- COLUMN 1 : AVATAR NAME -- # w_avatar_name = Label(self.grid.col_frames[2][count], text=avatar, bg="#ffffff") w_avatar_name.pack() # -- COLUMN 1 : AVATAR RADIO -- # w_avatar_radio = Radiobutton( self.grid.col_frames[2][count], variable=self.var_avatar, value=avatar, bg="#ffffff") w_avatar_radio.pack() count += 1 self.w_avatar_fill = True elif action == "refresh": pass def row_3(self, action=None): """ Name : SUBMIT BUTTON cols : 4 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=100, padx=0, pady=0, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=2, row=3, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=4, row=3, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=4, row=3, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=3, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": txt = self.json_script.get("row_3") # -- COLUMN 1/4 : EMPTY -- # # -- COLUMN 2/4 : SUBMIT BUTTON -- # if self.w_previous_button is None: self.w_previous_button = Button( self.grid.col_frames[3][1], text=txt.get("previous_button"), fg="#ffffff", bg="#7A57EC", activeforeground="#ffffff", activebackground="#845EFF", command=self.display_previous) self.w_previous_button.pack(side=BOTTOM, fill=X) # -- COLUMN 3/4 : SUBMIT BUTTON -- # if self.w_submit_button is None: self.w_submit_button = Button(self.grid.col_frames[3][2], text=txt.get("submit_button"), fg="#ffffff", bg="#7A57EC", activeforeground="#ffffff", activebackground="#845EFF", command=self.display_previous) self.w_submit_button.pack(side=BOTTOM, fill=X) # -- COLUMN 4/4 : EMPTY -- # elif action == "refresh": """ Refresh this row. """ self.w_previous_button.pack_forget() self.w_submit_button.pack_forget() self.w_previous_button = None self.w_submit_button = None
class ProductSheet(): def __init__(self, container=None, displayer=None, session=None): """ 'container' (Obj ): instance of Container. 'displayer' (obj ): instance of Displayer. 'session,' (obj ): instance of Session. 'grid' (Obj ): instance of Grid. 'f_container' (Frame): container frame. 'm_frame' (Frame): master frame of view. 'name' (str ): name of view. 'json_script' (dict ): json dict of script. 'width' (int ): view width. 'height' (int ): view height. 'padx' (int ): view 'pady' (int ): view 'bg' (str ): view bg. """ # Instances self.container = container self.displayer = displayer self.session = session self.grid = None # Frames self.f_container = self.container.f_container self.m_frame = None # Informations self.name = None # Script self.json_script = None # Style Sheet self.width = self.container.width self.height = self.container.height self.padx = 0 self.pady = 0 self.bg = "#ffffff" # Tk control variables # Widgets row 0 self.w_title = None # Widgets row 1 self.w_img_product = None self.w_name_product = None self.w_brand_product = None self.w_nutriscore_product = None # Widgets row 2 self.w_best_button = None self.w_edit_button = None self.w_trash_button = None self.w_add_button = None # Widgets row 4 self.canvas_calories = None self.w_calories_img = None self.w_calories_label = None # Widgets row 5 self.canvas_sugar = None self.w_sugar_img = None self.w_sugar_label = None self.w_sugar_value = None # Widgets row 6 self.w_stores_img = None self.w_stores_label = None self.w_stores_value = None # Widgets row 7 self.w_author_img = None self.w_author_label = None self.w_author_value = None # Widgets row 8 self.w_submit_button = None self.favorite_status = False self.product = None self.product_id = 0 self.product_img = None self.product_name = None self.product_brand = None self.product_nutriscore = None self.product_kcal = 0 self.product_sugar = 0 self.product_author = None self.product_store = None # Fill status self.fill_status = False # Previous View in **kwargs self.previous_view = None # -- Displayer initialisation -- # self.construct() def construct(self, **kwargs): """ Construt view. to not fill the view during initialization. 'grid' (obj): Instance of Grid. 'm_frame' (Frame): Tkinter master frame of view. """ # 1. Create new grid in page container. self.grid = Grid(frame=self.f_container, width=self.width, height=self.height, padx=self.padx, pady=self.pady, bg=self.bg) # 2. Get view frame for displayer function self.m_frame = self.grid.master_frame # 3. Construct the view rows self.row_0(action="construct") self.row_1(action="construct") self.row_2(action="construct") self.row_3(action="construct") self.row_4(action="construct") self.row_5(action="construct") self.row_6(action="construct") self.row_7(action="construct") def fill(self, **kwargs): """ Fill the view rows. 'json_script' (dict): texts for view. 'name' (str): view name. """ for key, value in kwargs.items(): if key == "view": self.previous_view = value elif key == "product_id": self.product_id = value # 1. Get the script. self.json_script = self.session.get_script(package_name="product", file_name="sheet") # 2. Save name of view for displayer. self.name = self.json_script.get("view_name") # Get product informations self.product = self.session.dbmanager.db_product.read( action="id", product_id=self.product_id) favorite = self.session.dbmanager.db_user_prod.read( action="test", user_id=self.session.user_id, product_id=self.product_id) if len(favorite) == 1: self.favorite_status = True else: self.favorite_status = False self.product_img = self.product[0]["product_img_url"] self.product_name = self.product[0]["product_name"] self.product_brand = self.product[0]["product_brand"] self.product_nutriscore = self.product[0]["product_nutriscore"] self.product_kcal = self.product[0]["product_kcal"] self.product_sugar = self.product[0]["product_sugar"] self.product_author = self.product[0]["product_creator"] self.product_store = self.product[0]["product_store"] # 3. Refresh rows. if self.fill_status is True: self.row_0(action="refresh") self.row_1(action="refresh") self.row_2(action="refresh") self.row_3(action="refresh") self.row_4(action="refresh") self.row_5(action="refresh") self.row_6(action="refresh") self.row_7(action="refresh") # 4. Fill the view rows. self.row_0(action="fill") self.row_1(action="fill") self.row_2(action="fill") self.row_3(action="fill") self.row_4(action="fill") self.row_5(action="fill") self.row_6(action="fill") self.row_7(action="fill") self.fill_status = True def display_substitutes(self): """ Display substitues. """ self.displayer.display(c_view="product_sheet", f_view="product_substitutes", product_id=self.product_id) def display_edit(self): """ Display product edit. """ self.displayer.display(c_view="product_sheet", f_view="product_edit", product_id=self.product_id) def display_search(self): """ Display "search". """ self.displayer.display(c_view="product_sheet", f_view="search_engine") def add_product(self): """ Add product to favorite in database. """ self.session.dbmanager.db_user_prod.create( user_id=self.session.user_id, product_id=self.product_id) self.favorite_status = True self.row_1("refresh") self.row_1("fill") def del_product_to_favorite(self): """ Add product to favorite in database. """ self.session.dbmanager.db_user_prod.delete( user_id=self.session.user_id, product_id=self.product_id) self.favorite_status = False self.row_1("refresh") self.row_1("fill") def trash_product(self): """ Delete product to database. """ self.session.dbmanager.db_product.delete(product_id=self.product_id) self.display_search() def row_0(self, action=None): """ Name : PRODUCT IMAGE cols : 3 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=250, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=6, row=0, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=5, row=0, width=None, height=None, padx=30, pady=30, bg=None) self.grid.column(span=1, row=0, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": if self.w_img_product is None: # -- COLUMN 1 : PRODUCT IMAGE -- # if self.product_img == "empty": img = Image.open("frontend/images/no_image.png") else: req = requests.get(self.product_img) img = Image.open(BytesIO(req.content)) img_resize = img.resize((150, 200), Image.ANTIALIAS) tk_img_product = ImageTk.PhotoImage(img_resize) self.w_img_product = Label(self.grid.col_frames[0][0], image=tk_img_product, bg="#ffffff") self.w_img_product.image = tk_img_product self.w_img_product.pack(fill='both', expand=True) if self.w_name_product is None: # -- COLUMN 2 : PRODUCT NAME -- # self.w_name_product = Label(self.grid.col_frames[0][1], text="{}".format( self.product_name), bg="#ffffff", fg="#000000", font="Helvetica 13 normal") self.w_name_product.pack(fill='both') if self.w_brand_product is None: # -- COLUMN 2 : PRODUCT BRAND -- # self.w_brand_product = Label(self.grid.col_frames[0][1], text="{}".format( self.product_brand), bg="#ffffff", fg="#000000", font="Helvetica 13 bold") self.w_brand_product.pack(fill='both') if self.w_nutriscore_product is None: # -- COLUMN 2 : PRODUCT NUTRISCORE -- # img = Image.open( "frontend/images/nutriscores/nutriscore_{}.png".format( self.product_nutriscore)) imgResize = img.resize((160, 90), Image.ANTIALIAS) nutriscore_img = ImageTk.PhotoImage(imgResize) self.w_nutriscore_product = Label(self.grid.col_frames[0][1], image=nutriscore_img, bg="#ffffff") self.w_nutriscore_product.image = nutriscore_img self.w_nutriscore_product.pack(fill="both", expand=True) elif action == "refresh": self.w_img_product.pack_forget() self.w_name_product.pack_forget() self.w_brand_product.pack_forget() self.w_nutriscore_product.pack_forget() self.w_img_product = None self.w_name_product = None self.w_brand_product = None self.w_nutriscore_product = None def row_1(self, action=None): """ Name : BUTTONS cols : 6 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=50, padx=0, pady=0, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=7, row=1, width=None, height=None, padx=5, pady=5, bg=None) self.grid.column(span=1, row=1, width=None, height=None, padx=5, pady=5, bg=None) self.grid.column(span=1, row=1, width=None, height=None, padx=5, pady=5, bg=None) self.grid.column(span=1, row=1, width=None, height=None, padx=5, pady=5, bg=None) self.grid.column(span=1, row=1, width=None, height=None, padx=5, pady=5, bg=None) self.grid.column(span=1, row=1, width=None, height=None, padx=5, pady=5, bg=None) elif action == "fill": # -- COLUMN 1 : EMPTY -- # if self.w_best_button is None: # -- COLUMN 3 : SUBSTITUTES BUTTON -- # img = Image.open( "frontend/images/views/product_sheet/best_product_1.png") imgResize = img.resize((25, 25), Image.ANTIALIAS) best_img = ImageTk.PhotoImage(imgResize) self.w_best_button = Button(self.grid.col_frames[1][1], image=best_img, bg="#ffffff", command=self.display_substitutes) self.w_best_button.image = best_img self.w_best_button.pack(fill='both', expand=True) if self.w_edit_button is None: # -- COLUMN 4 : PRODUCT SHEET BUTTON -- # img = Image.open( "frontend/images/views/product_sheet/edit.png") imgResize = img.resize((25, 25), Image.ANTIALIAS) edit_img = ImageTk.PhotoImage(imgResize) self.w_edit_button = Button(self.grid.col_frames[1][2], image=edit_img, bg="#ffffff", command=self.display_edit) self.w_edit_button.image = edit_img self.w_edit_button.pack(fill='both', expand=True) if self.w_trash_button is None: # -- COLUMN 5 : TRASH BUTTON -- # img = Image.open( "frontend/images/views/product_sheet/trash.png") imgResize = img.resize((25, 25), Image.ANTIALIAS) trash_img = ImageTk.PhotoImage(imgResize) self.w_trash_button = Button(self.grid.col_frames[1][3], image=trash_img, bg="#ffffff", command=self.trash_product) self.w_trash_button.image = trash_img self.w_trash_button.pack(fill='both', expand=True) if self.w_add_button is None: img = Image.open( "frontend/images/views/product_sheet/icon_add_{}.png". format(self.product_nutriscore)) imgResize = img.resize((25, 25), Image.ANTIALIAS) add_img = ImageTk.PhotoImage(imgResize) if self.favorite_status is False: # -- COLUMN 6 : ADD BUTTON -- # self.w_add_button = Button(self.grid.col_frames[1][4], image=add_img, bg="#ffffff", command=self.add_product) self.w_add_button.image = add_img self.w_add_button.pack(fill='both', expand=True) else: img = Image.open( "frontend/images/views/product_sheet/favorite.png") imgResize = img.resize((25, 25), Image.ANTIALIAS) add_img = ImageTk.PhotoImage(imgResize) # -- COLUMN 6 : ADD BUTTON -- # self.w_add_button = Button( self.grid.col_frames[1][4], image=add_img, bg="#ffffff", command=self.del_product_to_favorite) self.w_add_button.image = add_img self.w_add_button.pack(fill='both', expand=True) elif action == "refresh": self.w_best_button.pack_forget() self.w_edit_button.pack_forget() self.w_trash_button.pack_forget() self.w_add_button.pack_forget() self.w_best_button = None self.w_edit_button = None self.w_trash_button = None self.w_add_button = None def row_2(self, action=None): """ Name : SPACE cols : 1 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=25, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=12, row=2, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": pass elif action == "refresh": pass def row_3(self, action=None): """ Name : PRODUCT CALORIES cols : 3 """ line = "line_empty" line_lenght = 90 if self.product_kcal == 0: line = "line_empty" line_lenght = 90 elif self.product_kcal <= 100: line = "line_a" line_lenght = 90 elif self.product_kcal <= 500: line = "line_b" line_lenght = 180 elif self.product_kcal <= 1000: line = "line_c" line_lenght = 270 elif self.product_kcal <= 1500: line = "line_d" line_lenght = 360 elif self.product_kcal > 1501: line = "line_e" line_lenght = 450 if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=55, padx=0, pady=5, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=1, row=3, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=3, width=None, height=None, padx=None, pady=None, bg=None) self.col = self.grid.column(span=9, row=3, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_3") if self.w_calories_img is None: # -- COLUMN 1 : CALORIES IMAGE -- # img = Image.open( "frontend/images/views/product_sheet/calories.png") imgResize = img.resize((30, 30), Image.ANTIALIAS) calories_img = ImageTk.PhotoImage(imgResize) self.w_calories_img = Label(self.grid.col_frames[3][0], image=calories_img, bg="#ffffff") self.w_calories_img.image = calories_img self.w_calories_img.pack(fill="both", expand=True) if self.w_calories_label is None: # -- COLUMN 2 : CALORIES NAME -- # self.w_calories_label = Label(self.grid.col_frames[3][1], anchor="w", text=txt.get("calories_label"), bg="#ffffff", font="Helvetica 11 bold") self.w_calories_label.pack(fill="both", expand=True) if self.canvas_calories is None: img = Image.open( "frontend/images/views/product_sheet/{}.png".format(line)) imgResize = img.resize((line_lenght, 35), Image.ANTIALIAS) kcal_img = ImageTk.PhotoImage(imgResize) self.canvas_calories = Canvas(self.grid.col_frames[3][2], width=self.width, height=35, highlightthickness=0, bg="#ffffff") self.canvas_calories.pack(expand=True, fill="both") self.canvas_calories.create_image(0, 0, image=kcal_img, anchor="nw") self.canvas_calories.image = kcal_img self.canvas_calories.create_text(5, 9, text=" {} Kcal".format( self.product_kcal), anchor='nw', fill="#ffffff", font="Helvetica 10 bold") elif action == "refresh": self.canvas_calories.delete("all") self.canvas_calories.pack_forget() self.w_calories_label.pack_forget() self.w_calories_img.pack_forget() self.canvas_calories = None self.w_calories_label = None self.w_calories_img = None def row_4(self, action=None): """ Name : PRODUCT SUGAR cols : 3 """ line = "line_empty" line_lenght = 90 # ----- ROW 5 : PRODUCT SUGAR ----- # if self.product_sugar == 0: line = "line_empty" line_lenght = 90 elif self.product_sugar <= 10: line = "line_a" line_lenght = 90 elif self.product_sugar <= 50: line = "line_b" line_lenght = 180 elif self.product_sugar <= 100: line = "line_c" line_lenght = 270 elif self.product_sugar <= 150: line = "line_d" line_lenght = 360 elif self.product_sugar > 151: line = "line_e" line_lenght = 450 if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=55, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=1, row=4, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=4, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=9, row=4, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_4") if self.w_sugar_img is None: # -- COLUMN 1 : SUGAR IMAGE -- # img = Image.open( "frontend/images/views/product_sheet/sugar.png") img_resize = img.resize((30, 30), Image.ANTIALIAS) sugar_img = ImageTk.PhotoImage(img_resize) self.w_sugar_img = Label(self.grid.col_frames[4][0], image=sugar_img, bg="#ffffff") self.w_sugar_img.image = sugar_img self.w_sugar_img.pack(side=RIGHT, fill="both", expand=True) if self.w_sugar_label is None: # -- COLUMN 2 : SUGAR LABEL -- # self.w_sugar_label = Label(self.grid.col_frames[4][1], anchor="w", text=txt.get("sugar_label"), bg="#ffffff", font="Helvetica 11 bold") self.w_sugar_label.pack(fill="both", expand=True) if self.canvas_sugar is None: img = Image.open( "frontend/images/views/product_sheet/{}.png".format(line)) imgResize = img.resize((line_lenght, 35), Image.ANTIALIAS) kcal_img = ImageTk.PhotoImage(imgResize) self.canvas_sugar = Canvas(self.grid.col_frames[4][2], width=self.width, height=35, highlightthickness=0, bg="#ffffff") self.canvas_sugar.pack(expand=True, fill="both") self.canvas_sugar.create_image(0, 0, image=kcal_img, anchor="nw") self.canvas_sugar.image = kcal_img self.canvas_sugar.create_text(5, 9, text=" {} g".format( self.product_sugar), anchor='nw', fill="#ffffff", font="Helvetica 10 bold") elif action == "refresh": self.canvas_sugar.delete("all") self.canvas_sugar.pack_forget() self.w_sugar_img.pack_forget() self.w_sugar_label.pack_forget() self.w_sugar_img = None self.w_sugar_label = None self.canvas_sugar = None def row_5(self, action=None): """ Name : PRODUCT STORES cols : 3 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=55, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=1, row=5, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=5, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=9, row=5, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_5") if self.w_stores_img is None: # -- COLUMN 1 : STORES IMAGE -- # img = Image.open( "frontend/images/views/product_sheet/store.png") img_resize = img.resize((30, 30), Image.ANTIALIAS) store_img = ImageTk.PhotoImage(img_resize) self.w_stores_img = Label(self.grid.col_frames[5][0], image=store_img, bg="#ffffff") self.w_stores_img.image = store_img self.w_stores_img.pack(side=RIGHT, fill="both", expand=True) if self.w_stores_label is None: # -- COLUMN 2 : STORES LABEL -- # self.w_stores_label = Label(self.grid.col_frames[5][1], anchor="w", text=txt.get("stores_label"), bg="#ffffff", font="Helvetica 11 bold") self.w_stores_label.pack(fill="both", expand=True) if self.w_stores_value is None: # -- COLUMN 3 : STORES VALUE -- # self.w_stores_value = Label(self.grid.col_frames[5][2], anchor="w", text=" {}".format( self.product_store), bg="#ffffff") self.w_stores_value.pack(fill="both", expand=True) elif action == "refresh": self.w_stores_img.pack_forget() self.w_stores_label.pack_forget() self.w_stores_value.pack_forget() self.w_stores_img = None self.w_stores_label = None self.w_stores_value = None def row_6(self, action=None): """ Name : AUTHOR cols : 3 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=55, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=1, row=6, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=6, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=9, row=6, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_6") if self.w_author_img is None: # -- COLUMN 1 : AUTHOR IMAGE -- # img = Image.open( "frontend/images/views/product_sheet/copyright.png") img_resize = img.resize((30, 30), Image.ANTIALIAS) store_img = ImageTk.PhotoImage(img_resize) self.w_author_img = Label(self.grid.col_frames[6][0], image=store_img, bg="#ffffff") self.w_author_img.image = store_img self.w_author_img.pack(side=RIGHT, fill="both", expand=True) if self.w_author_label is None: # -- COLUMN 2 : AUTHOR LABEL -- # self.w_author_label = Label(self.grid.col_frames[6][1], anchor="w", text=txt.get("author_label"), bg="#ffffff", font="Helvetica 11 bold") self.w_author_label.pack(fill="both", expand=True) if self.w_author_value is None: # -- COLUMN 3 : AUTHOR VALUE -- # self.w_author_value = Label(self.grid.col_frames[6][2], anchor="w", text=" {}".format( self.product_author), bg="#ffffff") self.w_author_value.pack(fill="both", expand=True) elif action == "refresh": self.w_author_img.pack_forget() self.w_author_label.pack_forget() self.w_author_value.pack_forget() self.w_author_img = None self.w_author_label = None self.w_author_value = None def row_7(self, action=None): """ Name : SUBMIT BUTTON cols : 4 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=100, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=4, row=7, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=4, row=7, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=4, row=7, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_7") # -- COLUMN 1 : EMPTY -- # if self.w_submit_button is None: # -- COLUMN 3 : SUBMIT BUTTON -- # self.w_submit_button = Button(self.grid.col_frames[7][1], text=txt.get("submit_button"), fg="#ffffff", bg="#7A57EC", activeforeground="#ffffff", activebackground="#845EFF", command=self.display_search) self.w_submit_button.pack(side=BOTTOM, fill=X, expand=True) # -- COLUMN 4 : EMPTY -- # elif action == "refresh": self.w_submit_button.pack_forget() self.w_submit_button = None
class UserProfil(): def __init__(self, container=None, displayer=None, session=None): """ 'container' (Obj ): instance of Container. 'displayer' (obj ): instance of Displayer. 'session,' (obj ): instance of Session. 'grid' (Obj ): instance of Grid. 'f_container' (Frame): container frame. 'm_frame' (Frame): master frame of view. 'name' (str ): name of view. 'json_script' (dict ): json dict of script. 'width' (int ): view width. 'height' (int ): view height. 'padx' (int ): view 'pady' (int ): view 'bg' (str ): view bg. """ # Instances self.container = container self.displayer = displayer self.session = session self.grid = None # Frames self.f_container = self.container.f_container self.m_frame = None # Informations self.name = None # Script self.json_script = None # Style Sheet self.width = self.container.width self.height = self.container.height self.padx = 0 self.pady = 0 self.bg = "#ffffff" # Tk control variables self.var_name = StringVar() self.user = None self.user_name = None self.user_avatar_name = None # Widgets row 0 self.canvas = None # Widgets row 1 self.w_name_title = None self.w_name_entry = None # Widgets row 2 self.w_avatar_title = None self.w_avatar_name = None self.w_user_avatar = None self.w_avatar_button = None # Widgets row 3 self.w_delete_title = None self.w_delete_button = None # Widgets row 4 self.w_home_button = None self.w_submit_button = None # Fill status self.fill_status = False # Previous View in **kwargs self.previous_view = None # -- Displayer initialisation -- # self.construct() def construct(self, **kwargs): """ Construt view. to not fill the view during initialization. 'grid' (obj): Instance of Grid. 'm_frame' (Frame): Tkinter master frame of view. """ # 1. Create new grid in page container. self.grid = Grid(frame=self.f_container, width=self.width, height=self.height, padx=self.padx, pady=self.pady, bg=self.bg) # 2. Get view frame for displayer function self.m_frame = self.grid.master_frame # 3. Construct the view rows self.row_0(action="construct") self.row_1(action="construct") self.row_2(action="construct") self.row_3(action="construct") self.row_4(action="construct") def fill(self, **kwargs): """ Fill the view rows. 'json_script' (dict): texts for view. 'name' (str): view name. """ kwargs_avatar = False for key, value in kwargs.items(): if key == "view": self.previous_view = value elif key == "avatar_name": self.user_avatar_name = value kwargs_avatar = True # 1. Get the script. self.json_script = self.session.get_script(package_name="user", file_name="profil") # 2. Save name of view for displayer. self.name = self.json_script.get("view_name") # 3. Get user informations self.user = self.session.dbmanager.db_user.read( action="id", user_id=self.session.user_id) self.user_name = self.user.get("user_name") if kwargs_avatar is not True: self.user_avatar_name = self.user.get("user_avatar_name") # 3. Refresh rows. if self.fill_status is True: self.row_0(action="refresh") self.row_1(action="refresh") self.row_2(action="refresh") self.row_3(action="refresh") self.row_4(action="refresh") # 4. Fill the view rows. self.row_0(action="fill") self.row_1(action="fill") self.row_2(action="fill") self.row_3(action="fill") self.row_4(action="fill") self.fill_status = True def display_home(self): """ Display "home" view. """ self.displayer.display(c_view="user_profil", f_view="home") def display_avatars(self): """ Display view user_avatars. Package "USER" """ self.displayer.display(c_view="user_profil", f_view="user_avatars") def update_user(self): """ Update user.""" self.user_name = self.var_name.get() self.session.dbmanager.db_user.update( user_id=self.session.user_id, user_name=self.user_name, user_avatar_name=self.user_avatar_name) self.displayer.display(c_view="user_profil", f_view="home") def delete_user(self): """ Delete user.""" self.session.dbmanager.db_user.delete(user_id=self.session.user_id, ) self.session.user_id = None self.displayer.display(c_view="user_profil", f_view="user_welcome") def row_0(self, action=None): """ Name : TITLE cols : 1 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=250, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=12, row=0, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_0") if self.canvas is None: img = Image.open("frontend/images/views/profil/background.jpg") imgResize = img.resize((640, 427), Image.ANTIALIAS) imgTkinter = ImageTk.PhotoImage(imgResize) self.canvas = Canvas(self.grid.col_frames[0][0], width=self.width, height=250, highlightthickness=0) self.canvas.pack(expand=True, fill="both") self.canvas.create_image(0, 0, image=imgTkinter, anchor="nw") self.canvas.image = imgTkinter self.canvas.create_text(100, 100, text=txt.get("view_title"), anchor='nw', fill="#ffffff", font="Helvetica 20 bold") elif action == "refresh": self.canvas.delete("all") self.canvas.pack_forget() self.canvas = None def row_1(self, action=None): """ Name : USER AVATAR cols : 3 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=150, padx=0, pady=5, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=3, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=6, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=3, row=1, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_1") # -- COLUMN 1 : USER AVATAR TITLE -- # if self.w_avatar_title is None: self.w_avatar_title = Label(self.grid.col_frames[1][0], padx=10, anchor="w", text=txt.get("user_avatar"), bg="#ffffff", fg="#000000", font="Helvetica 12 bold") self.w_avatar_title.pack(fill="both", expand=True) # -- COLUMN 2 : USER AVATAR IMAGE -- # if self.w_user_avatar is None: img = Image.open("frontend/images/avatars/{}.png".format( self.user_avatar_name)) imgResize = img.resize((90, 90), Image.ANTIALIAS) imgTkinter = ImageTk.PhotoImage(imgResize) self.w_user_avatar = Label(self.grid.col_frames[1][1], image=imgTkinter, borderwidth=0, bg="#ffffff") self.w_user_avatar.image = imgTkinter self.w_user_avatar.pack(fill=X) # -- COLUMN 2 : USER AVATAR NAME -- # if self.w_avatar_name is None: self.w_avatar_name = Label(self.grid.col_frames[1][1], text="{}".format( self.user_avatar_name), bg="#ffffff", fg="#000000", font="Helvetica 12 bold") self.w_avatar_name.pack(fill=X) if self.w_avatar_button is None: self.w_avatar_button = Button(self.grid.col_frames[1][1], text=txt.get("avatars_button"), fg="#ffffff", bg="#1C51FF", activeforeground="#ffffff", activebackground="#1269FF", command=self.display_avatars) self.w_avatar_button.pack() elif action == "refresh": """ Refresh this row. """ self.w_avatar_title.pack_forget() self.w_user_avatar.pack_forget() self.w_avatar_name.pack_forget() self.w_avatar_button.pack_forget() self.w_avatar_title = None self.w_user_avatar = None self.w_avatar_name = None self.w_avatar_button = None def row_2(self, action=None): """ Name : USER NAME cols : 1 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=50, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=3, row=2, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=4, row=2, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=5, row=2, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_2") # -- COLUMN 1/1 : TITLE -- # if self.w_name_title is None: self.w_name_title = Label(self.grid.col_frames[2][0], padx=10, anchor="w", text=txt.get("user_name"), bg="#ffffff", fg="#000000", font="Helvetica 12 bold") self.w_name_title.pack(side=BOTTOM, fill=X) if self.w_name_entry is None: # -- COLUMN 2 : USER NAME ENTRY -- # self.w_name_entry = Entry(self.grid.col_frames[2][1], textvariable=self.var_name) self.w_name_entry.insert(0, self.user_name) self.w_name_entry.pack(side=BOTTOM, fill=X) elif action == "refresh": self.w_name_entry.delete(0, 10) self.w_name_title.pack_forget() self.w_name_entry.pack_forget() self.w_name_title = None self.w_name_entry = None def row_3(self, action=None): """ Name : USER DELETE cols : 3 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=50, padx=0, pady=0, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=3, row=3, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=4, row=3, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=5, row=3, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_3") # -- COLUMN 1 : USER DELETE TITLE -- # if self.w_delete_title is None: self.w_delete_title = Label(self.grid.col_frames[3][0], padx=10, anchor="w", text=txt.get("delete"), bg="#ffffff", fg="#000000", font="Helvetica 12 bold") self.w_delete_title.pack(side=BOTTOM, fill=X) # -- COLUMN 2 : USER DELETE BUTTON -- # if self.w_delete_button is None: self.w_delete_button = Button(self.grid.col_frames[3][1], text=txt.get("delete_button"), fg="#ffffff", bg="#f12d32", activeforeground="#ffffff", activebackground="#f12d32", command=self.delete_user) self.w_delete_button.pack(fill="x", side="bottom") elif action == "refresh": """ Refresh this row. """ self.w_delete_title.pack_forget() self.w_delete_button.pack_forget() self.w_delete_title = None self.w_delete_button = None def row_4(self, action=None): """ Name : SUBMIT BUTTON cols : 4 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=100, padx=0, pady=0, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=2, row=4, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=4, row=4, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=4, row=4, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=4, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": txt = self.json_script.get("row_4") # -- COLUMN 1/4 : EMPTY -- # # -- COLUMN 2/4 : SUBMIT BUTTON -- # if self.w_home_button is None: self.w_home_button = Button(self.grid.col_frames[4][1], text=txt.get("home_button"), fg="#ffffff", bg="#7A57EC", activeforeground="#ffffff", activebackground="#845EFF", command=self.display_home) self.w_home_button.pack(side=BOTTOM, fill=X) # -- COLUMN 3/4 : SUBMIT BUTTON -- # if self.w_submit_button is None: self.w_submit_button = Button(self.grid.col_frames[4][2], text=txt.get("submit_button"), fg="#ffffff", bg="#7A57EC", activeforeground="#ffffff", activebackground="#845EFF", command=self.update_user) self.w_submit_button.pack(side=BOTTOM, fill=X) # -- COLUMN 4/4 : EMPTY -- # elif action == "refresh": """ Refresh this row. """ self.w_home_button.pack_forget() self.w_submit_button.pack_forget() self.w_home_button = None self.w_submit_button = None
class Load(): def __init__(self, container=None, displayer=None, session=None): """ 'container' (Obj ): instance of Container. 'displayer' (obj ): instance of Displayer. 'session,' (obj ): instance of Session. 'grid' (Obj ): instance of Grid. 'f_container' (Frame): container frame. 'm_frame' (Frame): master frame of view. 'name' (str ): name of view. 'json_script' (dict ): json dict of script. 'width' (int ): view width. 'height' (int ): view height. 'padx' (int ): view 'pady' (int ): view 'bg' (str ): view bg. """ # Instances self.container = container self.displayer = displayer self.session = session self.grid = None # Frames self.f_container = self.container.f_container self.m_frame = None # Informations self.name = None # Script self.json_script = None # Style Sheet self.width = self.container.width self.height = self.container.height self.padx = 0 self.pady = 0 self.bg = "#ffffff" # Tk control variables # Fill status self.fill_status = False # Widgets row 0 self.w_title = None # -- Displayer initialisation -- # self.construct() def construct(self, **kwargs): """ Construt view. to not fill the view during initialization. 'grid' (obj): Instance of Grid. 'm_frame' (Frame): Tkinter master frame of view. """ # 1. Create new grid in page container. self.grid = Grid(frame=self.f_container, width=self.width, height=self.height, padx=self.padx, pady=self.pady, bg=self.bg) # 2. Get view frame for displayer function self.m_frame = self.grid.master_frame # 3. Construct the view rows self.row_0(action="construct") def fill(self, **kwargs): """ Fill the view rows. 'json_script' (dict): texts for view. 'name' (str): view name. """ # 1. Get the script. self.json_script = self.session.get_script(package_name="others", file_name="load") # 2. Save name of view for displayer. self.name = self.json_script.get("view_name") # 3. Refresh rows. if self.fill_status is True: self.row_0(action="refresh") # 4. Fill the view rows. self.row_0(action="fill") self.fill_status = True def display_previous(self): """ Display previous view. """ self.displayer.display(c_view="", f_view="") def row_0(self, action=None): """ Name : TITLE cols : 1 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=250, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=12, row=0, width=None, height=None, padx=None, pady=100, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_0") # -- COLUMN 1/1 : TITLE -- # if self.w_title is None: self.w_title = Label(self.grid.col_frames[0][0], padx=50, anchor="s", text=txt.get("view_title"), bg="#ffffff", fg="#000000", font="Helvetica 12 bold") self.w_title.pack(side="bottom") elif action == "refresh": pass
class UpdateLanguages(): def __init__(self, container=None, displayer=None, session=None): """ 'container' (Obj ): instance of Container. 'displayer' (obj ): instance of Displayer. 'session,' (obj ): instance of Session. 'grid' (Obj ): instance of Grid. 'f_container' (Frame): container frame. 'm_frame' (Frame): master frame of view. 'name' (str ): name of view. 'json_script' (dict ): json dict of script. 'width' (int ): view width. 'height' (int ): view height. 'padx' (int ): view 'pady' (int ): view 'bg' (str ): view bg. """ # Instances self.container = container self.displayer = displayer self.session = session self.grid = None # Frames self.f_container = self.container.f_container self.m_frame = None # Informations self.name = None # Script self.json_script = None # Style Sheet self.width = self.container.width self.height = self.container.height self.padx = 0 self.pady = 0 self.bg = "#ffffff" # Tk control variables self.var_notification = StringVar() self.var_language = StringVar() # Widgets row 0 self.w_title = None # Widgets row 1 self.w_en_flag = None self.w_en_name = None self.w_en_check = None self.w_fr_flag = None self.w_fr_name = None self.w_fr_check = None self.w_de_flag = None self.w_de_name = None self.w_de_check = None # Widgets row 2 self.w_it_flag = None self.w_it_name = None self.w_it_check = None self.w_es_flag = None self.w_es_name = None self.w_es_check = None self.w_nl_flag = None self.w_nl_name = None self.w_nl_check = None # Widgets row 3 self.w_previous_button = None self.w_submit_button = None # Fill status self.fill_status = False # -- Displayer initialisation -- # self.construct() def construct(self, **kwargs): """ Construt view. 'displayer' (Bool): to not create the view \ during initialization. """ # 2. Create new grid in page container. self.grid = Grid(frame=self.f_container, width=self.width, height=self.height, padx=self.padx, pady=self.pady, bg=self.bg) # 3. Get view frame for displayer function self.m_frame = self.grid.master_frame self.row_0(action="construct") self.row_1(action="construct") self.row_2(action="construct") self.row_3(action="construct") def fill(self, **kwargs): # 1. Get the script. self.json_script = self.session.get_script(package_name="update", file_name="languages") self.name = self.json_script.get("view_name") self.var_notification.set(" ") # 3. Refresh rows. if self.fill_status is True: self.row_0(action="refresh") self.row_1(action="refresh") self.row_2(action="refresh") self.row_3(action="refresh") self.row_0(action="fill") self.row_1(action="fill") self.row_2(action="fill") self.row_3(action="fill") self.fill_status = True def display_previous(self): """ Display view 'update_server_conn'. """ self.displayer.display(c_view="update_languages", f_view="update_server_conn") def display_step_3(self): """ Display view 'update_categories'. """ self.displayer.display(c_view="update_languages", f_view="update_categories", language=str(self.var_language.get())) def row_0(self, action=None): """ Name : VIEW TITLE cols : 1 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=250, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=12, row=0, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get script txt = self.json_script.get("row_0") # -- COLUMN 1/1 : VIEW TITLE -- # if self.w_title is None: self.w_title = Label(self.grid.col_frames[0][0], pady=50, anchor="s", text=txt.get("view_title"), bg="#ffffff", fg="#000000", font="Helvetica 12 bold") self.w_title.pack(fill='both', expand=True) elif action == "refresh": self.w_title.pack_forget() self.w_title = None def row_1(self, action=None): """ Name : LANGAGE 1-3 cols : 3 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=150, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=4, row=1, width=None, height=None, padx=None, pady=20, bg=None) self.grid.column(span=4, row=1, width=None, height=None, padx=None, pady=20, bg=None) self.grid.column(span=4, row=1, width=None, height=None, padx=None, pady=20, bg=None) elif action == "fill": # Get script txt = self.json_script.get("row_1") # -- COLUMN 1/3 : ENGLISH LANGUAGE -- # img = Image.open("frontend/images/flags/en.png") imgResize = img.resize((30, 30), Image.ANTIALIAS) imgTkinter = ImageTk.PhotoImage(imgResize) if self.w_en_flag is None: self.w_en_flag = Label(self.grid.col_frames[1][0], image=imgTkinter, borderwidth=0, bg="#ffffff") self.w_en_flag.image = imgTkinter self.w_en_flag.pack(fill='both', expand=True) if self.w_en_name is None: self.w_en_name = Label(self.grid.col_frames[1][0], pady=0, text=txt.get("english_label"), bg="#ffffff", fg="#000000", font="Helvetica 12 bold") self.w_en_name.pack(fill='both', expand=True) if self.w_en_check is None: self.w_en_check = Radiobutton(self.grid.col_frames[1][0], variable=self.var_language, value="en", bg="#ffffff") self.w_en_check.pack(fill='both', expand=True) if self.session.gui_language == "en": self.w_en_check.select() # -- COLUMN 2/3 : FRENCH LANGUAGE -- # img = Image.open("frontend/images/flags/fr.png") imgResize = img.resize((30, 30), Image.ANTIALIAS) imgTkinter = ImageTk.PhotoImage(imgResize) if self.w_fr_flag is None: self.w_fr_flag = Label(self.grid.col_frames[1][1], image=imgTkinter, borderwidth=0, bg="#ffffff") self.w_fr_flag.image = imgTkinter self.w_fr_flag.pack(fill='both', expand=True) if self.w_fr_name is None: self.w_fr_name = Label(self.grid.col_frames[1][1], pady=0, text=txt.get("french_label"), bg="#ffffff", fg="#000000", font="Helvetica 12 bold") self.w_fr_name.pack(fill='both', expand=True) if self.w_fr_check is None: self.w_fr_check = Radiobutton(self.grid.col_frames[1][1], variable=self.var_language, value="fr", bg="#ffffff") self.w_fr_check.pack(fill='both', expand=True) if self.session.gui_language == "fr": self.w_fr_check.select() # -- COLUMN 3/3 : GERMAN LANGUAGE -- # img = Image.open("frontend/images/flags/de.png") imgResize = img.resize((30, 30), Image.ANTIALIAS) imgTkinter = ImageTk.PhotoImage(imgResize) if self.w_de_flag is None: self.w_de_flag = Label(self.grid.col_frames[1][2], image=imgTkinter, borderwidth=0, bg="#ffffff") self.w_de_flag.image = imgTkinter self.w_de_flag.pack(fill='both', expand=True) if self.w_de_name is None: self.w_de_name = Label(self.grid.col_frames[1][2], pady=0, text=txt.get("german_label"), bg="#ffffff", fg="#000000", font="Helvetica 12 bold") self.w_de_name.pack(fill='both', expand=True) if self.w_de_check is None: self.w_de_check = Radiobutton(self.grid.col_frames[1][2], variable=self.var_language, value="de", bg="#ffffff") self.w_de_check.pack(fill='both', expand=True) elif action == "refresh": self.w_en_flag.pack_forget() self.w_en_name.pack_forget() self.w_en_check.pack_forget() self.w_fr_flag.pack_forget() self.w_fr_name.pack_forget() self.w_fr_check.pack_forget() self.w_de_flag.pack_forget() self.w_de_name.pack_forget() self.w_de_check.pack_forget() self.w_en_flag = None self.w_en_name = None self.w_en_check = None self.w_fr_flag = None self.w_fr_name = None self.w_fr_check = None self.w_de_flag = None self.w_de_name = None self.w_de_check = None def row_2(self, action=None): """ Name : LANGAGE 3-6 cols : 3 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=140, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=4, row=2, width=None, height=None, padx=None, pady=20, bg=None) self.grid.column(span=4, row=2, width=None, height=None, padx=None, pady=20, bg=None) self.grid.column(span=4, row=2, width=None, height=None, padx=None, pady=20, bg=None) elif action == "fill": # Get script txt = self.json_script.get("row_2") # -- COLUMN 1/3 : ITALIAN LANGUAGE -- # img = Image.open("frontend/images/flags/it.png") imgResize = img.resize((30, 30), Image.ANTIALIAS) imgTkinter = ImageTk.PhotoImage(imgResize) if self.w_it_flag is None: self.w_it_flag = Label(self.grid.col_frames[2][0], image=imgTkinter, borderwidth=0, bg="#ffffff") self.w_it_flag.image = imgTkinter self.w_it_flag.pack(fill='both', expand=True) if self.w_it_name is None: self.w_it_name = Label(self.grid.col_frames[2][0], pady=0, text=txt.get("italian_label"), bg="#ffffff", fg="#000000", font="Helvetica 12 bold") self.w_it_name.pack(fill='both', expand=True) if self.w_it_check is None: self.w_it_check = Radiobutton(self.grid.col_frames[2][0], variable=self.var_language, value="it", bg="#ffffff") self.w_it_check.pack(fill='both', expand=True) # -- COLUMN 2/3 : SPANISH LANGUAGE -- # img = Image.open("frontend/images/flags/es.png") imgResize = img.resize((30, 30), Image.ANTIALIAS) imgTkinter = ImageTk.PhotoImage(imgResize) if self.w_es_flag is None: self.w_es_flag = Label(self.grid.col_frames[2][1], image=imgTkinter, borderwidth=0, bg="#ffffff") self.w_es_flag.image = imgTkinter self.w_es_flag.pack(fill='both', expand=True) if self.w_es_name is None: self.w_es_name = Label(self.grid.col_frames[2][1], pady=0, text=txt.get("spanish_label"), bg="#ffffff", fg="#000000", font="Helvetica 12 bold") self.w_es_name.pack(fill='both', expand=True) if self.w_es_check is None: self.w_es_check = Radiobutton(self.grid.col_frames[2][1], variable=self.var_language, value="es", bg="#ffffff") self.w_es_check.pack(fill='both', expand=True) # -- COLUMN 3/3 : DUTCH LANGUAGE -- # img = Image.open("frontend/images/flags/nl.png") imgResize = img.resize((30, 30), Image.ANTIALIAS) imgTkinter = ImageTk.PhotoImage(imgResize) if self.w_nl_flag is None: self.w_nl_flag = Label(self.grid.col_frames[2][2], image=imgTkinter, borderwidth=0, bg="#ffffff") self.w_nl_flag.image = imgTkinter self.w_nl_flag.pack(fill='both', expand=True) if self.w_nl_name is None: self.w_nl_name = Label(self.grid.col_frames[2][2], pady=0, text=txt.get("dutch_label"), bg="#ffffff", fg="#000000", font="Helvetica 12 bold") self.w_nl_name.pack(fill='both', expand=True) if self.w_nl_check is None: self.w_nl_check = Radiobutton(self.grid.col_frames[2][2], variable=self.var_language, value="nl", bg="#ffffff") self.w_nl_check.pack(fill='both', expand=True) elif action == "refresh": self.w_it_flag.pack_forget() self.w_it_name.pack_forget() self.w_it_check.pack_forget() self.w_es_flag.pack_forget() self.w_es_name.pack_forget() self.w_es_check.pack_forget() self.w_nl_flag.pack_forget() self.w_nl_name.pack_forget() self.w_nl_check.pack_forget() self.w_it_flag = None self.w_it_name = None self.w_it_check = None self.w_es_flag = None self.w_es_name = None self.w_es_check = None self.w_nl_flag = None self.w_nl_name = None self.w_nl_check = None def row_3(self, action=None): """ Name : SUBMIT BUTTON cols : 4 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=60, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=2, row=3, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=4, row=3, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=4, row=3, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=3, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": txt = self.json_script.get("row_3") # -- COLUMN 1/4 : EMPTY -- # # -- COLUMN 2/4 : SUBMIT BUTTON -- # if self.w_previous_button is None: self.w_previous_button = Button( self.grid.col_frames[3][1], text=txt.get("previous_button"), fg="#ffffff", bg="#7A57EC", activeforeground="#ffffff", activebackground="#845EFF", command=self.display_previous) self.w_previous_button.pack(side=BOTTOM, fill=X) # -- COLUMN 3/4 : SUBMIT BUTTON -- # if self.w_submit_button is None: self.w_submit_button = Button(self.grid.col_frames[3][2], text=txt.get("submit_button"), fg="#ffffff", bg="#7A57EC", activeforeground="#ffffff", activebackground="#845EFF", command=self.display_step_3) self.w_submit_button.pack(side=BOTTOM, fill=X) # -- COLUMN 3/3 : EMPTY -- # elif action == "refresh": self.w_previous_button.pack_forget() self.w_submit_button.pack_forget() self.w_previous_button = None self.w_submit_button = None
class Settings(): def __init__(self, container=None, displayer=None, session=None): """ 'container' (Obj ): instance of Container. 'displayer' (obj ): instance of Displayer. 'session,' (obj ): instance of Session. 'grid' (Obj ): instance of Grid. 'f_container' (Frame): container frame. 'm_frame' (Frame): master frame of view. 'name' (str ): name of view. 'json_script' (dict ): json dict of script. 'width' (int ): view width. 'height' (int ): view height. 'padx' (int ): view 'pady' (int ): view 'bg' (str ): view bg. """ # Instances self.container = container self.displayer = displayer self.session = session self.grid = None # Frames self.f_container = self.container.f_container self.m_frame = None # Informations self.name = None # Script self.json_script = None # Style Sheet self.width = self.container.width self.height = self.container.height self.padx = 0 self.pady = 0 self.bg = "#ffffff" # Tk control variables # Widgets row 0 self.canvas = None # Widgets row 1 self.w_delete_title = None self.w_delete_button = None # Fill status self.fill_status = False # Previous View in **kwargs self.previous_view = None # -- Displayer initialisation -- # self.construct() def construct(self, **kwargs): """ Construt view. to not fill the view during initialization. 'grid' (obj): Instance of Grid. 'm_frame' (Frame): Tkinter master frame of view. """ # 1. Create new grid in page container. self.grid = Grid(frame=self.f_container, width=self.width, height=self.height, padx=self.padx, pady=self.pady, bg=self.bg) # 2. Get view frame for displayer function self.m_frame = self.grid.master_frame # 3. Construct the view rows self.row_0(action="construct") self.row_1(action="construct") def fill(self, **kwargs): """ Fill the view rows. 'json_script' (dict): texts for view. 'name' (str): view name. """ # 1. Get the script. self.json_script = self.session.get_script(package_name="others", file_name="settings") # 2. Save name of view for displayer. self.name = self.json_script.get("view_name") # 3. Refresh rows. if self.fill_status is True: self.row_0(action="refresh") self.row_1(action="refresh") # 4. Fill the view rows. self.row_0(action="fill") self.row_1(action="fill") self.fill_status = True def delete_program(self): """ Delete the program. """ self.session.dbmanager.remove() sys.exit() def row_0(self, action=None): """ Name : TITLE cols : 1 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=250, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=12, row=0, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_0") if self.canvas is None: img = Image.open( "frontend/images/views/settings/background.jpg") imgResize = img.resize((640, 500), Image.ANTIALIAS) imgTkinter = ImageTk.PhotoImage(imgResize) self.canvas = Canvas(self.grid.col_frames[0][0], width=self.width, height=250, highlightthickness=0) self.canvas.pack(expand=True, fill="both") self.canvas.create_image(0, 0, image=imgTkinter, anchor="nw") self.canvas.image = imgTkinter elif action == "refresh": self.canvas.delete("all") self.canvas.pack_forget() self.canvas = None def row_1(self, action=None): """ Name : DELETE PROGRAM cols : 3 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=50, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=3, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=4, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=5, row=1, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_1") # -- COLUMN 1 : USER DELETE TITLE -- # if self.w_delete_title is None: self.w_delete_title = Label(self.grid.col_frames[1][0], padx=10, anchor="w", text=txt.get("delete"), bg="#ffffff", fg="#000000", font="Helvetica 12 bold") self.w_delete_title.pack(side=BOTTOM, fill=X) # -- COLUMN 2 : USER DELETE BUTTON -- # if self.w_delete_button is None: self.w_delete_button = Button(self.grid.col_frames[1][1], text=txt.get("delete_button"), fg="#ffffff", bg="#f12d32", activeforeground="#ffffff", activebackground="#f12d32", command=self.delete_program) self.w_delete_button.pack(fill="x", side="bottom") elif action == "refresh": """ Refresh this row. """ self.w_delete_title.pack_forget() self.w_delete_button.pack_forget() self.w_delete_title = None self.w_delete_button = None
class UpdateCategories(): def __init__( self, container=None, displayer=None, session=None ): """ 'container' (Obj ): instance of Container. 'displayer' (obj ): instance of Displayer. 'session,' (obj ): instance of Session. 'grid' (Obj ): instance of Grid. 'f_container' (Frame): container frame. 'm_frame' (Frame): master frame of view. 'name' (str ): name of view. 'json_script' (dict ): json dict of script. 'width' (int ): view width. 'height' (int ): view height. 'padx' (int ): view 'pady' (int ): view 'bg' (str ): view bg. """ # Instances self.container = container self.displayer = displayer self.session = session self.grid = None # Frames self.f_container = self.container.f_container self.m_frame = None # Informations self.name = None # Script self.json_script = None # Style Sheet self.width = self.container.width self.height = self.container.height self.padx = 0 self.pady = 0 self.bg = "#ffffff" self.categories = None # Paging self.page = 0 self.pages = 0 self.p_start = None self.p_stop = None # Tk control variables self.var_notification = StringVar() self.var_categories = [] self.var_paging_label = StringVar() # Row 0 self.w_title = None # Row 1 self.w_paging_txt = None self.w_paging_previous = None self.w_paging_next = None # Row 2 self.w_language_flags = [] self.w_category_names = [] self.w_category_products = [] self.w_category_checks = [] # Row 3 self.w_previous_button = None self.w_submit_button = None self.language = None self.paging_categories = None # Fill status self.fill_status = False # -- Displayer initialisation -- # self.construct() def construct(self, **kwargs): """ Construt view. 'displayer' (Bool): to not create the view \ during initialization. """ # 2. Create new grid in page container. self.grid = Grid( frame=self.f_container, width=self.width, height=self.height, padx=self.padx, pady=self.pady, bg=self.bg ) # 3. Get view frame for displayer function self.m_frame = self.grid.master_frame self.row_0(action="construct") self.row_1(action="construct") self.row_2(action="construct") self.row_3(action="construct") def fill(self, **kwargs): # 1. Get the script. self.json_script = self.session.get_script( package_name="update", file_name="categories" ) self.name = self.json_script.get("view_name") for key, value in kwargs.items(): if key == "language": self.language = value self.categories = self.session.off_requests( req_type="categories", language=self.language ) # Initialization self.page = 0 self.var_categories = [] for cat in self.categories: var_category_dict = {} var_category = IntVar() var_category_dict["var_category"] = var_category var_category_dict["category_name"] = cat[ "category_name" ] var_category_dict["category_off_id"] = cat[ "category_off_id" ] self.var_categories.append(var_category_dict) self.pages = int(len(self.categories) / 15) self.paging_categories = self.categories[0:15] elif key == "p_action": self.paging(p_action=value) # 3. Refresh rows. if self.fill_status is True: self.row_0(action="refresh") self.row_1(action="refresh") self.row_2(action="refresh") self.row_3(action="refresh") self.row_0(action="fill") self.row_1(action="fill") self.row_2(action="fill") self.row_3(action="fill") self.fill_status = True def paging(self, p_action=None): """ 'current_page' (int ): Nunber of current page. 'action' (str ): Next or Previous 'elements_per_page' (int ): Number of element per page. 'list_start' (int ): 'list_stop' (int ): 'list' (list): List to cut. """ # Paging if p_action == "next": self.page = self.page + 1 elif p_action == "previous": self.page = self.page - 1 self.p_start = int( self.page * 15 ) self.p_stop = int( self.p_start + 15 ) self.paging_categories = self.categories[self.p_start:self.p_stop] self.row_0(action="refresh") self.row_1(action="refresh") self.row_2(action="refresh") self.row_0(action="fill") self.row_1(action="fill") self.row_2(action="fill") def paging_next(self): """ Paging. """ test = self.page + 1 if test <= self.pages: self.paging( p_action="next" ) def paging_prev(self): """ Paging. """ test = self.page - 1 if test >= 0: self.paging( p_action="previous" ) def display_previous(self): """ Display view 'update_language'. """ self.displayer.display( c_view="update_categories", f_view="update_languages" ) def display_welcome(self): """ Display "welcome" view. """ self.displayer.display( c_view="update_categories", f_view="user_welcome" ) def upload(self): var_category = None category_name = None category_off_id = None for cat_var in self.var_categories: for key, value in cat_var.items(): if key == "var_category": var_category = value.get() elif key == "category_name": category_name = value elif key == "category_off_id": category_off_id = value if var_category == 1: self.session.dbmanager.db_category.create( category_name=cat_var["category_name"], category_off_id=cat_var["category_off_id"], category_products=0 ) db_cat = self.session.dbmanager.db_category.read( action="*" ) for cat in db_cat: products = self.session.dbmanager.offmanager.get_products( language=self.language, category=cat["category_id_off"] ) for product in products: self.session.dbmanager.db_product.create( product_name=product.get("product_name"), product_url=product.get("product_url"), product_creator=product.get("product_creator"), product_stores=product.get("product_stores"), product_nutriscore=product.get("product_nutriscore"), product_image_url=product.get("product_image_url"), product_kcal=product.get("product_kcal"), product_kj=product.get("product_kj"), product_category_id=cat["category_id"], product_sugar=product.get("product_sugar"), product_brands=product.get("product_brands") ) self.session.dbmanager.db_category.update( category_id=cat["category_id"], category_products=len(products) ) self.display_welcome() def row_0(self, action=None): """ Name : VIEW TITLE cols : 1 """ if action == "construct": # -- CREATE ROW -- # self.grid.row( width=self.width, height=100, padx=self.padx, pady=self.pady, bg="#ffffff" ) # -- CREATE COLS -- # self.grid.column( span=12, row=0, width=None, height=None, padx=None, pady=None, bg=None ) elif action == "fill": # Get script txt = self.json_script.get("row_0") # -- COLUMN 1/1 : VIEW TITLE -- # if self.w_title is None: self.w_title = Label( self.grid.col_frames[0][0], pady=50, anchor="s", text=txt.get("view_title"), bg="#ffffff", fg="#000000", font="Helvetica 12 bold" ) self.w_title.pack(fill='both', expand=True) elif action == "refresh": self.w_title.pack_forget() self.w_title = None def row_1(self, action=None): """ Name : PAGING cols : 0 """ if action == "construct": # -- CREATE ROW -- # self.grid.row( width=self.width, height=40, padx=self.padx, pady=self.pady, bg="#ffffff" ) self.grid.column( span=8, row=1, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None ) elif action == "fill": # Get script txt = self.json_script.get("row_1") # -- COLUMN 1/3 : EMPTY -- # if self.w_paging_txt is None: self.var_paging_label.set( "{} {}/{}".format( txt.get("paging_label"), self.page, self.pages ) ) self.w_paging_txt = Label( self.grid.col_frames[1][0], anchor="w", pady=5, padx=5, textvariable=self.var_paging_label, bg="#ffffff", fg="#000000", font="Helvetica 10 bold" ) self.w_paging_txt.pack(fill='both', expand=True) # -- COLUMN 2/3 : PAGING BUTTON -- # if self.w_paging_previous is None: self.w_paging_previous = Button( self.grid.col_frames[1][1], text=txt.get("paging_prev"), fg="#000000", bg="#EDEDED", activeforeground="#000000", activebackground="#EDEDED", command=self.paging_prev ) self.w_paging_previous.pack(side=BOTTOM, fill=X) # -- COLUMN 2/3 : PAGING BUTTON -- # if self.w_paging_next is None: self.w_paging_next = Button( self.grid.col_frames[1][2], text=txt.get("paging_next"), fg="#000000", bg="#EDEDED", activeforeground="#000000", activebackground="#EDEDED", command=self.paging_next ) self.w_paging_next.pack(side=BOTTOM, fill=X) elif action == "refresh": # Get script txt = self.json_script.get("row_1") self.var_paging_label.set( "{} {}/{}".format( txt.get("paging_label"), self.page, self.pages ) ) self.w_paging_txt.pack_forget() self.w_paging_previous.pack_forget() self.w_paging_next.pack_forget() self.w_paging_txt = None self.w_paging_previous = None self.w_paging_next = None def row_2(self, action=None): """ Name : CATEGORIES cols : 3 """ if action == "construct": # -- CREATE ROW -- # self.grid.row( width=self.width, height=400, padx=self.padx, pady=self.pady, bg="#ffffff" ) # -- CREATE COLS -- # col_1 = self.grid.column( span=2, row=2, width=None, height=None, padx=None, pady=5, bg=None ) col_2 = self.grid.column( span=6, row=2, width=None, height=None, padx=None, pady=5, bg=None ) col_3 = self.grid.column( span=2, row=2, width=None, height=None, padx=None, pady=5, bg=None ) col_4 = self.grid.column( span=2, row=2, width=None, height=None, padx=None, pady=5, bg=None ) elif action == "fill": # Get script txt = self.json_script.get("row_2") count = self.page * 15 for category in self.paging_categories[0:15]: # -- COLUMN 1/5 : CATEGORY LANGUAGE -- # img = Image.open( "frontend/images/flags/{}.png" .format(category["language"]) ) imgResize = img.resize((20, 20), Image.ANTIALIAS) imgTkinter = ImageTk.PhotoImage(imgResize) w_language_flag = Label( self.grid.col_frames[2][0], image=imgTkinter, borderwidth=0, bg="#ffffff" ) w_language_flag.image = imgTkinter w_language_flag.pack(fill='both', expand=True) w_category_name = Label( self.grid.col_frames[2][1], anchor="w", pady=0, text=category["category_name"], bg="#ffffff", fg="#000000", font="Helvetica 10 bold" ) w_category_name.pack(fill='both', expand=True) w_category_product = Label( self.grid.col_frames[2][2], pady=0, text=category["category_products"], bg="#ffffff", fg="#000000", font="Helvetica 10 bold" ) w_category_product.pack(fill='both', expand=True) var_cat = self.var_categories[count]["var_category"] w_category_check = Checkbutton( self.grid.col_frames[2][3], variable=var_cat, bg="#ffffff" ) w_category_check.pack(fill='both', expand=True) self.w_language_flags.append(w_language_flag) self.w_category_names.append(w_category_name) self.w_category_products.append(w_category_product) self.w_category_checks.append(w_category_check) count += 1 elif action == "refresh": if len(self.w_language_flags) != 0: for tk_widget in self.w_language_flags: tk_widget.pack_forget() if len(self.w_category_names) != 0: for tk_widget in self.w_category_names: tk_widget.pack_forget() if len(self.w_category_products) != 0: for tk_widget in self.w_category_products: tk_widget.pack_forget() if len(self.w_category_checks) != 0: for tk_widget in self.w_category_checks: tk_widget.pack_forget() self.w_language_flags = [] self.w_category_names = [] self.w_category_products = [] self.w_category_checks = [] def row_3(self, action=None): """ Name : SUBMIT BUTTON cols : 4 """ if action == "construct": # -- CREATE ROW -- # self.grid.row( width=self.width, height=60, padx=self.padx, pady=self.pady, bg="#ffffff" ) # -- CREATE COLS -- # self.grid.column( span=2, row=3, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=4, row=3, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=4, row=3, width=None, height=None, padx=None, pady=None, bg=None ) self.grid.column( span=2, row=3, width=None, height=None, padx=None, pady=None, bg=None ) elif action == "fill": txt = self.json_script.get("row_3") # -- COLUMN 1/4 : EMPTY -- # # -- COLUMN 2/4 : SUBMIT BUTTON -- # if self.w_previous_button is None: self.w_previous_button = Button( self.grid.col_frames[3][1], text=txt.get("previous_button"), fg="#ffffff", bg="#7A57EC", activeforeground="#ffffff", activebackground="#845EFF", command=self.display_previous ) self.w_previous_button.pack(side=BOTTOM, fill=X) # -- COLUMN 3/4 : SUBMIT BUTTON -- # if self.w_submit_button is None: self.w_submit_button = Button( self.grid.col_frames[3][2], text=txt.get("submit_button"), fg="#ffffff", bg="#7A57EC", activeforeground="#ffffff", activebackground="#845EFF", command=self.upload ) self.w_submit_button.pack(side=BOTTOM, fill=X) # -- COLUMN 3/3 : EMPTY -- # elif action == "refresh": self.w_previous_button.pack_forget() self.w_submit_button.pack_forget() self.w_previous_button = None self.w_submit_button = None
class ProductEdit(): def __init__(self, container=None, displayer=None, session=None): """ 'container' (Obj ): instance of Container. 'displayer' (obj ): instance of Displayer. 'session,' (obj ): instance of Session. 'grid' (Obj ): instance of Grid. 'f_container' (Frame): container frame. 'm_frame' (Frame): master frame of view. 'name' (str ): name of view. 'json_script' (dict ): json dict of script. 'width' (int ): view width. 'height' (int ): view height. 'padx' (int ): view 'pady' (int ): view 'bg' (str ): view bg. """ # Instances self.container = container self.displayer = displayer self.session = session self.grid = None # Frames self.f_container = self.container.f_container self.m_frame = None # Informations self.name = None # Script self.json_script = None # Style Sheet self.width = self.container.width self.height = self.container.height self.padx = 0 self.pady = 0 self.bg = "#ffffff" # Tk control variables self.var_product_name = StringVar() self.var_product_store = StringVar() self.var_product_nutriscore = StringVar() self.var_product_img_url = StringVar() self.var_product_kcal = StringVar() self.var_product_kj = StringVar() self.var_product_sugar = StringVar() self.var_product_brand = StringVar() self.product_id = None self.product_name = None self.product_store = None self.product_nutriscore = None self.product_img_url = None self.product_kcal = 0 self.product_kj = 0 self.product_sugar = 0 self.product_brand = None # Widgets row 0 self.w_title = None # Widgets row 1 self.w_product_name_label = None self.w_product_name_entry = None # Widgets row 2 self.w_product_store_label = None self.w_product_store_entry = None # Widgets row 3 self.w_product_nutriscore_label = None self.w_product_nutriscore_entry = None # Widgets row 4 self.w_product_imgurl_label = None self.w_product_imgurl_entry = None # Widgets row 5 self.w_product_kcal_label = None self.w_product_kcal_entry = None # Widgets row 6 self.w_product_kj_label = None self.w_product_kj_entry = None # Widgets row 7 self.w_product_sugar_label = None self.w_product_sugar_entry = None # Widgets row 8 self.w_product_brand_label = None self.w_product_brand_entry = None # Widgets row 9 self.w_submit_button = None # Fill status self.fill_status = False # Previous View in **kwargs self.previous_view = None # -- Displayer initialisation -- # self.construct() def construct(self, **kwargs): """ Construt view. to not fill the view during initialization. 'grid' (obj): Instance of Grid. 'm_frame' (Frame): Tkinter master frame of view. """ # 1. Create new grid in page container. self.grid = Grid(frame=self.f_container, width=self.width, height=self.height, padx=self.padx, pady=self.pady, bg=self.bg) # 2. Get view frame for displayer function self.m_frame = self.grid.master_frame # 3. Construct the view rows self.row_0(action="construct") self.row_1(action="construct") self.row_2(action="construct") self.row_3(action="construct") self.row_4(action="construct") self.row_5(action="construct") self.row_6(action="construct") self.row_7(action="construct") self.row_8(action="construct") self.row_9(action="construct") def fill(self, **kwargs): """ Fill the view rows. 'json_script' (dict): texts for view. 'name' (str): view name. """ for key, value in kwargs.items(): if key == "view": self.previous_view = value elif key == "product_id": self.product_id = value # 1. Get the script. self.json_script = self.session.get_script(package_name="product", file_name="edit") # 2. Save name of view for displayer. self.name = self.json_script.get("view_name") # Get product informations self.product = self.session.dbmanager.db_product.read( action="id", product_id=self.product_id) self.product_img = self.product[0]["product_img_url"] self.product_name = self.product[0]["product_name"] self.product_brand = self.product[0]["product_brand"] self.product_nutriscore = self.product[0]["product_nutriscore"] self.product_img_url = self.product[0]["product_img_url"] self.product_kcal = self.product[0]["product_kcal"] self.product_sugar = self.product[0]["product_sugar"] self.product_author = self.product[0]["product_creator"] self.product_store = self.product[0]["product_store"] # 3. Refresh rows. if self.fill_status is True: self.row_0(action="refresh") self.row_1(action="refresh") self.row_2(action="refresh") self.row_3(action="refresh") self.row_4(action="refresh") self.row_5(action="refresh") self.row_6(action="refresh") self.row_7(action="refresh") self.row_8(action="refresh") self.row_9(action="refresh") # 3. Fill the view rows. self.row_0(action="fill") self.row_1(action="fill") self.row_2(action="fill") self.row_3(action="fill") self.row_4(action="fill") self.row_5(action="fill") self.row_6(action="fill") self.row_7(action="fill") self.row_8(action="fill") self.row_9(action="fill") self.fill_status = True def display_previous(self): """ Display previous view. """ self.displayer.display(c_view="product_edit", f_view=self.previous_view) def display_product_sheet(self): """ Display "product sheet". """ self.displayer.display(c_view="product_edit", f_view="product_sheet", product_id=self.product_id) def update_product(self): """ Update product in database. """ self.product_name = self.var_product_name.get() self.product_store = self.var_product_store.get() self.product_nutriscore = self.var_product_nutriscore.get() self.product_img_url = self.var_product_img_url.get() self.product_kcal = int(self.var_product_kcal.get()) self.product_kj = int(self.var_product_kj.get()) self.product_sugar = int(self.var_product_sugar.get()) self.product_brand = self.var_product_brand.get() self.session.dbmanager.db_product.update( product_id=self.product_id, product_name=self.product_name, product_store=self.product_store, product_nutriscore=self.product_nutriscore, product_img_url=self.product_img_url, product_kcal=self.product_kcal, product_kj=self.product_kj, product_sugar=self.product_sugar, product_brand=self.product_brand) self.display_product_sheet() def row_0(self, action=None): """ Name : TITLE cols : 1 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=150, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=12, row=0, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_0") # -- COLUMN 1/1 : TITLE -- # if self.w_title is None: self.w_title = Label(self.grid.col_frames[0][0], text=txt.get("view_title"), bg="#ffffff", fg="#000000", font="Helvetica 12 bold") self.w_title.pack(fill="both", expand=True) elif action == "refresh": self.w_title.pack_forget() self.w_title = None def row_1(self, action=None): """ Name : PRODUCT NAME cols : 3 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=50, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=3, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=7, row=1, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=1, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_1") if self.w_product_name_label is None: # -- COLUMN 1 : PRODUCT NAME LABEL -- # self.w_product_name_label = Label(self.grid.col_frames[1][0], anchor="w", text=txt.get("product_name"), bg="#ffffff") self.w_product_name_label.pack(fill="both", expand=True) if self.w_product_name_entry is None: # -- COLUMN 2 : PRODUCT NAME ENTRY -- # self.w_product_name_entry = Entry( self.grid.col_frames[1][1], textvariable=self.var_product_name) self.w_product_name_entry.insert(0, self.product_name) self.w_product_name_entry.pack(fill="both", expand=True) elif action == "refresh": self.w_product_name_label.pack_forget() self.w_product_name_entry.delete(0, 1000) self.w_product_name_entry.pack_forget() self.w_product_name_label = None self.w_product_name_entry = None def row_2(self, action=None): """ Name : PRODUCT STORES cols : 3 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=50, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=3, row=2, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=7, row=2, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=2, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_2") if self.w_product_store_label is None: # -- COLUMN 1 : PRODUCT STORES LABEL -- # self.w_product_store_label = Label( self.grid.col_frames[2][0], anchor="w", text=txt.get("product_stores"), bg="#ffffff") self.w_product_store_label.pack(fill="both", expand=True) if self.w_product_store_entry is None: # -- COLUMN 2 : PRODUCT STORES ENTRY -- # self.w_product_store_entry = Entry( self.grid.col_frames[2][1], textvariable=self.var_product_store) self.w_product_store_entry.insert(0, self.product_store) self.w_product_store_entry.pack(fill="both", expand=True) elif action == "refresh": self.w_product_store_label.pack_forget() self.w_product_store_entry.delete(0, 1000) self.w_product_store_entry.pack_forget() self.w_product_store_label = None self.w_product_store_entry = None def row_3(self, action=None): """ Name : PRODUCT NUTRISCORE cols : 3 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=50, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=3, row=3, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=7, row=3, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=3, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_3") if self.w_product_nutriscore_label is None: # -- COLUMN 1 : PRODUCT NUTRISCORE LABEL -- # self.w_product_nutriscore_label = Label( self.grid.col_frames[3][0], anchor="w", text=txt.get("product_nutriscore"), bg="#ffffff") self.w_product_nutriscore_label.pack(fill="both", expand=True) if self.w_product_nutriscore_entry is None: # -- COLUMN 2 : PRODUCT NUTRISCORE ENTRY -- # self.w_product_nutriscore_entry = Entry( self.grid.col_frames[3][1], textvariable=self.var_product_nutriscore) self.w_product_nutriscore_entry.insert(0, self.product_nutriscore) self.w_product_nutriscore_entry.pack(fill="both", expand=True) elif action == "refresh": self.w_product_nutriscore_label.pack_forget() self.w_product_nutriscore_entry.delete(0, 1000) self.w_product_nutriscore_entry.pack_forget() self.w_product_nutriscore_label = None self.w_product_nutriscore_entry = None def row_4(self, action=None): """ Name : PRODUCT IMAGE URL cols : 1 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=50, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=3, row=4, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=7, row=4, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=4, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_4") if self.w_product_imgurl_label is None: # -- COLUMN 1 : PRODUCT IMAGE URL LABEL -- # self.w_product_imgurl_label = Label( self.grid.col_frames[4][0], anchor="w", text=txt.get("product_img_url"), bg="#ffffff") self.w_product_imgurl_label.pack(fill="both", expand=True) if self.w_product_imgurl_entry is None: # -- COLUMN 2 : PRODUCT IMAGE URL ENTRY -- # self.w_product_imgurl_entry = Entry( self.grid.col_frames[4][1], textvariable=self.var_product_img_url) self.w_product_imgurl_entry.insert(0, self.product_img_url) self.w_product_imgurl_entry.pack(fill="both", expand=True) elif action == "refresh": self.w_product_imgurl_label.pack_forget() self.w_product_imgurl_entry.delete(0, 1000) self.w_product_imgurl_entry.pack_forget() self.w_product_imgurl_label = None self.w_product_imgurl_entry = None def row_5(self, action=None): """ Name : PRODUCT KCAL cols : 3 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=50, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=3, row=5, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=7, row=5, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=5, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_5") if self.w_product_kcal_label is None: # -- COLUMN 1 : PRODUCT KCAL LABEL -- # self.w_product_kcal_label = Label(self.grid.col_frames[5][0], anchor="w", text=txt.get("product_kcal"), bg="#ffffff") self.w_product_kcal_label.pack(fill="both", expand=True) if self.w_product_kcal_entry is None: # -- COLUMN 2 : PRODUCT KCAL ENTRY -- # self.w_product_kcal_entry = Entry( self.grid.col_frames[5][1], textvariable=self.var_product_kcal) self.w_product_kcal_entry.insert(0, self.product_kcal) self.w_product_kcal_entry.pack(fill="both", expand=True) elif action == "refresh": self.w_product_kcal_label.pack_forget() self.w_product_kcal_entry.delete(0, 1000) self.w_product_kcal_entry.pack_forget() self.w_product_kcal_label = None self.w_product_kcal_entry = None def row_6(self, action=None): """ Name : PRODUCT KJ cols : 3 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=50, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=3, row=6, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=7, row=6, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=6, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_6") if self.w_product_kj_label is None: # -- COLUMN 1 : PRODUCT KJ LABEL -- # self.w_product_kj_label = Label(self.grid.col_frames[6][0], anchor="w", text=txt.get("product_kj"), bg="#ffffff") self.w_product_kj_label.pack(fill="both", expand=True) if self.w_product_kj_entry is None: # -- COLUMN 2 : PRODUCT KJ ENTRY -- # self.w_product_kj_entry = Entry( self.grid.col_frames[6][1], textvariable=self.var_product_kj) self.w_product_kj_entry.insert(0, self.product_kj) self.w_product_kj_entry.pack(fill="both", expand=True) elif action == "refresh": self.w_product_kj_label.pack_forget() self.w_product_kj_entry.delete(0, 1000) self.w_product_kj_entry.pack_forget() self.w_product_kj_label = None self.w_product_kj_entry = None def row_7(self, action=None): """ Name : PRODUCT SUGAR cols : 3 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=50, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=3, row=7, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=7, row=7, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=7, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_7") if self.w_product_sugar_label is None: # -- COLUMN 1 : PRODUCT SUGAR LABEL -- # self.w_product_sugar_label = Label( self.grid.col_frames[7][0], anchor="w", text=txt.get("product_sugar"), bg="#ffffff") self.w_product_sugar_label.pack(fill="both", expand=True) if self.w_product_sugar_entry is None: # -- COLUMN 2 : PRODUCT SUGAR ENTRY -- # self.w_product_sugar_entry = Entry( self.grid.col_frames[7][1], textvariable=self.var_product_sugar) self.w_product_sugar_entry.insert(0, self.product_sugar) self.w_product_sugar_entry.pack(fill="both", expand=True) elif action == "refresh": self.w_product_sugar_entry.delete(0, 1000) self.w_product_sugar_entry.pack_forget() self.w_product_sugar_label.pack_forget() self.w_product_sugar_label = None self.w_product_sugar_entry = None def row_8(self, action=None): """ Name : PRODUCT BRAND cols : 3 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=50, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=3, row=8, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=7, row=8, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=2, row=8, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_8") if self.w_product_brand_label is None: # -- COLUMN 1 : PRODUCT BRAND LABEL -- # self.w_product_brand_label = Label( self.grid.col_frames[8][0], anchor="w", text=txt.get("product_brand"), bg="#ffffff") self.w_product_brand_label.pack(fill="both", expand=True) if self.w_product_brand_entry is None: # -- COLUMN 2 : PRODUCT BRAND ENTRY -- # self.w_product_brand_entry = Entry( self.grid.col_frames[8][1], textvariable=self.var_product_brand) self.w_product_brand_entry.insert(0, self.product_brand) self.w_product_brand_entry.pack(fill="both", expand=True) elif action == "refresh": self.w_product_brand_label.pack_forget() self.w_product_brand_entry.delete(0, 1000) self.w_product_brand_entry.pack_forget() self.w_product_brand_label = None self.w_product_brand_entry = None def row_9(self, action=None): """ Name : SUBMIT BUTTON cols : 3 """ if action == "construct": # -- CREATE ROW -- # self.grid.row(width=self.width, height=50, padx=self.padx, pady=self.pady, bg="#ffffff") # -- CREATE COLS -- # self.grid.column(span=4, row=9, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=4, row=9, width=None, height=None, padx=None, pady=None, bg=None) self.grid.column(span=4, row=9, width=None, height=None, padx=None, pady=None, bg=None) elif action == "fill": # Get texts for this row txt = self.json_script.get("row_9") if self.w_submit_button is None: # -- COLUMN 1 : SUBMIT BUTTON -- # self.w_submit_button = Button(self.grid.col_frames[9][1], text=txt.get("submit_button"), fg="#ffffff", bg="#7A57EC", activeforeground="#ffffff", activebackground="#845EFF", command=self.update_product) self.w_submit_button.pack(side=BOTTOM, fill=X) elif action == "refresh": self.w_submit_button.pack_forget() self.w_submit_button = None