def _property_column(self, name, value): name = urwid.Text(name) value = urwid.Text(value, align="right") return urwid.Columns([ ("weight", 0.5, colors.wrap(name, colors.PROPERTY_NAME)), ("fixed", 1, urwid.Divider()), ("weight", 0.5, colors.wrap(value, colors.PROPERTY)), ])
def set_color(self, color, title_color): for (row, col) in itertools.product(xrange(3), xrange(3)): if row == 1 and col == 1: continue line, space = self._w[row].contents[col] self._w[row].contents[col] = colors.wrap(line, color), space title_color = title_color or color title, space = self.tline_widget.contents[1] self.tline_widget.contents[1] = colors.wrap(title, title_color), space
def ui_for_item(self, item): cols = [ self._property_column(name, getattr(item, key)) for name, key in self.shown_properties if getattr(item, key) ] details = urwid.Text(item.details, align="center") properties = urwid.GridFlow(cols, 18, 6, 0, "left") sections = urwid.Pile([ urwid.Divider(), urwid.Padding(colors.wrap(details, colors.LOW), left=1, right=1), colors.wrap(urwid.Divider('─', top=1, bottom=1), colors.BOX), urwid.Padding(properties, left=2), ]) return sections
def __init__(self, body, width, height, title=None): self.size = (width, height) self.body = body title = self._truncate(title, width) or "" filler = colors.wrap(urwid.Filler(body), colors.DIALOG_BODY) self.frame = urwid.Frame(filler, focus_part='footer') box = ColoredLineBox(self.frame, title=title) # Dialog's shadow effect shadow = urwid.Text(('', ' ')) bottom_shadow = colors.wrap(shadow, colors.DIALOG_SHADOW) left_shadow = urwid.Filler(shadow, "top") w = urwid.Columns([ box, ('fixed', 2, colors.wrap(left_shadow, colors.DIALOG_SHADOW)) ]) self.__super.__init__(urwid.Frame(w, footer=bottom_shadow)) self.add_buttons([Button("OK", "close", delegate=self)])
def set_item_count(self, item, count, available=True): idx = self.items.index(item) _, count_pos = self.body[1][idx].contents[0] button, _ = self.body[1][idx].contents[1] if not available: color = colors.ITEM_UNAVAILABLE elif count > 0: color = colors.ITEM_SELECTED elif item.is_meal: color = colors.ITEM_MEAL else: color = colors.ITEM_NOMEAL button.set_color(color) count_string = str(count) if count else "" count_label = colors.wrap(urwid.Text(count_string), color) self.body[1][idx].contents[0] = count_label, count_pos
def ui(self): widgets = [] widgets += [urwid.Divider(top=0)] widgets += [urwid.Edit("Email: ")] widgets += [urwid.Edit("Password: "******"*")] widgets += [urwid.Divider(top=0)] widgets += [urwid.CheckBox("Remember password")] widgets += [urwid.Divider(top=0)] widgets += [Button("Sign In", "login", delegate=self)] widgets = [ colors.wrap(x, focus=colors.LOGIN_FIELDS_FOCUS) for x in widgets ] pile = urwid.Pile(widgets) pile = urwid.Padding(pile, left=2, right=2) pile = urwid.Columns([ ("weight", 0.3, urwid.Divider()), ("weight", 0.3, ColoredLineBox(pile, title="Login")), ("weight", 0.3, urwid.Divider()), ]) return pile
def show_closed(self): fonts = urwid.get_all_fonts() text = urwid.Text("Kitchen is closed, come back tomorrow!", align="center") self.body = colors.wrap(text, colors.ERROR)
def enabled(self, enabled): self._enabled = enabled color = self._color if enabled else colors.BUTTON_DISABLED focus = self._focus_color if enabled else None self._w = colors.wrap(self._button, color, focus)
def set_color(self, normal_color, focus_color=None): self._color = normal_color self._focus_color = focus_color or self._focus_color self._w = colors.wrap(self._button, normal_color, self._focus_color)
def _show_confirmation(self, items, payment, address, scheduled=False): widgets = [] widgets += [urwid.Divider()] # Add total as a line item total = LineItem({}) total.price = sum(x.price * x.quantity for x in items) total.title = "Total" items.append(total) # Order Items for item in filter(lambda x: x.type == LineItem.TYPE_DISH, items): price = "%.2f" % (item.price / 100.0) columns = urwid.Columns([ ("fixed", 2, urwid.Text(str(item.quantity), align="right")), ("fixed", 1, urwid.Divider()), ("weight", 1, ColoredText(item.title, colors.ITEM_MEAL)), ("fixed", 6, ColoredText(price, colors.PRICE, align="right")), ]) widgets += [columns] # Total & Taxes widgets += [urwid.Divider()] for item in filter(lambda x: x.type != LineItem.TYPE_DISH, items): price = "%.2f" % (item.price / 100.0) title = item.title columns = urwid.Columns([ ("weight", 1, ColoredText(title, colors.TAX, align="right")), ("fixed", 10, ColoredText(price, colors.PRICE, align="right")), ]) widgets += [columns] # Payment method columns = urwid.Columns([ ("weight", 0.5, ColoredText("Payment method", colors.LOW)), ("weight", 0.5, ColoredText(payment, colors.LOW, align="right")), ]) widgets += [urwid.Divider()] widgets += [columns] # Address columns = urwid.Columns([ ("weight", 0.5, ColoredText("Deliver to", colors.LOW)), ("weight", 0.5, ColoredText(address, colors.LOW, align="right")), ]) widgets += [columns] # Delay warning if scheduled: warning_label = urwid.Text(WARNING_TEXT, align="center") widgets += [urwid.Divider()] widgets += [colors.wrap(warning_label, colors.WARNING)] # Order button text = "Order when ready" if scheduled else "Order" buttons = urwid.Columns([ ("weight", 0.4, Button("Cancel", "cancel", delegate=self)), ("weight", 0.2, urwid.Divider()), ("weight", 0.4, Button(text, "order", delegate=self)), ], focus_column=2) widgets += [urwid.Divider()] widgets += [buttons] pile = urwid.Pile(widgets) pile = urwid.Padding(pile, left=2, right=2) pile = urwid.Columns([ ("weight", 0.2, urwid.Divider()), ("weight", 0.6, ColoredLineBox(pile, title="Confirmation")), ("weight", 0.2, urwid.Divider()), ]) self.body = pile