-
Notifications
You must be signed in to change notification settings - Fork 11
/
alert.py
35 lines (30 loc) · 1.01 KB
/
alert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.core.window import Window
class Alert(Popup):
def __init__(self, title, text, condition=None):
super(Alert, self).__init__()
self.condition = condition
content = BoxLayout(orientation='vertical')
content.add_widget(
Label(text=text, size_hint=(1, .5))
)
ok_button = Button(text='Ok', size_hint=(1, .5))
content.add_widget(ok_button)
self.popup = Popup(
title=title,
content=content,
size_hint=(None, None),
size=(Window.width / 3, Window.height / 3),
auto_dismiss=True,
)
ok_button.bind(on_press=self.close)
self.popup.open()
def close(self, instance):
if self.condition is None:
self.popup.dismiss()
else:
if self.condition():
self.popup.dismiss()