78 lines
2.5 KiB
Python
78 lines
2.5 KiB
Python
from kivy.metrics import dp
|
|
from kivy.uix.modalview import ModalView
|
|
from kivy.uix.boxlayout import BoxLayout
|
|
from kivy.uix.scrollview import ScrollView
|
|
from kivy.uix.gridlayout import GridLayout
|
|
from kivy.uix.button import Button
|
|
from kivy.uix.label import Label
|
|
|
|
class ClosureSelectDialog(ModalView):
|
|
def __init__(self, closures, on_select, title="Vyber uzávěrku", **kwargs):
|
|
super().__init__(**kwargs)
|
|
self.size_hint = (None, None)
|
|
self.size = (dp(700), dp(700))
|
|
self.auto_dismiss = True
|
|
self.closures = closures or []
|
|
self.on_select = on_select
|
|
scroll = ScrollView(size_hint=(1, 1))
|
|
content = GridLayout(
|
|
cols=1,
|
|
spacing=dp(10),
|
|
padding=dp(12),
|
|
size_hint_y=None,
|
|
)
|
|
content.bind(minimum_height=content.setter("height"))
|
|
lbl_title = Label(
|
|
text=title,
|
|
size_hint_y=None,
|
|
height=dp(40),
|
|
)
|
|
content.add_widget(lbl_title)
|
|
for c in self.closures:
|
|
txt = self._closure_text(c)
|
|
btn = Button(
|
|
text=txt,
|
|
markup=True,
|
|
size_hint_y=None,
|
|
height=dp(90),
|
|
halign="left",
|
|
valign="middle",
|
|
text_size=(dp(650), None),
|
|
)
|
|
btn.bind(
|
|
size=lambda inst, val: setattr(
|
|
inst, "text_size", (inst.width - dp(20), None)
|
|
)
|
|
)
|
|
btn.bind(
|
|
on_release=lambda inst, clsrep_no=c.clsrep_no: self._select(clsrep_no)
|
|
)
|
|
content.add_widget(btn)
|
|
btn_close = Button(
|
|
text="Zavřít",
|
|
size_hint_y=None,
|
|
height=dp(56),
|
|
)
|
|
btn_close.bind(on_release=self.dismiss)
|
|
content.add_widget(btn_close)
|
|
scroll.add_widget(content)
|
|
self.add_widget(scroll)
|
|
|
|
def _select(self, clsrep_no):
|
|
self.dismiss()
|
|
if self.on_select:
|
|
self.on_select(clsrep_no)
|
|
|
|
def _closure_text(self, c):
|
|
clsrep_no = getattr(c, "clsrep_no", "") or ""
|
|
ucislo_od = getattr(c, "ucislo_od", "") or ""
|
|
ucislo_do = getattr(c, "ucislo_do", "") or ""
|
|
closed_at_od = getattr(c, "closed_at_od", "") or ""
|
|
closed_at_do = getattr(c, "closed_at_do", "") or ""
|
|
|
|
return (
|
|
f"[b]Uzávěrka {clsrep_no}[/b]\n"
|
|
f"Účty: {ucislo_od} - {ucislo_do}\n"
|
|
f"Od: {closed_at_od}\n"
|
|
f"Do: {closed_at_do}"
|
|
) |