Пример #1
0
def demo_components_progressbar():
    print("Press any key to progress\n")

    progressbar = components.ProgressBar("Basic ProgressBar")
    for i in range(0, 6):
        progressbar.update(i, 5)
        io.get_key()
    print()

    progressbar = components.ProgressBar("Fixed Width ProgressBar", width=25)
    for i in range(0, 6):
        progressbar.update(i, 5)
        io.get_key()
    print()

    progressbar = components.ProgressBar("ASCII ProgressBar",
                                         **codes.CHARS_ASCII)
    for i in range(0, 6):
        progressbar.update(i, 5)
        io.get_key()
    print()

    style = codes.CHARS_DEFAULT.copy()
    style["block"] = io.style_format(style["block"], "yellow")
    style["left-edge"] = io.style_format(style["left-edge"], "green")
    style["right-edge"] = io.style_format(style["right-edge"], "green")
    title = io.style_format("Styled ProgressBar", "bold green")
    progressbar = components.ProgressBar(title, **style)
    for i in range(0, 6):
        progressbar.update(i, 5)
        io.get_key()
Пример #2
0
 def profit_and_loss(self) -> List[str]:
     lines = [style_format("PROFIT AND LOSS", style="bold")]
     for stock in self.stock_store.profit_and_loss:
         lines.append(
             style_format(
                 f"{stock.delta_percent*100:+.2f}% {stock.delta_amount:+,.2f} {stock.currency.value}",
                 stock.colour,
             ))
     return lines
Пример #3
0
def demo_components_selectmany():
    choices = (1, 2, 3, 4, 5)

    print("No Choices")
    choice = components.SelectMany([]).prompt()
    print("choice = {}\n".format(choice))

    print("Basic")
    choice = components.SelectMany(choices).prompt()
    print("choice = {}\n".format(choice))

    print("ASCII Chars")
    choice = components.SelectMany(choices, **codes.CHARS_ASCII).prompt()
    print("choice = {}\n".format(choice))

    print("Styled Chars")
    arrow = io.style_format(codes.CHARS_DEFAULT["arrow"], "blue")
    choice = components.SelectMany(choices, arrow=arrow).prompt()
    print("choice = {}\n".format(choice))

    print("ChoiceHelper")
    five = components.ChoiceHelper(5, "five", "red bold", "f")
    six = components.ChoiceHelper(6, "six", "yellow italic", "[s]")
    choice = components.SelectMany((five, six)).prompt()
    print("choice = {}\n".format(choice))
Пример #4
0
 def watchlist(self) -> List[str]:
     rows = []
     colours = []
     for stock in self.stock_store.watchlist:
         row = []
         row.append(stock.ticket)
         if stock.volume:
             row.append(stock.volume_str)
         else:
             row.append("")
         row.append(f"@ {stock.amount_current:.2f}")
         if stock.delta_amount < 0:
             symbol = "▼"
         elif stock.delta_amount == 0:
             symbol = "▬"
         else:
             symbol = "▲"
         row.append(symbol)
         row.append(f"{stock.delta_amount:+,.2f}")
         row.append(f"{stock.delta_percent*100:+.2f}%")
         rows.append(row)
         colours.append(stock.colour)
     return [style_format("WATCHLIST", style="bold")] + format_table(
         rows, colours
     )
Пример #5
0
def _chars() -> Dict[str, str]:
    if no_style:
        chars = codes.CHARS_ASCII
    else:
        chars = codes.CHARS_DEFAULT
        chars["arrow"] = style_format(chars["arrow"], "magenta")
    return chars
Пример #6
0
 def debug_settings(self) -> List[str]:
     lines = [style_format("SETTINGS", style="bold")]
     for field in fields(self.settings):
         key = field.name
         value = getattr(self.settings, key)
         lines.append(f"{key} = {value}")
     return lines
Пример #7
0
 def debug_system(self) -> List[str]:
     lines = [
         style_format("SYSTEM", style="bold"),
     ]
     for k, v in SYSTEM.items():
         lines.append(f"{k.title()} = {v}")
     return lines
