Kivy Python - How to access parent object whithout root -


i not know python, don't know if problem more kivy or python. want call parents' method on click/press. cannot access root object (attributeerror: 'issuebutton' object has no attribute 'root') nor global variable defined earlier (nameerror: name 'global_screen_manager' not defined)

i using screenmanager switch screens , using listview listadapter create these buttons want call method talking about. funny thing not button has several parents above it, gridlayout.

how can define root issuebutton @ bottom of py-file? there way call method on-detail_press issuescreen? ok use global screenmanager or there preferred way pass reference?

thanks in advance!

here's code: github.com/timokramer/repodigger

the py:

#!/usr/bin/python3 # -*- encoding: utf-8 -*-  kivy.app import app kivy.uix.screenmanager import screenmanager, screen kivy.uix.listview import listitembutton kivy.properties import objectproperty, listproperty kivy.network.urlrequest import urlrequest import re   class repodiggerapp(app):      def build(self):         root = manager()         global global_screen_manager         global_screen_manager = root         return root   class manager(screenmanager):     login_screen = objectproperty(none)     issue_screen = objectproperty(none)     detail_screen = objectproperty(none)     burndown_screen = objectproperty(none)   class detailscreen(screen):      def __init__(self, **kwargs):         super(detailscreen, self).__init__(**kwargs)      def populate_details(self):         pass   class burndownscreen(screen):     def __init__(self, **kwargs):         super(burndownscreen, self).__init__(**kwargs)   class loginscreen(screen):     def get_input(self, text_input):         if text_input != "":             self.parse_input(text_input)      def parse_input(self, text_input):         if re.search(".[/].", text_input):             self.make_request(text_input)         else:             print("not valid repo!")      def make_request(self, text_input):         headers = {'user-agent': 'timokramer/repodigger'}         req = urlrequest(             'https://api.github.com/repos/' + text_input + '/issues',             on_success=self.parse_request,             on_failure=self.parse_failure,             on_error=self.parse_error,             req_headers=headers,             debug=true         )         req.wait()         if req.is_finished:             print("request finished")      def parse_request(self, req, results):         print('succeeded requesting github issues')         global_screen_manager.current = 'issue screen'         global_screen_manager.get_screen('issue screen').build_issue_widgets(results)      def parse_failure(self, req, result):         print('there problem: "', result['message'], '"')      def parse_error(self, req, error):         print('there error: ', error)   class issuescreen(screen):     my_item_strings = listproperty([])      def __init__(self, **kwargs):         kwargs['cols'] = 1         super(issuescreen, self).__init__(**kwargs)      def build_issue_widgets(self, issues):         issue in issues:             if issue['state'] == 'open':                 self.my_item_strings.append(issue['title'])         self.issues_list.item_strings = self.my_item_strings         self.issues_list.adapter.data.clear()         self.issues_list.adapter.data.extend(self.my_item_strings)         self.issues_list._trigger_reset_populate()      def on_burndown_press(self):         global_screen_manager.current = 'burndown screen'      def on_change_press(self):         global_screen_manager.current = 'login screen'      def on_detail_press(self):         global_screen_manager.current = 'detail screen'         global_screen_manager.get_screen('detail screen').populate_details()   class issuebutton(listitembutton):     def on_detail_press(self):         print(self.parent)         print(self.parent.parent)         print(self.parent.parent.parent)         print(self.parent.parent.parent.parent)         print(self.parent.parent.parent.parent.parent)         self.parent.parent.parent.parent.parent.on_detail_press()   if __name__ == '__main__':     repodiggerapp().run() 

the kv:

#: import repodigger repodigger #: import listadapter kivy.adapters.listadapter.listadapter  <manager>:     id: screen_manager     login_screen: login_screen     issue_screen: issue_screen     detail_screen: detail_screen     burndown_screen: burndown_screen     canvas.before:         color:             rgba: .1, .1, .1, 1         rectangle:             pos: self.pos             size: self.size     loginscreen:         id: login_screen         name: 'login screen'         manager: screen_manager     issuescreen:         id: issue_screen         name: 'issue screen'         manager: screen_manager     detailscreen:         id: detail_screen         name: 'detail screen'         manager: screen_manager     burndownscreen:         id: burndown_screen         name: 'burndown screen'         manager: screen_manager  <burndownscreen>:     boxlayout:         id: burndown_screen         button:             text: 'burndown!'  <issuescreen>     issues_list: issues_list     boxlayout:         size_hint: 1, 1         orientation: 'vertical'         listview:             id: issues_list             size_hint: 1, .8             adapter:                 listadapter(data=[], cls=repodigger.issuebutton)         boxlayout:             orientation: 'horizontal'             size_hint: 1, .05             button:                 size_hint: .2, 1                 text: "change repository"                 on_press: root.on_change_press()             button:                 size_hint: .2, 1                 text: "show burndown"                 on_press: root.on_burndown_press()  <issuebutton>:     on_press: self.on_detail_press()  <detailscreen>:     boxlayout:         id: detail_screen         orientation: 'vertical'         button:             text: "detail view"  <loginscreen>:     boxlayout:         id: login_screen         size_hint: .7, .1         pos_hint: {'center_x': .5, 'center_y': .3}         rows:1         label:             text: "enter github-repo"             text_size: self.width-10, self.height-10             valign: 'middle'             halign: 'center'             size_hint_x: .3         textinput:             id: text_input             on_text_validate: root.get_input(self.text)             text: ""             hint_text: "eg. timokramer/repodigger"             text_size: self.width-10, self.height-10             valign: 'middle'             halign: 'center'             padding_y: ( self.height - self.line_height ) / 2             size_hint_x: .5             multiline: false         button:             id: ok_button             on_press: root.get_input(text_input.text)             text: "ok"             text_size: self.width-20, self.height-20             valign: 'middle'             halign: 'center'             size_hint_x: .2 


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -