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

質問編集履歴

4

追記

2020/02/09 15:36

投稿

kintarock777
kintarock777

スコア34

title CHANGED
File without changes
body CHANGED
@@ -140,4 +140,9 @@
140
140
 
141
141
  なんとかしてこの問題を解決したいので、
142
142
  質問の仕方も含め、間違っていたらいろいろ教えてください。
143
- よろしくお願いいたします。
143
+ よろしくお願いいたします。
144
+
145
+ kvファイルの中の削除buttonのon_pressにdetach_recycleview()を書き込んで、
146
+ 実行したところ
147
+ NameError: name 'detach_recycleview' is not defined
148
+ がでました。

3

kvコードの削除buttonに、on_pressの行を加えた

2020/02/09 15:36

投稿

kintarock777
kintarock777

スコア34

title CHANGED
File without changes
body CHANGED
@@ -56,6 +56,7 @@
56
56
  text: '削除'
57
57
  font_size: 20
58
58
  size_hint_x: 2
59
+ on_press: detach_recycleview() #どのように当該の行と関連づけるか?
59
60
 
60
61
  <RV>:
61
62
  viewclass: 'SelectableLabel'

2

とりあえず、知りたいことを書いてみました

2020/02/09 15:31

投稿

kintarock777
kintarock777

スコア34

title CHANGED
File without changes
body CHANGED
@@ -125,4 +125,18 @@
125
125
  Menu01App().run()
126
126
  ```
127
127
 
128
+ よろしくお願いいたします。
129
+
130
+ その後調べましたが、削除Buttonのon_pressにdetach_recycleview()を付けること
131
+ ぐらいしか思いつきませんでした。
132
+ 今知りたいことは、
133
+ 1. detach_recycleview であっているかどうか?
134
+ 2. あっている場合、その削除Buttonと削除したい行をどのように関連づけるか?
135
+ 3. あと、kivyファイルの方に書き込んだ方がよいか、classの中にdefとして、
136
+  書き込んだ方がよいかです。
137
+
138
+ 知識がなさ過ぎて、質問の仕方もよくわからなくてすみません。
139
+
140
+ なんとかしてこの問題を解決したいので、
141
+ 質問の仕方も含め、間違っていたらいろいろ教えてください。
128
142
  よろしくお願いいたします。

1

誤字

2020/02/09 15:23

投稿

kintarock777
kintarock777

スコア34

title CHANGED
File without changes
body CHANGED
@@ -124,124 +124,5 @@
124
124
  if __name__ == '__main__':
125
125
  Menu01App().run()
126
126
  ```
127
- from kivy.app import App
128
- from kivy.lang import Builder
129
- from kivy.uix.recycleview import RecycleView
130
- from kivy.uix.recycleview.views import RecycleDataViewBehavior
131
- from kivy.uix.label import Label
132
- from kivy.uix.button import Button
133
- from kivy.uix.gridlayout import GridLayout
134
- from kivy.uix.boxlayout import BoxLayout
135
- from kivy.properties import BooleanProperty
136
- from kivy.uix.recycleboxlayout import RecycleBoxLayout
137
- from kivy.uix.behaviors import FocusBehavior
138
- from kivy.uix.recycleview.layout import LayoutSelectionBehavior
139
127
 
140
- import japanize_kivy
141
-
142
- Builder.load_string('''
143
- <SelectableLabel>:
144
- canvas.before:
145
- Color:
146
- rgba: (.8, .8, .8, 1) if self.selected else (1, .8, .8, 1)
147
- Rectangle:
148
- pos: self.pos
149
- size: self.size
150
- label1_text: 'label 1 text'
151
- label2_text: 'label 2 text'
152
- label3_text: 'label 3 text'
153
- pos: self.pos
154
- size: self.size
155
-
156
- #Label:
157
- # id: id_label1
158
- # text: root.label1_text
159
- # color: [0,0,0,1]
160
- # font_size: 20
161
-
162
- Label:
163
- id: id_label2
164
- text: root.label2_text
165
- color: [0,0,0,1]
166
- font_size: 20
167
- size_hint_x: 4
168
-
169
- Label:
170
- id: id_label3
171
- text: root.label3_text
172
- color: [0,0,0,1]
173
- font_size: 20
174
- size_hint_x: 4
175
- Button:
176
- text: '削除'
177
- font_size: 20
178
- size_hint_x: 2
179
-
180
- <RV>:
181
- viewclass: 'SelectableLabel'
182
- SelectableRecycleBoxLayout:
183
- default_size: None, dp(45)
184
- default_size_hint: 1, None
185
- size_hint_y: None
186
- height: self.minimum_height
187
- orientation: 'vertical'
188
- multiselect: True
189
- touch_multiselect: True
190
-
191
- ''')
192
-
193
- items_1 = ['カツ丼','天丼','親子丼','玉子丼','オムライス','カツカレー']
194
- items_2 = ['850','850','750','670','800','850']
195
-
196
- class SelectableRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior,
197
- RecycleBoxLayout):
198
- pass
199
-
200
- class SelectableLabel(RecycleDataViewBehavior, GridLayout):
201
-
202
- index = None
203
- selected = BooleanProperty(False)
204
- selectable = BooleanProperty(True)
205
- cols = 3
206
-
207
- def refresh_view_attrs(self, rv, index, data):
208
- '''Catch and handle the view changes '''
209
- self.index = index
210
- self.label1_text = str(index)
211
- self.label2_text = data['label2']['text']
212
- self.label3_text = data['label3']['text']
213
- return super(SelectableLabel, self).refresh_view_attrs(
214
- rv, index, data)
215
-
216
- def on_touch_down(self, touch):
217
- ''' Add selection on touch down '''
218
- if super(SelectableLabel, self).on_touch_down(touch):
219
- return True
220
- if self.collide_point(*touch.pos) and self.selectable:
221
- return self.parent.select_with_touch(self.index, touch)
222
-
223
- def apply_selection(self, rv, index, is_selected):
224
- ''' Respond to the selection of items in the view. '''
225
- self.selected = is_selected
226
- if is_selected:
227
- print('selection changed to {}'.format(rv.data[index]))
228
- else:
229
- print('selection removed for {}'.format(rv.data[index]))
230
-
231
- class RV(RecycleView):
232
- def __init__(self, **kwargs):
233
- super(RV, self).__init__(**kwargs)
234
- paired_iter = zip(items_1, items_2)
235
- self.data = []
236
- for i1, i2 in paired_iter:
237
- d = {'label2': {'text': i1}, 'label3': {'text': i2}}
238
- self.data.append(d)
239
-
240
- class Menu01App(App):
241
- def build(self):
242
- return RV()
243
-
244
- if __name__ == '__main__':
245
- Menu01App().run()
246
- ```
247
128
  よろしくお願いいたします。