当前位置: 首页>>代码示例>>Python>>正文


Python common.AppLocation类代码示例

本文整理汇总了Python中openlp.core.common.AppLocation的典型用法代码示例。如果您正苦于以下问题:Python AppLocation类的具体用法?Python AppLocation怎么用?Python AppLocation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AppLocation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, plugin=None, name='PresentationController', document_class=PresentationDocument):
        """
        This is the constructor for the presentationcontroller object. This provides an easy way for descendent plugins

        to populate common data. This method *must* be overridden, like so::

            class MyPresentationController(PresentationController):
                def __init__(self, plugin):
                    PresentationController.__init(
                        self, plugin, 'My Presenter App')

        :param plugin:  Defaults to *None*. The presentationplugin object
        :param name: Name of the application, to appear in the application
        :param document_class:
        """
        self.supports = []
        self.also_supports = []
        self.docs = []
        self.plugin = plugin
        self.name = name
        self.document_class = document_class
        self.settings_section = self.plugin.settings_section
        self.available = None
        self.temp_folder = os.path.join(AppLocation.get_section_data_path(self.settings_section), name)
        self.thumbnail_folder = os.path.join(AppLocation.get_section_data_path(self.settings_section), 'thumbnails')
        self.thumbnail_prefix = 'slide'
        check_directory_exists(self.thumbnail_folder)
        check_directory_exists(self.temp_folder)
开发者ID:crossroadchurch,项目名称:paul,代码行数:28,代码来源:presentationcontroller.py

示例2: initialise

 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')
开发者ID:imkernel,项目名称:openlp,代码行数:35,代码来源:httprouter.py

示例3: _update_background_audio

 def _update_background_audio(self, song, item):
     song.media_files = []
     for i, bga in enumerate(item.background_audio):
         dest_file = os.path.join(
             AppLocation.get_section_data_path(self.plugin.name), 'audio', str(song.id), os.path.split(bga)[1])
         check_directory_exists(os.path.split(dest_file)[0])
         shutil.copyfile(os.path.join(AppLocation.get_section_data_path('servicemanager'), bga), dest_file)
         song.media_files.append(MediaFile.populate(weight=i, file_name=dest_file))
     self.plugin.manager.save_object(song, True)
开发者ID:crossroadchurch,项目名称:paul,代码行数:9,代码来源:mediaitem.py

示例4: find_qm_files

 def find_qm_files():
     """
     Find all available language files in this OpenLP install
     """
     log.debug("Translation files: %s", AppLocation.get_directory(AppLocation.LanguageDir))
     trans_dir = QtCore.QDir(AppLocation.get_directory(AppLocation.LanguageDir))
     file_names = trans_dir.entryList(["*.qm"], QtCore.QDir.Files, QtCore.QDir.Name)
     # Remove qm files from the list which start with "qt_".
     file_names = [file_ for file_ in file_names if not file_.startswith("qt_")]
     return list(map(trans_dir.filePath, file_names))
开发者ID:crossroadchurch,项目名称:paul,代码行数:10,代码来源:languagemanager.py

