A thumbnail of my app design is below for your reference. The app works fine in linux, but fails in android.
Specifically, the android app seems unable to find the myapp.ini. I can see a file at /mnt/sdcard/.myapp.ini with all the correct config data. It updates when you change the settings in the settings window - so kivy is writing to it. However, i need to read from it, and cannot. Specifically, the layout_x(RelativeLayout) needs to read it (cause it destroys its children, reads the config file, then recreates the appropriate children as instructed by the current config). All this works in the linux OS -- linux makes as myapp.ini file in the project folder with the correct data & can read & write it. In Android, the app can't seem to find the myapp.ini file (even when i point it to /mnt/sdcard/.myapp.ini specifically.)
How do i read data from a ConfigParser() myapp.ini file?
Any advice is welcome,
garrett
_______________________________________________________________________________
# File name: main.py
import kivy
kivy.require('1.8.0')
from kivy.lang import Builder
from kivy.config import ConfigParser
from settingsjson import general_settings_json, fund_settings_json, melody_settings_json
from file_x import Layout_x
class myApp(App):
def build(self):
self.title = "MyApp"
self.use_kivy_settings = False
config = self.config
return RootWidget()
def build_config(self, config):
config.setdefaults('Group1', {
'setting1': 1,
'setting2': 1})
config.setdefaults('Group2', {
'setting1': 1})
def build_settings(self, settings):
settings.add_json_panel('Group1', self.config, data=group1_settings_json)
settings.add_json_panel('Group2', self.config, data=group2_settings_json)
if __name__ == '__main__':
NoteGameApp().run()
_______________________________________________________________________
# File name: notegame.kv
#:kivy 1.8.0
<RootWidget>:
Layout_x:
_______________________________________________________________________
# File name: file_x.py
import kivy
import os
kivy.require('1.8.0')
from kivy.uix.relativelayout import RelativeLayout
from kivy.utils import platform
class Layout_x(RelativeLayout):
def __init__(self, **kwargs):
super(Layout_x, self).__init__(**kwargs)
self.get_config_variables()
self.redraw_layout()
def get_config_variables(self):
if platform=="android":
with open('mnt/sdcard/.myapp.ini', 'r') as g: # crashes as no file found
print type(g), dir(g) # (i'm trying different ways to get to myapp.ini
settings = ConfigParser()
settings.read('mnt/sdcard/.myapp.ini' )
self.scale = settings.get('Group1', 'setting1') # if 'with open(...)... commented out, crashes as
self.key = settings.get('Group1', 'setting2') # no Group 1 in settings
self.settings_list = settings.items('Groups2)
else:
settings = ConfigParser() # on linux, this command works
settings.read('notegame.ini')
print 'settings is:', dir(settings)
self.scale = settings.get('Group1', 'setting1')
(... layout details ...)