Exemplo n.º 1
0
    def __init__(self, nr, table, **kwargs):
        TabbedPanelItem.__init__(self, **kwargs)

        self.text = "Poziom {n}".format(n=nr)

        # Layout
        box = BoxLayout(orientation="vertical")
        self.add_widget(box)

        # Elementy
        box.add_widget(InfoLabel(text="Najlepszy wynik:", size_hint_y=0.1, font_name=DEFAULT_FONT))
        box.add_widget(BestScoreLabel(best=DataBase.get_best_score(table, nr), size_hint_y=0.3))
        box.add_widget(InfoLabel(text="Ostatnich {c}:".format(c=RECENT_COUNT), size_hint_y=0.1, font_name=DEFAULT_FONT))

        th = BoxLayout(orientation="horizontal", size_hint_y=0.15, spacing=1)

        th.add_widget(HeaderLabel(text="Data", size_hint_x=0.3))
        th.add_widget(HeaderLabel(text="Godzina", size_hint_x=0.3))
        th.add_widget(HeaderLabel(text="Uzyskany wynik"))

        box.add_widget(th)

        converter = lambda row_index, row: {
                    'size_hint_y': None,
                    'height': 40,
                    'cls_dicts': [
                        {'cls': RowLabel, 'kwargs': {'i': row_index, 'text': row.date, 'size_hint_x': 0.3} },
                        {'cls': RowLabel, 'kwargs': {'i': row_index, 'text': row.time, 'size_hint_x': 0.3} },
                        {'cls': RowLabel, 'kwargs': {'i': row_index, 'text': row.score, 'font_size': 20} },
                    ]
                }
        adapter = DictAdapter(
                    sorted_keys=range(RECENT_COUNT + 1),
                    args_converter=converter,
                    data={i: r for i, r in enumerate(DataBase.get_recent_scores(table, nr, RECENT_COUNT))},
                    cls=CompositeListItem
                    )

        box.add_widget(ListView(adapter=adapter))