示例5: check_installed

    def check_installed(self):
        """
        Check the viewer is installed.

        :return: True if program to open PDF-files was found, otherwise False.
        """
        log.debug('check_installed Pdf')
        self.mudrawbin = ''
        self.mutoolbin = ''
        self.gsbin = ''
        self.also_supports = []
        # Use the user defined program if given
        if Settings().value('presentations/enable_pdf_program'):
            pdf_program = Settings().value('presentations/pdf_program')
            program_type = self.process_check_binary(pdf_program)
            if program_type == 'gs':
                self.gsbin = pdf_program
            elif program_type == 'mudraw':
                self.mudrawbin = pdf_program
            elif program_type == 'mutool':
                self.mutoolbin = pdf_program
        else:
            # Fallback to autodetection
            application_path = AppLocation.get_directory(AppLocation.AppDir)
            if is_win():
                # for windows we only accept mudraw.exe or mutool.exe in the base folder
                application_path = AppLocation.get_directory(AppLocation.AppDir)
                if os.path.isfile(os.path.join(application_path, 'mudraw.exe')):
                    self.mudrawbin = os.path.join(application_path, 'mudraw.exe')
                elif os.path.isfile(os.path.join(application_path, 'mutool.exe')):
                    self.mutoolbin = os.path.join(application_path, 'mutool.exe')
            else:
                DEVNULL = open(os.devnull, 'wb')
                # First try to find mudraw
                self.mudrawbin = which('mudraw')
                # if mudraw isn't installed, try mutool
                if not self.mudrawbin:
                    self.mutoolbin = which('mutool')
                    # Check we got a working mutool
                    if not self.mutoolbin or self.process_check_binary(self.mutoolbin) != 'mutool':
                        self.gsbin = which('gs')
                # Last option: check if mudraw or mutool is placed in OpenLP base folder
                if not self.mudrawbin and not self.mutoolbin and not self.gsbin:
                    application_path = AppLocation.get_directory(AppLocation.AppDir)
                    if os.path.isfile(os.path.join(application_path, 'mudraw')):
                        self.mudrawbin = os.path.join(application_path, 'mudraw')
                    elif os.path.isfile(os.path.join(application_path, 'mutool')):
                        self.mutoolbin = os.path.join(application_path, 'mutool')
        if self.mudrawbin or self.mutoolbin:
            self.also_supports = ['xps', 'oxps']
            return True
        elif self.gsbin:
            return True
        else:
            return False
开发者ID:imkernel,项目名称:openlp,代码行数:55,代码来源:pdfcontroller.py

示例6: _download_selected

 def _download_selected(self):
     """
     Download selected songs, bibles and themes. Returns False on download error
     """
     # Build directories for downloads
     songs_destination = os.path.join(gettempdir(), 'openlp')
     bibles_destination = AppLocation.get_section_data_path('bibles')
     themes_destination = AppLocation.get_section_data_path('themes')
     missed_files = []
     # Download songs
     for i in range(self.songs_list_widget.count()):
         item = self.songs_list_widget.item(i)
         if item.checkState() == QtCore.Qt.Checked:
             filename, sha256 = item.data(QtCore.Qt.UserRole)
             self._increment_progress_bar(self.downloading % filename, 0)
             self.previous_size = 0
             destination = os.path.join(songs_destination, str(filename))
             if not self.url_get_file('%s%s' % (self.songs_url, filename), destination, sha256):
                 missed_files.append('Song: {}'.format(filename))
     # Download Bibles
     bibles_iterator = QtGui.QTreeWidgetItemIterator(self.bibles_tree_widget)
     while bibles_iterator.value():
         item = bibles_iterator.value()
         if item.parent() and item.checkState(0) == QtCore.Qt.Checked:
             bible, sha256 = item.data(0, QtCore.Qt.UserRole)
             self._increment_progress_bar(self.downloading % bible, 0)
             self.previous_size = 0
             if not self.url_get_file('%s%s' % (self.bibles_url, bible), os.path.join(bibles_destination, bible),
                                      sha256):
                 missed_files.append('Bible: {}'.format(bible))
         bibles_iterator += 1
     # Download themes
     for i in range(self.themes_list_widget.count()):
         item = self.themes_list_widget.item(i)
         if item.checkState() == QtCore.Qt.Checked:
             theme, sha256 = item.data(QtCore.Qt.UserRole)
             self._increment_progress_bar(self.downloading % theme, 0)
             self.previous_size = 0
             if not self.url_get_file('%s%s' % (self.themes_url, theme), os.path.join(themes_destination, theme),
                                      sha256):
                 missed_files.append('Theme: {}'.format(theme))
     if missed_files:
         file_list = ''
         for entry in missed_files:
             file_list += '{}<br \>'.format(entry)
         msg = QtGui.QMessageBox()
         msg.setIcon(QtGui.QMessageBox.Warning)
         msg.setWindowTitle(translate('OpenLP.FirstTimeWizard', 'Network Error'))
         msg.setText(translate('OpenLP.FirstTimeWizard', 'Unable to download some files'))
         msg.setInformativeText(translate('OpenLP.FirstTimeWizard',
                                          'The following files were not able to be '
                                          'downloaded:<br \>{}'.format(file_list)))
         msg.setStandardButtons(msg.Ok)
         ans = msg.exec_()
     return True
开发者ID:crossroadchurch,项目名称:paul,代码行数:55,代码来源:firsttimeform.py

