I
I
Ilya Neizvestnyj2020-05-15 15:11:38
Python
Ilya Neizvestnyj, 2020-05-15 15:11:38

I am loading and displaying Json files using Kivy UrlReguest but nothing works on android, why?

I have 18 Json files on Cloudinary, the files themselves are created with JsonStore from the Kivy library. Using the documentation , I download these files (the text itself is written in Cyrillic) with one click of a button and show them in a pop-up window, everything works fine on Windows and Linux, but on an Android smartphone, when I click on the button, nothing happens, although the text should displayed. What am I doing wrong?

buildozer.spec
Virtual Machine

The code itself will be shown below.

from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout

from kivymd.app import MDApp
from kivymd.theming import ThemableBehavior
from kivymd.uix.list import OneLineIconListItem, MDList
import webbrowser
import os
from kivy.storage.jsonstore import JsonStore
from difflib import get_close_matches
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.popup import Popup
from kivy.network.urlrequest import UrlRequest

KV = '''
<ContentNavigationDrawer>:
    orientation: "vertical"
    padding: "8dp"
    spacing: "8dp"

    AnchorLayout:
        anchor_x: "left"
        size_hint_y: None
        height: avatar.height

        Image:
            id: avatar
            size_hint: None, None
            size: "100dp", "100dp"
            source: "icon2.png"

    MDLabel:
        text: "..."
        font_style: "Button"
        size_hint_y: None
        height: self.texture_size[1]

    MDLabel:
        text: "..."
        font_style: "Caption"
        size_hint_y: None
        height: self.texture_size[1]



Screen:    
# Наша кнопка, при нажатии на которую отображается текст в label

    MDIconButton:
        id: image
        icon: ""
        pos_hint: {"center_x": 0.5, "center_y": 0.71}
        width: root.width*0.99
        height:root.height*0.38
        on_release: app.load_json() 

    MDLabel:
        id: info
        text: ""
        halign: 'center'

    MDFloatingActionButton:
        icon: "arrow-left-bold"
        elevation_normal: 10
        pos_hint: {"center_x": 0.1, "center_y": 0.05}
        on_release: app.previous()

    MDFloatingActionButton:
        elevation_normal: 10
        icon: "arrow-right-bold"
        pos_hint: {"center_x": 0.9, "center_y": 0.05}
        on_release: app.next()

    MDLabel:
        id: page
        text: ''
        text_color: 0, 0, 1, 1
        halign: "center"
        pos_hint: {"center_y": 0.05}

    MDLabel:
        id: name
        text: ''
        pos_hint: {"center_x": 0.51, "center_y": 0.47}

    MDIcon:
        id: review
        halign: "center"
        pos_hint: {"center_y": 0.3}
        icon: "thumb-up-outline"
        font_size: "100sp"


    NavigationLayout:
        ScreenManager:

            Screen:

                BoxLayout:
                    orientation: 'vertical'

                    MDToolbar:
                        elevation: 10
                        left_action_items: 
                    Widget:


        MDNavigationDrawer:
            id: nav_drawer
            swipe_edge_width: 200

            ContentNavigationDrawer:
                id: content_drawer
                ScrollView:
                    DrawerList:
                        padding: "5dp"
                        spacing: "15dp"

                        MDTextField:
                            id: search
                            hint_text: "..."
                            helper_text: "..."
                            helper_text_mode: "on_focus"
                            max_text_length: 30

                        MDRoundFlatIconButton:
                            icon: "feature-search"
                            text: "Search"
                            width: dp(250)
                            on_release: app.search()

                        # Тут некоторые повторяющиеся кнопки............

# ---------Popup----------
<Popups>:
    ScrollView:
    # Здесь наш загруженный текст
        MDLabel: 
            id: rev
            text: ''
            size_hint: None, None
            size: self.texture_size
            theme_text_color: "Custom"
            text_color: 1, 1, 1, 1
            padding_x: 10
            text_size: (root.width, None)
            # font_style: 

    MDFloatingActionButton:
        id: close
        icon: "cancel"
        text: "Close"
        # set size of the button 
        #size_hint: 0.2, 0.1
        # set position of the button   
        pos_hint: {"x":0.95, "y": -0.035}  
        on_release: app.close()

'''


