質問編集履歴

3

2018/10/06 07:14

投稿

shinya-ta
shinya-ta

スコア31

test CHANGED
File without changes
test CHANGED
@@ -325,3 +325,39 @@
325
325
  if __name__ == "__main__":
326
326
 
327
327
  run()
328
+
329
+
330
+
331
+ このようなエラーメッセージがでました。
332
+
333
+ しかも、2つ同時にです。
334
+
335
+
336
+
337
+ Warning: Could not bind action: name 'buttontap_up' is not defined
338
+
339
+ Warning: Could not bind action: name 'buttontap_left' is not defined
340
+
341
+ Warning: Could not bind action: name 'buttontap_right' is not defined
342
+
343
+ Warning: Could not bind action: name 'buttontap_return' is not defined
344
+
345
+ Warning: Could not bind action: name 'buttontap_down' is not defined
346
+
347
+ Warning: Could not bind action: name 'bottontap_backspace' is not defined
348
+
349
+ Warning: Could not bind action: unexpected EOF while parsing (<string>, line 1)
350
+
351
+ Warning: Could not bind action: name 'buttontap_up' is not defined
352
+
353
+ Warning: Could not bind action: name 'buttontap_left' is not defined
354
+
355
+ Warning: Could not bind action: name 'buttontap_right' is not defined
356
+
357
+ Warning: Could not bind action: name 'buttontap_return' is not defined
358
+
359
+ Warning: Could not bind action: name 'buttontap_down' is not defined
360
+
361
+ Warning: Could not bind action: name 'bottontap_backspace' is not defined
362
+
363
+ Warning: Could not bind action: unexpected EOF while parsing (<string>, line 1)

2

2018/10/06 07:14

投稿

shinya-ta
shinya-ta

スコア31

test CHANGED
File without changes
test CHANGED
@@ -31,3 +31,297 @@
31
31
 
32
32
 
33
33
  宜しくお願いします。
