-
Notifications
You must be signed in to change notification settings - Fork 18
/
yesnopopup.py
63 lines (42 loc) · 1.62 KB
/
yesnopopup.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Copyright (c) 2013 muodov (muodov[monkey]gmail.com)
"""
from kivy.uix.popup import Popup
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.properties import StringProperty
class AskPopup(Popup):
def __init__(self, content_class, title, text, callback, **kwargs):
# self.size_hint = (0.4, 0.4)
content = content_class(text)
content.bind(on_answer=lambda inst, ans: (callback(inst, ans), self.dismiss()))
# content.bind(on_answer=self.dismiss)
kwargs['content'] = content
kwargs['auto_dismiss'] = False
kwargs['title'] = title
super(AskPopup, self).__init__(**kwargs)
class AskContent(BoxLayout):
text = StringProperty('')
def __init__(self, text, **kwargs):
self.text = text
self.register_event_type('on_answer')
super(AskContent, self).__init__(**kwargs)
def on_answer(self, *args):
pass
class YesNoContent(AskContent):
pass
class YesNoPopup(AskPopup):
def __init__(self, title, text, callback, **kwargs):
super(YesNoPopup, self).__init__(YesNoContent, title, text, callback, **kwargs)
class YesNoQuitContent(AskContent):
pass
class YesNoQuitPopup(AskPopup):
def __init__(self, title, text, callback, **kwargs):
super(YesNoQuitPopup, self).__init__(YesNoQuitContent, title, text, callback, **kwargs)
class StringContent(AskContent):
pass
class StringPopup(AskPopup):
def __init__(self, title, text, callback, **kwargs):
super(StringPopup, self).__init__(StringContent, title, text, callback, **kwargs)
class LogMessage(Label):
pass