示例7: delete_database

def delete_database(plugin_name, db_file_name=None):
    """
    Remove a database file from the system.

    :param plugin_name: The name of the plugin to remove the database for
    :param db_file_name: The database file name. Defaults to None resulting in the plugin_name being used.
    """
    if db_file_name:
        db_file_path = os.path.join(AppLocation.get_section_data_path(plugin_name), db_file_name)
    else:
        db_file_path = os.path.join(AppLocation.get_section_data_path(plugin_name), plugin_name)
    return delete_file(db_file_path)
开发者ID:crossroadchurch,项目名称:paul,代码行数:12,代码来源:db.py

示例8: get_db_path

def get_db_path(plugin_name, db_file_name=None):
    """
    Create a path to a database from the plugin name and database name

    :param plugin_name: Name of plugin
    :param db_file_name: File name of database
    :return: The path to the database as type str
    """
    if db_file_name is None:
        return 'sqlite:///%s/%s.sqlite' % (AppLocation.get_section_data_path(plugin_name), plugin_name)
    else:
        return 'sqlite:///%s/%s' % (AppLocation.get_section_data_path(plugin_name), db_file_name)
开发者ID:crossroadchurch,项目名称:paul,代码行数:12,代码来源:db.py

示例9: controller_text

    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()
开发者ID:imkernel,项目名称:openlp,代码行数:53,代码来源:httprouter.py

示例10: get_db_path

def get_db_path(plugin_name, db_file_name=None):
    """
    Create a path to a database from the plugin name and database name

    :param plugin_name: Name of plugin
    :param db_file_name: File name of database
    :return: The path to the database as type str
    """
    if db_file_name is None:
        return 'sqlite:///{path}/{plugin}.sqlite'.format(path=AppLocation.get_section_data_path(plugin_name),
                                                         plugin=plugin_name)
    else:
        return 'sqlite:///{path}/{name}'.format(path=AppLocation.get_section_data_path(plugin_name),
                                                name=db_file_name)
开发者ID:imkernel,项目名称:openlp,代码行数:14,代码来源:db.py

示例11: on_clone_click

 def on_clone_click(self):
     """
     Clone a Song
     """
     log.debug('on_clone_click')
     if check_item_selected(self.list_view, UiStrings().SelectEdit):
         self.edit_item = self.list_view.currentItem()
         item_id = self.edit_item.data(QtCore.Qt.UserRole)
         old_song = self.plugin.manager.get_object(Song, item_id)
         song_xml = self.open_lyrics.song_to_xml(old_song)
         new_song = self.open_lyrics.xml_to_song(song_xml)
         new_song.title = '%s <%s>' % \
                          (new_song.title, translate('SongsPlugin.MediaItem', 'copy', 'For song cloning'))
         # Copy audio files from the old to the new song
         if len(old_song.media_files) > 0:
             save_path = os.path.join(AppLocation.get_section_data_path(self.plugin.name), 'audio', str(new_song.id))
             check_directory_exists(save_path)
             for media_file in old_song.media_files:
                 new_media_file_name = os.path.join(save_path, os.path.basename(media_file.file_name))
                 shutil.copyfile(media_file.file_name, new_media_file_name)
                 new_media_file = MediaFile()
                 new_media_file.file_name = new_media_file_name
                 new_media_file.type = media_file.type
                 new_media_file.weight = media_file.weight
                 new_song.media_files.append(new_media_file)
         self.plugin.manager.save_object(new_song)
     self.on_song_list_load()
开发者ID:crossroadchurch,项目名称:paul,代码行数:27,代码来源:mediaitem.py

