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


Python lib.VerseType类代码示例

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


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

示例1: song_to_line_dict

    def song_to_line_dict(self, song):

        song_xml = SongXML()
        if song.chords:
            verse_chords_xml = song_xml.get_verses(song.chords)
        else:
            verse_chords_xml = song_xml.get_verses(song.lyrics)

        section_line_dict = {}
        for count, verse in enumerate(verse_chords_xml):
            # This silently migrates from localized verse type markup.
            # If we trusted the database, this would be unnecessary.
            verse_tag = verse[0]['type']
            index = None
            if len(verse_tag) > 1:
                index = VerseType.from_translated_string(verse_tag)
                if index is None:
                    index = VerseType.from_string(verse_tag, None)
                else:
                    verse_tags_translated = True
            if index is None:
                index = VerseType.from_tag(verse_tag)
            verse[0]['type'] = VerseType.tags[index]
            if verse[0]['label'] == '':
                verse[0]['label'] = '1'
            section_header = '%s%s' % (verse[0]['type'], verse[0]['label'])

            line_list = []
            for line in verse[1].split('\n'):
                line_list.append(line)

            section_line_dict[section_header] = line_list

        return section_line_dict
开发者ID:leiwen83,项目名称:paul,代码行数:34,代码来源:openlyricsxml.py

示例2: on_verse_edit_all_button_clicked

 def on_verse_edit_all_button_clicked(self):
     verse_list = ''
     if self.verse_list_widget.rowCount() > 0:
         for row in range(self.verse_list_widget.rowCount()):
             item = self.verse_list_widget.item(row, 0)
             field = item.data(QtCore.Qt.UserRole)
             verse_tag = VerseType.translated_name(field[0])
             verse_num = field[1:]
             verse_list += '---[%s:%s]---\n' % (verse_tag, verse_num)
             verse_list += item.text()
             verse_list += '\n'
         self.verse_form.set_verse(verse_list)
     else:
         self.verse_form.set_verse('')
     if not self.verse_form.exec_():
         return
     verse_list = self.verse_form.get_all_verses()
     verse_list = str(verse_list.replace('\r\n', '\n'))
     self.verse_list_widget.clear()
     self.verse_list_widget.setRowCount(0)
     for row in self.find_verse_split.split(verse_list):
         for match in row.split('---['):
             for count, parts in enumerate(match.split(']---\n')):
                 if count == 0:
                     if len(parts) == 0:
                         continue
                     # handling carefully user inputted versetags
                     separator = parts.find(':')
                     if separator >= 0:
                         verse_name = parts[0:separator].strip()
                         verse_num = parts[separator+1:].strip()
                     else:
                         verse_name = parts
                         verse_num = '1'
                     verse_index = VerseType.from_loose_input(verse_name)
                     verse_tag = VerseType.tags[verse_index]
                     # Later we need to handle v1a as well.
                     #regex = re.compile(r'(\d+\w.)')
                     regex = re.compile(r'\D*(\d+)\D*')
                     match = regex.match(verse_num)
                     if match:
                         verse_num = match.group(1)
                     else:
                         verse_num = '1'
                     verse_def = '%s%s' % (verse_tag, verse_num)
                 else:
                     if parts.endswith('\n'):
                         parts = parts.rstrip('\n')
                     item = QtGui.QTableWidgetItem(parts)
                     item.setData(QtCore.Qt.UserRole, verse_def)
                     self.verse_list_widget.setRowCount(self.verse_list_widget.rowCount() + 1)
                     self.verse_list_widget.setItem(self.verse_list_widget.rowCount() - 1, 0, item)
     self.tag_rows()
     self.verse_edit_button.setEnabled(False)
     self.verse_delete_button.setEnabled(False)
     # Check if all verse tags are used.
     self.on_verse_order_text_changed(self.verse_order_edit.text())
开发者ID:marmyshev,项目名称:bug_1117098,代码行数:57,代码来源:editsongform.py

示例3: _validate_verse_list

 def _validate_verse_list(self, verse_order, verse_count):
     verses = []
     invalid_verses = []
     verse_names = []
     order_names = str(verse_order).split()
     order = self._extract_verse_order(verse_order)
     for index in range(verse_count):
         verse = self.verse_list_widget.item(index, 0)
         verse = verse.data(QtCore.Qt.UserRole)
         if verse not in verse_names:
             verses.append(verse)
             verse_names.append('%s%s' % (VerseType.translated_tag(verse[0]), verse[1:]))
     for count, item in enumerate(order):
         if item not in verses:
             invalid_verses.append(order_names[count])
     if invalid_verses:
         valid = create_separated_list(verse_names)
         if len(invalid_verses) > 1:
             msg = translate('SongsPlugin.EditSongForm', 'There are no verses corresponding to "%(invalid)s".'
                 'Valid entries are %(valid)s.\nPlease enter the verses seperated by spaces.') \
                 % {'invalid' : ', '.join(invalid_verses), 'valid' : valid}
         else:
             msg = translate('SongsPlugin.EditSongForm', 'There is no verse corresponding to "%(invalid)s".'
                 'Valid entries are %(valid)s.\nPlease enter the verses seperated by spaces.') \
                 % {'invalid' : invalid_verses[0], 'valid' : valid}
         critical_error_message_box(title=translate('SongsPlugin.EditSongForm', 'Invalid Verse Order'),
                                    message=msg)
     return len(invalid_verses) == 0
开发者ID:marmyshev,项目名称:bug_1117098,代码行数:28,代码来源:editsongform.py

示例4: save_song

    def save_song(self, song):
        """
        Save a song to the database, using the db_manager

        :param song:
        :return:
        """
        db_song = Song.populate(title=song['title'], copyright=song['copyright'], ccli_number=song['ccli_number'])
        song_xml = SongXML()
        verse_order = []
        for verse in song['verses']:
            verse_type, verse_number = verse['label'].split(' ')[:2]
            verse_type = VerseType.from_loose_input(verse_type)
            verse_number = int(verse_number)
            song_xml.add_verse_to_lyrics(VerseType.tags[verse_type], verse_number, verse['lyrics'])
            verse_order.append('%s%s' % (VerseType.tags[verse_type], verse_number))
        db_song.verse_order = ' '.join(verse_order)
        db_song.lyrics = song_xml.extract_xml()
        clean_song(self.db_manager, db_song)
        self.db_manager.save_object(db_song)
        db_song.authors_songs = []
        for author_name in song['authors']:
            author = self.db_manager.get_object_filtered(Author, Author.display_name == author_name)
            if not author:
                author = Author.populate(first_name=author_name.rsplit(' ', 1)[0],
                                         last_name=author_name.rsplit(' ', 1)[1],
                                         display_name=author_name)
            db_song.add_author(author)
        self.db_manager.save_object(db_song)
        return db_song
开发者ID:crossroadchurch,项目名称:paul,代码行数:30,代码来源:songselect.py

示例5: set_verse

    def set_verse(self, text, single=False, tag='%s1' % VerseType.tags[VerseType.Verse]):
        """
        Save the verse

        :param text: The text
        :param single: is this a single verse
        :param tag: The tag
        """
        self.has_single_verse = single
        if single:
            verse_type_index = VerseType.from_tag(tag[0], None)
            verse_number = tag[1:]
            if verse_type_index is not None:
                self.verse_type_combo_box.setCurrentIndex(verse_type_index)
            self.verse_number_box.setValue(int(verse_number))
            self.insert_button.setVisible(False)
        else:
            if not text:
                text = '---[%s:1]---\n' % VerseType.translated_names[VerseType.Verse]
            self.verse_type_combo_box.setCurrentIndex(0)
            self.verse_number_box.setValue(1)
            self.insert_button.setVisible(True)
        self.verse_text_edit.setPlainText(text)
        self.verse_text_edit.setFocus()
        self.verse_text_edit.moveCursor(QtGui.QTextCursor.End)
开发者ID:crossroadchurch,项目名称:paul,代码行数:25,代码来源:editverseform.py

示例6: translated_name_test

    def translated_name_test(self):
        """
        Test that the translated_name() method returns the correct name
        """
        # GIVEN: A mocked out translate() function that just returns what it was given
        with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
            mocked_translate.side_effect = lambda x, y: y

            # WHEN: We run the translated_name() method with a "verse"
            result = VerseType.translated_name('v')

            # THEN: The result should be "Verse"
            self.assertEqual(result, 'Verse', 'The result should be "Verse"')

            # WHEN: We run the translated_name() method with a "chorus"
            result = VerseType.translated_name('c')

            # THEN: The result should be "Chorus"
            self.assertEqual(result, 'Chorus', 'The result should be "Chorus"')
开发者ID:marmyshev,项目名称:bug_1117098,代码行数:19,代码来源:test_lib.py

示例7: test_from_loose_input_with_valid_input

    def test_from_loose_input_with_valid_input(self, mocked_translated_tags):
        """
        Test that the from_loose_input() method returns valid output on valid input.
        """
        # GIVEN: A mocked VerseType.translated_tags
        # WHEN: We run the from_loose_input() method with a valid verse type, we get the expected VerseType back
        result = VerseType.from_loose_input('v')

        # THEN: The result should be a Verse
        self.assertEqual(result, VerseType.Verse, 'The result should be a verse, but was "%s"' % result)
开发者ID:imkernel,项目名称:openlp,代码行数:10,代码来源:test_lib.py

示例8: test_from_loose_input_with_invalid_input

    def test_from_loose_input_with_invalid_input(self, mocked_translated_tags):
        """
        Test that the from_loose_input() method returns a sane default when passed an invalid tag and None as default.
        """
        # GIVEN: A mocked VerseType.translated_tags
        # WHEN: We run the from_loose_input() method with an invalid verse type, we get the specified default back
        result = VerseType.from_loose_input('m', None)

        # THEN: The result should be None
        self.assertIsNone(result, 'The result should be None, but was "%s"' % result)
