def set_edit_view(self): """ Defines the content to be shown in the edit_frame. """ ### FORM SETTINGS CONTAINER form_container = Frame(master=self.edit_frame, background=self._background) form_container.pack(side=LEFT, padx=20, pady=20, fill='y') form_title_label = Label(master=form_container, text=f"{REFS.ORDERS_TABLE_FORM_GER}", font=Fonts.xsmall(bold=True), background=self._background) form_title_label.pack(side=TOP, fill='x') form_radiobutton_group = RadioButtonGroup() def _form_button_pressed(button_form): self._changed_order.form = button_form for idx, form in enumerate(REFS.ORDER_FORMS): initial_state = (self._order.form == idx) command = partial(_form_button_pressed, idx) radio_button_container = Frame(master=form_container) radio_button_container.pack(side=TOP, fill='x', pady=10) form_radio_button = RadioButton(parent=radio_button_container, text=form, font=Fonts.xsmall(), image=self._empty_img, highlight_image=self._empty_img, command=command, initial_state=initial_state, group=form_radiobutton_group, fg="#000000", bg=REFS.LIGHT_GRAY, highlight=REFS.LIGHT_CYAN, row=0, column=0, width=1.5, height=0.6) # form_radio_button.pack(side=TOP, fill='x', pady=10) form_container.update() ### STATE SETTINGS CONTAINER state_container = Frame(master=self.edit_frame, background=self._background) state_container.pack(side=LEFT, padx=20, pady=20, fill='y') state_title_label = Label(master=state_container, text=f"{REFS.ORDERS_TABLE_STATE_GER}", font=Fonts.xsmall(bold=True), background=self._background) state_title_label.pack(side=TOP, fill='x') state_container.update()
def config_navigation(self, button_container, label_container): self._back_img = IMAGES.create(IMAGES.BACK) self._next_img = IMAGES.create(IMAGES.NEXT) next_command = partial(self.switch_page, PageSystem.NEXT) prev_command = partial(self.switch_page, PageSystem.PREVIOUS) # Button: Go to previous page self._prev_button = CButton(parent=button_container, image=self._back_img, command=prev_command, fg=CButton.DARK, bg=CButton.LIGHT, row=0, column=0) self._prev_button._disable() # Button: Go to next page self._next_button = CButton(parent=button_container, image=self._next_img, command=next_command, fg=CButton.DARK, bg=CButton.LIGHT, row=0, column=1) self._next_button._disable() parent_bg = label_container.cget('background') self._current_page_label = Label(master=label_container, text='<current page index>', font=Fonts.small(bold=True), foreground='black', background=parent_bg) self._current_page_label.pack(side=LEFT, padx=10, fill='x', expand=1)
def __init__( self, parent, image, command, width=-1, height=-1, vertical=False, fg=DARK, bg=WHITE, row=0, column=0, flip_row_and_col=False, text="", font=None, spaceX=(0.0, 0.0), # As a multiple of the buttons standard SIZE spaceY=(0.0, 0.0) # As a multiple of the buttons stamdard SIZE ): if width == -1: if REFS.MOBILE: width = 1.0 else: width = 2.0 if height == -1: if REFS.MOBILE: height = 1.0 - 0.4 * (not vertical) - 0.3 * vertical else: height = 1.0 textFont = Fonts.medium() if font != None: textFont = font super().__init__(master=parent, command=command, image=image, text=text, font=textFont, width=width * self.SIZE, height=height * self.SIZE, fg=fg, bg=bg, compound='c') # helv36 = tkFont.Font(family='Helvetica', size=26, weight=tkFont.BOLD) # self.config(font=helv36) if flip_row_and_col: self.grid(row=column, column=row) else: self.grid(row=row, column=column) sY = (self.SIZE * spaceY[0], self.SIZE * spaceY[1]) sX = (self.SIZE * spaceX[0], self.SIZE * spaceX[1]) self.grid(padx=sX, pady=sY) self.is_shown = True
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 _update_tiles(self, root_category): self._clear_frame() self._meal_tile_buttons = [] for idx, subcat in enumerate(root_category.subcategories): x = idx % QuickOrderView.COLUMNS y = int(idx / QuickOrderView.COLUMNS) if x == 0: self.row_container = Frame(self, background=self._background) paddingy = (0, 5) if y == 0: paddingy = (10, 5) self.row_container.pack(padx=5, pady=paddingy, side=TOP, fill="both", expand=1) meal_tile = Frame(self.row_container, background=self._background, borderwidth=2) meal_tile.pack(padx=5, pady=(0, 5), side=LEFT, fill="both", expand=1) meal_tile.pack_propagate(0) meal_tile.grid_propagate(0) meal_tile.update() # Button styles for 'category'-buttons foreground = '#000000' largefont = Fonts.xxxlarge(bold=True) buttoncmd = partial(self.finish_current_order, subcat.meal) # Replace every space with a new line character button_text = f"{subcat.name}" button_text = button_text.replace(' ', '\n', 1) meal_tile_button = Button(meal_tile, text=button_text, foreground=foreground, command=buttoncmd, font=largefont) meal_tile_button.pack(fill="both", expand=1) self._meal_tile_buttons.append(meal_tile_button) for meal_button in self._meal_tile_buttons: meal_button.update() meal_button.config(wraplength=meal_button.winfo_width() - 20)
def __init__(self, parent, background, shown: bool = False): super().__init__( master=parent, cnf={}, background=background ) if REFS.MOBILE: MealDetailsView.SEPARATOR_WIDTH = 3 MealDetailsView.SIZES_FRAME_WIDTH = MealDetailsView.SIZES_FRAME_WIDTH_SMALL # Assure that the frame won't resize with the contained widgets self.pack_propagate(0) self.grid_propagate(0) # Private members self._is_hidden = shown self._background = background # Initialize visibility-state if not shown: self.hide_view() else: self.show_view() # TITLE LABEL self._title = Label( master=self, text="<title>", font=Fonts.xxxxxlarge(bold=True), background=background ) self._title.grid(row=0, columnspan=3, sticky='nsew', pady=(10, 10)) # PRICE LABEL self._price = Label( master=self, text='<price>', font=Fonts.xxxlarge(bold=True, italic=True), background=background ) self._price.grid(row=0, column=4, sticky='nsew', pady=(10, 10)) # HORIZONTAL SEPARATOR Frame( master=self, background=MealDetailsView.SEPARATOR_COLOR, height=MealDetailsView.SEPARATOR_WIDTH ).grid(row=1, column=0, columnspan=5, sticky='nsew') # ZUTATEN LABEL self._ingredients_label = Label( master=self, text=REFS.INGREDIENTS_LABEL, font=Fonts.xxxlarge(bold=True, italic=True), background=background ) self._ingredients_label.grid( row=2, column=0, sticky='nsew', pady=(10, 0)) # EXTRAS LABEL self._extras_label = Label( master=self, text=REFS.ADDONS_LABEL, font=Fonts.xxxlarge(bold=True, italic=True), background=background ) self._extras_label.grid(row=2, column=2, sticky='nsew', pady=(10, 0)) # SIZES LABEL self._sizes_label = Label( master=self, text=REFS.SIZES_LABEL, font=Fonts.xxxlarge(bold=True, italic=True), background=background ) self._sizes_label.grid(row=2, column=4, sticky='nsew', pady=(10, 0)) # ZUTATEN BUTTONS FRAME self._frame_ingredients = Frame( master=self, background=background ) self._frame_ingredients.grid(row=3, column=0, sticky='nsew') # VERTICAL LEFT SEPARATOR Frame( master=self, background=MealDetailsView.SEPARATOR_COLOR, width=MealDetailsView.SEPARATOR_WIDTH ).grid(row=2, rowspan=2, column=1, sticky='nsew') # EXTRAS BUTTONS FRAME self._frame_addons = Frame( master=self, background=background ) self._frame_addons.grid(row=3, column=2, sticky='nsew') # VERTICAL RIGHT SEPARATOR Frame( master=self, background=MealDetailsView.SEPARATOR_COLOR, width=MealDetailsView.SEPARATOR_WIDTH ).grid(row=2, rowspan=2, column=3, sticky='nsew') # GROESSEN BUTTONS FRAME self._frame_sizes = Frame( master=self, background=background, width=MealDetailsView.SIZES_FRAME_WIDTH ) self._frame_sizes.grid(row=3, column=4, sticky='nsew') self._frame_sizes.pack_propagate(0) self.grid_rowconfigure(0, weight=0) self.grid_rowconfigure(1, weight=0) self.grid_rowconfigure(2, weight=0) self.grid_rowconfigure(3, weight=1) self.grid_columnconfigure(0, weight=1) self.grid_columnconfigure(1, weight=0) self.grid_columnconfigure(2, weight=1) self.grid_columnconfigure(3, weight=0) self.grid_columnconfigure(4, weight=0) self._ingredients_states = [] # state: 1 = Included, 0 = Excluded self._addons_states = [] # state: 1 = Added, 0 = Left Out self._sizes_states = [] # state: 1 = Selected, 0 = Not Selected self._opened_meal = None self._adapted_meal = None
def __init__(self, parent, order, background='white'): super().__init__(parent=parent, height=HistoryItem.HEIGHT, background='#F4F4F4') self._background = '#F4F4F4' self._order = OrdersService.convert_to_order_object(order) self.expanded = False self._changed_order = self._order.copy() self.edit_view_shown = False self.meals_view_shown = False column_names: [] = OrdersService.get_column_names() self._edit_img = IMAGES.create(IMAGES.EDIT) self._check_img = IMAGES.create(IMAGES.CHECK_MARK) self._down_img = IMAGES.create(IMAGES.DOWN) self._up_img = IMAGES.create(IMAGES.UP) self._empty_img = IMAGES.create(IMAGES.EMPTY) ########## COLUMNS ########## self.row_frame = Frame(master=self, background=background, height=HistoryItem.HEIGHT) self.row_frame.pack(side=TOP, fill='x') self.row_frame.pack_propagate(0) self.meals_frame = Frame(master=self, background='#F4F4F4') self.set_meals_content() self.edit_frame = Frame(master=self, background='#F4F4F4') self.set_edit_view() ##### TIMESTAMP ##### self.timestamp = Label(master=self.row_frame, text=OrdersService.convert_timestamp( self._order.timestamp, extended=True), font=Fonts.xsmall(), background=background, width=18) self.timestamp.pack(side=LEFT, padx=HistoryView.PADX_COL) ##### NUMBER ##### self.number = Label(master=self.row_frame, text=f"#{self._order.id}", font=Fonts.xsmall(bold=True), background=background, width=8) self.number.pack(side=LEFT, padx=HistoryView.PADX_COL) ##### FORM ##### self.form = Label(master=self.row_frame, text=OrdersService.convert_form(self._order.form), font=Fonts.xsmall(), background=background, width=10) self.form.pack(side=LEFT, padx=HistoryView.PADX_COL) ##### PRICE ##### self.price = Label(master=self.row_frame, text=f"{self._order.price_str}{REFS.CURRENCY}", font=Fonts.xsmall(), background=background, width=6) self.price.pack(side=LEFT, padx=HistoryView.PADX_COL) ##### EDIT BUTTON ##### self.edit_container = Frame(master=self.row_frame, width=HistoryView.EDIT_HEADER_WIDTH, height=60, bg=background) self.edit_container.pack(side=RIGHT, padx=HistoryView.PADX_COL) self.edit = Button(master=self.edit_container, image=self._edit_img, command=self.edit_order_command) self.edit.place(relx=0.5, rely=0.5, anchor="center") self.initial_button_background = self.edit.cget('background') if self._order.state != REFS.OPEN and self._order.state != REFS.CHANGED: self.edit.config(state="disabled") ##### EXPAND BUTTON ##### self.expand_container = Frame(master=self.row_frame, width=HistoryView.EXPAND_HEADER_WIDTH, height=60, bg=background) self.expand_container.pack(side=RIGHT, padx=(HistoryView.PADX_COL, 0)) expand_button_cmd = partial(self.expand_button_command, HistoryItem.MEALS_CONTENT_MODE) self.expand = Button(master=self.expand_container, image=self._down_img, command=expand_button_cmd) self.expand.place(relx=0.5, rely=0.5, anchor="center") ##### ACTIVE ##### active_i = column_names.index(REFS.ORDERS_TABLE_ACTIVE) self.active = Label(master=self.row_frame, text=OrdersService.convert_active(order[active_i]), font=Fonts.xsmall(), background=background, width=8) self.active.pack(side=RIGHT, padx=HistoryView.PADX_COL) ##### STATUS ##### state_i = column_names.index(REFS.ORDERS_TABLE_STATE) self.state = Label(master=self.row_frame, text=OrdersService.convert_status(order[state_i]), font=Fonts.xsmall(), background=REFS.ORDER_STATE_COLORS[int( order[state_i])], width=10) self.state.pack(side=RIGHT, padx=HistoryView.PADX_COL)
def __init__(self, parent, toolbar_container: Frame, background='white', shown: bool = False): super().__init__(parent=parent, title=REFS.HISTORYVIEW_TITLE, toolbar_container=toolbar_container, background='#696969', shown=shown) if REFS.MOBILE: HistoryView.SPACING = 2 HistoryView.PADX_COL = 15 HistoryItem.HEIGHT = 80 - 40 * REFS.MOBILE HistoryItem.EXPAND_HEIGHT = 600 - 300 * REFS.MOBILE OrderMessagingService.on_database_changed_event.add( self.update_view_and_database_content) OrdersService.on_orders_changed.add( self.update_view_and_database_content) self.order_items = [] self.page_system = PageSystem( on_page_changed=self.update_view_and_database_content, items_per_page=HistoryView.ITEMS_PER_PAGE, numbering_mode=PageSystem.ITEM_NUMBERING) self._back_img = IMAGES.create(IMAGES.BACK) self._next_img = IMAGES.create(IMAGES.NEXT) self._reset_i_img = IMAGES.create(IMAGES.RESET_I) self._trashcan_img = IMAGES.create(IMAGES.TRASH_CAN) ######## Setting toolbar content ######## #### Right Button Container self._button_container_right = Frame(self.toolbar, background="#EFEFEF") self._button_container_right.grid(row=0, column=2, sticky='nsew') # Button: Reset history self._reset_i_button = CButton(parent=self._button_container_right, image=self._reset_i_img, command=self.reset_order_counter, fg=CButton.DARK, bg=CButton.LIGHT, width=1.0, row=0, column=0) # Button: Clear history self._clear_button = CButton(parent=self._button_container_right, image=self._trashcan_img, command=self.clear_history, fg=CButton.DARK, bg=CButton.LIGHT, width=1.0, row=0, column=1) #### Page System # Middle Breadcrumb Container self._container_middle = Frame(self.toolbar, background="#EFEFEF") self._container_middle.grid(row=0, column=1, sticky='nsew') ## Left Button Container self._button_container_left = Frame(self.toolbar, background="#EFEFEF") self._button_container_left.grid(row=0, column=0, sticky='nsew') self.page_system.config_navigation( button_container=self._button_container_left, label_container=self._container_middle) self.toolbar.grid_rowconfigure(0, weight=1) self.toolbar.grid_columnconfigure( 0, weight=0) # Left Container -> fit self.toolbar.grid_columnconfigure( 1, weight=1) # Middle Container -> expand self.toolbar.grid_columnconfigure( 2, weight=0) # Right Container -> fit ######## END setting toolbar content ######## header_bg = '#F4F4F4' ########## HEADER ########## self.header = Frame(master=self, background=header_bg, height=HistoryItem.HEIGHT) self.header.pack(side=TOP, fill='x', pady=(0, HistoryView.SPACING)) self.header.pack_propagate(0) self.timestamp_head = Label( master=self.header, background=header_bg, text=REFS.ORDERS_TABLE_TIMESTAMP_GER.capitalize(), font=Fonts.xsmall(), width=18) self.timestamp_head.pack(side=LEFT, padx=HistoryView.PADX_COL) self.number_head = Label(master=self.header, background=header_bg, text=REFS.ORDERS_TABLE_ID_GER.capitalize(), font=Fonts.xsmall(bold=True), width=8) self.number_head.pack(side=LEFT, padx=HistoryView.PADX_COL) self.form_head = Label(master=self.header, background=header_bg, text=REFS.ORDERS_TABLE_FORM_GER.capitalize(), font=Fonts.xsmall(), width=10) self.form_head.pack(side=LEFT, padx=HistoryView.PADX_COL) self.price_head = Label(master=self.header, background=header_bg, text=REFS.ORDERS_TABLE_PRICE_GER.capitalize(), font=Fonts.xsmall(), width=6) self.price_head.pack(side=LEFT, padx=HistoryView.PADX_COL) self.edit_head = Label( master=self.header, background=header_bg, # text=REFS.HISTORY_TABLE_EDIT, font=Fonts.xsmall(), width=5) self.edit_head.pack(side=RIGHT, padx=HistoryView.PADX_COL) self.edit_head.update() HistoryView.EDIT_HEADER_WIDTH = self.edit_head.winfo_reqwidth() self.expand_head = Label( master=self.header, background=header_bg, # text=REFS.HISTORY_TABLE_EXPAND, font=Fonts.xsmall(), width=5) self.expand_head.pack(side=RIGHT, padx=(HistoryView.PADX_COL, 0)) self.expand_head.update() HistoryView.EXPAND_HEADER_WIDTH = self.expand_head.winfo_reqwidth() self.active_head = Label( master=self.header, background=header_bg, text=REFS.ORDERS_TABLE_ACTIVE_GER.capitalize(), font=Fonts.xsmall(), width=8) self.active_head.pack(side=RIGHT, padx=HistoryView.PADX_COL) self.state_head = Label(master=self.header, background=header_bg, text=REFS.ORDERS_TABLE_STATE_GER.capitalize(), font=Fonts.xsmall(), width=10) self.state_head.pack(side=RIGHT, padx=HistoryView.PADX_COL) ########## TABLE ########## self.table = Frame(master=self, background='#F4F4F4') self.table.pack(side=TOP, fill='both', expand=1) self.scrolllist = ScrollList(parent=self.table, spacing=HistoryView.SPACING, background='#696969')
def __init__(self, parent, order: Order, background="#A2ABAD"): super().__init__(master=parent, cnf={}, background=background) self._order: Order = order # self._order.on_state_changed.add(self._state_changed_cb) self._font_S = Fonts.xxxsmall(decrement=1) self._font = Fonts.medium(decrement=1) # xxsmall self._font_bold = Fonts.medium(bold=True, decrement=1) # xxsmall ### Header self._header_container = Frame(master=self, background=self.LIGHT_GRAY, height=30) self._header_container.pack(side=TOP, fill='x') self._id_label = Label(master=self._header_container, background=self.LIGHT_GRAY, font=self._font_bold, text="<id>") self._id_label.pack(side=LEFT, padx=2, pady=2) self._timestamp_label = Label(master=self._header_container, background=self.LIGHT_GRAY, font=self._font, text="<timestamp>") self._timestamp_label.pack(side=RIGHT, padx=2, pady=2) ### Body self._body_container = Frame(master=self, background=self.LIGHT_GRAY) self._body_container.pack(side=TOP, fill='both', expand=1) self._meal_labels_frame = Frame(master=self._body_container, background=self.LIGHT_GRAY) self._meal_labels_frame.pack(side=TOP, fill='both', expand=1, padx=10, pady=10) self._meals_labels = [] ## Scrollable List self.scrolllist = ScrollList(parent=self._meal_labels_frame, background=REFS.DARK_GRAY, spacing=1) ### Footer self._footer_container = Frame(master=self, background=background, height=30) self._footer_container.pack(side=BOTTOM, fill='x') self._form_label = Label(master=self._footer_container, background=background, font=self._font_bold, text="<form>") self._form_label.pack(side=RIGHT, padx=2, pady=2) self._state_label = Label(master=self._footer_container, background=background, font=self._font, text="<state>") self._state_label.pack(side=LEFT, padx=2, pady=2) self._update_content()
def __init__(self, parent, background, shown: bool = False): super().__init__( master=parent, cnf={}, background=background ) CurrentOrderView.NUM_COLUMNS = CurrentOrderView.NUM_COLUMNS - REFS.MOBILE self._meal_number_changed_event: Event = Event() self._meal_number_changed_event.add(self._update_price) self._meals_frame = Frame( master=self, background='#F4F4F4' ) self._meals_frame.pack(side=LEFT, fill='both', expand=1) self._info_frame = Frame( master=self, background=background ) self._info_frame.pack(side=RIGHT, fill='y') form_radiobutton_group = RadioButtonGroup() self._order_form = REFS.DEFAULT_FORM def _form_button_pressed(button_form): self._order_form = button_form for idx, form in enumerate(REFS.ORDER_FORMS): command = partial(_form_button_pressed, idx) form_radio_button = RadioButton( master=self._info_frame, text=form, group=form_radiobutton_group, highlight=REFS.LIGHT_CYAN, font=Fonts.medium(), command=command, initial_state=self._order_form, height=3 ) form_radio_button.pack(side=TOP, fill='x', padx=10, pady=10) self._price_label = Label( master=self._info_frame, text='<price>', font=Fonts.medium(), background=background ) self._price_label.pack(side=BOTTOM, fill='x', padx=10, pady=10) # Assure that the frame won't resize with the contained widgets self.pack_propagate(0) self.grid_propagate(0) # Private members self._is_hidden = shown self._background = background # Initialize visibility-state if not shown: self.hide_view() else: self.show_view() self._added_meal_tiles = [] self._update_price()
def __init__( self, title, summary, id, remove_cb, remove_all_cb, origin = (0,0), margin = (15,15), keep_alive = False # If True, the toast won't fade out ): self._timer_id = -1 self._fade_timer_id = -1 self._id = id self._keep_alive = keep_alive self._visible = True self._stop_checking = False self._title = title self._summary = summary self._dest_x = origin[0] self._dest_y = origin[1] self._margin = margin window = Toplevel() window.overrideredirect(1) window.attributes('-topmost', 1) window.config(background=self.BACKGROUND) window.attributes("-alpha", self.INITIAL_ALPHA) if keep_alive: window.config(highlightbackground=REFS.LIGHT_YELLOW) window.config(highlightthickness=4) window.update() self._window = window self.update_window_geometry() self._header_frame = Frame( master=window, bg=self.BACKGROUND ) self._header_frame.pack(side=TOP, fill='x', padx=5, pady=(5,0)) self._title_label = Label( master=self._header_frame, text=self._title, font=Fonts.xlarge(bold=True), anchor="nw", justify="left", bg=self.BACKGROUND ) self._title_label.pack(side=LEFT) self._button_frame = Frame( master=self._header_frame, bg=self.BACKGROUND ) self._button_frame.pack(side=RIGHT) self.close_img = IMAGES.create(IMAGES.CLOSE) self.close_all_img = IMAGES.create(IMAGES.CLOSE_ALL) std_button_width = 20 + 20 * (not REFS.MOBILE) self.remove_self = partial(remove_cb, self) self._close_button = Button( master=self._button_frame, image=self.close_img, command=self.remove_self, width=std_button_width, height=std_button_width, bg=self.BACKGROUND ) self._close_button.pack(side=RIGHT, padx=(5,0)) self._close_all_button = Button( master=self._button_frame, image=self.close_all_img, command=remove_all_cb, width=std_button_width, height=std_button_width, bg=self.BACKGROUND ) self._close_all_button.pack(side=RIGHT, padx=5) self._summary_label = Label( master=window, text=self._summary, font=Fonts.medium(), anchor="nw", justify="left", bg=self.BACKGROUND ) self._summary_label.pack(side=TOP, fill='both', padx=5, pady=5)
def __init__(self, parent, toolbar_container: Frame, background="white", shown: bool = False): super().__init__(parent=parent, title=REFS.ADDORDERVIEW_TITLE, toolbar_container=toolbar_container, background=background, shown=shown) if REFS.MOBILE: AddOrderView.COLUMNS = 3 self._checkmark_img = IMAGES.create(IMAGES.CHECK_MARK) self._close_light_img = IMAGES.create(IMAGES.CLOSE_LIGHT) self._add_img = IMAGES.create(IMAGES.ADD) self._back_img = IMAGES.create(IMAGES.BACK) self._trashcan_img = IMAGES.create(IMAGES.TRASH_CAN) self._order_img = IMAGES.create(IMAGES.ORDER) self._background = background self._root_category = None self._current_category = None self._views = [] self._meal_details_view = MealDetailsView(self, background, False) self._views.append(self._meal_details_view) self._current_order_view = CurrentOrderView(self, background, False) self._views.append(self._current_order_view) self._receipt_view = ReceiptView(parent=self, background=background, shown=False) self._views.append(self._receipt_view) self._current_order_view.meal_number_changed_event.add( self._added_meal_number_changed) ######## Setting toolbar content ######## # Right Button Container self._button_container_right = Frame(self.toolbar, background="#EFEFEF") self._button_container_right.grid(row=0, column=2, sticky='nsew') self._label_meal_counter = Label(master=self._button_container_right, text='0', foreground='red', font=Fonts.small(bold=True), background="#EFEFEF") self._label_meal_counter.grid(row=0, column=0, padx=15) # Button: Finish current order self._finish_order_button = CButton( parent=self._button_container_right, image=self._checkmark_img, command=self.finish_current_order, fg=CButton.WHITE, bg=CButton.GREEN, row=0, column=1) self._finish_order_button._hide() self._finish_order_button._disable() # Button: Finish current order self._close_receipt_button = CButton( parent=self._button_container_right, image=self._close_light_img, command=self.close_receipt, fg=CButton.WHITE, bg=REFS.LIGHT_RED, row=0, column=1) self._close_receipt_button._hide() # Button: Show current order self._current_order_button = CButton( parent=self._button_container_right, image=self._order_img, command=self.show_current_order, fg=CButton.WHITE, bg=CButton.LIGHT, row=0, column=2) # Middle Breadcrumb Container self._breadcrumb_container_middle = Frame(self.toolbar, background="#EFEFEF") self._breadcrumb_container_middle.grid(row=0, column=1, sticky='nsew') self._breadcrumb = Label(master=self._breadcrumb_container_middle, text='<breadcrumb>', font=Fonts.small(), foreground='black', background='#EFEFEF') self._breadcrumb.pack(side=LEFT, padx=10, fill='x', expand=1) # Left Button Container self._button_container_left = Frame(self.toolbar, background="#EFEFEF") self._button_container_left.grid(row=0, column=0, sticky='nsew') self.toolbar.grid_rowconfigure(0, weight=1) self.toolbar.grid_columnconfigure( 0, weight=0) # Left Container -> fit self.toolbar.grid_columnconfigure( 1, weight=1) # Middle Container -> expand self.toolbar.grid_columnconfigure( 2, weight=0) # Right Container -> fit # Button: Add meal to order self._add_meal_to_order_button = CButton( parent=self._button_container_left, image=self._add_img, command=self.add_meal_to_order, fg=CButton.WHITE, bg=CButton.GREEN, spaceX=(0.0, 1.0), row=0, column=0) # Button: Go up one category self._back_button = CButton(parent=self._button_container_left, image=self._back_img, command=self.go_back, fg=CButton.DARK, bg=CButton.LIGHT, row=0, column=1) # Button: Reset the category and content self._clear_button = CButton( parent=self._button_container_left, image=self._trashcan_img, command=self.clear_addorderview, fg=CButton.DARK, bg=CButton.LIGHT, # spaceX=(0.0,1.0), row=0, column=2)
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)
def __init__(self, parent, background='white'): super().__init__( parent=parent, height=HistoryItem.HEIGHT, background=background #'#F4F4F4' ) self.meal_added_event: Event = Event() self.expanded = False self.edit_view_shown = False self.details_view_shown = False self.row_frame = Frame(master=self, background=background, height=HistoryItem.HEIGHT) self.row_frame.pack(side=TOP, fill='x') self.row_frame.pack_propagate(0) self.details_frame = Frame(master=self, background='#F4F4F4') self.set_details_content() self._undo_img = IMAGES.create(IMAGES.UNDO) self._add_img = IMAGES.create(IMAGES.ADD) self._down_img = IMAGES.create(IMAGES.DOWN) self._up_img = IMAGES.create(IMAGES.UP) self.index = Label(master=self.row_frame, font=Fonts.xsmall(), text="", background=background, width=MealsSettingsView.INDEX_WIDTH) self.index.pack(side=LEFT, padx=MealsSettingsView.PADDING) self.category = Text(master=self.row_frame, font=Fonts.xsmall(), background=background, width=MealsSettingsView.CATEGORY_WIDTH, height=1) self.category.pack(side=LEFT, padx=MealsSettingsView.PADDING) self.name = Text(master=self.row_frame, font=Fonts.xsmall(bold=True), background=background, width=MealsSettingsView.NAME_WIDTH + 3, height=1) self.name.pack(side=LEFT, padx=MealsSettingsView.PADDING) self.name_bg = self.name.cget('background') ##### ADD BUTTON ##### self.add_container = Frame(master=self.row_frame, width=MealsSettingsView.DELETE_HEADER_WIDTH, height=60, bg=background) self.add_container.pack(side=RIGHT, padx=MealsSettingsView.PADDING) self.add = Button(master=self.add_container, image=self._add_img, command=self.add_meal_command, background=CButton.GREEN) self.add.place(relx=0.5, rely=0.5, anchor="center") ##### UNDO BUTTON ##### self.undo_container = Frame(master=self.row_frame, width=MealsSettingsView.EDIT_HEADER_WIDTH, height=60, bg=background) self.undo_container.pack(side=RIGHT, padx=(MealsSettingsView.PADDING, 0)) self.undo = Button(master=self.undo_container, image=self._undo_img, command=self.undo_command) self.undo.place(relx=0.5, rely=0.5, anchor="center") # self.initial_button_background = self.edit.cget('background') # if self._order.state != REFS.OPEN and self._order.state != REFS.CHANGED: # self.edit.config(state="disabled") ##### EXPAND BUTTON ##### self.expand_container = Frame( master=self.row_frame, width=MealsSettingsView.EXPAND_HEADER_WIDTH, height=60, bg=background) self.expand_container.pack(side=RIGHT, padx=(MealsSettingsView.PADDING, 0)) # self.expand = Button( # master=self.expand_container, # image=self._down_img, # command=self.expand_button_command # ) # self.expand.place(relx=0.5, rely=0.5, anchor="center") ##### BASE PRICE ##### self.base_price = Text(master=self.row_frame, font=Fonts.xsmall(), background=background, width=MealsSettingsView.PRICE_WIDTH, height=1) self.base_price.pack(side=RIGHT, padx=MealsSettingsView.PADDING) self.base_price_bg = self.base_price.cget('background')
def __init__(self, parent, background): super().__init__(master=parent, cnf={}, background='#696969') if REFS.MOBILE: MealsSettingsView.PADDING = 15 self.meal_items = [] ########## HEADER ########## header_bg = '#F4F4F4' self.header = Frame(master=self, background=header_bg, height=HistoryItem.HEIGHT) self.header.pack(side=TOP, fill='x', pady=(0, HistoryView.SPACING)) self.header.pack_propagate(0) self.index_head = Label(master=self.header, background=header_bg, text="#", font=Fonts.xsmall(), width=MealsSettingsView.INDEX_WIDTH) self.index_head.pack(side=LEFT, padx=MealsSettingsView.PADDING) self.category_head = Label( master=self.header, background=header_bg, text=REFS.MEALS_TABLE_KATEGORIE_COLUMN.capitalize(), font=Fonts.xsmall(), width=MealsSettingsView.CATEGORY_WIDTH) self.category_head.pack(side=LEFT, padx=MealsSettingsView.PADDING) self.name_head = Label(master=self.header, background=header_bg, text=REFS.MEALS_TABLE_NAME_COLUMN.capitalize(), font=Fonts.xsmall(bold=True), width=MealsSettingsView.NAME_WIDTH) self.name_head.pack(side=LEFT, padx=MealsSettingsView.PADDING) self.delete_head = Label( master=self.header, background=header_bg, # text=REFS.HISTORY_TABLE_EXPAND, font=Fonts.xsmall(), width=4) self.delete_head.pack(side=RIGHT, padx=MealsSettingsView.PADDING) self.delete_head.update() MealsSettingsView.DELETE_HEADER_WIDTH = self.delete_head.winfo_reqwidth( ) self.edit_head = Label( master=self.header, background=header_bg, # text=REFS.HISTORY_TABLE_EDIT, font=Fonts.xsmall(), width=4) self.edit_head.pack(side=RIGHT, padx=(MealsSettingsView.PADDING, 0)) self.edit_head.update() MealsSettingsView.EDIT_HEADER_WIDTH = self.edit_head.winfo_reqwidth() self.expand_head = Label( master=self.header, background=header_bg, # text=REFS.HISTORY_TABLE_EXPAND, font=Fonts.xsmall(), width=4) self.expand_head.pack(side=RIGHT, padx=(MealsSettingsView.PADDING, 0)) self.expand_head.update() MealsSettingsView.EXPAND_HEADER_WIDTH = self.expand_head.winfo_reqwidth( ) self.base_price_head = Label(master=self.header, background=header_bg, text=REFS.MEALS_BASE_PRICE.capitalize(), font=Fonts.xsmall(), width=MealsSettingsView.PRICE_WIDTH) self.base_price_head.pack(side=RIGHT, padx=MealsSettingsView.PADDING) ########## TABLE ########## self.table = Frame(master=self, background='#F4F4F4') self.table.pack(side=TOP, fill='both', expand=1) self.scrolllist = ScrollList(parent=self.table, spacing=HistoryView.SPACING, background='#696969')
def __init__(self, parent, meal, index, background='white'): super().__init__( parent=parent, height=HistoryItem.HEIGHT, background=background #'#F4F4F4' ) self.meal = meal self.meal_deleted_event: Event = Event() self.expanded = False self.edit_view_shown = False self.details_view_shown = False self.row_frame = Frame(master=self, background=background, height=HistoryItem.HEIGHT) self.row_frame.pack(side=TOP, fill='x') self.row_frame.pack_propagate(0) self.details_frame = Frame(master=self, background='#F4F4F4') self.set_details_content() self._edit_img = IMAGES.create(IMAGES.EDIT) self._check_img = IMAGES.create(IMAGES.CHECK_MARK) self._trashcan_img = IMAGES.create(IMAGES.TRASH_CAN_LIGHT) self._down_img = IMAGES.create(IMAGES.DOWN) self._up_img = IMAGES.create(IMAGES.UP) self.index = Label(master=self.row_frame, text=f"{index}", font=Fonts.xsmall(), background=background, width=MealsSettingsView.INDEX_WIDTH) self.index.pack(side=LEFT, padx=MealsSettingsView.PADDING) self.category = Label(master=self.row_frame, text=meal.category_raw, font=Fonts.xsmall(), background=background, width=MealsSettingsView.CATEGORY_WIDTH) self.category.pack(side=LEFT, padx=MealsSettingsView.PADDING) self.name = Label(master=self.row_frame, text=meal.name, font=Fonts.xsmall(bold=True), background=background, width=MealsSettingsView.NAME_WIDTH) self.name.pack(side=LEFT, padx=MealsSettingsView.PADDING) ##### DELETE BUTTON ##### self.delete_container = Frame( master=self.row_frame, width=MealsSettingsView.DELETE_HEADER_WIDTH, height=60, bg=background) self.delete_container.pack(side=RIGHT, padx=MealsSettingsView.PADDING) self.delete = Button(master=self.delete_container, image=self._trashcan_img, command=self.delete_meal_command, background=CButton.DARK_RED) self.delete.place(relx=0.5, rely=0.5, anchor="center") ##### EDIT BUTTON ##### self.edit_container = Frame(master=self.row_frame, width=MealsSettingsView.EDIT_HEADER_WIDTH, height=60, bg=background) self.edit_container.pack(side=RIGHT, padx=(MealsSettingsView.PADDING, 0)) self.edit = Button( master=self.edit_container, image=self._edit_img, command=None #self.edit_order_command ) self.edit.place(relx=0.5, rely=0.5, anchor="center") self.edit.config(state="disabled") # self.initial_button_background = self.edit.cget('background') # if self._order.state != REFS.OPEN and self._order.state != REFS.CHANGED: # self.edit.config(state="disabled") ##### EXPAND BUTTON ##### self.expand_container = Frame( master=self.row_frame, width=MealsSettingsView.EXPAND_HEADER_WIDTH, height=60, bg=background) self.expand_container.pack(side=RIGHT, padx=(MealsSettingsView.PADDING, 0)) self.expand = Button(master=self.expand_container, image=self._down_img, command=self.expand_button_command) self.expand.place(relx=0.5, rely=0.5, anchor="center") self.expand.config(state="disabled") ##### BASE PRICE ##### self.base_price_head = Label(master=self.row_frame, text=f"{meal.price_str}{REFS.CURRENCY}", font=Fonts.xsmall(), background=background, width=MealsSettingsView.PRICE_WIDTH) self.base_price_head.pack(side=RIGHT, padx=MealsSettingsView.PADDING)
def __init__(self, parent, toolbar_container: Frame, background="white", shown: bool = False): super().__init__(parent=parent, title=REFS.ADDORDERVIEW_TITLE, toolbar_container=toolbar_container, background=background, shown=shown) self._root_category = None self._order_type = REFS.EAT_IN self._checkmark_img = IMAGES.create(IMAGES.CHECK_MARK) self._close_light_img = IMAGES.create(IMAGES.CLOSE_LIGHT) self._add_img = IMAGES.create(IMAGES.ADD) self._back_img = IMAGES.create(IMAGES.BACK) self._trashcan_img = IMAGES.create(IMAGES.TRASH_CAN) self._order_img = IMAGES.create(IMAGES.ORDER) self._empty_img = IMAGES.create(IMAGES.EMPTY) self._background = background ######## Setting toolbar content ######## # #### Right Button Container self._button_container_right = Frame(self.toolbar, background="#EFEFEF") self._button_container_right.grid(row=0, column=2, sticky='nsew') self._radio_button_group = RadioButtonGroup() self._eat_in_button = RadioButton(parent=self._button_container_right, text=REFS.ORDER_FORMS[REFS.EAT_IN], image=self._empty_img, highlight_image=self._empty_img, command=self._update_order_type, initial_state=True, group=self._radio_button_group, fg="#000000", bg=REFS.LIGHT_GRAY, highlight=REFS.LIGHT_CYAN, row=0, column=0 # width=1.5, height=0.6 ) # Button: Change order type to "eat in" # self._eat_in_button = ToggleButton( # parent=self._button_container_right, # text=REFS.ORDER_FORMS[REFS.EAT_IN], # image=self._empty_img, # highlight_image=self._empty_img, # command=self._update_order_type, # initial_state=True, # group=self._toggle_button_group, # bg=REFS.LIGHT_GRAY, # highlight=REFS.LIGHT_CYAN, # row=0, column=0 # ) self._takeaway_button = RadioButton( parent=self._button_container_right, text=REFS.ORDER_FORMS[REFS.TAKEAWAY], image=self._empty_img, highlight_image=self._empty_img, command=self._update_order_type, initial_state=False, group=self._radio_button_group, fg="#000000", bg=REFS.LIGHT_GRAY, highlight=REFS.LIGHT_CYAN, row=0, column=1 # width=1.5, height=0.6 ) # Button: Change order type to "takeaway" # self._takeaway_button = ToggleButton( # parent=self._button_container_right, # text=REFS.ORDER_FORMS[REFS.TAKEAWAY], # image=self._empty_img, # highlight_image=self._empty_img, # command=self._update_order_type, # initial_state=False, # group=self._toggle_button_group, # bg=REFS.LIGHT_GRAY, # highlight=REFS.LIGHT_CYAN, # row=0, column=1 # ) self._update_order_type() # Middle Breadcrumb Container self._breadcrumb_container_middle = Frame(self.toolbar, background="#EFEFEF") self._breadcrumb_container_middle.grid(row=0, column=1, sticky='nsew') self._breadcrumb = Label(master=self._breadcrumb_container_middle, text='Preis letzter Bestellung: -.--€', font=Fonts.small(), foreground='black', background='#EFEFEF') self._breadcrumb.pack(side=LEFT, padx=10, fill='x', expand=1) self.toolbar.grid_rowconfigure(0, weight=1) self.toolbar.grid_columnconfigure( 0, weight=0) # Left Container -> fit self.toolbar.grid_columnconfigure( 1, weight=1) # Middle Container -> expand self.toolbar.grid_columnconfigure( 2, weight=0) # Right Container -> fit
def __init__(self, mobile_view: bool = False, main_station: bool = True, debug: bool = False, suppress_logs: bool = False): CashDeskGUI.DEBUG = debug if suppress_logs: sys.stdout = open(os.devnull, 'w') REFS.MOBILE = mobile_view REFS.MAIN_STATION = main_station # Initializing the main window root = Tk() ## root.resizable(False, False) root.resizable(True, True) root.attributes('-fullscreen', True) root.config(background='#696969') #if not CashDeskGUI.DEBUG: # root.attributes('-fullscreen', True) # Window Size: approx. 7 in root_bg = "#696969" # root.config(width=866, height=487, background=root_bg) #root.config(width=800, height=480, background=root_bg) station = 'Küche' #if main_station: # station = 'Kasse' title_size = 'Mobile Ansicht (7")' #if not mobile_view: # title_size = 'Vollbild' # if CashDeskGUI.DEBUG: # root.attributes('-fullscreen', True) root.wm_title(f"Bestellsystem - {station} - {title_size}") root.update() root.pack_propagate(0) self._root = root # The default font for the labels def_font = Fonts.medium() paddings = (5, 5) if mobile_view: # The default font for the labels def_font = Fonts.xxsmall() paddings = (0, 0) # Declaring the cash desk's model object self.model = CashDeskModel(root) ## -------- HEADER STUFF -------- ## self._headercontainer = Frame(root, background="#EFEFEF") self._headercontainer.pack(side=TOP, fill='x', padx=paddings, pady=paddings) self._toolbar_container = Frame(self._headercontainer, background="#EFEFEF") self._toolbar_container.pack(side=LEFT, fill='both', expand=1) if REFS.MOBILE: self._nav_img = IMAGES.create(IMAGES.NAVIGATION) self._more_button_container = Frame(master=self._headercontainer, background="#EFEFEF") self._more_button_container.pack(side=RIGHT, fill='both') self._more_button = CButton(parent=self._more_button_container, image=self._nav_img, width=1, command=self.open_side_bar, fg=CButton.DARK, bg=CButton.LIGHT, row=0, column=0) # The frame at the top of the window # header = Frame(self._headercontainer, background="#EFEFEF") # header.pack(side=TOP, fill='x', padx=5, pady=5) # header.grid(row=0, column=0, sticky='nsew') ## -------- BODY STUFF -------- ## self.body_container = Frame(root, background=root_bg) self.body_container.pack(side=TOP, expand=1, fill='both', padx=paddings) # The content panel (container) in the middle of the window self.body = ContentPanel( self.body_container, self._toolbar_container) #self.model.body_content_changed_event) self.body.pack(side=LEFT, expand=1, fill='both') # Lowered to the minimum z-Layer, so that the notification toasts are visible self.body.lower() ## -------- FOOTER STUFF -------- ## # The frame at the bottom of the window that acts as a container for all the elements footerContainer = Frame(root, background="#EFEFEF") if REFS.MOBILE: self.side_bar_visible = False self.side_bar = Frame(self.body_container, background="#EFEFEF") footerContainer = self.side_bar else: footerContainer.pack(side=BOTTOM, fill='x', padx=paddings, pady=paddings) # The frame within the container holding all the buttons footer = Frame(footerContainer, background="#EFEFEF") # The label within the container with the current timestamp self._footer_clock = Label(master=footerContainer, text="<CURRENT_TIME>", background="#EFEFEF", font=def_font, padx=10) self.connection_image = IMAGES.create(IMAGES.CONNECTION) self.connection_lost_image = IMAGES.create(IMAGES.CONNECTION_LOST) self.connection_ready_image = IMAGES.create(IMAGES.CONNECTION_READY) self._connection_symbol = Label(master=footerContainer, background="#EFEFEF", image=self.connection_image, padx=5, pady=5) if mobile_view: footer.pack(side=BOTTOM) self._footer_clock.pack(side=TOP) self._connection_symbol.pack(side=TOP) else: footer.pack(side=LEFT) # The label within the container with the title of the currently active view self._footer_title = Label(master=footerContainer, text="<Current Content View>", background="#EFEFEF", font=def_font, padx=10) self._footer_title.pack(side=LEFT) self._footer_clock.pack(side=RIGHT) self._connection_symbol.pack(side=RIGHT) spaceX = (0.0, 1.0) spaceY = (0.0, 0.0) if mobile_view: spaceX = (0.0, 0.0) spaceY = (0.0, 0.5) self._exit_img = IMAGES.create(IMAGES.EXIT) # The button to exit the program self._exit_button = CButton(parent=footer, image=self._exit_img, width=1 - 2 * mobile_view, vertical=mobile_view, spaceX=spaceX, spaceY=(spaceY[1], spaceY[0]), command=self.terminate, fg=CButton.WHITE, bg=CButton.DARK_RED, row=0, column=0 + 5 * mobile_view, flip_row_and_col=mobile_view) if REFS.MAIN_STATION: self.add_order_view_img = IMAGES.create(IMAGES.BURGER_DARK) # The button to bring up the add order view self._add_order_view_button = CButton( parent=footer, image=self.add_order_view_img, vertical=mobile_view, command=self.show_add_order, fg=CButton.DARK, bg=CButton.LIGHT, row=0, column=1, flip_row_and_col=mobile_view) self.in_progress_img = IMAGES.create(IMAGES.IN_PROGRESS) # The button to bring up the active orders view self._active_orders_button = CButton(parent=footer, image=self.in_progress_img, vertical=mobile_view, command=self.show_active_orders, fg=CButton.DARK, bg=CButton.LIGHT, row=0, column=2, flip_row_and_col=mobile_view) self.history_img = IMAGES.create(IMAGES.HISTORY) # The button to bring up the history view self._history_button = CButton(parent=footer, image=self.history_img, vertical=mobile_view, spaceX=spaceX, command=self.show_history, fg=CButton.DARK, bg=CButton.LIGHT, row=0, column=3, flip_row_and_col=mobile_view) if REFS.MAIN_STATION: self.settings_img = IMAGES.create(IMAGES.SETTINGS) # The button to bring up the settings view self._settings_button = CButton(parent=footer, image=self.settings_img, vertical=mobile_view, spaceX=spaceX, command=self.show_settings, fg=CButton.DARK, bg=CButton.LIGHT, row=0, column=4, flip_row_and_col=mobile_view) ## -------- ADDITIONAL STUFF -------- ## # Add callback functions that are called as soon as the database connection is established if REFS.MAIN_STATION: self.model.db_connection_ready_event.add( self.body.add_order_view.initialize) else: self.model.db_connection_ready_event.add( self.body.active_orders_view.update_view_and_database_content) # self.body.add_order_view.initialize() # Initializing the model after the GUI has finished the init process self.model.initialize(debug=CashDeskGUI.DEBUG) # Adding the GUI's callback function to the main periodic thread event of the model self.model.on_cycle_event.add(self.on_cycle) self.model.body_content_changed_event.add(self.body_changed) # Start main loop to wait for actions mainloop()
def _fill_frame(self, container: Frame, button_contents: [], buttonCommand, default_button_foreground: str = '#000000', cols=3, rows=3): pad_size = (not REFS.MOBILE) * 5 NUM_COLUMNS = cols # Minimum number of columns NUM_ROWS = rows # Minimum number of rows tile_buttons = [] for idx, content in enumerate(button_contents): x = idx % NUM_COLUMNS y = int(idx / NUM_COLUMNS) if x == 0: self.row_container = Frame( container, background=self._background) paddingy = (0, 5) if y == 0: paddingy = (10, 5) self.row_container.pack( padx=5, pady=paddingy, side=TOP, fill="both", expand=1) container_tile = Frame(self.row_container, background=self._background, borderwidth=2) container_tile.pack(padx=pad_size, pady=(0, pad_size), side=LEFT, fill="both", expand=1) container_tile.pack_propagate(0) container_tile.update() foreground = default_button_foreground wrap_length = 100 + (not REFS.MOBILE) * 120 tile_button = Button(container_tile, text=content, foreground=foreground, font=Fonts.medium(bold=True), wraplength=wrap_length ) tile_button.pack(fill="both", expand=1) tile_button.config(command=partial(buttonCommand, tile_button, idx)) tile_buttons.append(tile_button) if MealDetailsView.BUTTON_DEFAULT_BACKGROUND == None: MealDetailsView.BUTTON_DEFAULT_BACKGROUND = tile_button.cget( 'background') # -- Fill last row with empty space -- # rest = len(button_contents) % NUM_COLUMNS if rest != 0: empty = NUM_COLUMNS - rest for i in range(0, empty): empty_tile = Frame(self.row_container, background=self._background, borderwidth=2) empty_tile.pack(padx=pad_size, pady=(0, pad_size), side=LEFT, fill="both", expand=1) # -- Fill space with empty rows if necessary -- # needed_rows = math.ceil(len(button_contents) / NUM_COLUMNS) if needed_rows < NUM_ROWS: for i in range(0, (NUM_ROWS - needed_rows)): self.empty_row = Frame(container, background=self._background) self.empty_row.pack(padx=5, pady=( 0, 5), side=TOP, fill="both", expand=1) empty_tile = Frame(self.empty_row, background=self._background, borderwidth=2) empty_tile.pack(padx=pad_size, pady=(0, pad_size), side=LEFT, fill="both", expand=1)
def _update_tiles(self, root_category): self._clear_frame() self._meal_details_view.hide_view() self._current_order_view.hide_view() if self._receipt_view.is_shown: self.close_receipt(update=False) self._finish_order_button._hide() self._close_receipt_button._hide() self._label_meal_counter.grid() self._current_category = root_category # Update the breadcrumb in the toolbar to fit the current category self._update_breadcrumb(root_category) if root_category.has_meal(): self._add_meal_to_order_button._enable() self._open_meal_details(root_category.meal, root_category) return self._add_meal_to_order_button._disable() self._meal_tile_buttons = [] for idx, subcat in enumerate(root_category.subcategories): x = idx % AddOrderView.COLUMNS y = int(idx / AddOrderView.COLUMNS) if x == 0: self.row_container = Frame(self, background=self._background) paddingy = (0, 5) if y == 0: paddingy = (10, 5) self.row_container.pack(padx=5, pady=paddingy, side=TOP, fill="both", expand=1) meal_tile = Frame(self.row_container, background=self._background, borderwidth=2) meal_tile.pack(padx=5, pady=(0, 5), side=LEFT, fill="both", expand=1) meal_tile.pack_propagate(0) meal_tile.grid_propagate(0) meal_tile.update() has_a_meal = subcat.has_meal() # Button styles for 'category'-buttons foreground = '#646464' largefont = Fonts.xxxxlarge(bold=True, italic=not has_a_meal) buttoncmd = partial(self._update_tiles, subcat) if has_a_meal: # Button styles for 'meal'-buttons foreground = '#000000' # Replace every space with a new line character button_text = f"{subcat.name}" button_text = button_text.replace(' ', '\n') meal_tile_button = Button(meal_tile, text=button_text, foreground=foreground, command=buttoncmd, font=largefont) meal_tile_button.pack(fill="both", expand=1) self._meal_tile_buttons.append(meal_tile_button) for meal_button in self._meal_tile_buttons: meal_button.update() meal_button.config(wraplength=meal_button.winfo_width() - 20)
def __init__(self, parent, order, background='white'): super().__init__( parent=parent, height=800, background=background ) self._order = order self._timestamp_str = OrdersService.convert_timestamp( timestamp=order.timestamp, extended=True ) self._background = background ########## COLUMNS ########## self.text_container = Frame( master=self, background=background ) self.text_container.pack(side=TOP, fill='x', padx=5, pady=5) receipt_text_lines = self.create_text(order, raw_array=True) self._raw_lines = [] Fonts.family(family="Consolas", sustain=True) for line in receipt_text_lines: self.row_frame = Frame( master=self.text_container, background=background ) self.row_frame.pack(side=TOP, fill='x') content = line line_components = line.split(Receipt.DEL) bold = False size = 1 if len(line_components) >= 1: content = line_components[len(line_components) - 1] for index,comp in enumerate(line_components): if index != (len(line_components) - 1): if comp == Receipt.LARGE: size = 2 elif comp == Receipt.SMALL: size = 0 elif comp == Receipt.BOLD: bold = True font = Fonts.medium(bold=bold) if size == 0: font = Fonts.small(bold=bold) elif size == 2: font = Fonts.xxlarge(bold=bold) self._raw_lines.append(content) self._text = Label( master=self.row_frame, text=content, background=background, font=font ) self._text.pack(side=LEFT)#, padx=5, pady=(5,0)) Fonts.family(family=Fonts.DEFAULT_FAMILY, sustain=False) self.update()