示例12: add_from_command

    def add_from_command(self, path, file_name, image, display_title=None, notes=None):
        """
        Add a slide from a command.

        :param path: The title of the slide in the service item.
        :param file_name: The title of the slide in the service item.
        :param image: The command of/for the slide.
        :param display_title: Title to show in gui/webinterface, optional.
        :param notes: Notes to show in the webinteface, optional.
        """
        self.service_item_type = ServiceItemType.Command
        # If the item should have a display title but this frame doesn't have one, we make one up
        if self.is_capable(ItemCapabilities.HasDisplayTitle) and not display_title:
            display_title = translate('OpenLP.ServiceItem',
                                      '[slide {frame:d}]').format(frame=len(self._raw_frames) + 1)
        # Update image path to match servicemanager location if file was loaded from service
        if image and not self.has_original_files and self.name == 'presentations':
            file_location = os.path.join(path, file_name)
            file_location_hash = md5_hash(file_location.encode('utf-8'))
            image = os.path.join(AppLocation.get_section_data_path(self.name), 'thumbnails',
                                 file_location_hash, ntpath.basename(image))
        self._raw_frames.append({'title': file_name, 'image': image, 'path': path,
                                 'display_title': display_title, 'notes': notes})
        if self.is_capable(ItemCapabilities.HasThumbnails):
            self.image_manager.add_image(image, ImageSource.CommandPlugins, '#000000')
        self._new_item()
开发者ID:imkernel,项目名称:openlp,代码行数:26,代码来源:serviceitem.py

示例13: load

 def load(self):
     """
     Load the configuration and update the server configuration if necessary
     """
     self.is_secure = Settings().value(self.settings_section + '/https enabled')
     self.port_spin_box.setValue(Settings().value(self.settings_section + '/port'))
     self.https_port_spin_box.setValue(Settings().value(self.settings_section + '/https port'))
     self.address_edit.setText(Settings().value(self.settings_section + '/ip address'))
     self.twelve_hour = Settings().value(self.settings_section + '/twelve hour')
     self.twelve_hour_check_box.setChecked(self.twelve_hour)
     self.thumbnails = Settings().value(self.settings_section + '/thumbnails')
     self.thumbnails_check_box.setChecked(self.thumbnails)
     local_data = AppLocation.get_directory(AppLocation.DataDir)
     if not os.path.exists(os.path.join(local_data, 'remotes', 'openlp.crt')) or \
             not os.path.exists(os.path.join(local_data, 'remotes', 'openlp.key')):
         self.https_settings_group_box.setChecked(False)
         self.https_settings_group_box.setEnabled(False)
         self.https_error_label.setVisible(True)
     else:
         self.https_settings_group_box.setChecked(Settings().value(self.settings_section + '/https enabled'))
         self.https_settings_group_box.setEnabled(True)
         self.https_error_label.setVisible(False)
     self.user_login_group_box.setChecked(Settings().value(self.settings_section + '/authentication enabled'))
     self.user_id.setText(Settings().value(self.settings_section + '/user id'))
     self.password.setText(Settings().value(self.settings_section + '/password'))
     self.set_urls()
     self.https_changed()
开发者ID:imkernel,项目名称:openlp,代码行数:27,代码来源:remotetab.py

示例14: backup_on_upgrade

    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)
开发者ID:crossroadchurch,项目名称:paul,代码行数:33,代码来源:__init__.py

示例15: on_data_directory_default_button_clicked

 def on_data_directory_default_button_clicked(self):
     """
     Re-set the data directory location to the 'default' location.
     """
     new_data_path = AppLocation.get_directory(AppLocation.DataDir)
     if self.current_data_path.lower() != new_data_path.lower():
         # Make sure they want to change the data location back to the
         # default.
         answer = QtWidgets.QMessageBox.question(self, translate('OpenLP.AdvancedTab', 'Reset Data Directory'),
                                                 translate('OpenLP.AdvancedTab', 'Are you sure you want to change '
                                                                                 'the location of the OpenLP data '
                                                                                 'directory to the default location?'
                                                                                 '\n\nThis location will be used '
                                                                                 'after OpenLP is closed.'),
                                                 QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Yes |
                                                                                       QtWidgets.QMessageBox.No),
                                                 QtWidgets.QMessageBox.No)
         if answer != QtWidgets.QMessageBox.Yes:
             return
         self.check_data_overwrite(new_data_path)
         # Save the new location.
         self.main_window.set_new_data_path(new_data_path)
         self.new_data_directory_edit.setText(os.path.abspath(new_data_path))
         self.data_directory_cancel_button.show()
     else:
         # We cancel the change in case user changed their mind.
         self.on_data_directory_cancel_button_clicked()
开发者ID:imkernel,项目名称:openlp,代码行数:27,代码来源:advancedtab.py


注:本文中的openlp.core.common.AppLocation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。