本文整理汇总了Python中openlp.core.common.AppLocation.get_data_path方法的典型用法代码示例。如果您正苦于以下问题:Python AppLocation.get_data_path方法的具体用法?Python AppLocation.get_data_path怎么用?Python AppLocation.get_data_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openlp.core.common.AppLocation
的用法示例。
在下文中一共展示了AppLocation.get_data_path方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: controller_text
# 需要导入模块: from openlp.core.common import AppLocation [as 别名]
# 或者: from openlp.core.common.AppLocation import get_data_path [as 别名]
def controller_text(self, var):
"""
Perform an action on the slide controller.
:param var: variable - not used
"""
log.debug("controller_text var = {var}".format(var=var))
current_item = self.live_controller.service_item
data = []
if current_item:
for index, frame in enumerate(current_item.get_frames()):
item = {}
# Handle text (songs, custom, bibles)
if current_item.is_text():
if frame['verseTag']:
item['tag'] = str(frame['verseTag'])
else:
item['tag'] = str(index + 1)
item['text'] = str(frame['text'])
item['html'] = str(frame['html'])
# Handle images, unless a custom thumbnail is given or if thumbnails is disabled
elif current_item.is_image() and not frame.get('image', '') and Settings().value('remotes/thumbnails'):
item['tag'] = str(index + 1)
thumbnail_path = os.path.join('images', 'thumbnails', frame['title'])
full_thumbnail_path = os.path.join(AppLocation.get_data_path(), thumbnail_path)
# Create thumbnail if it doesn't exists
if not os.path.exists(full_thumbnail_path):
create_thumb(current_item.get_frame_path(index), full_thumbnail_path, False)
item['img'] = urllib.request.pathname2url(os.path.sep + thumbnail_path)
item['text'] = str(frame['title'])
item['html'] = str(frame['title'])
else:
# Handle presentation etc.
item['tag'] = str(index + 1)
if current_item.is_capable(ItemCapabilities.HasDisplayTitle):
item['title'] = str(frame['display_title'])
if current_item.is_capable(ItemCapabilities.HasNotes):
item['slide_notes'] = str(frame['notes'])
if current_item.is_capable(ItemCapabilities.HasThumbnails) and \
Settings().value('remotes/thumbnails'):
# If the file is under our app directory tree send the portion after the match
data_path = AppLocation.get_data_path()
if frame['image'][0:len(data_path)] == data_path:
item['img'] = urllib.request.pathname2url(frame['image'][len(data_path):])
item['text'] = str(frame['title'])
item['html'] = str(frame['title'])
item['selected'] = (self.live_controller.selected_row == index)
data.append(item)
json_data = {'results': {'slides': data}}
if current_item:
json_data['results']['item'] = self.live_controller.service_item.unique_identifier
self.do_json_header()
return json.dumps(json_data).encode()
示例2: backup_on_upgrade
# 需要导入模块: from openlp.core.common import AppLocation [as 别名]
# 或者: from openlp.core.common.AppLocation import get_data_path [as 别名]
def backup_on_upgrade(self, has_run_wizard):
"""
Check if OpenLP has been upgraded, and ask if a backup of data should be made
:param has_run_wizard: OpenLP has been run before
"""
data_version = Settings().value('core/application version')
openlp_version = get_application_version()['version']
# New installation, no need to create backup
if not has_run_wizard:
Settings().setValue('core/application version', openlp_version)
# If data_version is different from the current version ask if we should backup the data folder
elif data_version != openlp_version:
if QtGui.QMessageBox.question(None, translate('OpenLP', 'Backup'),
translate('OpenLP', 'OpenLP has been upgraded, '
'do you want to create a backup of OpenLPs data folder?'),
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
QtGui.QMessageBox.Yes) == QtGui.QMessageBox.Yes:
# Create copy of data folder
data_folder_path = AppLocation.get_data_path()
timestamp = time.strftime("%Y%m%d-%H%M%S")
data_folder_backup_path = data_folder_path + '-' + timestamp
try:
shutil.copytree(data_folder_path, data_folder_backup_path)
except OSError:
QtGui.QMessageBox.warning(None, translate('OpenLP', 'Backup'),
translate('OpenLP', 'Backup of the data folder failed!'))
return
QtGui.QMessageBox.information(None, translate('OpenLP', 'Backup'),
translate('OpenLP', 'A backup of the data folder has been created at %s')
% data_folder_backup_path)
# Update the version in the settings
Settings().setValue('core/application version', openlp_version)
示例3: initialise
# 需要导入模块: from openlp.core.common import AppLocation [as 别名]
# 或者: from openlp.core.common.AppLocation import get_data_path [as 别名]
def initialise(self):
"""
Initialise the router stack and any other variables.
"""
auth_code = "{user}:{password}".format(user=Settings().value('remotes/user id'),
password=Settings().value('remotes/password'))
try:
self.auth = base64.b64encode(auth_code)
except TypeError:
self.auth = base64.b64encode(auth_code.encode()).decode()
self.default_route = {'function': self.serve_file, 'secure': False}
self.routes = [
('^/$', {'function': self.serve_file, 'secure': False}),
('^/(stage)$', {'function': self.serve_file, 'secure': False}),
('^/(stage)/(.*)$', {'function': self.stages, 'secure': False}),
('^/(main)$', {'function': self.serve_file, 'secure': False}),
(r'^/(\w+)/thumbnails([^/]+)?/(.*)$', {'function': self.serve_thumbnail, 'secure': False}),
(r'^/api/poll$', {'function': self.poll, 'secure': False}),
(r'^/main/poll$', {'function': self.main_poll, 'secure': False}),
(r'^/main/image$', {'function': self.main_image, 'secure': False}),
(r'^/api/controller/(live|preview)/text$', {'function': self.controller_text, 'secure': False}),
(r'^/api/controller/(live|preview)/(.*)$', {'function': self.controller, 'secure': True}),
(r'^/api/service/list$', {'function': self.service_list, 'secure': False}),
(r'^/api/service/(.*)$', {'function': self.service, 'secure': True}),
(r'^/api/display/(hide|show|blank|theme|desktop)$', {'function': self.display, 'secure': True}),
(r'^/api/alert$', {'function': self.alert, 'secure': True}),
(r'^/api/plugin/(search)$', {'function': self.plugin_info, 'secure': False}),
(r'^/api/(.*)/search$', {'function': self.search, 'secure': False}),
(r'^/api/(.*)/live$', {'function': self.go_live, 'secure': True}),
(r'^/api/(.*)/add$', {'function': self.add_to_service, 'secure': True})
]
self.settings_section = 'remotes'
self.translate()
self.html_dir = os.path.join(AppLocation.get_directory(AppLocation.PluginsDir), 'remotes', 'html')
self.config_dir = os.path.join(AppLocation.get_data_path(), 'stages')
示例4: load
# 需要导入模块: from openlp.core.common import AppLocation [as 别名]
# 或者: from openlp.core.common.AppLocation import get_data_path [as 别名]
def load(self):
"""
Load settings from disk.
"""
settings = Settings()
settings.beginGroup(self.settings_section)
# The max recent files value does not have an interface and so never
# gets actually stored in the settings therefore the default value of
# 20 will always be used.
self.recent_spin_box.setMaximum(settings.value('max recent files'))
self.recent_spin_box.setValue(settings.value('recent file count'))
self.media_plugin_check_box.setChecked(settings.value('save current plugin'))
self.double_click_live_check_box.setChecked(settings.value('double click live'))
self.single_click_preview_check_box.setChecked(settings.value('single click preview'))
self.single_click_service_preview_check_box.setChecked(settings.value('single click service preview'))
self.expand_service_item_check_box.setChecked(settings.value('expand service item'))
slide_max_height_value = settings.value('slide max height')
for i in range(0, self.slide_max_height_combo_box.count()):
if self.slide_max_height_combo_box.itemData(i) == slide_max_height_value:
self.slide_max_height_combo_box.setCurrentIndex(i)
autoscroll_value = settings.value('autoscrolling')
for i in range(0, len(self.autoscroll_map)):
if self.autoscroll_map[i] == autoscroll_value and i < self.autoscroll_combo_box.count():
self.autoscroll_combo_box.setCurrentIndex(i)
self.enable_auto_close_check_box.setChecked(settings.value('enable exit confirmation'))
self.hide_mouse_check_box.setChecked(settings.value('hide mouse'))
self.service_name_day.setCurrentIndex(settings.value('default service day'))
self.service_name_time.setTime(QtCore.QTime(settings.value('default service hour'),
settings.value('default service minute')))
self.should_update_service_name_example = True
self.service_name_edit.setText(settings.value('default service name'))
default_service_enabled = settings.value('default service enabled')
self.service_name_check_box.setChecked(default_service_enabled)
self.service_name_check_box_toggled(default_service_enabled)
self.x11_bypass_check_box.setChecked(settings.value('x11 bypass wm'))
self.slide_limits = settings.value('slide limits')
self.is_search_as_you_type_enabled = settings.value('search as type')
self.search_as_type_check_box.setChecked(self.is_search_as_you_type_enabled)
# Prevent the dialog displayed by the alternate_rows_check_box to display.
self.alternate_rows_check_box.blockSignals(True)
self.alternate_rows_check_box.setChecked(settings.value('alternate rows'))
self.alternate_rows_check_box.blockSignals(False)
if self.slide_limits == SlideLimits.End:
self.end_slide_radio_button.setChecked(True)
elif self.slide_limits == SlideLimits.Wrap:
self.wrap_slide_radio_button.setChecked(True)
else:
self.next_item_radio_button.setChecked(True)
settings.endGroup()
self.data_directory_copy_check_box.hide()
self.new_data_directory_has_files_label.hide()
self.data_directory_cancel_button.hide()
# Since data location can be changed, make sure the path is present.
self.current_data_path = AppLocation.get_data_path()
self.data_directory_label.setText(os.path.abspath(self.current_data_path))
# Don't allow data directory move if running portable.
if settings.value('advanced/is portable'):
self.data_directory_group_box.hide()
示例5: get_data_path_with_custom_location_test
# 需要导入模块: from openlp.core.common import AppLocation [as 别名]
# 或者: from openlp.core.common.AppLocation import get_data_path [as 别名]
def get_data_path_with_custom_location_test(self):
"""
Test the AppLocation.get_data_path() method when a custom location is set in the settings
"""
with patch('openlp.core.common.applocation.Settings') as mocked_class,\
patch('openlp.core.common.applocation.os') as mocked_os:
# GIVEN: A mocked out Settings class which returns a custom data location
mocked_settings = mocked_class.return_value
mocked_settings.contains.return_value = True
mocked_settings.value.return_value.toString.return_value = 'custom/dir'
mocked_os.path.normpath.return_value = 'custom/dir'
# WHEN: we call AppLocation.get_data_path()
data_path = AppLocation.get_data_path()
# THEN: the mocked Settings methods were called and the value returned was our set up value
mocked_settings.contains.assert_called_with('advanced/data path')
mocked_settings.value.assert_called_with('advanced/data path')
self.assertEqual('custom/dir', data_path, 'Result should be "custom/dir"')
示例6: get_data_path_test
# 需要导入模块: from openlp.core.common import AppLocation [as 别名]
# 或者: from openlp.core.common.AppLocation import get_data_path [as 别名]
def get_data_path_test(self):
"""
Test the AppLocation.get_data_path() method
"""
with patch('openlp.core.common.applocation.Settings') as mocked_class, \
patch('openlp.core.common.AppLocation.get_directory') as mocked_get_directory, \
patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists, \
patch('openlp.core.common.applocation.os') as mocked_os:
# GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory()
mocked_settings = mocked_class.return_value
mocked_settings.contains.return_value = False
mocked_get_directory.return_value = os.path.join('test', 'dir')
mocked_check_directory_exists.return_value = True
mocked_os.path.normpath.return_value = os.path.join('test', 'dir')
# WHEN: we call AppLocation.get_data_path()
data_path = AppLocation.get_data_path()
# THEN: check that all the correct methods were called, and the result is correct
mocked_settings.contains.assert_called_with('advanced/data path')
mocked_get_directory.assert_called_with(AppLocation.DataDir)
mocked_check_directory_exists.assert_called_with(os.path.join('test', 'dir'))
self.assertEqual(os.path.join('test', 'dir'), data_path, 'Result should be "test/dir"')
示例7: update_preview_text
# 需要导入模块: from openlp.core.common import AppLocation [as 别名]
# 或者: from openlp.core.common.AppLocation import get_data_path [as 别名]
def update_preview_text(self):
"""
Creates the html text and updates the html of *self.document*.
"""
html_data = self._add_element('html')
self._add_element('head', parent=html_data)
self._add_element('title', self.title_line_edit.text(), html_data.head)
css_path = os.path.join(AppLocation.get_data_path(), 'service_print.css')
custom_css = get_text_file_string(css_path)
if not custom_css:
custom_css = DEFAULT_CSS
self._add_element('style', custom_css, html_data.head, attribute=('type', 'text/css'))
self._add_element('body', parent=html_data)
self._add_element('h1', html.escape(self.title_line_edit.text()), html_data.body, classId='serviceTitle')
for index, item in enumerate(self.service_manager.service_items):
self._add_preview_item(html_data.body, item['service_item'], index)
# Add the custom service notes:
if self.footer_text_edit.toPlainText():
div = self._add_element('div', parent=html_data.body, classId='customNotes')
self._add_element(
'span', translate('OpenLP.ServiceManager', 'Custom Service Notes: '), div, classId='customNotesTitle')
self._add_element('span', html.escape(self.footer_text_edit.toPlainText()), div, classId='customNotesText')
self.document.setHtml(lxml.html.tostring(html_data).decode())
self.preview_widget.updatePreview()
示例8: load
# 需要导入模块: from openlp.core.common import AppLocation [as 别名]
# 或者: from openlp.core.common.AppLocation import get_data_path [as 别名]
def load(self):
"""
Load settings from disk.
"""
settings = Settings()
settings.beginGroup(self.settings_section)
# The max recent files value does not have an interface and so never
# gets actually stored in the settings therefore the default value of
# 20 will always be used.
self.recent_spin_box.setMaximum(settings.value('max recent files'))
self.recent_spin_box.setValue(settings.value('recent file count'))
self.media_plugin_check_box.setChecked(settings.value('save current plugin'))
self.double_click_live_check_box.setChecked(settings.value('double click live'))
self.single_click_preview_check_box.setChecked(settings.value('single click preview'))
self.expand_service_item_check_box.setChecked(settings.value('expand service item'))
self.enable_auto_close_check_box.setChecked(settings.value('enable exit confirmation'))
self.hide_mouse_check_box.setChecked(settings.value('hide mouse'))
self.service_name_day.setCurrentIndex(settings.value('default service day'))
self.service_name_time.setTime(QtCore.QTime(settings.value('default service hour'),
settings.value('default service minute')))
self.should_update_service_name_example = True
self.service_name_edit.setText(settings.value('default service name'))
default_service_enabled = settings.value('default service enabled')
self.service_name_check_box.setChecked(default_service_enabled)
self.service_name_check_box_toggled(default_service_enabled)
self.x11_bypass_check_box.setChecked(settings.value('x11 bypass wm'))
self.default_color = settings.value('default color')
self.default_file_edit.setText(settings.value('default image'))
self.slide_limits = settings.value('slide limits')
# Prevent the dialog displayed by the alternate_rows_check_box to display.
self.alternate_rows_check_box.blockSignals(True)
self.alternate_rows_check_box.setChecked(settings.value('alternate rows'))
self.alternate_rows_check_box.blockSignals(False)
if self.slide_limits == SlideLimits.End:
self.end_slide_radio_button.setChecked(True)
elif self.slide_limits == SlideLimits.Wrap:
self.wrap_slide_radio_button.setChecked(True)
else:
self.next_item_radio_button.setChecked(True)
settings.endGroup()
self.data_directory_copy_check_box.hide()
self.new_data_directory_has_files_label.hide()
self.data_directory_cancel_button.hide()
# Since data location can be changed, make sure the path is present.
self.current_data_path = AppLocation.get_data_path()
if not os.path.exists(self.current_data_path):
log.error('Data path not found %s' % self.current_data_path)
answer = QtGui.QMessageBox.critical(
self, translate('OpenLP.AdvancedTab', 'Data Directory Error'),
translate('OpenLP.AdvancedTab', 'OpenLP data directory was not found\n\n%s\n\n'
'This data directory was previously changed from the OpenLP '
'default location. If the new location was on removable '
'media, that media needs to be made available.\n\n'
'Click "No" to stop loading OpenLP. allowing you to fix the the problem.\n\n'
'Click "Yes" to reset the data directory to the default '
'location.').replace('%s', self.current_data_path),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No),
QtGui.QMessageBox.No)
if answer == QtGui.QMessageBox.No:
log.info('User requested termination')
self.main_window.clean_up()
sys.exit()
# Set data location to default.
settings.remove('advanced/data path')
self.current_data_path = AppLocation.get_data_path()
log.warning('User requested data path set to default %s' % self.current_data_path)
self.data_directory_label.setText(os.path.abspath(self.current_data_path))
self.default_color_button.color = self.default_color
# Don't allow data directory move if running portable.
if settings.value('advanced/is portable'):
self.data_directory_group_box.hide()