-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmulti_input_box.py
82 lines (70 loc) · 2.36 KB
/
multi_input_box.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from kivy.properties import StringProperty, ObjectProperty, ListProperty
from kivy.lang import Builder
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.core.window import Window
Builder.load_string('''
<MultiInputBox>:
id: optionPopup
size_hint : (None,None)
width : min(0.95 * self.window.width, dp(500))
height: dp(content.height) + dp(80)
title: "Option Title"
pos_hint: {'top': 1} if app.is_touch else {'center_y': 0.5}
auto_dismiss: False
BoxLayout:
id: content
size_hint : (1,None)
orientation: 'vertical'
spacing: '5dp'
height: dp(content.minimum_height)
GridLayout:
id: contentButtons
cols: 2
padding: '12dp'
size_hint : (1,None)
height : dp(self.minimum_height)
spacing: '0dp'
BoxLayout:
size_hint_y: None
height: sp(48)
Button:
text: root.cancel_text
on_press: root._dismiss()
Button:
text: root.ok_text
on_press: root._ok()
''')
class MultiInputBox(Popup):
ok_text = StringProperty('OK')
cancel_text = StringProperty('Cancel')
def __init__(self, **kwargs):
self.window = Window
super(MultiInputBox, self).__init__(**kwargs)
self.content = self.ids["content"]
self.contentButtons = self.ids["contentButtons"]
self.wl = []
def _dismiss(self):
self.dismiss()
def open(self):
super(MultiInputBox, self).open()
def _ok(self):
if self.optionCallBack is not None:
opts = {}
for x in self.wl:
opts[x[0]] = x[1].text
self.optionCallBack(opts)
self.dismiss()
def on_open(self):
if self.wl:
self.wl[0][1].focus = True
def setOptions(self, options, callBack):
self.optionCallBack = callBack
self.contentButtons.clear_widgets()
self.wl = []
for name in options:
self.contentButtons.add_widget(Label(text=name, size_hint_y=None, height='30dp', halign='right'))
tw = TextInput(multiline=False, write_tab=False, use_bubble=False, use_handles=False)
self.contentButtons.add_widget(tw)
self.wl.append((name, tw))