class ConfirmationFrame(tk.Frame): def __init__(self, parent, first="Confirm", font=None, **kwargs): super().__init__(parent, **kwargs) self.confirm_bt = LabelButton(self, "Confirm", width=7, font=font, bg="green") self.return_bt = LabelButton(self, "Return", width=7, font=font) confirm_grid_info = { "row": 0, "column": 1, "sticky": "nswe", "padx": 2 } return_grid_info = {"row": 0, "column": 1, "sticky": "nswe", "padx": 2} if first == "Confirm": confirm_grid_info["column"] = 0 else: return_grid_info["column"] = 0 self.confirm_bt.grid(**confirm_grid_info) self.return_bt.grid(**return_grid_info) def set_confirm(self, command): self.confirm_bt.command = command def set_return(self, command): self.return_bt.command = command
def __init__(self, parent, **kwargs): super().__init__(parent, **kwargs) self.grid_columnconfigure(2, weight=1) self.original_order = None self.ticket_no = tk.Label(self, font=self.font, relief=tk.SUNKEN, bd=1, bg="white") self.index = None self.completed = False self.is_gridded = False self.progress = ProgressBar(self) self.cancel_button = LabelButton(self, "Cancel", width=7, font=self.font, bg="red", command=self.on_cancel) self.modify_button = LabelButton(self, "Modify", width=7, font=self.font, command=self.on_modify) self.confirm_cancel = ConfirmationFrame(self, font=self.font) self.confirm_cancel.set_confirm(self.on_cancel_confirm) self.confirm_cancel.set_return(self.on_cancel_return) self.confirm_modify = ConfirmationFrame(self, first="Return", font=self.font) self.confirm_modify.set_confirm(self.on_modify_confirm) self.confirm_modify.set_return(self.on_modify_return) ttk.Separator(self, orient=tk.HORIZONTAL).grid(row=0, column=0, columnspan=5, sticky="we", pady=2) self.ticket_no.grid(row=1, column=0, sticky="nswe", padx=2) self.progress.grid(row=1, column=1, sticky="nswe", columnspan=2, padx=2) self.modify_button.grid(row=1, column=3, padx=2, sticky="nswe") self.cancel_button.grid(row=1, column=4, padx=2, sticky="nswe") self.confirm_cancel.grid(row=1, column=3, columnspan=2, sticky="nswe") self.modify_button.lift() self.cancel_button.lift()
def __init__(self, parent, **kwargs): super().__init__(parent, **kwargs) self.variables = TimeVariable(self) labels = ["MM", "DD", "YYYY", "HH", "MM", "AM/PM"] labels = [ tk.Label(self, font=self.font, text=label) for label in labels ] for i, label in enumerate(labels): label.grid(row=0, column=i, sticky="w") self.variables[i].grid(row=1, column=i, sticky="w") confirm = LabelButton(self, "Set Time", command=self.set_time, font=self.font) confirm.grid(row=1, column=6)
def __init__(self, **kwargs): super().__init__(**kwargs) current_time = ServerTime(self, bd=2) current_time.grid(row=0, column=0, pady=5, padx=5, sticky="nswe") edittime = EditTime(self) edittime.grid(row=1, column=0, pady=5, padx=5, sticky="nswe") confirm = LabelButton(self, text="Confirm", bg="green", command=self.destroy, font=current_time.font) confirm.grid(row=1, column=1, pady=5, padx=5, sticky="swe") self.current_time = current_time self.configure(bd=10) self.resizable(width=False, height=False) self.wm_title("Set Time")
def __init__(self, parent, **kwargs): self.removed = True self._ticket = None self.category = None self.item_selector = ttk.Combobox(parent, state="readonly", style="ItemEditor.TCombobox", font=self.font, width=type(self).longest_item, postcommand=self.post_command) self.edit_options = LabelButton(parent, "Options", width=7, font=self.font, command=self._options_callback(parent)) self.remove_item = LabelButton(parent, "Remove", width=7, font=self.font, bg="red", command=self._remove_callback) self.add_item = LabelButton(parent, "", width=7, font=self.font, command=self._add_callback)
def __init__(self, parent, **kwargs): super().__init__(parent, **kwargs) self.grid_columnconfigure(0, weight=1) self.grid_columnconfigure(1, weight=1) self.buttons = [ LabelButton(self, payment_type, font=self.font, width=15) for payment_type in type(self).payment_types ] # pylint:disable=E1101 self.cash_button = None rowcount = 3 columncount = 0 for i, button in enumerate(self.buttons): if i < 3: button.grid(row=i, column=0, columnspan=2, sticky="nswe", padx=10, pady=2) else: button.configure(font=(self.font[0], self.font[1] + 2)) if columncount == 2: columncount = 0 rowcount += 1 button.grid(row=rowcount, column=columncount, sticky="nswe", padx=10, pady=2) columncount += 1 if button["text"] == "Cash": self.cash_button = button assert self.cash_button is not None self.ctor_args = None
class ItemEditor(metaclass=ItemEditorType, device="POS"): font = ("Courier", 14) style = None def __new__(cls, parent, **kwargs): if cls.style is None: cls.style = ttk.Style(parent) cls.style.configure("ItemEditor.TCombobox", font=cls.font) cls.style.map("ItemEditor.TCombobox", fieldbackground=[("readonly", "white")], selectbackground=[("readonly", "white")], selectforeground=[("readonly", "black")]) return super().__new__(cls) def __init__(self, parent, **kwargs): self.removed = True self._ticket = None self.category = None self.item_selector = ttk.Combobox(parent, state="readonly", style="ItemEditor.TCombobox", font=self.font, width=type(self).longest_item, postcommand=self.post_command) self.edit_options = LabelButton(parent, "Options", width=7, font=self.font, command=self._options_callback(parent)) self.remove_item = LabelButton(parent, "Remove", width=7, font=self.font, bg="red", command=self._remove_callback) self.add_item = LabelButton(parent, "", width=7, font=self.font, command=self._add_callback) def grid(self, row=None, column=None, isaddon=True): if isaddon: self.item_selector.grid(row=row, column=column + 1, sticky="nswe", padx=2, pady=1) self.add_item.grid(row=row, column=column + 1, sticky="nswe", padx=2, pady=1) else: self.item_selector.grid(row=row, column=column, columnspan=2, sticky="nswe", padx=2, pady=1) self.add_item.grid(row=row, column=column, columnspan=2, sticky="nswe", padx=2, pady=1) self.edit_options.grid(row=row, column=column + 3, sticky="nswe", padx=2, pady=1) self.remove_item.grid(row=row, column=column + 4, sticky="nswe", padx=2, pady=1) def send_alert(self): if self.ticket.parameters.get("register", False): alert(f"'{self.ticket.name}' may have been completed") def post_command(self): self.send_alert() self.ticket.selected_options.clear() @property def ticket(self): return self._ticket @ticket.setter def ticket(self, value): self.category = value.category self.item_selector["values"] = type(self).item_names(value.category) self.item_selector.set(value.name) self.add_item["text"] = value.category if value.name: self._add_callback() else: self._remove_callback() self._ticket = value def get(self): if self.removed or self.ticket is None: return type(self).null_item item_name = self.item_selector.get() if item_name: self.ticket.name = item_name self.ticket.price, self.ticket.options = \ type(self).item_lookup(self._ticket.category, item_name) self.ticket.parameters["status"] = None else: self.ticket.price = 0 self.ticket.selected_options.clear() self.ticket.parameters.clear() return self.ticket def _remove_callback(self, *args): self.removed = True if self.ticket is not None: self.send_alert self.item_selector.lower() self.edit_options.grid_remove() self.remove_item.grid_remove() self.add_item.lift() def _add_callback(self, *args): self.removed = False self.item_selector.lift() self.edit_options.grid() self.remove_item.grid() self.add_item.lower() def _options_callback(self, parent): def inner(*args): EditOptions(parent, self.get()) return inner def destroy(self, *args): self.item_selector.destroy() self.edit_options.destroy() self.remove_item.destroy() self.add_item.destroy()
class OrderProgress(tk.Frame, metaclass=MenuWidget, device="POS"): font = ("Courier", 14) editor = None def __new__(cls, parent, **kwargs): if cls.editor is None: cls.editor = TicketEditorFrame(parent) cls.editor.update() return super().__new__(cls) @classmethod def set_keypress_bind(cls, *args, **kwargs): cls.editor.calculator.price_input.set_keypress_bind(*args, **kwargs) def __init__(self, parent, **kwargs): super().__init__(parent, **kwargs) self.grid_columnconfigure(2, weight=1) self.original_order = None self.ticket_no = tk.Label(self, font=self.font, relief=tk.SUNKEN, bd=1, bg="white") self.index = None self.completed = False self.is_gridded = False self.progress = ProgressBar(self) self.cancel_button = LabelButton(self, "Cancel", width=7, font=self.font, bg="red", command=self.on_cancel) self.modify_button = LabelButton(self, "Modify", width=7, font=self.font, command=self.on_modify) self.confirm_cancel = ConfirmationFrame(self, font=self.font) self.confirm_cancel.set_confirm(self.on_cancel_confirm) self.confirm_cancel.set_return(self.on_cancel_return) self.confirm_modify = ConfirmationFrame(self, first="Return", font=self.font) self.confirm_modify.set_confirm(self.on_modify_confirm) self.confirm_modify.set_return(self.on_modify_return) ttk.Separator(self, orient=tk.HORIZONTAL).grid(row=0, column=0, columnspan=5, sticky="we", pady=2) self.ticket_no.grid(row=1, column=0, sticky="nswe", padx=2) self.progress.grid(row=1, column=1, sticky="nswe", columnspan=2, padx=2) self.modify_button.grid(row=1, column=3, padx=2, sticky="nswe") self.cancel_button.grid(row=1, column=4, padx=2, sticky="nswe") self.confirm_cancel.grid(row=1, column=3, columnspan=2, sticky="nswe") self.modify_button.lift() self.cancel_button.lift() def _update(self, ticket_no): ticket_no = int(ticket_no) self.ticket_no["text"] = "{:03d}".format(ticket_no) self.progress.status = status = AsyncTk().forward( "get_order_status", ticket_no) if status == 100: self.modify_button.deactivate() self.cancel_button.deactivate() else: self.modify_button.activate() self.cancel_button.activate() if self.editor.grid_info().get("in") != self: self.confirm_modify.lower() def on_cancel(self): items, = AsyncTk().forward("get_order_info", int(self.ticket_no["text"]), "items") names = [] for ticket in items: for item in (ticket, ticket.addon1, ticket.addon2): if item.parameters.get("register", False): names.append(f"'{item.name}'") alert(f"{', '.join(names)} may have been completed.") self.confirm_cancel.lift() def on_modify(self, *args): self.confirm_modify.grid(row=1, column=3, columnspan=2, sticky="nswe") self.confirm_modify.lift() self.editor.set(str(int(self.ticket_no["text"])), self.index + 1, self) self.editor.grid(row=2, column=0, columnspan=5, sticky="nswe", pady=2, in_=self) self.editor.lift() def on_cancel_confirm(self): self.cancel_button.lift() self.modify_button.lift() ticket_no = int(self.ticket_no["text"]) #uncomment to prevent cancellation of completed items. #original, = AsyncTk().forward("get_order_info", ticket_no, "items") #modified_order = [] #for ticket in original: # items = ticket[:6], ticket[6], ticket[7] # for item in items: # if item[5].get("status") == TICKET_COMPLETE: # _item = MutableTicket(item) # null_ticket = MutableTicket(("", "", 0, {}, [], {})) # _item.data.extend((null_ticket, null_ticket)) # modified_order.append(_item) # # #if modified_order: # names = ", ".join(f"'{ticket.name}'" for ticket in modified_order) # logging.getLogger("main.POS.gui.stdout").info( # f"{names} cannot be removed. Modifying ticket instead..." # ) # return AsyncTk().forward("modify_order", ticket_no, modified_order) AsyncTk().forward("cancel_order", ticket_no) if self.editor.ticket_no == ticket_no: self.editor.grid_remove() self.confirm_modify.grid_remove() def on_cancel_return(self): self.cancel_button.lift() self.modify_button.lift() def on_modify_confirm(self, *args): AsyncTk().forward("modify_order", self.editor.ticket_no, self.editor.create_order(), self.editor.calculator.cash_given.get(), self.editor.calculator.change_due.get(), self.editor.difference) self.editor.grid_remove() self.confirm_modify.grid_remove() def on_modify_return(self): self.editor.grid_remove() self.editor.calculator.cash_given.set("0.00") self.confirm_modify.grid_remove() self.modify_button.lift() self.cancel_button.lift() def grid(self, **kwargs): self.is_gridded = True super().grid(**kwargs) def grid_remove(self): if self.editor.grid_info().get("in") == self: self.editor.grid_remove() self.confirm_modify.grid_remove() super().grid_remove()