from kivy.storage.jsonstore import JsonStore
store = JsonStore('hello.json')
# put some values
store.put('tito', name='Mathieu', age=30)
store.put('tshirtman', name='Gabriel', age=27)
# get from a key
print('tito is', store.get('tito'))
# or guess the key/entry for a part of the key
#key, tshirtman = store.find(name='Gabriel')
#print('tshirtman is', tshirtman)
res = store.find(name='Gabriel')
for item in res:
print "res=", str(item)
print "res=", str(item[1]['age'])
res= (u'tshirtman', {'age': 27, 'name': 'Gabriel'})
from kivy.app import App
from kivy.storage.jsonstorage import JsonStore
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
store = JsonStore('hello.json')
store.put('tito', name='Mathieu', age=30)
store.put('tshirtman', name='Gabriel', age=27)
class MyLayout (BoxLayout):
pass
class MyApp (App):
def build (self):
return MyLayout()
if __name__ == 'main':
MyApp().run()
<MyLayout>
Label:
text: store.get('tito')['name'] # store not defined which is correct
Label:
text: root.store.get('tito')['name'] # MyLayout does not have a property store correct also
class MyLayout(BoxLayout):
app = App.get_running_app()
print (app.store.get('channel4')) # is printing the initial value from json
app.store.put ('channel4', name = 'some other name')
print (app.store.get('channel4') # is printing the new value but the label from kv will not update
class MyApp (self) :
def build (self):
self.store = JsonStore (myJsonData)
self.store.put(<somevalues>)
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To post to this group, send email to kivy-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kivy-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/d9ff1804-9826-4b38-b681-1ba6898eb0c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You want to use a kivy StringProperty. Declare the string property in MyLayout. Update the String property when setting new data.
from kivy.properties import StringProperty
class MyLayout(BoxLayout):
my_jsondata = StringProperty('Initial Data') # this looks like a class variable, but it is an instance variable.
def update_data(self, new_data):
app = App.get_running_app()
print (app.store.get('channel4')) # is printing the initial value from json
self.my_jsondata = new_data
app.store.put ('channel4', name = new_data)
print (app.store.get('channel4'))
in KV point use the string property to update the text:
.kv
<MyLayout>
Label:
text: root.my_jsondata # this will update when my_jsondata changes.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAGfUSDKYMEf70kgXMqM8d7A%2BeEm88DWg_kepUgMPWbTYisrMgw%40mail.gmail.com.
--
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAM6f4CwZw7Z_Yp%2B8O1cB4iKz2kpH4xSoGsA6oHRSMdhcQa2jag%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAGfUSDLuzVum6HgNh8Qwn%3DrukieLaYJJ_X%3DyWeVu5zPL87dmpw%40mail.gmail.com.
Jsonstore is not allowing to give user defined name for a key!
# put some values store.put('tito', name='Mathieu', org='kivy')
store.put('tshirtman', name='Gabriel', age=27)
# get a value using a index key and key print('tito is', store.get('tito')['age'])
# using the same index key erases all previously added key-value pairsstore.put('tito', name='Mathieu', age=30)
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAAytCsjDZQZ_hqEnAPgyq1_1iyN5GgZSh_0NQbYAeM8SUgasww%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAGfUSDLEOxLejcgJPm40-eRmq98A-WzSUnjD6-j2XspH8_eS%3Dg%40mail.gmail.com.
Key word arguments use dictionaries to pass the keyword value pairs. I suspect you did not pass a dictionary.
How did you make the call?
Here is a small example of how key word arguments and dictionaries work.
from kivy.storage.jsonstore import JsonStore
def show_me(**kwargs):
print(kwargs)
for k,v in kwargs.items():
print(f'{k} = {v}')
d1 = {'dog': 1, 'cat': 2, 'mouse': 3}
print('\nPass a dictionary as keywords')
show_me(**d1)
print('\nPass Keywords')
show_me(box=4, fox=5, eggs=6)
store = JsonStore('test_1.json')
store.put('color', red=1, white=2, blue=3)
store.put('critters', **d1)
print(f"\nstore.get('critters') = {store.get('critters')}")
Here is the output of the code:
Pass a dictionary as keywords
{'dog': 1, 'cat': 2, 'mouse': 3}
dog = 1
cat = 2
mouse = 3
Pass Keywords
{'box': 4, 'fox': 5, 'eggs': 6}
box = 4
fox = 5
eggs = 6
store.get('critters') = {'dog': 1, 'cat': 2, 'mouse': 3}
Here is the contents of test_1.json:
{"color": {"red": 1, "white": 2, "blue": 3}, "critters": {"dog": 1, "cat": 2, "mouse": 3}}
From: srinivas sagit
Sent: Sunday, July 14, 2019 5:36 AM
To: kivy-...@googlegroups.com
Subject: Re: [kivy-users] Re: How to correctly use the kivy.storage.JsonStore module?
Json Store problem!
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAAytCsht5hXCz-fB3HE8nQUEi_V1Vha7e9MvTOyCU98fYZzrBQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/5d2b4496.1c69fb81.12e17.06b3SMTPIN_ADDED_MISSING%40gmr-mx.google.com.