import math from kivy.uix.screenmanager import Screen from kivy.clock import Clock from kivy.metrics import dp COLS = 7 BTN_W = dp(150) BTN_H = dp(120) SP = dp(10) PAD = dp(10) class BaseAccountSelectScreen(Screen): def _create_ucet_button(self, u): raise NotImplementedError( "_create_ucet_button must be implemented in subclass" ) def _load_ucty(self, ucty): self.grid.clear_widgets() for u in ucty: if not u.stul: continue btn = self._create_ucet_button(u) self.grid.add_widget(btn) Clock.schedule_once(self._update_scroll, 0) def _update_scroll(self, *_): if not self.scroll or not self.grid: return count = len(self.grid.children) if count == 0: self.scroll.do_scroll_x = False self.scroll.do_scroll_y = False return rows = math.ceil(count / COLS) content_h = rows * BTN_H + (rows - 1) * SP + 2 * PAD self.scroll.do_scroll_y = content_h > self.scroll.height