Пример #8
0
 def __str__(self):
     if self._idx < 0:
         s = io.style_format(self._str, self.style)
     elif self._bracketed:
         s = "%s[%s]%s" % (
             self._str[:self._idx],
             self._str[self._idx],
             self._str[self._idx + 1:],
         )
         s = io.style_format(s, self.style)
     else:
         s = (io.style_format(self._str[:self._idx], self.style) +
              io.style_format(self._str[self._idx],
                              "underline " + self.style) +
              io.style_format(self._str[self._idx + 1:], self.style))
     return s
Пример #9
0
 def positions(self) -> List[str]:
     rows = []
     colours = []
     for stock in self.stock_store.positions:
         row = [
             stock.ticket,
             f"{stock.delta_amount:+,.2f}",
             f"{stock.delta_percent*100:+.2f}%",
         ]
         rows.append(row)
         colours.append(stock.colour)
     return [style_format("POSITIONS", style="bold")] + format_table(
         rows, colours)
Пример #10
0
def format_table(rows: List[List[str]], colours: List[str]):
    column_widths = [
        len(max(columns, key=len))
        for columns in [list(column) for column in zip(*rows)]
    ]
    return [
        style_format(
            " ".join([
                col.ljust(column_widths[idx_col] + 1)
                for idx_col, col in enumerate(row)
            ]),
            colours[idx],
        ) for idx, row in enumerate(rows)
    ]
Пример #11
0
def metadata_guess(
    metadata: Metadata, ) -> Optional[Metadata]:  # pragma: no cover
    """Prompts user to confirm a single match."""
    label = str(metadata)
    if no_style:
        label += " (best guess)"
    else:
        label += style_format(" (best guess)", "blue")
    option = ChoiceHelper(metadata, label)
    selector = SelectOne([option] + _abort_helpers(), **_chars())
    choice = selector.prompt()
    if choice in (MnamerAbortException, MnamerSkipException):
        raise choice
    else:
        return choice
Пример #12
0
def demo_components_selectone():
    choices = (1, 2, 3, 4, 5)

    print("No Choices")
    choice = components.SelectOne([]).prompt()
    print("choice = {}\n".format(choice))

    print("Basic")
    choice = components.SelectOne(choices).prompt()
    print("choice = {}\n".format(choice))

    print("ASCII Chars")
    choice = components.SelectOne(choices, **codes.CHARS_ASCII).prompt()
    print("choice = {}\n".format(choice))

    print("Styled Chars")
    arrow = io.style_format(codes.CHARS_DEFAULT["arrow"], "blue")
    choice = components.SelectOne(choices, arrow=arrow).prompt()
    print("choice = {}\n".format(choice))

    print("ChoiceHelper")
    one = components.ChoiceHelper(1, None, "blue", "1")
    two = components.ChoiceHelper(2, None, "cyan", "2")
    three = components.ChoiceHelper(3, None, "green", "3")
    four = components.ChoiceHelper(4, None, "grey", "4")
    five = components.ChoiceHelper(5, None, "magenta", "5")
    six = components.ChoiceHelper(6, None, "red", "6")
    seven = components.ChoiceHelper(7, None, "yellow", "7")
    choice = components.SelectOne(
        (one, two, three, four, five, six, seven)
    ).prompt()
    print("choice = {}\n".format(choice))

    print("ChoiceHelper label")
    five = components.ChoiceHelper(5, "five", "red bold", "f")
    six = components.ChoiceHelper(6, "six", "yellow italic", "[s]")
    choice = components.SelectOne((five, six)).prompt()
    print("choice = {}\n".format(choice))
Пример #13
0
 def balances_str(self) -> List[str]:
     lines = [style_format("BALANCES", style="bold")]
     for currency, balance in self.stock_store.balances.items():
         lines.append(f"{balance:,.2f} {currency.value}")
     return lines
Пример #14
0
 def profit_and_loss(self) -> List[str]:
     lines = [style_format("PROFIT AND LOSS", style="bold")]
     for stock in self.stock_store.profit_and_loss:
         lines.append(style_format(stock.profit_and_loss, stock.colour))
     return lines
Пример #15
0
 def positions(self) -> List[str]:
     lines = [style_format("POSITIONS", style="bold")]
     for stock in self.stock_store.positions:
         lines.append(style_format(stock.position, stock.colour))
     return lines
Пример #16
0
 def watchlist(self) -> List[str]:
     lines = [style_format("WATCHLIST", style="bold")]
     for stock in self.stock_store.watchlist:
         lines.append(style_format(stock.ticker_tape, stock.colour))
     return lines