def load_custom(self, id, preview=False): """ Called when editing or creating a new custom. :param id: The custom's id. If zero, then a new custom is created. :param preview: States whether the custom is edited while being previewed in the preview panel. """ self.slide_list_view.clear() if id == 0: self.custom_slide = CustomSlide() self.title_edit.setText('') self.credit_edit.setText('') self.theme_combo_box.setCurrentIndex(0) else: self.custom_slide = self.manager.get_object(CustomSlide, id) self.title_edit.setText(self.custom_slide.title) self.credit_edit.setText(self.custom_slide.credits) custom_xml = CustomXMLParser(self.custom_slide.text) slide_list = custom_xml.get_verses() self.slide_list_view.addItems([slide[1] for slide in slide_list]) theme = self.custom_slide.theme_name find_and_set_in_combo_box(self.theme_combo_box, theme) self.title_edit.setFocus() # If not preview hide the preview button. self.preview_button.setVisible(preview)
def loadBibles(self): log.debug('Loading Bibles') self.quickVersionComboBox.clear() self.quickSecondComboBox.clear() self.advancedVersionComboBox.clear() self.advancedSecondComboBox.clear() self.quickSecondComboBox.addItem('') self.advancedSecondComboBox.addItem('') # Get all bibles and sort the list. bibles = list(self.plugin.manager.get_bibles().keys()) bibles = [_f for _f in bibles if _f] bibles.sort(key=get_locale_key) # Load the bibles into the combo boxes. self.quickVersionComboBox.addItems(bibles) self.quickSecondComboBox.addItems(bibles) self.advancedVersionComboBox.addItems(bibles) self.advancedSecondComboBox.addItems(bibles) # set the default value bible = Settings().value(self.settings_section + '/advanced bible') if bible in bibles: find_and_set_in_combo_box(self.advancedVersionComboBox, bible) self.initialiseAdvancedBible(str(bible)) elif bibles: self.initialiseAdvancedBible(bibles[0]) bible = Settings().value(self.settings_section + '/quick bible') find_and_set_in_combo_box(self.quickVersionComboBox, bible)
def loadCustom(self, id, preview=False): """ Called when editing or creating a new custom. ``id`` The cutom's id. If zero, then a new custom is created. ``preview`` States whether the custom is edited while being previewed in the preview panel. """ self.slideListView.clear() if id == 0: self.customSlide = CustomSlide() self.titleEdit.setText(u'') self.creditEdit.setText(u'') self.themeComboBox.setCurrentIndex(0) else: self.customSlide = self.manager.get_object(CustomSlide, id) self.titleEdit.setText(self.customSlide.title) self.creditEdit.setText(self.customSlide.credits) customXML = CustomXMLParser(self.customSlide.text) slideList = customXML.get_verses() for slide in slideList: self.slideListView.addItem(slide[1]) theme = self.customSlide.theme_name find_and_set_in_combo_box(self.themeComboBox, theme) self.titleEdit.setFocus() # If not preview hide the preview button. self.previewButton.setVisible(preview)
def loadBibles(self): log.debug(u'Loading Bibles') self.quickVersionComboBox.clear() self.quickSecondComboBox.clear() self.advancedVersionComboBox.clear() self.advancedSecondComboBox.clear() self.quickSecondComboBox.addItem(u'') self.advancedSecondComboBox.addItem(u'') # Get all bibles and sort the list. bibles = self.plugin.manager.get_bibles().keys() bibles = filter(None, bibles) bibles.sort(cmp=locale_compare) # Load the bibles into the combo boxes. self.quickVersionComboBox.addItems(bibles) self.quickSecondComboBox.addItems(bibles) self.advancedVersionComboBox.addItems(bibles) self.advancedSecondComboBox.addItems(bibles) # set the default value bible = Settings().value(self.settingsSection + u'/advanced bible') if bible in bibles: find_and_set_in_combo_box(self.advancedVersionComboBox, bible) self.initialiseAdvancedBible(unicode(bible)) elif bibles: self.initialiseAdvancedBible(bibles[0]) bible = Settings().value(self.settingsSection + u'/quick bible') find_and_set_in_combo_box(self.quickVersionComboBox, bible)
def update_theme_list(self, theme_list): """ Called from ThemeManager when the Themes have changed. ``theme_list`` The list of available themes:: [u'Bible Theme', u'Song Theme'] """ self.bible_theme_combo_box.clear() self.bible_theme_combo_box.addItem('') self.bible_theme_combo_box.addItems(theme_list) find_and_set_in_combo_box(self.bible_theme_combo_box, self.bible_theme)
def update_theme_list(self, theme_list): """ Called from ThemeManager when the Themes have changed. :param theme_list: The list of available themes:: ['Bible Theme', 'Song Theme'] """ self.bible_theme_combo_box.clear() self.bible_theme_combo_box.addItem('') self.bible_theme_combo_box.addItems(theme_list) find_and_set_in_combo_box(self.bible_theme_combo_box, self.bible_theme)
def update_theme_list(self, theme_list): """ Called from ThemeManager when the Themes have changed. :param theme_list: The list of available themes:: ['Bible Theme', 'Song Theme'] """ # Reload as may have been triggered by the ThemeManager. self.global_theme = Settings().value(self.settings_section + '/global theme') self.default_combo_box.clear() self.default_combo_box.addItems(theme_list) find_and_set_in_combo_box(self.default_combo_box, self.global_theme) self.renderer.set_global_theme() self.renderer.set_theme_level(self.theme_level) if self.global_theme is not '': self._preview_global_theme()
def updateThemeList(self, theme_list): """ Called from ThemeManager when the Themes have changed. ``theme_list`` The list of available themes:: [u'Bible Theme', u'Song Theme'] """ # Reload as may have been triggered by the ThemeManager. self.global_theme = Settings().value(self.settingsSection + u'/global theme') self.DefaultComboBox.clear() self.DefaultComboBox.addItems(theme_list) find_and_set_in_combo_box(self.DefaultComboBox, self.global_theme) self.renderer.set_global_theme(self.global_theme) self.renderer.set_theme_level(self.theme_level) if self.global_theme is not u'': self.__previewGlobalTheme()
def populate_bible_combo_boxes(self): """ Populate the bible combo boxes with the list of bibles that have been loaded :return: None """ log.debug('Loading Bibles') self.version_combo_box.clear() self.second_combo_box.clear() self.second_combo_box.addItem('', None) # Get all bibles and sort the list. bibles = self.plugin.manager.get_bibles() bibles = [(_f, bibles[_f]) for _f in bibles if _f] bibles.sort(key=lambda k: get_locale_key(k[0])) for bible in bibles: self.version_combo_box.addItem(bible[0], bible[1]) self.second_combo_box.addItem(bible[0], bible[1]) # set the default value bible = self.settings.value('{settings_section}/primary bible'.format(settings_section=self.settings_section)) find_and_set_in_combo_box(self.version_combo_box, bible)
def populate_bible_combo_boxes(self): """ Populate the bible combo boxes with the list of bibles that have been loaded :return: None """ log.debug('Loading Bibles') self.version_combo_box.clear() self.second_combo_box.clear() self.second_combo_box.addItem('', None) # Get all bibles and sort the list. bibles = self.plugin.manager.get_bibles() bibles = [(_f, bibles[_f]) for _f in bibles if _f] bibles.sort(key=lambda k: get_locale_key(k[0])) for bible in bibles: self.version_combo_box.addItem(bible[0], bible[1]) self.second_combo_box.addItem(bible[0], bible[1]) # set the default value bible = Settings().value('{settings_section}/primary bible'.format(settings_section=self.settings_section)) find_and_set_in_combo_box(self.version_combo_box, bible)
def find_and_set_in_combo_box_test(self): """ Test finding a string in a combo box and setting it as the selected item if present """ # GIVEN: A ComboBox combo = QtGui.QComboBox() combo.addItems(['One', 'Two', 'Three']) combo.setCurrentIndex(1) # WHEN: We call the method with a non-existing value and set_missing=False find_and_set_in_combo_box(combo, 'Four', set_missing=False) # THEN: The index should not have changed self.assertEqual(1, combo.currentIndex()) # WHEN: We call the method with a non-existing value find_and_set_in_combo_box(combo, 'Four') # THEN: The index should have been reset self.assertEqual(0, combo.currentIndex()) # WHEN: We call the method with the default behavior find_and_set_in_combo_box(combo, 'Three') # THEN: The index should have changed self.assertEqual(2, combo.currentIndex())
def test_find_and_set_in_combo_box(self): """ Test finding a string in a combo box and setting it as the selected item if present """ # GIVEN: A ComboBox combo = QtWidgets.QComboBox() combo.addItems(['One', 'Two', 'Three']) combo.setCurrentIndex(1) # WHEN: We call the method with a non-existing value and set_missing=False find_and_set_in_combo_box(combo, 'Four', set_missing=False) # THEN: The index should not have changed self.assertEqual(1, combo.currentIndex()) # WHEN: We call the method with a non-existing value find_and_set_in_combo_box(combo, 'Four') # THEN: The index should have been reset self.assertEqual(0, combo.currentIndex()) # WHEN: We call the method with the default behavior find_and_set_in_combo_box(combo, 'Three') # THEN: The index should have changed self.assertEqual(2, combo.currentIndex())
def load_song(self, song_id, preview=False): """ Loads a song. ``song_id`` The song id (int). ``preview`` Should be ``True`` if the song is also previewed (boolean). """ log.debug('Load Song') self.initialise() self.song_tab_widget.setCurrentIndex(0) self.load_authors() self.load_topics() self.load_books() self.load_media_files() self.song = self.manager.get_object(Song, song_id) self.title_edit.setText(self.song.title) self.alternative_edit.setText( self.song.alternate_title if self.song.alternate_title else '') if self.song.song_book_id != 0: book_name = self.manager.get_object(Book, self.song.song_book_id) find_and_set_in_combo_box(self.song_book_combo_box, str(book_name.name)) else: self.song_book_combo_box.setEditText('') self.song_book_combo_box.setCurrentIndex(0) if self.song.theme_name: find_and_set_in_combo_box(self.theme_combo_box, str(self.song.theme_name)) else: # Clear the theme combo box in case it was previously set (bug #1212801) self.theme_combo_box.setEditText('') self.theme_combo_box.setCurrentIndex(0) self.copyright_edit.setText(self.song.copyright if self.song.copyright else '') self.comments_edit.setPlainText(self.song.comments if self.song.comments else '') self.ccli_number_edit.setText(self.song.ccli_number if self.song.ccli_number else '') self.song_book_number_edit.setText(self.song.song_number if self.song.song_number else '') # lazy xml migration for now self.verse_list_widget.clear() self.verse_list_widget.setRowCount(0) verse_tags_translated = False if self.song.lyrics.startswith('<?xml version='): songXML = SongXML() verse_list = songXML.get_verses(self.song.lyrics) for count, verse in enumerate(verse_list): self.verse_list_widget.setRowCount(self.verse_list_widget.rowCount() + 1) # 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' verse_def = '%s%s' % (verse[0]['type'], verse[0]['label']) item = QtGui.QTableWidgetItem(verse[1]) item.setData(QtCore.Qt.UserRole, verse_def) self.verse_list_widget.setItem(count, 0, item) else: verses = self.song.lyrics.split('\n\n') for count, verse in enumerate(verses): self.verse_list_widget.setRowCount(self.verse_list_widget.rowCount() + 1) item = QtGui.QTableWidgetItem(verse) verse_def = '%s%s' % (VerseType.tags[VerseType.Verse], str(count + 1)) item.setData(QtCore.Qt.UserRole, verse_def) self.verse_list_widget.setItem(count, 0, item) if self.song.verse_order: # we translate verse order translated = [] for verse_def in self.song.verse_order.split(): verse_index = None if verse_tags_translated: verse_index = VerseType.from_translated_tag(verse_def[0], None) if verse_index is None: verse_index = VerseType.from_tag(verse_def[0]) verse_tag = VerseType.translated_tags[verse_index].upper() translated.append('%s%s' % (verse_tag, verse_def[1:])) self.verse_order_edit.setText(' '.join(translated)) else: self.verse_order_edit.setText('') self.tag_rows() # clear the results self.authors_list_view.clear() for author in self.song.authors: author_name = QtGui.QListWidgetItem(str(author.display_name)) author_name.setData(QtCore.Qt.UserRole, author.id) self.authors_list_view.addItem(author_name) # clear the results self.topics_list_view.clear() for topic in self.song.topics: topic_name = QtGui.QListWidgetItem(str(topic.name)) topic_name.setData(QtCore.Qt.UserRole, topic.id) self.topics_list_view.addItem(topic_name) self.audio_list_widget.clear() for media in self.song.media_files: media_file = QtGui.QListWidgetItem(os.path.split(media.file_name)[1]) media_file.setData(QtCore.Qt.UserRole, media.file_name) self.audio_list_widget.addItem(media_file) self.title_edit.setFocus() # Hide or show the preview button. self.preview_button.setVisible(preview) # Check if all verse tags are used. self.on_verse_order_text_changed(self.verse_order_edit.text())