teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

2018/10/06 07:14

投稿

shinya-ta
shinya-ta

スコア31

title CHANGED
File without changes
body CHANGED
@@ -161,4 +161,22 @@
161
161
  root.present("sheet")
162
162
 
163
163
  if __name__ == "__main__":
164
- run()
164
+ run()
165
+
166
+ このようなエラーメッセージがでました。
167
+ しかも、2つ同時にです。
168
+
169
+ Warning: Could not bind action: name 'buttontap_up' is not defined
170
+ Warning: Could not bind action: name 'buttontap_left' is not defined
171
+ Warning: Could not bind action: name 'buttontap_right' is not defined
172
+ Warning: Could not bind action: name 'buttontap_return' is not defined
173
+ Warning: Could not bind action: name 'buttontap_down' is not defined
174
+ Warning: Could not bind action: name 'bottontap_backspace' is not defined
175
+ Warning: Could not bind action: unexpected EOF while parsing (<string>, line 1)
176
+ Warning: Could not bind action: name 'buttontap_up' is not defined
177
+ Warning: Could not bind action: name 'buttontap_left' is not defined
178
+ Warning: Could not bind action: name 'buttontap_right' is not defined
179
+ Warning: Could not bind action: name 'buttontap_return' is not defined
180
+ Warning: Could not bind action: name 'buttontap_down' is not defined
181
+ Warning: Could not bind action: name 'bottontap_backspace' is not defined
182
+ Warning: Could not bind action: unexpected EOF while parsing (<string>, line 1)

2

2018/10/06 07:14

投稿

shinya-ta
shinya-ta

スコア31

title CHANGED
File without changes
body CHANGED
@@ -14,4 +14,151 @@
14
14
 
15
15
  どなたか、教えて頂けないでしょうか?
16
16
 
17
- 宜しくお願いします。
17
+ 宜しくお願いします。
18
+
19
+
20
+ 以前、こういうのを探しだして試したところ、buttonが定義されていないとのないようのエラーが出ました。
21
+
22
+ 出先からの投稿ですので、詳細なエラーメッセージは後で載せますが、どこが悪いのかが、さっぱりわかりません。
23
+
24
+ # -*- coding: utf-8 -*-
25
+
26
+ import ui
27
+
28
+ DEFAULT_TEXT = "w\n\nw w WWWW w w\n\nw"
29
+ DEFAULT_LEN = len(DEFAULT_TEXT)
30
+ DEFAULT_MID = DEFAULT_LEN/2
31
+ DEFAULT_RNG = (DEFAULT_MID, DEFAULT_MID)
32
+
33
+ class KBControlDelegate(object):
34
+ def __init__(self):
35
+ self.bksp = False
36
+
37
+ def keypress(self, key):
38
+ out.text += key + " "
39
+
40
+ def textview_should_change(self, textview, range, replacement):
41
+ if replacement == "":
42
+ # some deletion
43
+ if range == (DEFAULT_MID-1, DEFAULT_MID):
44
+ self.keypress("bksp")
45
+ elif len(replacement) > 1:
46
+ # paste
47
+ self.keypress("cmd-v")
48
+ else:
49
+ self.keypress(replacement)
50
+ return False
51
+
52
+ def textview_did_change_selection(self, textview):
53
+ nop = False
54
+ if len(ctrl.text) == DEFAULT_LEN:
55
+ # no change to text, only selection
56
+ if ctrl.selected_range == DEFAULT_RNG:
57
+ # no important changes, cursor was likely reset by script
58
+ nop = True
59
+ elif ctrl.selected_range[0] == ctrl.selected_range[1]:
60
+ # shift was not used
61
+ if ctrl.selected_range == (0, 0):
62
+ # cursor is at the top
63
+ self.keypress("cmd-up")
64
+ elif ctrl.selected_range in ((1, 1), (2, 2)):
65
+ # cursor is near the top
66
+ self.keypress("up")
67
+ elif ctrl.selected_range == (3, 3):
68
+ # cursor is at the left
69
+ self.keypress("cmd-left")
70
+ elif ctrl.selected_range == (DEFAULT_LEN/2-2, DEFAULT_LEN/2-2):
71
+ # cursor is exactly two chars to the left
72
+ self.keypress("alt-left")
73
+ elif ctrl.selected_range == (DEFAULT_LEN/2-1, DEFAULT_LEN/2-1):
74
+ # cursor is exactly one char to the left
75
+ self.keypress("left")
76
+ elif ctrl.selected_range == (DEFAULT_LEN/2+1, DEFAULT_LEN/2+1):
77
+ # cursor is exactly one char to the right
78
+ self.keypress("right")
79
+ elif ctrl.selected_range == (DEFAULT_LEN/2+2, DEFAULT_LEN/2+2):
80
+ # cursor is exactly two chars to the right
81
+ self.keypress("alt-right")
82
+ elif ctrl.selected_range == (DEFAULT_LEN-3, DEFAULT_LEN-3):
83
+ # cursor is at the right
84
+ self.keypress("cmd-right")
85
+ elif ctrl.selected_range in ((DEFAULT_LEN-2, DEFAULT_LEN-2), (DEFAULT_LEN-1, DEFAULT_LEN-1)):
86
+ # cursor is near the bottom
87
+ self.keypress("down")
88
+ elif ctrl.selected_range == (DEFAULT_LEN, DEFAULT_LEN):
89
+ # cursor is at the bottom
90
+ self.keypress("cmd-down")
91
+ else:
92
+ # some unhandled movement
93
+ nop = True
94
+ self.keypress(str(ctrl.selected_range))
95
+ else:
96
+ # shift was used
97
+ if ctrl.selected_range == (0, DEFAULT_MID):
98
+ # cursor is at the top
99
+ self.keypress("shift-cmd-up")
100
+ elif ctrl.selected_range in ((1, DEFAULT_MID), (2, DEFAULT_MID)):
101
+ # cursor is near the top
102
+ self.keypress("shift-up")
103
+ elif ctrl.selected_range == (3, DEFAULT_MID):
104
+ # cursor is at the left
105
+ self.keypress("shift-cmd-left")
106
+ elif ctrl.selected_range == (DEFAULT_LEN/2-2, DEFAULT_MID):
107
+ # cursor is exactly two chars to the left
108
+ self.keypress("shift-alt-left")
109
+ elif ctrl.selected_range == (DEFAULT_LEN/2-1, DEFAULT_MID):
110
+ # cursor is exactly one char to the left
111
+ self.keypress("shift-left")
112
+ elif ctrl.selected_range == (DEFAULT_MID, DEFAULT_LEN/2+1):
113
+ # cursor is exactly one char to the right
114
+ self.keypress("shift-right")
115
+ elif ctrl.selected_range == (DEFAULT_MID, DEFAULT_LEN/2+2):
116
+ # cursor is exactly two chars to the right
117
+ self.keypress("shift-alt-right")
118
+ elif ctrl.selected_range == (DEFAULT_MID, DEFAULT_LEN-3):
119
+ # cursor is at the right
120
+ self.keypress("shift-cmd-right")
121
+ elif ctrl.selected_range in ((DEFAULT_MID, DEFAULT_LEN-2), (DEFAULT_MID, DEFAULT_LEN-1)):
122
+ # cursor is near the bottom
123
+ self.keypress("shift-down")
124
+ elif ctrl.selected_range == (DEFAULT_MID, DEFAULT_LEN):
125
+ # cursor is at the bottom
126
+ self.keypress("shift-cmd-down")
127
+ else:
128
+ # some unhandled movement
129
+ nop = True
130
+ self.keypress(str(ctrl.selected_range))
131
+
132
+ elif len(ctrl.text) == DEFAULT_LEN - 1:
133
+ # exactly one character was removed
134
+ # due to the nature of bksp, this is only triggered for delete (fn-bksp)
135
+ self.keypress("del")
136
+ elif len(ctrl.text) < DEFAULT_LEN:
137
+ # more than one character was deleted, i. e. alt-bksp
138
+ self.keypress("alt-bksp")
139
+ elif len(ctrl.text) > DEFAULT_LEN:
140
+ # one or more characters were added and not handled by should_change
141
+ # i. e. sticky key/accentuation character, need manual reset of control field
142
+ # accented chars can still be typed
143
+ pass
144
+ else:
145
+ # some unknown situation
146
+ out.text += "\nSome unhandled situation: " + ctrl.selected_range + "\n" + ctrl.text + "\n\n"
147
+
148
+ if not nop:
149
+ ctrl.text = DEFAULT_TEXT
150
+ ctrl.selected_range = DEFAULT_RNG
151
+
152
+ def run():
153
+ global root
154
+ global ctrl
155
+ global out
156
+ root = ui.load_view()
157
+ ctrl = root["ctrl"]
158
+ out = root["out"]
159
+ ctrl.delegate = KBControlDelegate()
160
+
161
+ root.present("sheet")
162
+
163
+ if __name__ == "__main__":
164
+ run()

1

2018/10/04 09:54

投稿

shinya-ta
shinya-ta

スコア31

title CHANGED
File without changes
body CHANGED
File without changes