###やりたいこと
kivyを使用して,ID管理アプリを作成しようとしています.
何かしらの手段によって,現在登録されているIDの一覧を取得・表示し,管理したいと考えています.
###現状
とりあえずIDを取得した状態で,RecycleViewを用いてIDのリストを表示します.
リストにはチェックボックスがあり,それらをチェックした後,リスト外にある「削除」ボタンを押下することでリストから削除するアクションを実装することを検討しております.
###困っていること
表外にある削除ボタンを押下した際に,チェックがONの行だけ削除したいですが,そもそもボタン押下時にリスト内のでチェックボックスの状態を取得できず,思った通りの実装ができていません.
削除ボタン押下時(on_press)の際に,Rowで定義したCheckBoxのidを取得する方法についてご教示お願いいたします。
(Widgetの親子関係について不勉強で大変申し訳ございません。。。)
以下は使用しているkvファイルのソースコードになります。
lang
<Manager>: rv: rv BoxLayout: BoxLayout: orientation: "vertical" Label: size_hint_y: 0.2 text: "登録ID一覧" color: 0, 0, 0, 1 canvas.before: Color: rgba: 0.75, 0.75, 0.75, 1 Rectangle: pos: self.pos size: self.size BoxLayout: BoxLayout: orientation: "vertical" BoxLayout: size_hint_y: 0.2 Label: text: "ID" Label: text: "権限" Label: text: "削除" BoxLayout: canvas: Color: rgba: 0.85, 0.85, 0.85, 1 Rectangle: size: self.size pos: self.pos orientation: 'vertical' RecycleView: id: rv scroll_type: ['bars', 'content'] scroll_wheel_distance: dp(56) bar_width: dp(10) viewclass: 'Row' RecycleBoxLayout: default_size: None, dp(56) default_size_hint: 1, None size_hint_y: None height: self.minimum_height orientation: 'vertical' spacing: dp(2) AnchorLayout: size_hint_x: 0.3 anchor_x: "center" anchor_y: "center" Button: text: "削除" size: 80, 40 size_hint: None, None on_press: root.delete(num,a) # 押下時に表中でチェックの入った行を削除したい <Row@BoxLayout>: canvas.before: Color: rgba: 0.5, 0.5, 0.5, 1 Rectangle: size: self.size pos: self.pos data: ("","","") Label: id: num text: root.data[0] Label: id: a text: root.data[1] CheckBox:
python
from kivy.app import App from kivy.config import Config from kivy.lang import Builder from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition from kivy.uix.boxlayout import BoxLayout from kivy.properties import StringProperty, ObjectProperty, BooleanProperty from kivy.core.text import LabelBase, DEFAULT_FONT from kivy.resources import resource_add_path Config.set('graphics', 'width', '800') Config.set('graphics', 'height', '600') Config.set('input', 'mouse', 'mouse,disable_multitouch') # 右クリック赤丸消去 Config.set('kivy', 'exit_on_escape', '0') # kivy ESC無効化 # Path of Fonts resource_add_path('/usr/share/fonts/truetype/takao-gothic') LabelBase.register(DEFAULT_FONT, 'TakaoGothic.ttf') # 日本語が使用できるように日本語フォントを指定する # Path of KV_Lang Builder.load_file("./Account_for_teratail.kv") # Setting Screen SM = ScreenManager(transition=NoTransition()) class Manager(Screen): rv = ObjectProperty() def on_enter(self): self.rv.data = [{'data': ("000000", "manager", "pass")}] def delete(self, id, per): print(id, per) # class Row(BoxLayout): # is_checked = BooleanProperty(False) # id = StringProperty() # permission = StringProperty() class GUIApp(App): """ 実行クラス """ def build(self): SM.add_widget(Manager(name="manager")) self.title = 'アカウント管理ソフト' return SM if __name__ == '__main__': GUIApp().run()
###備考
python: 3.4.2
kivy: 1.10.0
まだ回答がついていません
会員登録して回答してみよう