本文整理汇总了Python中openlp.core.lib.Settings类的典型用法代码示例。如果您正苦于以下问题:Python Settings类的具体用法?Python Settings怎么用?Python Settings使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Settings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_action_different_parent
def test_add_action_different_parent(self):
"""
ActionList test - Tests the add_action method. The actions have the different parent, the same shortcuts and
both have the QtCore.Qt.WindowShortcut shortcut context set.
"""
# GIVEN: Two actions with the same shortcuts.
parent = QtCore.QObject()
action2 = QtGui.QAction(parent)
action2.setObjectName('action2')
second_parent = QtCore.QObject()
action_with_same_shortcuts2 = QtGui.QAction(second_parent)
action_with_same_shortcuts2.setObjectName('action_with_same_shortcuts2')
# Add default shortcuts to Settings class.
default_shortcuts = {
'shortcuts/action2': [QtGui.QKeySequence('c'), QtGui.QKeySequence('d')],
'shortcuts/action_with_same_shortcuts2': [QtGui.QKeySequence('d'), QtGui.QKeySequence('c')]
}
Settings.extend_default_settings(default_shortcuts)
# WHEN: Add the two actions to the action list.
self.action_list.add_action(action2, 'example_category')
self.action_list.add_action(action_with_same_shortcuts2, 'example_category')
# Remove the actions again.
self.action_list.remove_action(action2, 'example_category')
self.action_list.remove_action(action_with_same_shortcuts2, 'example_category')
# THEN: As both actions have the same shortcuts, they should be removed from one action.
assert len(action2.shortcuts()) == 2, 'The action should have two shortcut assigned.'
assert len(action_with_same_shortcuts2.shortcuts()) == 0, 'The action should not have a shortcut assigned.'
示例2: test_add_action_different_context
def test_add_action_different_context(self):
"""
ActionList test - Tests the add_action method. The actions have the different parent, the same shortcuts and
both have the QtCore.Qt.WidgetShortcut shortcut context set.
"""
# GIVEN: Two actions with the same shortcuts.
parent = QtCore.QObject()
action3 = QtGui.QAction(parent)
action3.setObjectName('action3')
action3.setShortcutContext(QtCore.Qt.WidgetShortcut)
second_parent = QtCore.QObject()
action_with_same_shortcuts3 = QtGui.QAction(second_parent)
action_with_same_shortcuts3.setObjectName('action_with_same_shortcuts3')
action_with_same_shortcuts3.setShortcutContext(QtCore.Qt.WidgetShortcut)
# Add default shortcuts to Settings class.
default_shortcuts = {
'shortcuts/action3': [QtGui.QKeySequence('e'), QtGui.QKeySequence('f')],
'shortcuts/action_with_same_shortcuts3': [QtGui.QKeySequence('e'), QtGui.QKeySequence('f')]
}
Settings.extend_default_settings(default_shortcuts)
# WHEN: Add the two actions to the action list.
self.action_list.add_action(action3, 'example_category2')
self.action_list.add_action(action_with_same_shortcuts3, 'example_category2')
# Remove the actions again.
self.action_list.remove_action(action3, 'example_category2')
self.action_list.remove_action(action_with_same_shortcuts3, 'example_category2')
# THEN: Both action should keep their shortcuts.
assert len(action3.shortcuts()) == 2, 'The action should have two shortcut assigned.'
assert len(action_with_same_shortcuts3.shortcuts()) == 2, 'The action should have two shortcuts assigned.'
示例3: __init__
def __init__(self, name, default_settings, media_item_class=None, settings_tab_class=None, version=None):
"""
This is the constructor for the plugin object. This provides an easy
way for descendent plugins to populate common data. This method *must*
be overridden, like so::
class MyPlugin(Plugin):
def __init__(self):
Plugin.__init__(self, u'MyPlugin', version=u'0.1')
``name``
Defaults to *None*. The name of the plugin.
``default_settings``
A dict containing the plugin's settings. The value to each key is the default value to be used.
``media_item_class``
The class name of the plugin's media item.
``settings_tab_class``
The class name of the plugin's settings tab.
``version``
Defaults to *None*, which means that the same version number is used as OpenLP's version number.
"""
log.debug(u'Plugin %s initialised' % name)
QtCore.QObject.__init__(self)
self.name = name
self.textStrings = {}
self.setPluginTextStrings()
self.nameStrings = self.textStrings[StringContent.Name]
if version:
self.version = version
else:
self.version = get_application_version()[u'version']
self.settingsSection = self.name
self.icon = None
self.mediaItemClass = media_item_class
self.settingsTabClass = settings_tab_class
self.settingsTab = None
self.mediaItem = None
self.weight = 0
self.status = PluginStatus.Inactive
# Add the default status to the default settings.
default_settings[name + u'/status'] = PluginStatus.Inactive
default_settings[name + u'/last directory'] = u''
# Append a setting for files in the mediamanager (note not all plugins
# which have a mediamanager need this).
if media_item_class is not None:
default_settings[u'%s/%s files' % (name, name)] = []
# Add settings to the dict of all settings.
Settings.extend_default_settings(default_settings)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'%s_add_service_item' % self.name),
self.processAddServiceEvent)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'%s_config_updated' % self.name),
self.configUpdated)
示例4: get_list
def get_list(self, type=MediaType.Audio):
media = Settings().value(self.settings_section + '/media files')
media.sort(key=lambda filename: get_locale_key(os.path.split(str(filename))[1]))
extension = []
if type == MediaType.Audio:
extension = self.media_controller.audio_extensions_list
else:
extension = self.media_controller.video_extensions_list
extension = [x[1:] for x in extension]
media = [x for x in media if os.path.splitext(x)[1] in extension]
return media
示例5: getList
def getList(self, type=MediaType.Audio):
media = Settings().value(self.settingsSection + u'/media files')
media.sort(cmp=locale_compare, key=lambda filename: os.path.split(unicode(filename))[1])
ext = []
if type == MediaType.Audio:
ext = self.media_controller.audio_extensions_list
else:
ext = self.media_controller.video_extensions_list
ext = map(lambda x: x[1:], ext)
media = filter(lambda x: os.path.splitext(x)[1] in ext, media)
return media
示例6: __init__
def __init__(self, plugin_name, init_schema, db_file_name=None, upgrade_mod=None):
"""
Runs the initialisation process that includes creating the connection to the database and the tables if they do
not exist.
``plugin_name``
The name to setup paths and settings section names
``init_schema``
The init_schema function for this database
``upgrade_schema``
The upgrade_schema function for this database
``db_file_name``
The file name to use for this database. Defaults to None resulting in the plugin_name being used.
"""
settings = Settings()
settings.beginGroup(plugin_name)
self.db_url = ''
self.is_dirty = False
self.session = None
db_type = settings.value('db type')
if db_type == 'sqlite':
if db_file_name:
self.db_url = 'sqlite:///%s/%s' % (AppLocation.get_section_data_path(plugin_name), db_file_name)
else:
self.db_url = 'sqlite:///%s/%s.sqlite' % (AppLocation.get_section_data_path(plugin_name), plugin_name)
else:
self.db_url = '%s://%s:%[email protected]%s/%s' % (db_type,
urlquote(settings.value('db username')),
urlquote(settings.value('db password')),
urlquote(settings.value('db hostname')),
urlquote(settings.value('db database')))
if db_type == 'mysql':
db_encoding = settings.value('db encoding')
self.db_url += '?charset=%s' % urlquote(db_encoding)
settings.endGroup()
if upgrade_mod:
db_ver, up_ver = upgrade_db(self.db_url, upgrade_mod)
if db_ver > up_ver:
critical_error_message_box(
translate('OpenLP.Manager', 'Database Error'),
translate('OpenLP.Manager', 'The database being loaded was created in a more recent version of '
'OpenLP. The database is version %d, while OpenLP expects version %d. The database will not '
'be loaded.\n\nDatabase: %s') % (db_ver, up_ver, self.db_url)
)
return
try:
self.session = init_schema(self.db_url)
except (SQLAlchemyError, DBAPIError):
log.exception('Error loading database: %s', self.db_url)
critical_error_message_box(
translate('OpenLP.Manager', 'Database Error'),
translate('OpenLP.Manager', 'OpenLP cannot load your database.\n\nDatabase: %s') % self.db_url
)
示例7: load
def load(self):
settings = Settings()
settings.beginGroup(self.settings_section)
self.song_search = settings.value('search as type')
self.tool_bar = settings.value('display songbar')
self.update_edit = settings.value('update service on edit')
self.update_load = settings.value('add song from service')
self.search_as_type_check_box.setChecked(self.song_search)
self.tool_bar_active_check_box.setChecked(self.tool_bar)
self.update_on_edit_check_box.setChecked(self.update_edit)
self.add_from_service_check_box.setChecked(self.update_load)
settings.endGroup()
示例8: load
def load(self):
settings = Settings()
settings.beginGroup(self.settingsSection)
self.song_search = settings.value(u'search as type')
self.tool_bar = settings.value(u'display songbar')
self.update_edit = settings.value(u'update service on edit')
self.update_load = settings.value(u'add song from service')
self.searchAsTypeCheckBox.setChecked(self.song_search)
self.toolBarActiveCheckBox.setChecked(self.tool_bar)
self.updateOnEditCheckBox.setChecked(self.update_edit)
self.addFromServiceCheckBox.setChecked(self.update_load)
settings.endGroup()
示例9: save
def save(self):
"""
Save the settings
"""
settings = Settings()
settings.beginGroup(self.settingsSection)
settings.setValue(u'theme level', self.theme_level)
settings.setValue(u'global theme', self.global_theme)
settings.endGroup()
self.renderer.set_global_theme(self.global_theme)
self.renderer.set_theme_level(self.theme_level)
Receiver.send_message(u'theme_update_global', self.global_theme)
示例10: save
def save(self):
"""
Save the settings
"""
settings = Settings()
settings.beginGroup(self.settings_section)
settings.setValue('theme level', self.theme_level)
settings.setValue('global theme', self.global_theme)
settings.endGroup()
self.renderer.set_theme_level(self.theme_level)
if self.tab_visited:
self.settings_form.register_post_process('theme_update_global')
self.tab_visited = False
示例11: get_media_players
def get_media_players():
"""
This method extracts the configured media players and overridden player
from the settings.
"""
log.debug('get_media_players')
saved_players = Settings().value('media/players')
reg_ex = QtCore.QRegExp(".*\[(.*)\].*")
if Settings().value('media/override player') == QtCore.Qt.Checked:
if reg_ex.exactMatch(saved_players):
overridden_player = '%s' % reg_ex.cap(1)
else:
overridden_player = 'auto'
else:
overridden_player = ''
saved_players_list = saved_players.replace('[', '').replace(']', '').split(',')
return saved_players_list, overridden_player
示例12: save
def save(self):
settings = Settings()
settings.beginGroup(self.settings_section)
settings.setValue('background color', self.background_color)
settings.endGroup()
if self.initial_color != self.background_color:
self.settings_form.register_post_process('images_config_updated')
示例13: save
def save(self):
settings = Settings()
settings.beginGroup(self.settingsSection)
settings.setValue(u'background color', self.bg_color)
settings.endGroup()
if self.initial_color != self.bg_color:
Receiver.send_message(u'image_updated')
示例14: setDefaults
def setDefaults(self):
"""
Set default values for the wizard pages.
"""
settings = Settings()
settings.beginGroup(self.plugin.settingsSection)
self.restart()
self.finishButton.setVisible(False)
self.cancelButton.setVisible(True)
self.setField(u'source_format', 0)
self.setField(u'osis_location', '')
self.setField(u'csv_booksfile', '')
self.setField(u'csv_versefile', '')
self.setField(u'opensong_file', '')
self.setField(u'web_location', WebDownload.Crosswalk)
self.setField(u'web_biblename', self.webTranslationComboBox.currentIndex())
self.setField(u'proxy_server', settings.value(u'proxy address'))
self.setField(u'proxy_username', settings.value(u'proxy username'))
self.setField(u'proxy_password', settings.value(u'proxy password'))
self.setField(u'openlp1_location', '')
self.setField(u'license_version', self.versionNameEdit.text())
self.setField(u'license_copyright', self.copyrightEdit.text())
self.setField(u'license_permissions', self.permissionsEdit.text())
self.onWebSourceComboBoxIndexChanged(WebDownload.Crosswalk)
settings.endGroup()
示例15: setUp
def setUp(self):
"""
Prepare the tests
"""
self.action_list = ActionList.get_instance()
self.settings = Settings()
fd, self.ini_file = mkstemp('.ini')
self.settings.set_filename(self.ini_file)
self.settings.beginGroup('shortcuts')