def add_meal_command(self): raw_cat = self.category.get(1.0, END).strip() raw_name = self.name.get(1.0, END).strip() raw_price = self.base_price.get(1.0, END).strip() price = 0.0 if raw_name == "": self.name.config(background=REFS.LIGHT_RED) return else: self.name.config(background=self.name_bg) if raw_price != "": if REFS.CURRENCY in raw_price: raw_price = raw_price.replace(REFS.CURRENCY, "") try: price = float(raw_price) self.base_price.config(background=self.base_price_bg) except: self.base_price.config(background=REFS.LIGHT_RED) return MealsService.create_new_meal( category=raw_cat, name=raw_name, base_price=price, ingredients=[], # TODO addons=[], # TODO sizes=[]) # TODO self.meal_added_event()
def initialize(self): meals_db = MealsService.get_raw_meals() self._root_category = MealsService.split_meals_by_categories( meals_db, MealsService.NO_SPLIT) # Update the tiles on the view to match the category self._update_tiles(self._root_category)
def initialize(self): meals_db = MealsService.get_raw_meals() self._root_category = MealsService.split_meals_by_categories( meals_db, MealsService.SPLIT_ALL) # Print a tree of all categories self._root_category.printc() # Update the tiles on the view to match the category self._update_tiles(self._root_category)
def initialize(self, debug: bool = False): """ Has to be called, when the GUI is finished with initialization. """ self._main_cycle_thread() ##### Handler Registration # EncryptionHandler self._encryption_handler = EncryptionHandler(key=REFS.PUBLIC_KEY_16BIT) # Initialize database handler self._database_handler = DatabaseHandler(debug=debug) # Initialize network handler self._network_handler = NetworkHandler(main_station = REFS.MAIN_STATION) # Start continous receive-loop self._network_handler.start_receive_loop() self._secondary_cycle_thread() ##### Service Registration # Initialize meals service (which is using the database handler) self._meals_service = MealsService() self._orders_service = OrdersService() self._order_messaging_service = OrderMessagingService() # If the db connection has been established: trigger the event if self._database_handler.CONNECTION_READY: self._db_connection_ready_event()
def _set_meals_list_text(self): self._meal_labels_frame.pack(side=TOP, fill='both', expand=1, padx=10, pady=10) self.scrolllist.remove_all() meals: [] = self._order.meals for meal in meals: # Create additional text for the ingredients and addons for the meal (meal_name_text, meal_text) = MealsService.meal_content_to_text(meal) meal_list_item = MealListItem(parent=self.scrolllist, title=meal_name_text, text=meal_text, font_title=self._font_bold, font_text=self._font_S, background=self.LIGHT_GRAY) self.scrolllist.add_row(meal_list_item, update=False) self.scrolllist.update_view()
def update_view_and_database_content(self): # Get all orders from the database sorted by their timestamp meals_sorted_by_category = MealsService.get_meal_objects( order_by=f"{REFS.MEALS_TABLE_KATEGORIE_COLUMN} ASC") # Safe the result in this class's array self.meal_items.clear() self.meal_items.extend(meals_sorted_by_category) self.refresh_view()
def delete_meal_command(self): confirmed = False condition = f"{REFS.MEALS_TABLE_NAME_COLUMN}='{self.meal.name}'" # AND " \ f"{REFS.MEALS_TABLE_KATEGORIE_COLUMN}='{self.meal.category_raw}'" try: confirmed = MealsService.delete_from_table(condition=condition, confirm=True) except: pass if confirmed: self.meal_deleted_event()
def set_meals_content(self): """ Defines the content to be shown in the meals_frame. """ meals = self._order.meals bg = 'white' containers = [] for meal in meals: meal_container = Frame(master=self.meals_frame, background=bg) meal_container.pack(side=LEFT, padx=20, pady=20) containers.append(meal_container) (meal_title, meal_text) = MealsService.meal_content_to_text(meal) # amount_text = "" # if meal.amount > 1: # amount_text = f"{meal.amount}x " # meal_title = f"{amount_text}{meal.name}" # if len(meal.sizes) != 0 and meal.sizes[0] != '': # meal_title = f"{meal_title} ({meal.sizes[0]})" meal_title_label = Label(master=meal_container, text=meal_title, background=bg, font=Fonts.large(bold=True), justify='left', anchor='nw') meal_title_label.pack(side=TOP, fill='x', padx=10, pady=10) if meal_text != "": # Label that contains the list of ingredients and addons of this meal meal_ingredients_label = Label(master=meal_container, text=meal_text, font=Fonts.xsmall(), background=bg, anchor='w', justify='left') meal_ingredients_label.pack(side=TOP, fill='x', padx=10, pady=(0, 10)) meal_container.update()
def __init__(self, parent, meal, index, remove_meal_cb, on_amount_changed_cb=None, background='white'): super().__init__(master=parent, cnf={}, background=background, highlightbackground='#606060', highlightthickness=2) self.padding = 15 if REFS.MOBILE: self.padding = 5 if AddedMealTile.PADDING != self.padding: AddedMealTile.PADDING = self.padding self.on_amount_changed_event: Event = Event() if on_amount_changed_cb != None and callable(on_amount_changed_cb): self.on_amount_changed_event.add(on_amount_changed_cb) self._meal = meal self.close_img = IMAGES.create(IMAGES.CLOSE) self.up_img = IMAGES.create(IMAGES.UP) self.down_img = IMAGES.create(IMAGES.DOWN) # TODO: Maybe as subheading to the name title we can add the last category of the meal #### Setup header std_button_width = 20 + 20 * (not REFS.MOBILE) self._header = Frame(master=self, background=background) self._header.pack(side=TOP, padx=self.padding, pady=self.padding, fill='x') self._l_name = Label(master=self._header, text=meal.name, background=background, foreground='black', font=Fonts.large(bold=True)) self._l_name.pack(side=LEFT, fill='x', expand=1) self._b_delete = Button(master=self._header, image=self.close_img, command=partial(remove_meal_cb, self), width=std_button_width, height=std_button_width) self._b_delete.pack(side=RIGHT, padx=(5, 0)) self.body_frame = Frame(master=self, background=background) self.body_frame.pack(side=TOP, padx=self.padding, pady=(0, self.padding), fill='both', expand=1) self.left_frame = Frame(master=self.body_frame, background=background) self.left_frame.pack(side=LEFT, fill='both', expand=1) #### Counter buttons self.right_frame = Frame(master=self.body_frame, background=background) self.right_frame.pack(side=RIGHT, fill='y') self._b_count_up = Button(master=self.right_frame, image=self.up_img, command=partial(self.change_amount, +1), width=std_button_width, height=std_button_width * 2) self._b_count_up.pack(side=TOP, pady=(0, 5)) self._b_count_down = Button(master=self.right_frame, image=self.down_img, command=partial(self.change_amount, -1), width=std_button_width, height=std_button_width * 2) self._b_count_down.pack(side=TOP) self._b_count_down.config(state="disabled") #### Setup size if len(meal.size_objects) > 0: size_text = f"{meal.size_objects[0].name}" if not REFS.MOBILE: size_text = f"{REFS.SIZE_LABEL}: " + size_text self._l_size = Label(master=self.left_frame, text=size_text, background=background, foreground='black', font=Fonts.xxsmall(), justify='left') self._l_size.pack(side=TOP, padx=self.padding, pady=(0, self.padding), anchor='nw') (meal_title, meal_text) = MealsService.meal_content_to_text(meal, indent="") self._l_content = Label(master=self.left_frame, text=meal_text, background=background, foreground='black', font=Fonts.xsmall(), justify='left') self._l_content.pack(side=TOP, padx=self.padding, pady=(0, self.padding), anchor='nw') # #### Setup ingredients list # # Only add ingredients, if there are any # if len(meal.ingredient_objects) > 0: # self._l_ingredients = Label( # master=self.left_frame, # text='', # background=background, # foreground='black', # font=Fonts.xxsmall(), # justify='left' # ) # self._l_ingredients.pack(side=TOP, padx=15, pady=(0, 15), anchor='nw') # for idx,ingr in enumerate(meal.ingredients): # curr_text = self._l_ingredients.cget('text') # nl = '\n' # if idx == len(meal.ingredients) - 1: # nl = '' # self._l_ingredients.config(text=f"{curr_text}- OHNE {ingr}{nl}") # #### Setup extras list # # Only add extras, if there are any # if len(meal.addons) > 0: # self._l_addons = Label( # master=self.left_frame, # text='', # background=background, # foreground='black', # font=Fonts.xxsmall(), # justify='left' # ) # self._l_addons.pack(side=TOP, padx=15, pady=(0, 15), anchor='nw') # for idx,addon in enumerate(meal.addons): # curr_text = self._l_addons.cget('text') # nl = '\n' # if idx == len(meal.addons) - 1: # nl = '' # self._l_addons.config(text=f"{curr_text}+ MIT {addon}{nl}") self.set_position(0, index) self.grid_propagate(0) self.pack_propagate(0)