python 2.7 - How do I capture text from ListItemButton click in listadapter? -


how capture text value listitembutton in listview , store text value in objectproperty can use listitembutton text value in different function?

error getting:

attributeerror: 'nonetype' object has no attribute 'adapter' 

references: https://groups.google.com/forum/#!msg/kivy-users/4opq2wszeks/xm9f1psj8juj

screenshot:

1

trying accomplish in python:

from kivy.app import app kivy.uix.gridlayout import gridlayout kivy.uix.label import label kivy.lang import builder kivy.properties import * random import randint import cx_oracle import os  class mygrid(gridlayout):     data = []     team_list = listproperty()     search_input = objectproperty()     cols = numericproperty()     lv11 = objectproperty()     lv22 = objectproperty()     team1 = objectproperty()     team2 = objectproperty()     list_adapter = lv11.adapter     def __init__(self, **kwargs):         super(mygrid, self).__init__(**kwargs)         self.fetch_team_list()         self.list_adapter = self.lv11.adapter         self.list_adapter.bind(on_selection_change=self.respond_list_view_action())      def respond_list_view_action(self):         text = self.list_adapter.get_view(listitembutton.text)         self.team1 = text      def args_converter(self, index, data_item):         return {'text': data_item['team'],                 'size_hint_y': none,                 'height': 25}      def fetch_team_list(self):         con = cx_oracle.connect('scott/******@localhost/j1db')         cur = con.cursor()         statement = 'select team fbsteampassing group team'         exe = cur.execute(statement)         columns = [i[0] in cur.description]         exe2 = [dict(zip(columns, row)) row in cur]         self.team_list = []         row in exe2:             self.team_list.append(row)         return self.team_list ... 

relevant .kv file

#:kivy 1.9.0 #:import listadapter kivy.adapters.listadapter.listadapter #:import listitembutton kivy.uix.listview.listitembutton   tabbedpanel:     do_default_tab: false     tab_width: 200     tabbedpanelitem:         text: "team query"         boxlayout:             orientation: "vertical"             textinput:                 id: search_box                 focus: true                 size_hint_y: .1                 multiline: false                 on_text_validate: rootgrid.on_enter()             button:                 size_hint_y: .1                 text: "return"                 on_press: rootgrid.on_enter()             scrollview:                 size_hint_y: none                 height: '500dp'                  mygrid:                     id: rootgrid                     search_input: search_box                     lv11: lv1                     cols: 10                     size_hint_y: none                     height: self.minimum_height                     spacing: '1dp'     tabbedpanelitem:         text: "select all"         boxlayout:             orientation: "vertical"             button:                 size_hint_y: .1                 text: "return data"                 on_press: rootgrid2.on_enter_2()             scrollview:                 size_hint_y: none                 height: '500dp'                  mygrid:                     id: rootgrid2                     search_input: search_box                     cols: 10                     size_hint_y: none                     height: self.minimum_height                     spacing: '1dp'     tabbedpanelitem:         text: "compare teams"         stacklayout:             scrollview:                 size_hint_x: .5                 size_hint_y: none                 height: '100dp'                 listview:                     id: lv1                     adapter:                         listadapter(data=rootgrid.team_list, cls=listitembutton, args_converter=rootgrid.args_converter)             scrollview:                 lv1: lv1                 size_hint_x: .5                 size_hint_y: none                 height: '100dp'                 listview:                     id: lv2                     adapter:                         listadapter(data=rootgrid.team_list, cls=listitembutton, args_converter=rootgrid.args_converter)              button:                 size_hint: (1, .1)                 text: "return team compare"                 on_press: rootgrid3.on_enter_3()             scrollview:                 size_hint_y: none                 height: '500dp'                 mygrid:                     id: rootgrid3                     search_input: search_box                     cols: self.cols                     size_hint_y: none                     height: self.minimum_height                     spacing: '1dp' ... 

direct answer: can capture value function bound on_selection_changelink event of listadapter. name string stored in adapter.selection[0].text property. can more computation there.

your code kind of long, messy, , have no idea line error comes from. have example you:

test.kv:

#:kivy 1.9.0 screen:      gridlayout:         cols: 1          teamsgrid:         scoregrid:  <teamsgrid@gridlayout>:     rows: 1     padding: '50dp', '20dp'     spacing: '10dp'      teamsview:         name: 'left'     teamsview:         name: 'right'  <scoregrid>:     cols: 2      teamname:         id: left_name      teamname:         id: right_name      teamscore:         id: left_score         bgcolor: 0.1, 0.1, 0.3      teamscore:         id: right_score         bgcolor: 0.3, 0.1, 0.1  <teamname@label>:     size_hint_y: 0.1     text: 'score'  <teamscore@label>:     markup: true     bgcolor: 0, 0, 0      canvas.before:         color:             rgb: self.bgcolor         rectangle:             pos: self.pos             size: self.size 

main.py:

#!/usr/bin/env python # -*- coding: utf-8 -*- kivy.uix.listview import listview, listitembutton kivy.app import app kivy.adapters.listadapter import listadapter kivy.properties import stringproperty kivy.uix.gridlayout import gridlayout kivy.clock import mainthread  beans = {}   class teamsview(listview):      name = stringproperty()      def __init__(self, **kwargs):         super(teamsview, self).__init__(**kwargs)         self.fetch_teams_from_database()         self.set_adapter()         self.save_bean()      def fetch_teams_from_database(self):         self.teams = [             {'team': 'pogoĊ„ szczecin', 'score': '55'},             {'team': 'arizona state', 'score': '32'},             {'team': 'idaho', 'score': '44'},             {'team': 'nebraska', 'score': '48'},             {'team': 'dummy', 'score': '0'},             {'team': 'dummy', 'score': '0'},             {'team': 'dummy', 'score': '0'},             {'team': 'dummy', 'score': '0'},             {'team': 'dummy', 'score': '0'}         ]      def set_adapter(self):         self.adapter = listadapter(             data=self.teams,             args_converter=self.args_converter,             selection_mode='single',             allow_empty_selection=true,             cls=listitembutton         )          self.adapter.bind(             on_selection_change=self.on_selection_change)      def args_converter(self, row_index, item):         return {             'text': item['team'],             'size_hint_y': none,             'height': 50         }      def on_selection_change(self, adapter):         team_score, team_name = self.get_team(adapter)         team_score = '[size=50]' + team_score + '[/size]'          beans['score_grid'].ids[self.name + '_name'].text =\             team_name + ' score:'         beans['score_grid'].ids[self.name + '_score'].text =\             team_score      def get_team(self, adapter):         try:             team in self.teams:                 if team['team'] in adapter.selection[0].text:                     return team['score'], team['team']         except indexerror:             return '', ''      @mainthread     def save_bean(self):         beans[self.name + 'list'] = self.proxy_ref   class scoregrid(gridlayout):      def __init__(self, **kwargs):         super(scoregrid, self).__init__(**kwargs)         beans['score_grid'] = self.proxy_ref   class test(app):     pass  test().run() 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -