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


Python Registry.information_message方法代码示例

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


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

示例1: report_song_list

# 需要导入模块: from openlp.core.common import Registry [as 别名]
# 或者: from openlp.core.common.Registry import information_message [as 别名]
def report_song_list():
    """
    Export the song list as a CSV file.
    :return: Nothing
    """
    main_window = Registry().get('main_window')
    plugin = Registry().get('songs').plugin
    report_file_name, filter_used = QtWidgets.QFileDialog.getSaveFileName(
        main_window,
        translate('SongPlugin.ReportSongList', 'Save File'),
        translate('SongPlugin.ReportSongList', 'song_extract.csv'),
        translate('SongPlugin.ReportSongList', 'CSV format (*.csv)'))

    if not report_file_name:
        main_window.error_message(
            translate('SongPlugin.ReportSongList', 'Output Path Not Selected'),
            translate('SongPlugin.ReportSongList', 'You have not set a valid output location for your '
                                                   'report. \nPlease select an existing path '
                                                   'on your computer.')
        )
        return
    if not report_file_name.endswith('csv'):
        report_file_name += '.csv'
    file_handle = None
    Registry().get('application').set_busy_cursor()
    try:
        file_handle = open(report_file_name, 'wt')
        fieldnames = ('Title', 'Alternative Title', 'Copyright', 'Author(s)', 'Song Book', 'Topic')
        writer = csv.DictWriter(file_handle, fieldnames=fieldnames, quoting=csv.QUOTE_ALL)
        headers = dict((n, n) for n in fieldnames)
        writer.writerow(headers)
        song_list = plugin.manager.get_all_objects(Song)
        for song in song_list:
            author_list = []
            for author_song in song.authors_songs:
                author_list.append(author_song.author.display_name)
            author_string = ' | '.join(author_list)
            book_list = []
            for book_song in song.songbook_entries:
                if hasattr(book_song, 'entry') and book_song.entry:
                    book_list.append('{name} #{entry}'.format(name=book_song.songbook.name, entry=book_song.entry))
            book_string = ' | '.join(book_list)
            topic_list = []
            for topic_song in song.topics:
                if hasattr(topic_song, 'name'):
                    topic_list.append(topic_song.name)
            topic_string = ' | '.join(topic_list)
            writer.writerow({'Title': song.title,
                             'Alternative Title': song.alternate_title,
                             'Copyright': song.copyright,
                             'Author(s)': author_string,
                             'Song Book': book_string,
                             'Topic': topic_string})
        Registry().get('application').set_normal_cursor()
        main_window.information_message(
            translate('SongPlugin.ReportSongList', 'Report Creation'),
            translate('SongPlugin.ReportSongList',
                      'Report \n{name} \nhas been successfully created. ').format(name=report_file_name)
        )
    except OSError as ose:
        Registry().get('application').set_normal_cursor()
        log.exception('Failed to write out song usage records')
        critical_error_message_box(translate('SongPlugin.ReportSongList', 'Song Extraction Failed'),
                                   translate('SongPlugin.ReportSongList',
                                             'An error occurred while extracting: {error}'
                                             ).format(error=ose.strerror))
    finally:
        if file_handle:
            file_handle.close()
开发者ID:imkernel,项目名称:openlp,代码行数:71,代码来源:reporting.py


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