本文整理汇总了Python中kivy.storage.jsonstore.JsonStore.put方法的典型用法代码示例。如果您正苦于以下问题:Python JsonStore.put方法的具体用法?Python JsonStore.put怎么用?Python JsonStore.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.storage.jsonstore.JsonStore
的用法示例。
在下文中一共展示了JsonStore.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WeatherRoot
# 需要导入模块: from kivy.storage.jsonstore import JsonStore [as 别名]
# 或者: from kivy.storage.jsonstore.JsonStore import put [as 别名]
class WeatherRoot(BoxLayout):
carousel = ObjectProperty()
current_weather = ObjectProperty()
forecast = ObjectProperty()
locations = ObjectProperty()
add_location_form = ObjectProperty()
def __init__(self, **kwargs):
super(WeatherRoot, self).__init__(**kwargs)
self.store = JsonStore("weather_store.json")
if self.store.exists('locations'):
current_location = self.store.get("locations")["current_location"]
self.show_current_weather(current_location)
def show_current_weather(self, location=None):
self.clear_widgets()
if self.current_weather is None:
self.current_weather = CurrentWeather()
if self.locations is None:
self.locations = Factory.Locations()
if (self.store.exists('locations')):
locations = self.store.get("locations")['locations']
self.locations.locations_list.adapter.data.extend(locations)
if location is not None:
self.current_weather.location = location
if location not in self.locations.locations_list.adapter.data:
self.locations.locations_list.adapter.data.append(location)
self.locations.locations_list._trigger_reset_populate()
self.store.put("locations",
locations=list(self.locations.locations_list.adapter.data),
current_location=location)
self.current_weather.update_weather()
self.add_widget(self.current_weather)
def show_forecast(self, location=None):
self.clear_widgets()
if self.forecast is None:
self.forecast = Factory.Forecast()
if location is not None:
self.forecast.location = location
self.forecast.update_weather()
self.add_widget(self.forecast)
# BEGIN SHOW_MODAL_VIEW
def show_add_location_form(self):
self.add_location_form = AddLocationForm()
self.add_location_form.open()
# END SHOW_MODAL_VIEW
def show_locations(self):
self.clear_widgets()
self.add_widget(self.locations)
示例2: MbtMergeManager
# 需要导入模块: from kivy.storage.jsonstore import JsonStore [as 别名]
# 或者: from kivy.storage.jsonstore.JsonStore import put [as 别名]
class MbtMergeManager(object):
"""
Keeps track mbtiles merging state (merged vs not merged)
and handles merging.
"""
def __init__(self):
json_store_path = App.get_running_app().json_store_path
self.store = JsonStore(json_store_path)
def merge_not_merged(self):
"""
Merges not merged files.
"""
mbtmerge = MbtMerge()
sources = self.not_merged()
destination = App.get_running_app().main_mbtiles_path
mbtmerge.merge(sources, destination)
for source in sources:
self.add_to_merged(source)
def not_merged(self):
"""
Returns the list of not merged files.
"""
merged_list = self.merged()
not_merged_list = App.get_running_app().mbtiles_paths
for merged in merged_list:
not_merged_list.remove(merged)
return not_merged_list
def merged(self):
"""
Returns the list of merged files.
"""
try:
merged = self.store.get('merged_mbtiles')['list']
except KeyError:
merged = []
return merged
def add_to_merged(self, mbtiles_path):
"""
Adds the mbtiles to the merged list.
"""
merged = self.merged()
merged.append(mbtiles_path)
self.store.put('merged_mbtiles', list=merged)
def remove_from_merged(self, mbtiles_path):
"""
Removes the mbtiles from the merged list.
"""
merged = self.merged()
merged.remove(mbtiles_path)
self.store.put('merged_mbtiles', list=merged)
示例3: storeformdata
# 需要导入模块: from kivy.storage.jsonstore import JsonStore [as 别名]
# 或者: from kivy.storage.jsonstore.JsonStore import put [as 别名]
def storeformdata(self):
store = JsonStore('forms.json')
store.put('forms',
walletname=self.input_name.text,
sendtoaddress=self.input_address.text,
amount=self.input_amount.text,
mixin=self.input_mixin.text,
paymentid=self.input_paymentid.text,
mineraddress=self.minerurl_input.text,
mineruser=self.mineruser_input.text,
minerpw=self.minerpw_input.text,
minerthreads=self.minerthreads_input.text)
示例4: ScoreBar
# 需要导入模块: from kivy.storage.jsonstore import JsonStore [as 别名]
# 或者: from kivy.storage.jsonstore.JsonStore import put [as 别名]
class ScoreBar(BoxLayout):
score = NumericProperty()
hi_score = NumericProperty()
game_id = StringProperty()
players = NumericProperty()
active_player = NumericProperty()
def __init__(self,**kwargs):
super(ScoreBar,self).__init__(**kwargs)
self.store = JsonStore(os.path.join(get_user_path(),'scores.json'))
self.bind(score = self.score_changed)
self.set_game_id()
def set_game_id(self, game_id = 'default', multiplayer = False):
self.players = int(multiplayer) + 1
self.active_player = 1
self.game_id = game_id
if self.players == 1:
if self.store.exists(game_id):
data = self.store.get(game_id)
self.hi_score = data['high_score']
else:
self.hi_score = 0
def score_changed(self, *args):
if self.players == 2:
return
if self.game_id != 'default':
date = uspac.fromutc(datetime.datetime.utcnow())
game_id = 'd%i%i%i'%(date.year, date.month, date.day)
if self.game_id != game_id:
#daily challenge has finished, the game reverts to default type so we only update the default high score table
self.set_game_id()
else:
#store the high score in the default table as well as in the daily table
hi_score = 0
if self.store.exists('default'):
data = self.store.get('default')
hi_score = data['high_score']
if self.score > hi_score:
self.store.put('default',high_score=int(self.score))
if self.score > self.hi_score:
self.hi_score = self.score
self.store.put(self.game_id,high_score=int(self.score))
if platform == 'android' and self.players == 1:
if self.score > 600:
App.get_running_app().gs_achieve('achievement_score_of_600')
if self.score > 800:
App.get_running_app().gs_achieve('achievement_score_of_800')
if self.score > 1000:
App.get_running_app().gs_achieve('achievement_score_of_1000')
if self.score > 1200:
App.get_running_app().gs_achieve('achievement_score_of_1200')
示例5: UrbanRoot
# 需要导入模块: from kivy.storage.jsonstore import JsonStore [as 别名]
# 或者: from kivy.storage.jsonstore.JsonStore import put [as 别名]
class UrbanRoot(BoxLayout):
urbansearch = ObjectProperty()
urbandict = ObjectProperty()
def __init__(self, **kwargs):
super(UrbanRoot, self).__init__(**kwargs)
self.store = JsonStore("dictionary.json")
self.update_urbandict()
def add_to_dictionary(self, word, definition, example):
current = self.store.get('dictionary')['dictionary'] if self.store.exists('dictionary') else []
d = {
'word' : word.encode('utf-8'),
'definition' : definition.encode('utf-8'),
'example' : example.encode('utf-8')
}
if d not in current:
current.append(d)
self.store.put('dictionary', dictionary = list(current))
self.update_urbandict()
Popup(size_hint=(0.8,0.2),title='Success', content = Label(text = 'Word has been added into dictionary')).open()
def update_urbandict(self):
current = self.store.get('dictionary')['dictionary'] if self.store.exists('dictionary') else []
self.urbandict.urbandictcontainer.clear_widgets()
for d in current:
item = Factory.UrbanItemDict()
item.word = d['word'].encode('utf-8')
item.definition = d['definition'].replace('\r','').replace('\t','').encode('utf-8')
item.example = d['example'].replace('\r','').replace('\t','').encode('utf-8')
self.urbandict.urbandictcontainer.add_widget(item)
def remove_from_dict(self, word, definition, example):
current = self.store.get('dictionary')['dictionary'] if self.store.exists('dictionary') else []
d = {
'word' : word.encode('utf-8'),
'definition' : definition.encode('utf-8'),
'example' : example.encode('utf-8')
}
if d in current:
current.remove(d)
self.store.put('dictionary', dictionary = list(current))
print 'removed'
self.update_urbandict()
示例6: MainApp
# 需要导入模块: from kivy.storage.jsonstore import JsonStore [as 别名]
# 或者: from kivy.storage.jsonstore.JsonStore import put [as 别名]
class MainApp(App):
#create the application screens
def build(self):
data_dir = getattr(self, 'user_data_dir') #get a writable path to save our score
self.store = JsonStore(join(data_dir, 'score.json')) # create a JsonScore file in the available location
if(not self.store.exists('score')): # if there is no file, we need to save the best score as 1
self.store.put('score', best=1)
if platform() == 'android': # if we are on Android, we can initialize the ADs service
revmob.start_session('54c247f420e1fb71091ad44a')
self.screens = {} # list of app screens
self.screens['menu'] = MenuScreen(self) #self the MainApp instance, so others objects can change the screen
self.screens['game'] = GameScreen(self)
self.root = FloatLayout()
self.open_screen('menu')
self.sound = SoundLoader.load('res/background.mp3') # open the background music
# kivy support music loop, but it was not working on Android. I coded in a different way to fix it
# but if fixed, we can just set the loop to True and call the play(), so it'll auto repeat
# self.sound.loop = True It # was not working on android, so I wrote the following code:
self.sound.play() # play the sound
Clock.schedule_interval(self.check_sound, 1) #every second force the music to be playing
return self.root
# play the sound
def check_sound(self, dt = None):
self.sound.play()
# when the app is minimized on Android
def on_pause(self):
self.sound.stop() # the stop the sound
Clock.unschedule(self.check_sound)
if platform() == 'android': #if on android, we load an ADs and show it
revmob.show_popup()
return True
# when the app is resumed
def on_resume(self):
self.sound.play() # we start the music again
Clock.schedule_interval(self.check_sound, 1)
# show a new screen.
def open_screen(self, name):
self.root.clear_widgets() #remove the current screen
self.root.add_widget(self.screens[name]) # add a new one
self.screens[name].run() # call the run method from the desired screen
示例7: get_public_key
# 需要导入模块: from kivy.storage.jsonstore import JsonStore [as 别名]
# 或者: from kivy.storage.jsonstore.JsonStore import put [as 别名]
def get_public_key():
if DataMode.communication in KivyLogger.base_mode:
# get from communication
pub_pem = KivyLogger.socket.recv(1024)
else:
private_key = RSA.generate(2048, e=65537)
prv_pem = private_key.exportKey("PEM")
store = JsonStore(KivyLogger.filename + '.enc')
store.put('private_key', pem=prv_pem)
pub_pem = private_key.publickey().exportKey("PEM")
KivyLogger.public_key = RSA.importKey(pub_pem)
pass
示例8: on_pre_leave
# 需要导入模块: from kivy.storage.jsonstore import JsonStore [as 别名]
# 或者: from kivy.storage.jsonstore.JsonStore import put [as 别名]
def on_pre_leave(self, *args):
if len(self.haberadi.text)<3 and len(self.takmaadi.text)<3:
return
js=JsonStore("UmutRss.json")
fst=True
url_str="{"
for k,v in self.urls.items():
if fst:
url_str +=k+":"+v
fst=False
else:
url_str += ","+k + ":" + v
url_str +="}"
js.put(self.haberadi.text,title=self.takmaadi.text,url=url_str)
示例9: ReGalData
# 需要导入模块: from kivy.storage.jsonstore import JsonStore [as 别名]
# 或者: from kivy.storage.jsonstore.JsonStore import put [as 别名]
class ReGalData(object):
servertypes = [
import_module('regallery.servers.piwigo').ReGalServerPiwigo
]
@staticmethod
def get_servertypes():
'''Returns a list with all valids server types'''
return [cls.name for cls in ReGalData.servertypes]
@staticmethod
def get_sever(_type, url, user, pw):
'''
Get new instance of a server
_type - type from get_servertypes()
url - base url for server
user - username
pw - password
'''
for cls in ReGalData.servertypes:
if cls.name == _type:
return cls(url, user, pw)
raise LookupError()
def __init__(self):
self._app = App.get_running_app()
serverconfig = os.path.join(self._app.user_data_dir, 'servers.json')
self._servers = JsonStore(serverconfig)
def add_server(self, url, name, username, password):
self._servers.put(name, url=url, username=username, password=password)
def get_servers(self):
servers = {}
for name in self._servers:
servers[name] = self._servers.get(name)
return servers
示例10: ClockApp
# 需要导入模块: from kivy.storage.jsonstore import JsonStore [as 别名]
# 或者: from kivy.storage.jsonstore.JsonStore import put [as 别名]
class ClockApp(App):
clearcolor = (0,0,0,1)
def __init__(self,**kwargs):
super(ClockApp,self).__init__(**kwargs)
from os.path import join
self.store = JsonStore(join(self.user_data_dir,"clockalarm.json"))
def build(self):
root = ClockWidget()
root.init_alarms()
self.root=root
return self.root
def on_pause(self):
return True
def on_resume(self):
pass
def get_alarm_from_store(self,id):
if self.store.exists("alarms"):
try:
return self.store.get("alarms")["a{}".format(id)]
except:
return None
def set_alarm_to_store(self,id,alarm):
allAlarms = {}
for i in range(1,5):
if i == int(id):
allAlarms["{}".format(i)]=alarm
else:
allAlarms["{}".format(i)]=app.get_alarm_from_store("{}".format(i))
self.store.put("alarms",a1=allAlarms["1"],a2=allAlarms["2"],a3=allAlarms["3"],a4=allAlarms["4"])
示例11: Settings
# 需要导入模块: from kivy.storage.jsonstore import JsonStore [as 别名]
# 或者: from kivy.storage.jsonstore.JsonStore import put [as 别名]
class Settings(object):
MIN_TOASTING_TIME = 10
MAX_TOASTING_TIME = 600
FILENAME = 'sofatech_toaster_storage'
SETTINGS_KEY = 'settings'
def __init__(self):
self._ip = '127.0.0.1'
self._port = 50007
self._store = JsonStore(Settings.FILENAME)
@property
def ip(self):
return self._ip
@ip.setter
def ip(self, value):
self._ip = value
@property
def port(self):
return self._port
@port.setter
def port(self, value):
self._port = value
def load(self):
if self._store.exists(Settings.SETTINGS_KEY):
settings_dict = self._store.get(Settings.SETTINGS_KEY)
self._ip = settings_dict['ip']
self._port = settings_dict['port']
def save(self):
self._store.put(Settings.SETTINGS_KEY, ip=self._ip, port=self._port)
示例12: addStory
# 需要导入模块: from kivy.storage.jsonstore import JsonStore [as 别名]
# 或者: from kivy.storage.jsonstore.JsonStore import put [as 别名]
class addStory(object):
'''
This class is used for adding story to the game
Syntax for the story is a key based dictionary, these keys are hexadacimal numbers
that will be used to track progress. Starting point is 1, so if scenario 1 had 3
possible options then there would be 11, 12, and 13. If 13 had 2 options then it would
be 131, and 132. This will continue until there is a string of 16 characters
basic syntax: {key
'''
def __init__(self):
self.File = raw_input("Which story would you like to edit?\n\n").lower()
self.data = JsonStore(self.File + '.json')
self.start = 1 #default start code
if self.data.count(): #If file has been started
print '\nLooking for where you left off...\n'
keys = self.data.keys()
leftOff = int(keys[len(keys) - 1])
print ('It seems like you left off at event number'
' %d, so let\'s move on to number %d.'
% (leftOff, leftOff + 1)
)
self.start = leftOff
self.addToDBLoop(self.start)
def addToDBLoop(self, number):
event = raw_input('What is event number %d?\n' % number).lower()
optionsStr = raw_input(('What are the available options for player?\n'
'If none just type \'none\'.\n')).lower().split()
c = 0
options = {}
for o in optionsStr:
c += 1
options[o] = str(number) + str(c)
self.data.put(str(number), event = event, options = options)
示例13: LoginScreen
# 需要导入模块: from kivy.storage.jsonstore import JsonStore [as 别名]
# 或者: from kivy.storage.jsonstore.JsonStore import put [as 别名]
class LoginScreen(Screen):
store=''
username=''
def __init__(self,**kwargs):
super(LoginScreen, self).__init__(**kwargs)
Clock.schedule_once(self.update_layout,1/60)
def update_layout(self,btn):
data_dir= App.get_running_app().user_data_dir+'/'
self.store = JsonStore(join(data_dir, 'storage.json'))
try:
self.username=self.store.get('credentials')['username']
exp_data.set_username(self.username)
self.parent.current = 'ExperimentSelectScreen'
except KeyError:
box=BoxLayout(orientation= 'vertical',padding=(100,100,100,100))
#l=Label(size_hint_y=0.25)
#box.add_widget(l)
box.add_widget(Label(text="Enter email",font_size= sp(30),size_hint_y=.5))
self.t=TextInput(font_size= sp(30),size_hint_y=0.5)
box.add_widget(self.t)
box.add_widget(Button(text="Okay",on_press=self.change_screen,font_size=sp(25),size_hint_y=.25))
#box.add_widget(l)
self.add_widget(box)
# #AppScreen.store.put('credentials', username=username, password=password)
def change_screen(self,btn):
if len(self.t.text) == 0: #deal with exception here of not selecting a single experiment
error_popup=Popup(title='Error',content=Label(text="Email cannot be left blank")\
,size_hint=(.75,.75),auto_dismiss=True)
error_popup.open()
Clock.schedule_interval(error_popup.dismiss, 3)
else:
self.store.put('credentials', username=self.t.text)
self.username=self.store.get('credentials')['username']
exp_data.set_username(self.username)
self.parent.current = 'ExperimentSelectScreen'
示例14: __int__
# 需要导入模块: from kivy.storage.jsonstore import JsonStore [as 别名]
# 或者: from kivy.storage.jsonstore.JsonStore import put [as 别名]
def __int__(self, **kwargs):
super().__init__(**kwargs)
store = JsonStore('hello.json')
#put some values
store.put('tito', name='Mathieu', org='kivy')
store.put('tshirtman', name='Gabriel', age=27)
store.put('tito', name='Mathieu', age=30)
print('tito is', store.get('tito')['age'])
示例15: __init__
# 需要导入模块: from kivy.storage.jsonstore import JsonStore [as 别名]
# 或者: from kivy.storage.jsonstore.JsonStore import put [as 别名]
def __init__(self,**kwargs):
super(MainScreen,self).__init__(**kwargs)
js=JsonStore(filename="UmutRss.json")
js.put("current_rss",title=u"Haber Türk",url={"gundem": "http://www.haberturk.com/rss/manset.xml",
"siyaset": "http://www.haberturk.com/rss/siyaset.xml",
"dunya": "http://www.haberturk.com/rss/dunya.xml",
"yasam": "http://www.haberturk.com/rss/yasam.xml",
"sanat": "http://www.haberturk.com/rss/kultur-sanat.xml",
"ekonomi": "http://www.haberturk.com/rss/ekonomi.xml",
"spor": "http://www.haberturk.com/rss/spor.xml"})
js.put("Sabah",title="Sabah",url={"gundem": "http://www.sabah.com.tr/rss/gundem.xml",
"saglik": "http://www.sabah.com.tr/rss/saglik.xml",
"dunya": "http://www.sabah.com.tr/rss/dunya.xml",
"sanat": "http://www.sabah.com.tr/rss/kultur_sanat.xml",
"ekonomi": "http://www.sabah.com.tr/rss/ekonomi.xml",
"spor": "http://www.sabah.com.tr/rss/spor.xml",
"yasam": "http://www.sabah.com.tr/rss/yasam.xml",
"oyun": "http://www.sabah.com.tr/rss/oyun.xml",
"sondakika": "http://www.sabah.com.tr/rss/sondakika.xml",
"teknoloji": "http://www.sabah.com.tr/rss/teknoloji.xml"})
js.put("BBC",title="BBC",url={"gundem": "http://feeds.bbci.co.uk/turkce/rss.xml"
})
js.put("Cmh",title="Cumhuriyet",url={"egitim":"http://www.cumhuriyet.com.tr/rss/18.xml",
"yasam":"http://www.cumhuriyet.com.tr/rss/10.xml",
"sanat":"http://www.cumhuriyet.com.tr/rss/7.xml",
"dunya":"http://www.cumhuriyet.com.tr/rss/5.xml",
"sondakika":"http://www.cumhuriyet.com.tr/rss/son_dakika.xml",
"gundem":"http://www.cumhuriyet.com.tr/rss/1.xml"
})
js.put("AHaber",title="A Haber",url={"gundem": "http://www.ahaber.com.tr/rss/gundem.xml",
"ekonomi": "http://www.ahaber.com.tr/rss/ekonomi.xml",
"spor": "http://www.ahaber.com.tr/rss/spor.xml",
"saglik": "http://www.ahaber.com.tr/rss/saglik.xml",
"dunya": "http://www.ahaber.com.tr/rss/dunya.xml",
"manset": "http://www.ahaber.com.tr/rss/haberler.xml",
"yasam": "http://www.ahaber.com.tr/rss/yasam.xml",
"anasayfa": "http://www.ahaber.com.tr/rss/anasayfa.xml",
"ozelhaber": "http://www.ahaber.com.tr/rss/ozel-haberler.xml",
"teknoloji": "http://www.ahaber.com.tr/rss/teknoloji.xml"
})
titles=JsonStore(filename="titles.json")
titles.put("titles",all={"gundem":u"Gündem","egitim":u"Eğitim","dunya":u"Dünya","sanat":u"Sanat",
"ekonomi":u"Ekonomi","spor":u"Spor","saglik":u"Sağlık","yasam":u"Yaşam",
"oyun":u"Oyun","sondakika":u"Son Dakika","teknoloji":u"Teknoloji",
"basinozeti":u"Basın Özeti","ozelhaber":u"Özel Haber","anasayfa":"Anasayfa",
"turkiye":u"Türkiye","siyaset":"Siyaset","manset":u"Manşet"})