blob: d7cc69f39750bbd6b2da4cc37aad37f6918fe744 (
plain)
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
|
"""Dialogue with a single-line text input field.
Part of the tagit module.
A copy of the license is provided with the project.
Author: Matthias Baumgartner, 2022
"""
# standard imports
import os
# kivy imports
from kivy.lang import Builder
import kivy.properties as kp
# inner-module imports
from .dialogue import Dialogue
# exports
__all__ = ('SimpleInput', )
## code ##
# load kv
Builder.load_file(os.path.join(os.path.dirname(__file__), 'simple_input.kv'))
# classes
class SimpleInput(Dialogue):
"""Dialogue with a single-line text input field.
Pass the default text as **text**.
>>> SimpleInput(text='Hello world').open()
In case of touch events, they need to be inhibited to change the focus.
>>> FocusBehavior.ignored_touch.append(touch)
"""
# Defocus problem:
# Buttons defocus when on_press, but on_release is ok.
# Touch events must be blocked via FocusBehavior
text = kp.StringProperty('')
cancel_on_defocus = kp.BooleanProperty(True)
suggestions = kp.ListProperty()
suggestion_sep = kp.StringProperty(',')
suggestion_suffix = kp.StringProperty(' ')
def on_text_focus(self, instance, focus):
if not focus and self.cancel_on_defocus:
self.dismiss()
## EOF ##
|