Cheloved
@Cheloved
Good man

Я загружаю и отображаю файлы Json с помощью Kivy UrlReguest, но на android ничего не работает, почему?

У меня есть 18 файлов Json на Cloudinary, сами файлы создаются с помощью JsonStore из библиотеки Kivy. Используя документацию, я скачиваю эти файлы (сам текст написан на кириллице) одним нажатием кнопки и показываю их во всплывающем окне, все отлично работает на Windows и Linux, но на Android смартфоне, когда я нажимаю на кнопку, ничего не происходит, хотя текст должен отображаться. Что я делаю не так?

buildozer.spec
Виртуальная машина

Сам код будет приведен ниже.

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: [['menu', lambda x: nav_drawer.set_state()]]
                    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()
  • Вопрос задан
  • 508 просмотров
Решения вопроса 1
Cheloved
@Cheloved Автор вопроса
Good man
Решено здесь
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
@101-s
как вы загрузили kivy на андроид? через https://play.google.com/store/apps/details?id=org.... это?
последний раз оно обновлялось в 2016 году
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
19 апр. 2024, в 05:01
999999 руб./за проект
19 апр. 2024, в 03:52
1000 руб./за проект
19 апр. 2024, в 03:01
1000 руб./за проект