ポータブルな Mekiku 互換ビューワ
Revision | 8dc1f5210a731e03d9ab813ba581b3d3909dc749 (tree) |
---|---|
Zeit | 2019-08-29 02:27:42 |
Autor | TAKAHASHI Tamotsu <ttakah+osdn@gmai...> |
Commiter | TAKAHASHI Tamotsu |
delete trailing space after textedit is done
@@ -1,29 +1,31 @@ | ||
1 | 1 | __all__ = ("IMETextInput", ) |
2 | 2 | |
3 | 3 | from kivy.uix.textinput import TextInput |
4 | -from kivy.properties import StringProperty | |
5 | 4 | from kivy.base import EventLoop |
6 | 5 | from kivy.core.text.markup import MarkupLabel |
7 | 6 | from kivy.core.text import Label |
8 | 7 | |
9 | 8 | |
10 | 9 | class IMETextInput(TextInput): |
11 | - editing = StringProperty() | |
12 | - | |
13 | 10 | def __init__(self, **kwargs): |
14 | 11 | super(IMETextInput, self).__init__(**kwargs) |
12 | + | |
15 | 13 | EventLoop.window.bind(on_textedit=self._on_textedit) |
14 | + self.editing = False | |
15 | + self._spacehack = False | |
16 | 16 | |
17 | 17 | def _on_textedit(self, window, text): |
18 | - self.editing = text | |
19 | - if len(text): | |
20 | - self.suggestion_text = "[" + text + "]" | |
21 | - else: | |
22 | - self.suggestion_text = "" | |
18 | + self.editing = True if len(text) else False | |
19 | + self.suggestion_text = text | |
20 | + | |
21 | + # hack: see below for the reason | |
22 | + if not self.editing and self._spacehack: | |
23 | + self.text = self.text.rsplit(" ", 1)[0] | |
23 | 24 | |
24 | 25 | def keyboard_on_key_down(self, window, keycode, text, modifiers): |
25 | - if len(self.editing): | |
26 | + if self.editing: | |
26 | 27 | return True # IME consumes it all |
28 | + | |
27 | 29 | super(IMETextInput, self).keyboard_on_key_down( |
28 | 30 | window, keycode, text, modifiers) |
29 | 31 |
@@ -34,8 +36,9 @@ class IMETextInput(TextInput): | ||
34 | 36 | # even when _lines_labels is given |
35 | 37 | if not len(self._lines) or ( |
36 | 38 | len(self._lines) == 1 and not self._lines[0]): |
37 | - self._set_text(" ") # hack: when should I delete it? | |
39 | + self._set_text(" ") | |
38 | 40 | self.cursor = [0, 0] |
41 | + self._spacehack = True | |
39 | 42 | |
40 | 43 | cursor_row = self.cursor_row |
41 | 44 | if cursor_row >= len(self._lines) or self.canvas is None: |
@@ -52,7 +55,7 @@ class IMETextInput(TextInput): | ||
52 | 55 | lbl = None |
53 | 56 | if value: |
54 | 57 | lbl = MarkupLabel( |
55 | - text=pre + "[b]{}[/b]".format(value) + suf, **kw) | |
58 | + text=pre + "[u]{}[/u]".format(value) + suf, **kw) | |
56 | 59 | else: |
57 | 60 | lbl = Label(text=txt, **kw) |
58 | 61 |