質問編集履歴
4
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -283,3 +283,13 @@
|
|
283
283
|
質問の仕方も含め、間違っていたらいろいろ教えてください。
|
284
284
|
|
285
285
|
よろしくお願いいたします。
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
kvファイルの中の削除buttonのon_pressにdetach_recycleview()を書き込んで、
|
290
|
+
|
291
|
+
実行したところ
|
292
|
+
|
293
|
+
NameError: name 'detach_recycleview' is not defined
|
294
|
+
|
295
|
+
がでました。
|
3
kvコードの削除buttonに、on_pressの行を加えた
test
CHANGED
File without changes
|
test
CHANGED
@@ -114,6 +114,8 @@
|
|
114
114
|
|
115
115
|
size_hint_x: 2
|
116
116
|
|
117
|
+
on_press: detach_recycleview() #どのように当該の行と関連づけるか?
|
118
|
+
|
117
119
|
|
118
120
|
|
119
121
|
<RV>:
|
2
とりあえず、知りたいことを書いてみました
test
CHANGED
File without changes
|
test
CHANGED
@@ -253,3 +253,31 @@
|
|
253
253
|
|
254
254
|
|
255
255
|
よろしくお願いいたします。
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
その後調べましたが、削除Buttonのon_pressにdetach_recycleview()を付けること
|
260
|
+
|
261
|
+
ぐらいしか思いつきませんでした。
|
262
|
+
|
263
|
+
今知りたいことは、
|
264
|
+
|
265
|
+
1. detach_recycleview であっているかどうか?
|
266
|
+
|
267
|
+
2. あっている場合、その削除Buttonと削除したい行をどのように関連づけるか?
|
268
|
+
|
269
|
+
3. あと、kivyファイルの方に書き込んだ方がよいか、classの中にdefとして、
|
270
|
+
|
271
|
+
書き込んだ方がよいかです。
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
知識がなさ過ぎて、質問の仕方もよくわからなくてすみません。
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
なんとかしてこの問題を解決したいので、
|
280
|
+
|
281
|
+
質問の仕方も含め、間違っていたらいろいろ教えてください。
|
282
|
+
|
283
|
+
よろしくお願いいたします。
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -250,244 +250,6 @@
|
|
250
250
|
|
251
251
|
```
|
252
252
|
|
253
|
-
|
253
|
+
|
254
|
-
|
255
|
-
from kivy.lang import Builder
|
256
|
-
|
257
|
-
from kivy.uix.recycleview import RecycleView
|
258
|
-
|
259
|
-
from kivy.uix.recycleview.views import RecycleDataViewBehavior
|
260
|
-
|
261
|
-
from kivy.uix.label import Label
|
262
|
-
|
263
|
-
from kivy.uix.button import Button
|
264
|
-
|
265
|
-
from kivy.uix.gridlayout import GridLayout
|
266
|
-
|
267
|
-
from kivy.uix.boxlayout import BoxLayout
|
268
|
-
|
269
|
-
from kivy.properties import BooleanProperty
|
270
|
-
|
271
|
-
from kivy.uix.recycleboxlayout import RecycleBoxLayout
|
272
|
-
|
273
|
-
from kivy.uix.behaviors import FocusBehavior
|
274
|
-
|
275
|
-
from kivy.uix.recycleview.layout import LayoutSelectionBehavior
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
import japanize_kivy
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
Builder.load_string('''
|
284
|
-
|
285
|
-
<SelectableLabel>:
|
286
|
-
|
287
|
-
canvas.before:
|
288
|
-
|
289
|
-
Color:
|
290
|
-
|
291
|
-
rgba: (.8, .8, .8, 1) if self.selected else (1, .8, .8, 1)
|
292
|
-
|
293
|
-
Rectangle:
|
294
|
-
|
295
|
-
pos: self.pos
|
296
|
-
|
297
|
-
size: self.size
|
298
|
-
|
299
|
-
label1_text: 'label 1 text'
|
300
|
-
|
301
|
-
label2_text: 'label 2 text'
|
302
|
-
|
303
|
-
label3_text: 'label 3 text'
|
304
|
-
|
305
|
-
pos: self.pos
|
306
|
-
|
307
|
-
size: self.size
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
#Label:
|
312
|
-
|
313
|
-
# id: id_label1
|
314
|
-
|
315
|
-
# text: root.label1_text
|
316
|
-
|
317
|
-
# color: [0,0,0,1]
|
318
|
-
|
319
|
-
# font_size: 20
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
Label:
|
324
|
-
|
325
|
-
id: id_label2
|
326
|
-
|
327
|
-
text: root.label2_text
|
328
|
-
|
329
|
-
color: [0,0,0,1]
|
330
|
-
|
331
|
-
font_size: 20
|
332
|
-
|
333
|
-
size_hint_x: 4
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
Label:
|
338
|
-
|
339
|
-
id: id_label3
|
340
|
-
|
341
|
-
text: root.label3_text
|
342
|
-
|
343
|
-
color: [0,0,0,1]
|
344
|
-
|
345
|
-
font_size: 20
|
346
|
-
|
347
|
-
size_hint_x: 4
|
348
|
-
|
349
|
-
Button:
|
350
|
-
|
351
|
-
text: '削除'
|
352
|
-
|
353
|
-
font_size: 20
|
354
|
-
|
355
|
-
size_hint_x: 2
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
<RV>:
|
360
|
-
|
361
|
-
viewclass: 'SelectableLabel'
|
362
|
-
|
363
|
-
SelectableRecycleBoxLayout:
|
364
|
-
|
365
|
-
default_size: None, dp(45)
|
366
|
-
|
367
|
-
default_size_hint: 1, None
|
368
|
-
|
369
|
-
size_hint_y: None
|
370
|
-
|
371
|
-
height: self.minimum_height
|
372
|
-
|
373
|
-
orientation: 'vertical'
|
374
|
-
|
375
|
-
multiselect: True
|
376
|
-
|
377
|
-
touch_multiselect: True
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
''')
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
items_1 = ['カツ丼','天丼','親子丼','玉子丼','オムライス','カツカレー']
|
386
|
-
|
387
|
-
items_2 = ['850','850','750','670','800','850']
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
class SelectableRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior,
|
392
|
-
|
393
|
-
RecycleBoxLayout):
|
394
|
-
|
395
|
-
pass
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
class SelectableLabel(RecycleDataViewBehavior, GridLayout):
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
index = None
|
404
|
-
|
405
|
-
selected = BooleanProperty(False)
|
406
|
-
|
407
|
-
selectable = BooleanProperty(True)
|
408
|
-
|
409
|
-
cols = 3
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
def refresh_view_attrs(self, rv, index, data):
|
414
|
-
|
415
|
-
'''Catch and handle the view changes '''
|
416
|
-
|
417
|
-
self.index = index
|
418
|
-
|
419
|
-
self.label1_text = str(index)
|
420
|
-
|
421
|
-
self.label2_text = data['label2']['text']
|
422
|
-
|
423
|
-
self.label3_text = data['label3']['text']
|
424
|
-
|
425
|
-
return super(SelectableLabel, self).refresh_view_attrs(
|
426
|
-
|
427
|
-
rv, index, data)
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
def on_touch_down(self, touch):
|
432
|
-
|
433
|
-
''' Add selection on touch down '''
|
434
|
-
|
435
|
-
if super(SelectableLabel, self).on_touch_down(touch):
|
436
|
-
|
437
|
-
return True
|
438
|
-
|
439
|
-
if self.collide_point(*touch.pos) and self.selectable:
|
440
|
-
|
441
|
-
return self.parent.select_with_touch(self.index, touch)
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
def apply_selection(self, rv, index, is_selected):
|
446
|
-
|
447
|
-
''' Respond to the selection of items in the view. '''
|
448
|
-
|
449
|
-
self.selected = is_selected
|
450
|
-
|
451
|
-
if is_selected:
|
452
|
-
|
453
|
-
print('selection changed to {}'.format(rv.data[index]))
|
454
|
-
|
455
|
-
else:
|
456
|
-
|
457
|
-
print('selection removed for {}'.format(rv.data[index]))
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
class RV(RecycleView):
|
462
|
-
|
463
|
-
def __init__(self, **kwargs):
|
464
|
-
|
465
|
-
super(RV, self).__init__(**kwargs)
|
466
|
-
|
467
|
-
paired_iter = zip(items_1, items_2)
|
468
|
-
|
469
|
-
self.data = []
|
470
|
-
|
471
|
-
for i1, i2 in paired_iter:
|
472
|
-
|
473
|
-
d = {'label2': {'text': i1}, 'label3': {'text': i2}}
|
474
|
-
|
475
|
-
self.data.append(d)
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
class Menu01App(App):
|
480
|
-
|
481
|
-
def build(self):
|
482
|
-
|
483
|
-
return RV()
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
if __name__ == '__main__':
|
488
|
-
|
489
|
-
Menu01App().run()
|
490
|
-
|
491
|
-
```
|
492
254
|
|
493
255
|
よろしくお願いいたします。
|