Search code examples
pythonandroidkivy

How to access a specific content with ids on kivy


my problem is that I am doing recycle view of async Images that have a special url. I am loading them thanks to a recycle view. My problem is that I want to print the source of the async image thanks to an app function, on another screen. All I did, didn"t work. The idea is only to recup the source of the async image and to show it on UserInfo screen. Only that. Nb : (The images are taken on an API server.) Thanks !

The code :

class ReviewinApp(MDApp):
    new_dialog = None
    notdialog = None
    dialog =None
    dialoge = None
    asyncimage = None
    doc = None
    data = ListProperty()
    id_ = ListProperty()
    def build(self):
        dialog = None
        self.title = "ReviewinApp"
        global sm 
        sm = ScreenManager()
        sm.add_widget(Builder.load_file("splash.kv"))
        sm.add_widget(Builder.load_file("accueil.kv"))
        sm.add_widget(Builder.load_file('conditions.kv'))
        sm.add_widget(Builder.load_file("register.kv"))
        sm.add_widget(Builder.load_file("faq.kv"))
        sm.add_widget(Builder.load_file("login.kv"))
        sm.add_widget(Builder.load_file("User2.kv"))
        sm.add_widget(Builder.load_file("rules.kv"))
        sm.add_widget(Builder.load_file("commentinput.kv"))
        sm.add_widget(Builder.load_file("UserInfo.kv"))
        sm.add_widget(Builder.load_file('test.kv'))
        return sm
    def load_products(self):
        token = self.token
        json = {"token":token}
        res = requests.post('http://127.0.0.1:2223/products/list', json=json)
        self.doc = res.json()
        self.data = [{'source': 'http://127.0.0.1:2223/products/' + str(self.doc[i].replace('.png', ''))} for i in range(len(self.doc))]
    def en(self):
        app = App.get_running_app()
        print(app.data)
    ```
    MDScreen:
    name: 'test'
    md_bg_color: 41/255, 34/255, 34/255, 1
    on_enter: app.load_products()
    image1: ""
    RecycleView:
        viewclass: "OwnWidget" 
        data: app.data
        RecycleBoxLayout:
            default_size: None, dp(300)
            default_size_hint: 1, None
            size_hint_y: None
            height: self.minimum_height
            orientation: 'vertical'
            spacing: dp(20)
<OwnWidget@BoxLayout>:
    id: recycle
    orientation: 'vertical'
    text: ''
    source:'' 
    MDIconButton:
        icon: 'arrow-left'
        icon_color: 'white'
        theme_icon_color: 'Custom'
        pos_hint: {'center_x':0.3, 'center_y': 0.1}  
        size_hint_x: 0.3
        height: dp(40)
        on_press:
            app.reload_datas()
            app.root.current = "UserInfo"
            print(product.source)
    AsyncImage:
        id: product
        source: root.source
    ```
    MDScreen:
    name: "UserInfo"
    on_enter: app.en()
    MDFloatLayout:
        md_bg_color: 41/255, 34/255, 34/255, 1
        MDLabel:
            id: test_text
            text: ""
    ```

Solution

  • All you need to access objects in a different screen is the .get screen() method, the name of the screen, object id, and object property.