34
+
35
+
36
+
37
+
38
+
39
+ 以前、こういうのを探しだして試したところ、buttonが定義されていないとのないようのエラーが出ました。
40
+
41
+
42
+
43
+ 出先からの投稿ですので、詳細なエラーメッセージは後で載せますが、どこが悪いのかが、さっぱりわかりません。
44
+
45
+
46
+
47
+ # -*- coding: utf-8 -*-
48
+
49
+
50
+
51
+ import ui
52
+
53
+
54
+
55
+ DEFAULT_TEXT = "w\n\nw w WWWW w w\n\nw"
56
+
57
+ DEFAULT_LEN = len(DEFAULT_TEXT)
58
+
59
+ DEFAULT_MID = DEFAULT_LEN/2
60
+
61
+ DEFAULT_RNG = (DEFAULT_MID, DEFAULT_MID)
62
+
63
+
64
+
65
+ class KBControlDelegate(object):
66
+
67
+ def __init__(self):
68
+
69
+ self.bksp = False
70
+
71
+
72
+
73
+ def keypress(self, key):
74
+
75
+ out.text += key + " "
76
+
77
+
78
+
79
+ def textview_should_change(self, textview, range, replacement):
80
+
81
+ if replacement == "":
82
+
83
+ # some deletion
84
+
85
+ if range == (DEFAULT_MID-1, DEFAULT_MID):
86
+
87
+ self.keypress("bksp")
88
+
89
+ elif len(replacement) > 1:
90
+
91
+ # paste
92
+
93
+ self.keypress("cmd-v")
94
+
95
+ else:
96
+
97
+ self.keypress(replacement)
98
+
99
+ return False
100
+
101
+
102
+
103
+ def textview_did_change_selection(self, textview):
104
+
105
+ nop = False
106
+
107
+ if len(ctrl.text) == DEFAULT_LEN:
108
+
109
+ # no change to text, only selection
110
+
111
+ if ctrl.selected_range == DEFAULT_RNG:
112
+
113
+ # no important changes, cursor was likely reset by script
114
+
115
+ nop = True
116
+
117
+ elif ctrl.selected_range[0] == ctrl.selected_range[1]:
118
+
119
+ # shift was not used
120
+
121
+ if ctrl.selected_range == (0, 0):
122
+
123
+ # cursor is at the top
124
+
125
+ self.keypress("cmd-up")
126
+
127
+ elif ctrl.selected_range in ((1, 1), (2, 2)):
128
+
129
+ # cursor is near the top
130
+
131
+ self.keypress("up")
132
+
133
+ elif ctrl.selected_range == (3, 3):
134
+
135
+ # cursor is at the left
136
+
137
+ self.keypress("cmd-left")
138
+
139
+ elif ctrl.selected_range == (DEFAULT_LEN/2-2, DEFAULT_LEN/2-2):
140
+
141
+ # cursor is exactly two chars to the left
142
+
143
+ self.keypress("alt-left")
144
+
145
+ elif ctrl.selected_range == (DEFAULT_LEN/2-1, DEFAULT_LEN/2-1):
146
+
147
+ # cursor is exactly one char to the left
148
+
149
+ self.keypress("left")
150
+
151
+ elif ctrl.selected_range == (DEFAULT_LEN/2+1, DEFAULT_LEN/2+1):
152
+
153
+ # cursor is exactly one char to the right
154
+
155
+ self.keypress("right")
156
+
157
+ elif ctrl.selected_range == (DEFAULT_LEN/2+2, DEFAULT_LEN/2+2):
158
+
159
+ # cursor is exactly two chars to the right
160
+
161
+ self.keypress("alt-right")
162
+
163
+ elif ctrl.selected_range == (DEFAULT_LEN-3, DEFAULT_LEN-3):
164
+
165
+ # cursor is at the right
166
+
167
+ self.keypress("cmd-right")
168
+
169
+ elif ctrl.selected_range in ((DEFAULT_LEN-2, DEFAULT_LEN-2), (DEFAULT_LEN-1, DEFAULT_LEN-1)):
170
+
171
+ # cursor is near the bottom
172
+
173
+ self.keypress("down")
174
+
175
+ elif ctrl.selected_range == (DEFAULT_LEN, DEFAULT_LEN):
176
+
177
+ # cursor is at the bottom
178
+
179
+ self.keypress("cmd-down")
180
+
181
+ else:
182
+
183
+ # some unhandled movement
184
+
185
+ nop = True
186
+
187
+ self.keypress(str(ctrl.selected_range))
188
+
189
+ else:
190
+
191
+ # shift was used
192
+
193
+ if ctrl.selected_range == (0, DEFAULT_MID):
194
+
195
+ # cursor is at the top
196
+
197
+ self.keypress("shift-cmd-up")
198
+
199
+ elif ctrl.selected_range in ((1, DEFAULT_MID), (2, DEFAULT_MID)):
200
+
201
+ # cursor is near the top
202
+
203
+ self.keypress("shift-up")
204
+
205
+ elif ctrl.selected_range == (3, DEFAULT_MID):
206
+
207
+ # cursor is at the left
208
+
209
+ self.keypress("shift-cmd-left")
210
+
211
+ elif ctrl.selected_range == (DEFAULT_LEN/2-2, DEFAULT_MID):
212
+
213
+ # cursor is exactly two chars to the left
214
+
215
+ self.keypress("shift-alt-left")
216
+
217
+ elif ctrl.selected_range == (DEFAULT_LEN/2-1, DEFAULT_MID):
218
+
219
+ # cursor is exactly one char to the left
220
+
221
+ self.keypress("shift-left")
222
+
223
+ elif ctrl.selected_range == (DEFAULT_MID, DEFAULT_LEN/2+1):
224
+
225
+ # cursor is exactly one char to the right
226
+
227
+ self.keypress("shift-right")
228
+
229
+ elif ctrl.selected_range == (DEFAULT_MID, DEFAULT_LEN/2+2):
230
+
231
+ # cursor is exactly two chars to the right
232
+
233
+ self.keypress("shift-alt-right")
234
+
235
+ elif ctrl.selected_range == (DEFAULT_MID, DEFAULT_LEN-3):
236
+
237
+ # cursor is at the right
238
+
239
+ self.keypress("shift-cmd-right")
240
+
241
+ elif ctrl.selected_range in ((DEFAULT_MID, DEFAULT_LEN-2), (DEFAULT_MID, DEFAULT_LEN-1)):
242
+
243
+ # cursor is near the bottom
244
+
245
+ self.keypress("shift-down")
246
+
247
+ elif ctrl.selected_range == (DEFAULT_MID, DEFAULT_LEN):
248
+
249
+ # cursor is at the bottom
250
+
251
+ self.keypress("shift-cmd-down")
252
+
253
+ else:
254
+
255
+ # some unhandled movement
256
+
257
+ nop = True
258
+
259
+ self.keypress(str(ctrl.selected_range))
260
+
261
+
262
+
263
+ elif len(ctrl.text) == DEFAULT_LEN - 1:
264
+
265
+ # exactly one character was removed
266
+
267
+ # due to the nature of bksp, this is only triggered for delete (fn-bksp)
268
+
269
+ self.keypress("del")
270
+
271
+ elif len(ctrl.text) < DEFAULT_LEN:
272
+
273
+ # more than one character was deleted, i. e. alt-bksp
274
+
275
+ self.keypress("alt-bksp")
276
+
277
+ elif len(ctrl.text) > DEFAULT_LEN:
278
+
279
+ # one or more characters were added and not handled by should_change
280
+
281
+ # i. e. sticky key/accentuation character, need manual reset of control field
282
+
283
+ # accented chars can still be typed
284
+
285
+ pass
286
+
287
+ else:
288
+
289
+ # some unknown situation
290
+
291
+ out.text += "\nSome unhandled situation: " + ctrl.selected_range + "\n" + ctrl.text + "\n\n"
292
+
293
+
294
+
295
+ if not nop:
296
+
297
+ ctrl.text = DEFAULT_TEXT
298
+
299
+ ctrl.selected_range = DEFAULT_RNG
300
+
301
+
302
+
303
+ def run():
304
+
305
+ global root
306
+
307
+ global ctrl
308
+
309
+ global out
310
+
311
+ root = ui.load_view()
312
+
313
+ ctrl = root["ctrl"]
314
+
315
+ out = root["out"]
316
+
317
+ ctrl.delegate = KBControlDelegate()
318
+
319
+
320
+
321
+ root.present("sheet")
322
+
323
+
324
+
325
+ if __name__ == "__main__":
326
+
327
+ run()

1

2018/10/04 09:54

投稿

shinya-ta
shinya-ta

スコア31

test CHANGED
File without changes
test CHANGED
File without changes