久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='YZma7'><style id='YZma7'><dir id='YZma7'><q id='YZma7'></q></dir></style></legend>

    <tfoot id='YZma7'></tfoot>

        <bdo id='YZma7'></bdo><ul id='YZma7'></ul>
      <i id='YZma7'><tr id='YZma7'><dt id='YZma7'><q id='YZma7'><span id='YZma7'><b id='YZma7'><form id='YZma7'><ins id='YZma7'></ins><ul id='YZma7'></ul><sub id='YZma7'></sub></form><legend id='YZma7'></legend><bdo id='YZma7'><pre id='YZma7'><center id='YZma7'></center></pre></bdo></b><th id='YZma7'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='YZma7'><tfoot id='YZma7'></tfoot><dl id='YZma7'><fieldset id='YZma7'></fieldset></dl></div>
    1. <small id='YZma7'></small><noframes id='YZma7'>

    2. Kivy 和 android 共享首選項(xiàng)

      Kivy and android sharedpreferences(Kivy 和 android 共享首選項(xiàng))
    3. <tfoot id='0ro7m'></tfoot>
    4. <legend id='0ro7m'><style id='0ro7m'><dir id='0ro7m'><q id='0ro7m'></q></dir></style></legend>

        <small id='0ro7m'></small><noframes id='0ro7m'>

        <i id='0ro7m'><tr id='0ro7m'><dt id='0ro7m'><q id='0ro7m'><span id='0ro7m'><b id='0ro7m'><form id='0ro7m'><ins id='0ro7m'></ins><ul id='0ro7m'></ul><sub id='0ro7m'></sub></form><legend id='0ro7m'></legend><bdo id='0ro7m'><pre id='0ro7m'><center id='0ro7m'></center></pre></bdo></b><th id='0ro7m'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='0ro7m'><tfoot id='0ro7m'></tfoot><dl id='0ro7m'><fieldset id='0ro7m'></fieldset></dl></div>
          <bdo id='0ro7m'></bdo><ul id='0ro7m'></ul>
            <tbody id='0ro7m'></tbody>
                本文介紹了Kivy 和 android 共享首選項(xiàng)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                問(wèn)題描述

                我正在尋找一種從 Kivy 框架中將設(shè)置持久存儲(chǔ)在 android 設(shè)備上的方法.

                I am looking for a method to store settings persistently on android device, from Kivy framework.

                我發(fā)現(xiàn) Kivy 文檔,整體信息豐富,在這個(gè)特定領(lǐng)域含糊不清.它提到了三種方法(抱歉,沒(méi)有足夠的聲譽(yù)來(lái)提供 clicable 鏈接,提供了 kivy.org 的相對(duì)路徑,如果有人可以修復(fù)這些鏈接,我會(huì)很高興em>):

                I found Kivy documentation, overall informative, vague in this particular area. It mentions three methods (sorry, dont have enough reputation to provide clicable links, relative paths to kivy.org provided, I'd be glad if someone could fix those links):

                1. [存儲(chǔ)] ./docs/api-kivy.storage.html#module-kivy.storage
                2. [設(shè)置] ./docs/api-kivy.uix.settings.html
                3. [配置] ./docs/api-kivy.config.html

                除此之外,我知道我可以通過(guò) pickle 或數(shù)據(jù)庫(kù)將數(shù)據(jù)存儲(chǔ)在文件中,但我想專門(mén)使用 sharedpreferences,或至少任何 Android/Kivy 特定的持久存儲(chǔ).

                In addition to those, I'm aware that I could store data in a file, via pickle or database, but I'd like to use specifically sharedpreferences, or at least any Android/Kivy specific persistent storage.

                1. 但是,我找不到任何比較或解釋它們有何不同以及如何使用它們.任何人都可以闡明一下,已經(jīng)使用過(guò)它們了嗎?

                1. However, I was unable to find any comparison, or explanation how they are different, and how they are used. Could anyone shed some light, had used them already?

                實(shí)際上,我有 80% 的把握這種方法都沒(méi)有使用 Android 的共享首選項(xiàng),因此我考慮使用 jnius (4),并且我嘗試過(guò)這樣做(方法 1,2/3?,4),基于簡(jiǎn)單的 hello world 示例:

                Actually, I'm 80% sure that neither of this method uses Android's shared preferences, thus I thought about using jnius (4), and to do that I've tried (methods 1,2/3?,4), based on simple hello world example:

                from kivy.app import App
                from kivy.uix.button import Button
                
                import jnius  
                from kivy.config import Config  
                from kivy.storage.dictstore import DictStore  
                
                class MyApp(App):
                
                    def build(self):
                
                        path = "DEFAULT"
                        try:  
                            path = Config.get('kivy', 'my_important_variable')  
                            print "			 KIVY 1:", Config.get('kivy', 'my_important_variable')  
                        except Exception as err:
                            print ("KIVY, 1, error: {}".format(repr(err)))  
                
                        try:
                            store = DictStore("MY_SETTINGS")
                            path = store.get("my_important_variable")
                            print "			 KIVY 2:", path
                        except KeyError as err:
                            print ("KIVY, 2, error: {}".format(repr(err)))
                
                        try:
                            prefs_m = jnius.autoclass('android.preference.PreferenceManager')
                            prefs = prefs_m.getSharedPreferences()
                            path = prefs.getString("my_important_variable", None)
                            print "			 KIVY 3:", path
                        except jnius.jnius.JavaException as err:
                            print ("KIVY, 3, error: {}".format(repr(err)))
                
                        btn1 = Button(text=path)
                        btn1.bind(on_press=app.callback) #
                        return btn1
                
                    def callback(self, instance):
                        print('The button <%s> is being pressed, SAVING...' % instance.text)
                
                        try:
                            Config.set('kivy', 'my_important_variable', "my_value_1")
                        except Exception as err:
                            print ("KIVY, 4, error: {}".format(repr(err)))
                
                        try:
                            store = DictStore("MY_SETTINGS")
                            store.put("MY_SETTINGS", my_important_variable="my_value_2")
                        except Exception as err:
                            print ("KIVY, 5, error: {}".format(repr(err)))
                
                        try:
                            prefs_c = jnius.autoclass('android.content.SharedPreferences')
                            prefs_m = jnius.autoclass('android.preference.PreferenceManager')
                            prefs = prefs_m.getSharedPreferences()
                            prefs_e = prefs.Editor()
                            prefs_e.putString("my_important_variable", "my_value_3")
                            prefs_e.commit()
                        except Exception as err:
                            print ("KIVY, 6, error: {}".format(repr(err)))
                
                        try:
                            context = jnius.autoclass('android.content.Context')
                            # do I actually get context or a class here?
                            prefs = context.getPreferences(0).edit();
                            prefs.putString("my_important_variable", "my_value_4")
                            prefs.commit()
                        except Exception as err:
                            print ("KIVY, 7, error: {}".format(repr(err)))
                
                if __name__ == '__main__':
                    app = MyApp()
                    app.run()
                

                這是 logcat 的結(jié)果

                and here are logcat's results

                ... each time app is launched 
                I/python  ( 5973): KIVY, 1, error: No option 'my_important_variable' in section: 'kivy'
                I/python  ( 5973): KIVY, 2, error: KeyError('my_important_variable',)
                I/python  ( 5973): KIVY, 3, error: JavaException('Unable to find a None method!',)
                
                ... button pressed
                I/python  ( 5973): The button <DEFAULT> is being pressed, SAVING...
                I/python  ( 5973): KIVY, 6, error: JavaException('Unable to find a None method!',)
                I/python  ( 5973): KIVY, 7, error: AttributeError("type object 'android.content.Context' has no attribute 'getPreferences'",)
                

                請(qǐng)注意,沒(méi)有調(diào)用 4、5 個(gè)錯(cuò)誤消息",所以理論上它們應(yīng)該可以工作,但是第二次啟動(dòng)我得到了同樣的錯(cuò)誤.我已經(jīng)沒(méi)有辦法破解它了.

                Notice, that 4, 5 "error msg's" didn't get called, so in theory they should have worked, but second launch I get same errors. I've run out of ideas how to crack it.

                推薦答案

                Kivy.Config 用于存儲(chǔ)與 App 類的實(shí)例化相關(guān)的設(shè)置.它通常在導(dǎo)入任何其他 kivy 模塊之前放置在 Python 腳本的最頂部.此方法不是特定于平臺(tái)的,但配置文件的默認(rèn)路徑會(huì)根據(jù)平臺(tái)而變化.

                Kivy.Config is used to store settings that relate to the instantiation of the App class. It is usually placed at the very top of your Python script before any other kivy module is imported. This method is not platform specific, but the default path to the config file changes depending on the platform.

                from kivy.config import Config
                desktop=Config.getint('kivy', 'desktop')
                if desktop == 1:
                    print "This app is being run on a desktop."
                

                DictStore 是一個(gè)將字典存儲(chǔ)到磁盤(pán)的存儲(chǔ)類.filename 參數(shù)指定存儲(chǔ)字典的文件的名稱.調(diào)用 get 函數(shù)時(shí),會(huì)返回一個(gè) Python 字典.

                The DictStore is a storage class that stores a dictionary to disk. The filename argument specifies the name of the file where the dictionary is stored. When the get function is called, a Python dictionary is returned.

                from kivy.app import App
                from kivy.uix.button import Button
                from kivy.storage.dictstore import DictStore
                
                class TestApp(App):
                    def build(self):
                        try:
                            store = DictStore(filename="MY_SETTINGS")
                            dictionary = store.get("my_important_variable")
                            print "			 KIVY 2: DictStore Succeeded",
                        except KeyError as err:
                            dictionary = {'name': 'None'}
                            print ("KIVY, 2, error: {}".format(repr(err)))
                
                        self.text = str(dictionary)
                        btn1 = Button(text=self.text)
                        btn1.bind(on_press=self.callback) #
                        return btn1
                
                    def callback(self, instance):
                        print('The button <%s> is being pressed, SAVING...' % instance.text)
                        try:
                            store = DictStore(filename="MY_SETTINGS")
                            store.put("my_important_variable", name="John")
                        except Exception as err:
                            print ("KIVY, 5, error: {}".format(repr(err)))
                
                
                
                if __name__ == '__main__':
                    TestApp().run()
                

                我將在下面提供訪問(wèn)共享首選項(xiàng)的代碼.如果您有興趣了解更多信息,請(qǐng)閱讀 http://developer.android.com/guide/topics/data/data-storage.html 和 https://kivy.org/planet/2015/04/python-on%C2%A0android/

                I will provide the code for accessing shared prefs below. If you are interested in learning more please read http://developer.android.com/guide/topics/data/data-storage.html and https://kivy.org/planet/2015/04/python-on%C2%A0android/

                from kivy.app import App
                from kivy.uix.button import Button
                
                import jnius
                
                class TestApp(App):
                    def build(self):
                        try:
                            PythonActivity = jnius.autoclass('org.renpy.android.PythonActivity')
                            activity = PythonActivity.mActivity
                            cntxt = activity.getApplicationContext()
                            prefs = cntxt.getSharedPreferences("MY_PREFS", cntxt.MODE_PRIVATE )
                            print "KIVY ACQUIRED SHARED PREFS"
                            myVar = prefs.getString("my_important_variable", "Default String")
                            print "	KIVY 3: Retrieved SharedPref"
                        except jnius.jnius.JavaException as err:
                            myVar="Error Loading Prefs."
                            print ("KIVY, 3, error: {}".format(repr(err)))
                
                        self.text = myVar
                        btn1 = Button(text=self.text)
                        btn1.bind(on_press=self.callback) #
                        return btn1
                
                    def callback(self, instance):
                        print('The button <%s> is being pressed, SAVING...' % instance.text)
                        try:
                            PythonActivity = jnius.autoclass('org.renpy.android.PythonActivity')
                            activity = PythonActivity.mActivity
                            cntxt = activity.getApplicationContext()
                            prefs = cntxt.getSharedPreferences("MY_PREFS", cntxt.MODE_PRIVATE)
                            editor = prefs.edit()
                            editor.putString("my_important_variable", "This is important!")
                            editor.commit()
                            print "	KIVY: Added string <This is important!> to shared prefs."
                        except Exception as err:
                            print ("	KIVY, 6, error: {}".format(repr(err)))
                
                if __name__ == '__main__':
                    TestApp().run()
                

                這篇關(guān)于Kivy 和 android 共享首選項(xiàng)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                How to make a discord bot that gives roles in Python?(如何制作一個(gè)在 Python 中提供角色的不和諧機(jī)器人?)
                Discord bot isn#39;t responding to commands(Discord 機(jī)器人沒(méi)有響應(yīng)命令)
                Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關(guān)于我嗎?Discord 機(jī)器人的功能?(不和諧.py))
                message.channel.id Discord PY(message.channel.id Discord PY)
                How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機(jī)器人?)
                discord.py - Automaticaly Change an Role Color(discord.py - 自動(dòng)更改角色顏色)
                    <tbody id='Z66wy'></tbody>
                  <i id='Z66wy'><tr id='Z66wy'><dt id='Z66wy'><q id='Z66wy'><span id='Z66wy'><b id='Z66wy'><form id='Z66wy'><ins id='Z66wy'></ins><ul id='Z66wy'></ul><sub id='Z66wy'></sub></form><legend id='Z66wy'></legend><bdo id='Z66wy'><pre id='Z66wy'><center id='Z66wy'></center></pre></bdo></b><th id='Z66wy'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Z66wy'><tfoot id='Z66wy'></tfoot><dl id='Z66wy'><fieldset id='Z66wy'></fieldset></dl></div>

                  <legend id='Z66wy'><style id='Z66wy'><dir id='Z66wy'><q id='Z66wy'></q></dir></style></legend>

                        <bdo id='Z66wy'></bdo><ul id='Z66wy'></ul>

                        <small id='Z66wy'></small><noframes id='Z66wy'>

                        • <tfoot id='Z66wy'></tfoot>

                          主站蜘蛛池模板: 日韩一区二 | 国产999精品久久久久久 | 久久大陆 | 韩国精品在线观看 | 免费99精品国产自在在线 | 综合五月 | 99热碰 | 中文字幕亚洲精品在线观看 | 国产九九九 | 亚洲欧美一区二区三区视频 | 欧美视频精品 | 欧美日韩视频一区二区 | 激情五月婷婷综合 | 人人干人人爽 | 亚洲精品乱码久久久久久按摩观 | 婷婷精品 | 精品综合久久 | 一级黄色播放 | 日韩在线观看中文字幕 | 日日干夜夜操天天操 | 一级做a | 国产精品亚洲精品日韩已方 | 精品视频一区二区三区 | 久久精品国产清自在天天线 | 风间由美一区二区三区在线观看 | 91一区二区 | 九九福利| 国产精品一区在线 | 精品99爱视频在线观看 | 日韩视频一区二区三区 | 精品一区二区观看 | 一区二区视频在线 | 亚洲性视频网站 | 亚洲精品第一 | 久久久久国产一区二区三区 | 91精品久久久久久久久中文字幕 | 我要看黄色录像一级片 | 91成人免费看片 | 在线中文字幕国产 | 麻豆91av | 亚洲精品一区二区在线观看 |