class ContentNavigationDrawer(BoxLayout):
    pass


class DrawerList(ThemableBehavior, MDList):
    pass


class Popups(FloatLayout):
    def __init__(self, text):
        super(Popups, self).__init__()
        try:
            self.ids.rev.text = str(text)
        except:
            pass


class TestNavigationDrawer(MDApp):
    def build(self):
        return Builder.load_string(KV)

    def on_start(self):
        self.im_folder = 'im'
        self.image_arr = []
        self.name_for_urls = []
        self.bad_rev = ['....png']
        self.page = 1

    # Здесь я беру название картинок для показа и дальнейшего использования

        for i in os.listdir('im'):
            self.image_arr.append(i)
            self.name_for_urls.append(i.replace(' ', '_').replace('png', 'json'))

        print(self.name_for_urls)

        self.rev_dir = 'revDir'
    # ---url (Сам текст написан кириллицей) ---
        self.url = 'https://res.cloudinary.com/http-f0433942-xsph-ru/raw/upload/v1589534191/files/folder/'

        self.store = JsonStore('hello.json')

        if os.path.exists('hello.json'):
            pass
        else:
            # put some values
            self.store.put('Theme', name='Light')

        self.color = self.store.get('Theme')['name']

        if self.color == 'Light':
            self.theme_black = False

        else:
            self.theme_black = True

        self.theme_cls.theme_style = self.color
        self.st = ''
        self.show_page_image_name()
        self.rev_show()

    def got_json(self, req, result):
        self.st = ''
        self.root.ids.info.text = 'Start'
        for key, value in result['Review'].items():
            # print('{}: {}'.format(key, value))
            self.st += '{}: {}'.format(key, value)
        print(req)
        self.root.ids.info.text = 'Loaded'
        self.show_popup()

    def load_json(self):
        UrlRequest(self.url + self.name_for_urls[self.page - 1], self.got_json)

    def show_popup(self):

        self.show = Popups(text=str(self.st))

        self.popupWindow = Popup(title="...", content=self.show,
                                 size_hint=(None, None), size=(self.root.width, self.root.height))

        # открыть всплывающее окно
        self.popupWindow.open()

    def close(self):
        print(1)
        self.popupWindow.dismiss()
        # Attach close button press with popup.dismiss action

    def show_page_image_name(self):
        self.root.ids.page.text = str(self.page)
        self.root.ids.image.icon = os.path.join(self.im_folder, self.image_arr[self.page - 1])
        self.root.ids.name.text = self.image_arr[self.page - 1].replace('.png', '')

    def search(self):
        self.get = self.root.ids.search.text
        try:
            if self.get.isdigit() == True:
                if int(self.get) > len(self.image_arr):
                    self.root.ids.search.hint_text = 'Pages Exceeded'
                else:
                    self.root.ids.search.hint_text = 'Search'

                    self.page = int(self.get)
                    self.rev_show()
                    self.show_page_image_name()
            else:
                try:
                    self.root.ids.search.hint_text = 'Search'
                    matches = get_close_matches(self.get, self.image_arr)
                    self.page = self.image_arr.index(matches[0]) + 1
                    print(self.page)
                    self.rev_show()
                    self.show_page_image_name()
                except:
                    self.root.ids.search.hint_text = '...'
        except:
            pass

    def rev_show(self):
        if self.image_arr[self.page - 1] in self.bad_rev:
            self.root.ids.review.icon = 'thumb-down-outline'
        else:
            self.root.ids.review.icon = 'thumb-up-outline'


    def previous(self):
        self.page -= 1
        if self.page == 0:
            self.page = len(self.image_arr)

        self.rev_show()
        self.show_page_image_name()
        print('previous')

    def next(self):
        self.page += 1
        if self.page > len(self.image_arr):
            self.page = 1

        self.rev_show()
        self.show_page_image_name()
        print('next')

    def click(self):
        print('click')


TestNavigationDrawer().run()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya Neizvestnyj, 2020-05-17
@Cheloved

Decided here

1
101-s, 2020-05-15
@101-s

how did you download kivy on android? via https://play.google.com/store/apps/details?id=org.... is it?
it was last updated in 2016

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question