开发者ID:imkernel,项目名称:openlp,代码行数:10,代码来源:test_lib.py

示例9: insert_verse

    def insert_verse(self, verse_tag, verse_num=1):
        """
        Insert a verse

        :param verse_tag: The verse tag
        :param verse_num: The verse number
        """
        if self.verse_text_edit.textCursor().columnNumber() != 0:
            self.verse_text_edit.insertPlainText('\n')
        verse_tag = VerseType.translated_name(verse_tag)
        self.verse_text_edit.insertPlainText('---[%s:%s]---\n' % (verse_tag, verse_num))
        self.verse_text_edit.setFocus()
开发者ID:crossroadchurch,项目名称:paul,代码行数:12,代码来源:editverseform.py

示例10: _extract_verse_order

 def _extract_verse_order(self, verse_order):
     order = []
     order_names = str(verse_order).split()
     for item in order_names:
         if len(item) == 1:
             verse_index = VerseType.from_translated_tag(item, None)
             if verse_index is not None:
                 order.append(VerseType.tags[verse_index] + '1')
             else:
                 # it matches no verses anyway
                 order.append('')
         else:
             verse_index = VerseType.from_translated_tag(item[0], None)
             if verse_index is None:
                 # it matches no verses anyway
                 order.append('')
             else:
                 verse_tag = VerseType.tags[verse_index]
                 verse_num = item[1:].lower()
                 order.append(verse_tag + verse_num)
     return order
开发者ID:marmyshev,项目名称:bug_1117098,代码行数:21,代码来源:editsongform.py

示例11: translated_invalid_name_with_invalid_default_test

    def translated_invalid_name_with_invalid_default_test(self):
        """
        Test that the translated_name() method returns the specified default tag when passed an invalid tag
        """
        # GIVEN: A mocked out translate() function that just returns what it was given
        with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
            mocked_translate.side_effect = lambda x, y: y

            # WHEN: We run the translated_name() method with an invalid verse type and specify an invalid default
            result = VerseType.translated_name('q', 29)

            # THEN: The result should be "Other"
            self.assertEqual(result, 'Other', 'The result should be "Other", but was "%s"' % result)
开发者ID:marmyshev,项目名称:bug_1117098,代码行数:13,代码来源:test_lib.py

示例12: from_tag_test

    def from_tag_test(self):
        """
        Test that the from_tag() method returns the correct VerseType.
        """
        # GIVEN: A mocked out translate() function that just returns what it was given
        with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
            mocked_translate.side_effect = lambda x, y: y

            # WHEN: We run the from_tag() method with a valid verse type, we get the name back
            result = VerseType.from_tag('v')

            # THEN: The result should be VerseType.Verse
            self.assertEqual(result, VerseType.Verse, 'The result should be VerseType.Verse, but was "%s"' % result)
开发者ID:marmyshev,项目名称:bug_1117098,代码行数:13,代码来源:test_lib.py

示例13: test_translated_invalid_tag

    def test_translated_invalid_tag(self):
        """
        Test that the translated_tag() method returns the default tag when passed an invalid tag
        """
        # GIVEN: A mocked out translate() function that just returns what it was given
        with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
            mocked_translate.side_effect = lambda x, y: y

            # WHEN: We run the translated_tag() method with an invalid verse type
            result = VerseType.translated_tag('z')

            # THEN: The result should be "O"
            self.assertEqual(result, 'O', 'The result should be "O", but was "%s"' % result)
开发者ID:imkernel,项目名称:openlp,代码行数:13,代码来源:test_lib.py

示例14: from_tag_with_invalid_default_test

    def from_tag_with_invalid_default_test(self):
        """
        Test that the from_tag() method returns a sane default when passed an invalid tag and an invalid default.
        """
        # GIVEN: A mocked out translate() function that just returns what it was given
        with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
            mocked_translate.side_effect = lambda x, y: y

            # WHEN: We run the from_tag() method with an invalid verse type, we get the specified default back
            result = VerseType.from_tag('m', 29)

            # THEN: The result should be VerseType.Other
            self.assertEqual(result, VerseType.Other, 'The result should be VerseType.Other, but was "%s"' % result)
开发者ID:marmyshev,项目名称:bug_1117098,代码行数:13,代码来源:test_lib.py

示例15: tag_rows

 def tag_rows(self):
     """
     Tag the Song List rows based on the verse list
     """
     row_label = []
     for row in range(self.verse_list_widget.rowCount()):
         item = self.verse_list_widget.item(row, 0)
         verse_def = item.data(QtCore.Qt.UserRole)
         verse_tag = VerseType.translated_tag(verse_def[0])
         row_def = '%s%s' % (verse_tag, verse_def[1:])
         row_label.append(row_def)
     self.verse_list_widget.setVerticalHeaderLabels(row_label)
     self.verse_list_widget.resizeRowsToContents()
     self.verse_list_widget.repaint()
开发者ID:marmyshev,项目名称:bug_1117098,代码行数:14,代码来源:editsongform.py


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