本文整理汇总了Python中kivy.config.ConfigParser.set方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigParser.set方法的具体用法?Python ConfigParser.set怎么用?Python ConfigParser.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.config.ConfigParser
的用法示例。
在下文中一共展示了ConfigParser.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DesignerSettings
# 需要导入模块: from kivy.config import ConfigParser [as 别名]
# 或者: from kivy.config.ConfigParser import set [as 别名]
class DesignerSettings(Settings):
'''Subclass of :class:`kivy.uix.settings.Settings` responsible for
showing settings of Kivy Designer.
'''
config_parser = ObjectProperty(None)
'''Config Parser for this class. Instance
of :class:`kivy.config.ConfigParser`
'''
def load_settings(self):
'''This function loads project settings
'''
self.config_parser = ConfigParser()
DESIGNER_CONFIG = os.path.join(get_kivy_designer_dir(),
DESIGNER_CONFIG_FILE_NAME)
_dir = os.path.dirname(designer.__file__)
_dir = os.path.split(_dir)[0]
DEFAULT_CONFIG = os.path.join(_dir, DESIGNER_CONFIG_FILE_NAME)
if not os.path.exists(DESIGNER_CONFIG):
shutil.copyfile(DEFAULT_CONFIG,
DESIGNER_CONFIG)
self.config_parser.read(DESIGNER_CONFIG)
self.config_parser.upgrade(DEFAULT_CONFIG)
self.add_json_panel('Kivy Designer Settings', self.config_parser,
os.path.join(_dir, 'designer',
'settings', 'designer_settings.json'))
path = self.config_parser.getdefault(
'global', 'python_shell_path', '')
if path == "":
self.config_parser.set('global', 'python_shell_path',
sys.executable)
self.config_parser.write()
def on_config_change(self, *args):
'''This function is default handler of on_config_change event.
'''
self.config_parser.write()
super(DesignerSettings, self).on_config_change(*args)
示例2: on_new
# 需要导入模块: from kivy.config import ConfigParser [as 别名]
# 或者: from kivy.config.ConfigParser import set [as 别名]
def on_new(self, *args):
'''Handler for "New Profile" button
'''
new_name = 'new_profile'
i = 1
while os.path.exists(os.path.join(
self.PROFILES_PATH, new_name + str(i) + '.ini')):
i += 1
new_name += str(i)
new_prof_path = os.path.join(
self.PROFILES_PATH, new_name + '.ini')
shutil.copy2(os.path.join(self.DEFAULT_PROFILES, 'desktop.ini'),
new_prof_path)
config_parser = ConfigParser()
config_parser.read(new_prof_path)
config_parser.set('profile', 'name', new_name.upper())
config_parser.write()
self.update_panel()
self.settings_changed = True
示例3: AddCardMenuScreen
# 需要导入模块: from kivy.config import ConfigParser [as 别名]
# 或者: from kivy.config.ConfigParser import set [as 别名]
class AddCardMenuScreen(Screen):
question = ""
answer = ""
def __init__(self):
Screen.__init__(self)
self.name = "add"
self.config = ConfigParser()
self.config.add_section("add")
self.config.set("add", "question", "Question")
self.config.set("add", "answer", "Answer")
self.config.set("add", "make", "action")
self.config.add_callback(self.update_qa, section="add", key="question")
self.config.add_callback(self.update_qa, section="add", key="answer")
self.menu = SettingsWithNoMenu()
self.menu.register_type("action", FlashcardAppManager.SettingDoAction)
self.menu.add_json_panel("Add a card", self.config, os.path.join(os.path.dirname(__file__), 'add_menu.json'))
self.add_widget(self.menu)
def update_qa(self, *args):
FlashcardAppManager.AddCardMenuScreen.question = self.config.get('add', 'question')
FlashcardAppManager.AddCardMenuScreen.answer = self.config.get('add', 'answer')
示例4: DesignerSettings
# 需要导入模块: from kivy.config import ConfigParser [as 别名]
# 或者: from kivy.config.ConfigParser import set [as 别名]
class DesignerSettings(Settings):
"""Subclass of :class:`kivy.uix.settings.Settings` responsible for
showing settings of Kivy Designer.
"""
config_parser = ObjectProperty(None)
"""Config Parser for this class. Instance
of :class:`kivy.config.ConfigParser`
"""
def load_settings(self):
"""This function loads project settings
"""
self.config_parser = ConfigParser()
DESIGNER_CONFIG = os.path.join(get_kivy_designer_dir(), DESIGNER_CONFIG_FILE_NAME)
_dir = os.path.dirname(designer.__file__)
_dir = os.path.split(_dir)[0]
if not os.path.exists(DESIGNER_CONFIG):
shutil.copyfile(os.path.join(_dir, DESIGNER_CONFIG_FILE_NAME), DESIGNER_CONFIG)
self.config_parser.read(DESIGNER_CONFIG)
self.add_json_panel(
"Kivy Designer Settings",
self.config_parser,
os.path.join(_dir, "designer", "settings", "designer_settings.json"),
)
path = self.config_parser.getdefault("global", "python_shell_path", "")
if path == "":
self.config_parser.set("global", "python_shell_path", sys.executable)
self.config_parser.write()
def on_config_change(self, *args):
"""This function is default handler of on_config_change event.
"""
self.config_parser.write()
super(DesignerSettings, self).on_config_change(*args)
示例5: update
# 需要导入模块: from kivy.config import ConfigParser [as 别名]
# 或者: from kivy.config.ConfigParser import set [as 别名]
def update(self):
"""
add data to Category settings
retrieves data from database for a particular 'catid'
"""
#/// add data ///
self.clear_widgets()
#define structure of fields (like an INI file)
config = ConfigParser()
config.add_section('category')
config.add_section('icon_file')
#--- set values (needs to come from database)
#config.set('category','category_name','TestnameID: ' + str(self.catid))
if self.data == None:
config.set('category','category_name','Enter your category name here')
else:
config.set('category','category_name',self.data['name'])
config.set('icon_file','icon_file','Testpath') #todo:how to deal with image data ???
return config
示例6: EditCardMenuScreen
# 需要导入模块: from kivy.config import ConfigParser [as 别名]
# 或者: from kivy.config.ConfigParser import set [as 别名]
class EditCardMenuScreen(Screen):
question = ""
answer = ""
nquestion = ""
nanswer = ""
EditCardMenuConfig = None
def update_qa(self, *args):
FlashcardAppManager.EditCardMenuScreen.nquestion = self.config.get('edit', 'nquestion')
FlashcardAppManager.EditCardMenuScreen.nanswer = self.config.get("edit", "nanswer")
def __init__(self):
Screen.__init__(self)
self.name = "edit"
self.config = ConfigParser()
self.config.add_section("edit")
self.config.set("edit", "question", "Question")
self.config.set("edit", "answer", "Answer")
self.config.set("edit", "nquestion", "Question")
self.config.set("edit", "nanswer", "Answer")
self.config.set("edit", "edit", "action")
FlashcardAppManager.EditCardMenuScreen.question = self.config.get('edit', 'question')
FlashcardAppManager.EditCardMenuScreen.answer = self.config.get('edit', 'answer')
FlashcardAppManager.EditCardMenuScreen.nquestion = self.config.get('edit', 'nquestion')
FlashcardAppManager.EditCardMenuScreen.nanswer = self.config.get('edit', 'nanswer')
self.config.add_callback(self.update_qa, section="edit", key="nquestion")
self.config.add_callback(self.update_qa, section="edit", key="nanswer")
self.menu = SettingsWithNoMenu()
self.menu.register_type("action", FlashcardAppManager.SettingDoAction)
self.menu.add_json_panel("Add a card", self.config, os.path.join(os.path.dirname(__file__), 'edit_menu.json'))
FlashcardAppManager.EditCardMenuScreen.EditCardMenuConfig = self.config
self.add_widget(self.menu)
def on_pre_enter(self, *args):
FlashcardAppManager.EditCardMenuScreen.question = FlashcardAppManager.deck_widget.deck.get_selected().get_question()
FlashcardAppManager.EditCardMenuScreen.answer = FlashcardAppManager.deck_widget.deck.get_selected().get_answer()
self.config.set("edit", "question", FlashcardAppManager.EditCardMenuScreen.question)
self.config.set("edit", "answer", FlashcardAppManager.EditCardMenuScreen.answer)
示例7: MenuScreen
# 需要导入模块: from kivy.config import ConfigParser [as 别名]
# 或者: from kivy.config.ConfigParser import set [as 别名]
class MenuScreen(Screen):
def __init__(self):
Screen.__init__(self)
self.name = 'menu'
self.config = ConfigParser()
self.config.add_section("deck")
self.config.add_section("card")
self.config.adddefaultsection("menu")
self.config.set("deck", "start_studying", 1)
self.config.set("deck", "change_deck_mode", "Normal")
self.config.set("deck", "show_list", True)
self.config.set("deck", "undo", True)
self.config.set("deck", "redo", True)
self.config.set("card", "add", "")
self.config.set("card", "edit", True)
self.config.set("card", "remove", True)
self.config.add_callback(self.check_deck_locks, "deck", "redo")
self.config.add_callback(self.check_deck_locks, "deck", "undo")
self.config.add_callback(self.check_card_locks, "card", "edit")
self.config.add_callback(self.check_card_locks, "card", "add")
self.menu = SettingsWithNoMenu()
self.menu.register_type("screen", FlashcardAppManager.SettingNewScreen)
self.menu.register_type("action", FlashcardAppManager.SettingDoAction)
self.menu.add_json_panel("Flashcards", self.config, os.path.join(os.path.dirname(__file__), 'menu.json'))
self.add_widget(self.menu)
def check_deck_locks(self, section, key, value):
print(self.config.get(section, key))
def check_card_locks(self, section, key, value):
print()
示例8: Program
# 需要导入模块: from kivy.config import ConfigParser [as 别名]
# 或者: from kivy.config.ConfigParser import set [as 别名]
class Program(App, prog_class.ShowPlugin, prog_class.ShowThemesForum,
prog_class.ShowSectionsForum, prog_class.ShowSendMailForm,
prog_class.ShowTopicsForum, prog_class.ShowListMail,
prog_class.ShowFileDetails, prog_class.ShowUploadForm,
prog_class.ShowFiles, prog_class.ShowUserProfile,
ConnectionToServer):
"""Функционал программы."""
# Языковая локализация - переменные с префиксом core.string_lang_.
# Используются в классах библиотеки programclass. В текущем классе -
# без ключевого слова self, так как были импортированы из programdata
exec(open("{}/Data/Language/{}.txt".format(
core.prog_path, language)).read().replace(
"#key_text_color", core.theme_key_text_color.encode("u8")).replace(
"#text_color", core.theme_text_color.encode("u8")).replace(
"#link_color", core.theme_link_color.encode("u8")))
# TODO: Константа CONST_SCREEN используется модулем kdialog для
# вычесления ширины диалогового окна (Window.size[0] / CONST_SCREEN).
# size_hint_x для этих целей неуместен. Например, при размере экрана
# 600x300 и параметре size_hint_x=.5 окно будет слишком
# узким и наоборот - 300x600 и тот же параметр size_hint_x - покажут окно
# занимаемое бОльшую плоскость экрана.
WIDTH, HEIGHT = Window.size
if WIDTH <= HEIGHT:
CONST_SCREEN = 1.2
else:
CONST_SCREEN = 2
window_text_size = 15
update = None # нет обновлений
messages_unread = None # количество новых сообщений
open_dialog = False # если True - открыто диалоговое окно
number_user = None # номер участника на сайте
cookie = None
site = "http://m.dimonvideo.ru"
previous_screen = None
def __init__(self, **kvargs):
super(Program, self).__init__(**kvargs)
Window.bind(on_keyboard=self.events_program)
# Для области видимомти в programclass.
self.FadeTransition = FadeTransition
self.Screen = Screen
self.Clock = Clock
# ----------------------------------
self.parsing_xml = parsing_xml
self.get_page = get_page
self.set_cookie = set_cookie
self.Manifest = Manifest
self.core = core
# ----------------------------------
self.sendmail = sendmail
self.setattachtoforum = setattachtoforum
# ----------------------------------
self.KDialog = KDialog
self.FileChooser = FileChooser
self.SelectColor = SelectColor
self.CustomSpinner = CustomSpinner
self.PageSendMail = PageSendMail
self.ScrollButton = ScrollButton
self.ThemesForum = ThemesForum
self.AboutDialog = AboutDialog
self.UploadFiles = UploadFiles
self.MessageViewer = MessageViewer
self.MailList = MailList
self.BugReporter = BugReporter
self.ImageViewer = ImageViewer
self.customspinner = customspinner
self._urllib = _urllib
self.traceback = traceback
# ----------------------------------
self.clipboard = clipboard
# ----------------------------------
self.theme_decorator_window = core.theme_decorator_window
def get_application_config(self):
return super(Program, self).get_application_config(
"{}/program.ini".format(core.prog_path))
def build_config(self, config):
config.adddefaultsection("General")
config.setdefault("General", "showonstartpage", u"Новости сайта")
config.setdefault("General", "language", u"Русский")
config.setdefault("General", "showwarning", "1")
config.setdefault("General", "resmessages", "1")
config.setdefault("General", "authorization", "0")
config.setdefault("General", "progresstextsize", "15")
config.setdefault("General", "downloadkey", "0")
config.setdefault("General", "downloadfolder",
{0: 'Downloads', 1: ''})
config.setdefault("General", "user_reg",
{"login": "login", "password": "password"})
config.adddefaultsection("Network")
config.setdefault("Network", "authoconnect", "0")
config.setdefault("Network", "checkattachtoforum", "1")
config.setdefault("Network", "loadscr", "0")
config.setdefault("Network", "authoupdate", "1")
#.........这里部分代码省略.........
示例9: DictionaryApp
# 需要导入模块: from kivy.config import ConfigParser [as 别名]
# 或者: from kivy.config.ConfigParser import set [as 别名]
class DictionaryApp(App):
def __init__(self, **kwargs):
super(DictionaryApp, self).__init__(**kwargs)
global i, unerwuenscht, invalsettings, status, durchlauf, bu_pfad
invalsettings = True
self.config = ConfigParser()
# Zaehler um anzuzueigen, wie viele Vokabeln in Dict
i = 0
status = "main"
# Abfragedurchlauf Initialisieren
anzahl = "0"
durchlauf = 0
# unerwuenschte Zeichen
unerwuenscht = "[(?!:;.1234567890)+-]"
# switch off Kivy_settings
self.use_kivy_settings = False
# Directory for Backups
if platform == "android":
bu_pfad = "/sdcard/backups/voctrainer/"
try:
if not os.path.exists(bu_pfad):
os.makedirs(bu_pfad)
except:
bu_pfad = "../backups/voctrainer/"
os.makedirs(bu_pfad)
else:
bu_pfad = "../backups/voctrainer/"
if not os.path.exists(bu_pfad):
os.makedirs(bu_pfad)
def build(self):
self.root = DictionaryRoot()
# init the variables for search-query
self.take_from_build_away()
self.title = "Voc-Trainer"
return self.root
# this needs to be separated from def build(); otherwise you get problems when running
# from def on_config_change()
def take_from_build_away(self):
global learn_lang, mother_lang, return_lang, lang_learn, lang_mother, lang_return, invalsettings, dictlist, dateiname, ersatz_pfad
# capture error on android
self.build_config(self.config)
# get values from settingsmenu
learn_lang = self.config.get("languages", "learnlanguage")
mother_lang = self.config.get("languages", "motherlanguage")
return_lang = self.config.get("languages", "returnlanguage")
## load backupfile
try:
# dateiname bei erstem durchlauf noch nicht konfiguriert --> Error
# check language of backupfile
if not ersatz_pfad[ersatz_pfad.find("VOC_TR_"):] == dateiname:
raise
# get data in backupfile
open_dict = DateiHandling()
# overwrite global variable dictlist
dictlist = open_dict.oeffnen(ersatz_pfad)
open_dict.schreiben_datei(dateiname, dictlist)
ersatz_pfad = ""
# reset backuppath
except:
pass
# reset backuppath
try:
self.config.read("dictionary.ini")
# reset path
self.config.set("languages", "backuppath", bu_pfad)
except:
pass
# exception handler neccessary because of opening app after having made
# backup causes issues
try:
if self.config.get("languages", "makebackup") == "yes" and len(dictlist) != 0:
Backup()
except:
pass
# reset settings
self.config.set("languages", "makebackup", "no")
# get varibles for search-query
lang_learn, lang_mother, lang_return = self.init_variables(learn_lang, mother_lang, return_lang)
#.........这里部分代码省略.........
示例10: UserPrefs
# 需要导入模块: from kivy.config import ConfigParser [as 别名]
# 或者: from kivy.config.ConfigParser import set [as 别名]
class UserPrefs(EventDispatcher):
'''
A class to manage user preferences for the RaceCapture app
'''
DEFAULT_DASHBOARD_SCREENS = ['5x_gauge_view', 'laptime_view', 'tach_view', 'rawchannel_view']
DEFAULT_PREFS_DICT = {'range_alerts': {},
'gauge_settings':{},
'screens':DEFAULT_DASHBOARD_SCREENS,
'alerts': {}}
DEFAULT_ANALYSIS_CHANNELS = ['Speed']
prefs_file_name = 'prefs.json'
def __init__(self, data_dir, user_files_dir, save_timeout=0.2, **kwargs):
self._prefs_dict = UserPrefs.DEFAULT_PREFS_DICT
self.config = ConfigParser()
self.data_dir = data_dir
self.user_files_dir = user_files_dir
self.prefs_file = path.join(self.data_dir, self.prefs_file_name)
self.register_event_type("on_pref_change")
self.load()
def on_pref_change(self, section, option, value):
pass
def set_range_alert(self, key, range_alert):
'''
Sets a range alert with the specified key
:param key the key for the range alert
:type string
:param range_alert the range alert
:type object
'''
self._prefs_dict["range_alerts"][key] = range_alert
self.save()
def get_range_alert(self, key, default=None):
'''
Retrives a range alert for the specified key
:param key the key for the range alert
:type key string
:param default the default value, optional
:type default user specified
:return the range alert, or the default value
'''
return self._prefs_dict["range_alerts"].get(key, default)
def get_alertrules(self, channel):
'''
Retrieve the alert_rules for the specified channel. If the
alertrules do not exist for the specified channel, return an empty
default AlertRuleCollection
:return AlertRuleCollection
'''
alertrules = self._prefs_dict['alerts'].get(channel)
if alertrules is None:
alertrules = AlertRuleCollection(channel, [])
self._prefs_dict['alerts'][channel] = alertrules
return alertrules
def set_alertrules(self, channel, alertrules):
self._prefs_dict['alerts'][channel] = alertrules
self.save()
def set_gauge_config(self, gauge_id, config_value):
'''
Stores a gauge configuration for the specified gauge_id
:param gauge_id the key for the gauge
:type gauge_id string
:param config_value the configuration value to set
:type config_value string
'''
self._prefs_dict["gauge_settings"][gauge_id] = config_value
self.save()
def get_gauge_config(self, gauge_id):
'''
Get the gauge configuration for the specified gauge_id
:param gauge_id the key for the gauge
:type string
:return the gauge configuration
'''
return self._prefs_dict["gauge_settings"].get(gauge_id, False)
def get_dashboard_screens(self):
return copy(self._prefs_dict['screens'])
def set_dashboard_screens(self, screens):
self._prefs_dict['screens'] = copy(screens)
self.save()
# Regular preferences below here
def get_last_selected_track_id(self):
return self.get_pref('track_detection', 'last_selected_track_id')
def get_last_selected_track_timestamp(self):
#.........这里部分代码省略.........
示例11: UserPrefs
# 需要导入模块: from kivy.config import ConfigParser [as 别名]
# 或者: from kivy.config.ConfigParser import set [as 别名]
class UserPrefs(EventDispatcher):
'''
A class to manage user preferences for the RaceCapture app
'''
_schedule_save = None
_prefs_dict = {'range_alerts': {}, 'gauge_settings':{}}
store = None
prefs_file_name = 'prefs.json'
prefs_file = None
config = None
data_dir = '.'
user_files_dir = '.'
def __init__(self, data_dir, user_files_dir, save_timeout=2, **kwargs):
self.data_dir = data_dir
self.user_files_dir = user_files_dir
self.prefs_file = path.join(self.data_dir, self.prefs_file_name)
self.load()
self._schedule_save = Clock.create_trigger(self.save, save_timeout)
def set_range_alert(self, key, range_alert):
'''
Sets a range alert with the specified key
:param key the key for the range alert
:type string
:param range_alert the range alert
:type object
'''
self._prefs_dict["range_alerts"][key] = range_alert
self._schedule_save()
def get_range_alert(self, key, default=None):
'''
Retrives a range alert for the specified key
:param key the key for the range alert
:type key string
:param default the default value, optional
:type default user specified
:return the range alert, or the default value
'''
return self._prefs_dict["range_alerts"].get(key, default)
def set_gauge_config(self, gauge_id, channel):
'''
Stores a gauge configuration for the specified gauge_id
:param gauge_id the key for the gauge
:type gauge_id string
:param channel the configuration for the channel
:type channel object
'''
self._prefs_dict["gauge_settings"][gauge_id] = channel
self._schedule_save()
def get_gauge_config(self, gauge_id):
'''
Get the gauge configuration for the specified gauge_id
:param gauge_id the key for the gauge
:type string
:return the gauge configuration
'''
return self._prefs_dict["gauge_settings"].get(gauge_id, False)
def get_last_selected_track_id(self):
return self.get_pref('track_detection', 'last_selected_track_id')
def get_last_selected_track_timestamp(self):
return self.get_pref_int('track_detection', 'last_selected_track_timestamp')
def set_last_selected_track(self, track_id, timestamp):
self.set_pref('track_detection', 'last_selected_track_id', track_id)
self.set_pref('track_detection', 'last_selected_track_timestamp', timestamp)
@property
def datastore_location(self):
return os.path.join(self.data_dir, 'datastore.sq3')
def save(self, *largs):
'''
Saves the current configuration
'''
with open(self.prefs_file, 'w+') as prefs_file:
data = self.to_json()
prefs_file.write(data)
def set_config_defaults(self):
'''
Set defaults for preferences
'''
# Base system preferences
self.config.adddefaultsection('help')
self.config.adddefaultsection('preferences')
self.config.setdefault('preferences', 'distance_units', 'miles')
self.config.setdefault('preferences', 'temperature_units', 'Fahrenheit')
self.config.setdefault('preferences', 'show_laptimes', 1)
self.config.setdefault('preferences', 'startup_screen', 'Home Page')
default_user_files_dir = self.user_files_dir
self.config.setdefault('preferences', 'config_file_dir', default_user_files_dir)
self.config.setdefault('preferences', 'firmware_dir', default_user_files_dir)
self.config.setdefault('preferences', 'import_datalog_dir', default_user_files_dir)
self.config.setdefault('preferences', 'first_time_setup', '1')
#.........这里部分代码省略.........
示例12: UserPrefs
# 需要导入模块: from kivy.config import ConfigParser [as 别名]
# 或者: from kivy.config.ConfigParser import set [as 别名]
class UserPrefs(EventDispatcher):
_schedule_save = None
_prefs_dict = {'range_alerts': {}, 'gauge_settings':{}}
store = None
prefs_file_name = 'prefs.json'
prefs_file = None
config = None
data_dir = '.'
user_files_dir = '.'
def __init__(self, data_dir, user_files_dir, save_timeout=2, **kwargs):
self.data_dir = data_dir
self.user_files_dir = user_files_dir
self.prefs_file = path.join(self.data_dir, self.prefs_file_name)
self.load()
self._schedule_save = Clock.create_trigger(self.save, save_timeout)
def set_range_alert(self, key, range_alert):
self._prefs_dict["range_alerts"][key] = range_alert
self._schedule_save()
def get_range_alert(self, key, default=None):
return self._prefs_dict["range_alerts"].get(key, default)
def set_gauge_config(self, gauge_id, channel):
self._prefs_dict["gauge_settings"][gauge_id] = channel
self._schedule_save()
def get_gauge_config(self, gauge_id):
return self._prefs_dict["gauge_settings"].get(gauge_id, False)
def save(self, *largs):
with open(self.prefs_file, 'w+') as prefs_file:
data = self.to_json()
prefs_file.write(data)
def set_config_defaults(self):
self.config.adddefaultsection('preferences')
self.config.setdefault('preferences', 'distance_units', 'miles')
self.config.setdefault('preferences', 'temperature_units', 'Fahrenheit')
self.config.setdefault('preferences', 'show_laptimes', 1)
self.config.setdefault('preferences', 'startup_screen', 'Home Page')
default_user_files_dir = self.user_files_dir
self.config.setdefault('preferences', 'config_file_dir', default_user_files_dir )
self.config.setdefault('preferences', 'firmware_dir', default_user_files_dir )
self.config.setdefault('preferences', 'first_time_setup', True)
self.config.setdefault('preferences', 'send_telemetry', False)
self.config.setdefault('preferences', 'last_dash_screen', 'gaugeView')
def load(self):
print("the data dir " + self.data_dir)
self.config = ConfigParser()
self.config.read(os.path.join(self.data_dir, 'preferences.ini'))
self.set_config_defaults()
self._prefs_dict = {'range_alerts': {}, 'gauge_settings':{}}
try:
with open(self.prefs_file, 'r') as data:
content = data.read()
content_dict = json.loads(content)
if content_dict.has_key("range_alerts"):
for name, settings in content_dict["range_alerts"].iteritems():
self._prefs_dict["range_alerts"][name] = Range.from_dict(settings)
if content_dict.has_key("gauge_settings"):
for id, channel in content_dict["gauge_settings"].iteritems():
self._prefs_dict["gauge_settings"][id] = channel
except Exception:
pass
def get_pref(self, section, option):
return self.config.get(section, option)
def set_pref(self, section, option, value):
self.config.set(section, option, value)
self.config.write()
def to_json(self):
data = {'range_alerts': {}, 'gauge_settings':{}}
for name, range_alert in self._prefs_dict["range_alerts"].iteritems():
data["range_alerts"][name] = range_alert.to_dict()
for id, channel in self._prefs_dict["gauge_settings"].iteritems():
data["gauge_settings"][id] = channel
return json.dumps(data)
示例13: DesignerSettings
# 需要导入模块: from kivy.config import ConfigParser [as 别名]
# 或者: from kivy.config.ConfigParser import set [as 别名]
class DesignerSettings(Settings):
"""Subclass of :class:`kivy.uix.settings.Settings` responsible for
showing settings of Kivy Designer.
"""
config_parser = ObjectProperty(None)
"""Config Parser for this class. Instance
of :class:`kivy.config.ConfigParser`
"""
def __init__(self, **kwargs):
super(DesignerSettings, self).__init__(*kwargs)
self.register_type("list", SettingList)
self.register_type("shortcut", SettingShortcut)
def load_settings(self):
"""This function loads project settings
"""
self.config_parser = ConfigParser(name="DesignerSettings")
DESIGNER_CONFIG = os.path.join(get_kivy_designer_dir(), DESIGNER_CONFIG_FILE_NAME)
_dir = os.path.dirname(designer.__file__)
_dir = os.path.split(_dir)[0]
DEFAULT_CONFIG = os.path.join(_dir, DESIGNER_CONFIG_FILE_NAME)
if not os.path.exists(DESIGNER_CONFIG):
shutil.copyfile(DEFAULT_CONFIG, DESIGNER_CONFIG)
self.config_parser.read(DESIGNER_CONFIG)
self.config_parser.upgrade(DEFAULT_CONFIG)
# creates a panel before insert it to update code input theme list
panel = self.create_json_panel(
"Kivy Designer Settings",
self.config_parser,
os.path.join(_dir, "designer", "settings", "designer_settings.json"),
)
uid = panel.uid
if self.interface is not None:
self.interface.add_panel(panel, "Kivy Designer Settings", uid)
# loads available themes
for child in panel.children:
if child.id == "code_input_theme_options":
child.items = styles.get_all_styles()
# tries to find python and buildozer path if it's not defined
path = self.config_parser.getdefault("global", "python_shell_path", "")
if path.strip() == "":
self.config_parser.set("global", "python_shell_path", sys.executable)
self.config_parser.write()
buildozer_path = self.config_parser.getdefault("buildozer", "buildozer_path", "")
if buildozer_path.strip() == "":
buildozer_path = find_executable("buildozer")
if buildozer_path:
self.config_parser.set("buildozer", "buildozer_path", buildozer_path)
self.config_parser.write()
self.add_json_panel(
"Buildozer", self.config_parser, os.path.join(_dir, "designer", "settings", "buildozer_settings.json")
)
self.add_json_panel(
"Hanga", self.config_parser, os.path.join(_dir, "designer", "settings", "hanga_settings.json")
)
self.add_json_panel(
"Keyboard Shortcuts", self.config_parser, os.path.join(_dir, "designer", "settings", "shortcuts.json")
)
def on_config_change(self, *args):
"""This function is default handler of on_config_change event.
"""
self.config_parser.write()
super(DesignerSettings, self).on_config_change(*args)
示例14: DesignerSettings
# 需要导入模块: from kivy.config import ConfigParser [as 别名]
# 或者: from kivy.config.ConfigParser import set [as 别名]
class DesignerSettings(Settings):
'''Subclass of :class:`kivy.uix.settings.Settings` responsible for
showing settings of Kivy Designer.
'''
config_parser = ObjectProperty(None)
'''Config Parser for this class. Instance
of :class:`kivy.config.ConfigParser`
'''
def __init__(self, **kwargs):
super(DesignerSettings, self).__init__(*kwargs)
self.register_type('list', SettingList)
self.register_type('shortcut', SettingShortcut)
def load_settings(self):
'''This function loads project settings
'''
self.config_parser = ConfigParser(name='DesignerSettings')
DESIGNER_CONFIG = os.path.join(get_config_dir(),
DESIGNER_CONFIG_FILE_NAME)
_dir = os.path.dirname(designer.__file__)
_dir = os.path.split(_dir)[0]
DEFAULT_CONFIG = os.path.join(_dir, DESIGNER_CONFIG_FILE_NAME)
if not os.path.exists(DESIGNER_CONFIG):
shutil.copyfile(DEFAULT_CONFIG,
DESIGNER_CONFIG)
self.config_parser.read(DESIGNER_CONFIG)
self.config_parser.upgrade(DEFAULT_CONFIG)
# creates a panel before insert it to update code input theme list
panel = self.create_json_panel('Kivy Designer Settings',
self.config_parser,
os.path.join(_dir, 'designer',
'settings', 'designer_settings.json'))
uid = panel.uid
if self.interface is not None:
self.interface.add_panel(panel, 'Kivy Designer Settings', uid)
# loads available themes
for child in panel.children:
if child.id == 'code_input_theme_options':
child.items = styles.get_all_styles()
# tries to find python and buildozer path if it's not defined
path = self.config_parser.getdefault(
'global', 'python_shell_path', '')
if path.strip() == '':
self.config_parser.set('global', 'python_shell_path',
sys.executable)
self.config_parser.write()
buildozer_path = self.config_parser.getdefault('buildozer',
'buildozer_path', '')
if buildozer_path.strip() == '':
buildozer_path = find_executable('buildozer')
if buildozer_path:
self.config_parser.set('buildozer',
'buildozer_path',
buildozer_path)
self.config_parser.write()
self.add_json_panel('Buildozer', self.config_parser,
os.path.join(_dir, 'designer', 'settings',
'buildozer_settings.json'))
self.add_json_panel('Hanga', self.config_parser,
os.path.join(_dir, 'designer', 'settings',
'hanga_settings.json'))
self.add_json_panel('Keyboard Shortcuts', self.config_parser,
os.path.join(_dir, 'designer', 'settings',
'shortcuts.json'))
def on_config_change(self, *args):
'''This function is default handler of on_config_change event.
'''
self.config_parser.write()
super(DesignerSettings, self).on_config_change(*args)
示例15: set
# 需要导入模块: from kivy.config import ConfigParser [as 别名]
# 或者: from kivy.config.ConfigParser import set [as 别名]
def set(self, *args, **kwargs):
KivyConfigParser.set(self, *args, **kwargs)
self.write()