From 24041c7f17a7b772a30ac91744ccf33e850aabbf Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Thu, 11 Oct 2012 23:03:54 +0100 Subject: [PATCH 01/18] Presentation error traps --- .../presentations/lib/impresscontroller.py | 4 ++ .../presentations/lib/messagelistener.py | 50 ++++++++++++++++--- .../presentations/lib/powerpointcontroller.py | 6 ++- 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index a85f43592..ceb793cb2 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -155,6 +155,8 @@ class ImpressController(PresentationController): desktop = self.manager.createInstance(u'com.sun.star.frame.Desktop') except AttributeError: log.warn(u'Failure to find desktop - Impress may have closed') + except pywintypes.com_error: + log.warn(u'Failure to find desktop - Impress may have closed') return desktop if desktop else None def get_com_servicemanager(self): @@ -284,6 +286,8 @@ class ImpressDocument(PresentationDocument): props = tuple(props) doc = self.document pages = doc.getDrawPages() + if not pages: + return if not os.path.isdir(self.get_temp_folder()): os.makedirs(self.get_temp_folder()) for idx in range(pages.getCount()): diff --git a/openlp/plugins/presentations/lib/messagelistener.py b/openlp/plugins/presentations/lib/messagelistener.py index cb8f7b7b8..dc8ac79d1 100644 --- a/openlp/plugins/presentations/lib/messagelistener.py +++ b/openlp/plugins/presentations/lib/messagelistener.py @@ -88,29 +88,40 @@ class Controller(object): Use the last slide number. """ log.debug(u'Live = %s, activate' % self.is_live) + if not self.doc: + return False if self.doc.is_active(): - return + return True if not self.doc.is_loaded(): if not self.doc.load_presentation(): - return + log.warn(u'Failed to activate %s' % self.doc.filepath) + return False if self.is_live: self.doc.start_presentation() if self.doc.slidenumber > 1: if self.doc.slidenumber > self.doc.get_slide_count(): self.doc.slidenumber = self.doc.get_slide_count() self.doc.goto_slide(self.doc.slidenumber) + if self.doc.is_active(): + return True + else: + log.warn(u'Failed to activate %s' % self.doc.filepath) + return False def slide(self, slide): """ Go to a specific slide """ log.debug(u'Live = %s, slide' % self.is_live) + if not self.doc: + return if not self.is_live: return if self.doc.is_blank(): self.doc.slidenumber = int(slide) + 1 return - self.activate() + if not self.activate(): + return self.doc.goto_slide(int(slide) + 1) self.doc.poll_slidenumber(self.is_live) @@ -119,12 +130,15 @@ class Controller(object): Based on the handler passed at startup triggers the first slide """ log.debug(u'Live = %s, first' % self.is_live) + if not self.doc: + return if not self.is_live: return if self.doc.is_blank(): self.doc.slidenumber = 1 return - self.activate() + if not self.activate(): + return self.doc.start_presentation() self.doc.poll_slidenumber(self.is_live) @@ -133,12 +147,15 @@ class Controller(object): Based on the handler passed at startup triggers the last slide """ log.debug(u'Live = %s, last' % self.is_live) + if not self.doc: + return if not self.is_live: return if self.doc.is_blank(): self.doc.slidenumber = self.doc.get_slide_count() return - self.activate() + if not self.activate(): + return self.doc.goto_slide(self.doc.get_slide_count()) self.doc.poll_slidenumber(self.is_live) @@ -147,6 +164,8 @@ class Controller(object): Based on the handler passed at startup triggers the next slide event """ log.debug(u'Live = %s, next' % self.is_live) + if not self.doc: + return if not self.is_live: return if self.doc.is_blank(): @@ -158,7 +177,8 @@ class Controller(object): # contain animations that need to be stepped through. if self.doc.slidenumber > self.doc.get_slide_count(): return - self.activate() + if not self.activate(): + return self.doc.next_step() self.doc.poll_slidenumber(self.is_live) @@ -167,13 +187,16 @@ class Controller(object): Based on the handler passed at startup triggers the previous slide event """ log.debug(u'Live = %s, previous' % self.is_live) + if not self.doc: + return if not self.is_live: return if self.doc.is_blank(): if self.doc.slidenumber > 1: self.doc.slidenumber = self.doc.slidenumber - 1 return - self.activate() + if not self.activate(): + return self.doc.previous_step() self.doc.poll_slidenumber(self.is_live) @@ -182,6 +205,8 @@ class Controller(object): Based on the handler passed at startup triggers slide show to shut down """ log.debug(u'Live = %s, shutdown' % self.is_live) + if not self.doc: + return self.doc.close_presentation() self.doc = None @@ -190,6 +215,8 @@ class Controller(object): Instruct the controller to blank the presentation """ log.debug(u'Live = %s, blank' % self.is_live) + if not self.doc: + return if not self.is_live: return if not self.doc.is_loaded(): @@ -205,6 +232,8 @@ class Controller(object): Instruct the controller to stop and hide the presentation """ log.debug(u'Live = %s, stop' % self.is_live) + if not self.doc: + return if not self.is_live: return if not self.doc.is_loaded(): @@ -218,9 +247,12 @@ class Controller(object): Instruct the controller to unblank the presentation """ log.debug(u'Live = %s, unblank' % self.is_live) + if not self.doc: + return if not self.is_live: return - self.activate() + if not self.activate(): + return if self.doc.slidenumber and \ self.doc.slidenumber != self.doc.get_slide_number(): self.doc.goto_slide(self.doc.slidenumber) @@ -228,6 +260,8 @@ class Controller(object): Receiver.send_message(u'live_display_hide', HideMode.Screen) def poll(self): + if not self.doc: + return self.doc.poll_slidenumber(self.is_live) diff --git a/openlp/plugins/presentations/lib/powerpointcontroller.py b/openlp/plugins/presentations/lib/powerpointcontroller.py index 54b9c2144..63183e7b5 100644 --- a/openlp/plugins/presentations/lib/powerpointcontroller.py +++ b/openlp/plugins/presentations/lib/powerpointcontroller.py @@ -94,9 +94,9 @@ class PowerpointController(PresentationController): self.docs[0].close_presentation() if self.process is None: return - if self.process.Presentations.Count > 0: - return try: + if self.process.Presentations.Count > 0: + return self.process.Quit() except pywintypes.com_error: pass @@ -253,6 +253,8 @@ class PowerpointDocument(PresentationDocument): renderer = self.controller.plugin.renderer rect = renderer.screens.current[u'size'] ppt_window = self.presentation.SlideShowSettings.Run() + if not ppt_window: + return ppt_window.Top = rect.y() * 72 / dpi ppt_window.Height = rect.height() * 72 / dpi ppt_window.Left = rect.x() * 72 / dpi From 0836306f1bd3b03ab3e4b48805dcbe16aa998781 Mon Sep 17 00:00:00 2001 From: Martin Zibricky Date: Fri, 12 Oct 2012 00:55:21 +0200 Subject: [PATCH 02/18] Bug 687638: add function locale_compare. --- openlp/core/utils/__init__.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 41a097a15..957fde829 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -488,10 +488,24 @@ def format_time(text, local_time): return re.sub('\%[a-zA-Z]', match_formatting, text) +def locale_compare(string1, string2): + """ + Compares two strings according to the current QLocale settings. + + As any other compare function, returns a negative, or a positive value, + or 0, depending on whether string1 collates before or after string2 or + is equal to it. + """ + # Function locale.strcol() from standard Python library does not work + # properly on Windows and probably somewhere else. + return int(QtCore.QString.localeAwareCompare( + QtCore.QString(string1).toLower(), QtCore.QString(string2).toLower())) + + from languagemanager import LanguageManager from actions import ActionList __all__ = [u'AppLocation', u'get_application_version', u'check_latest_version', u'add_actions', u'get_filesystem_encoding', u'LanguageManager', u'ActionList', u'get_web_page', u'get_uno_command', u'get_uno_instance', - u'delete_file', u'clean_filename', u'format_time'] + u'delete_file', u'clean_filename', u'format_time', u'locale_compare'] From 7b608a948ad473b9f514dc10cc6a85f40b6a6683 Mon Sep 17 00:00:00 2001 From: Martin Zibricky Date: Fri, 12 Oct 2012 02:03:37 +0200 Subject: [PATCH 03/18] Bug 687638: use locale aware comparison for song list. --- openlp/plugins/songs/lib/mediaitem.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 88999dce4..e338a11d9 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -27,7 +27,6 @@ ############################################################################### import logging -import locale import re import os import shutil @@ -40,7 +39,7 @@ from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, \ check_directory_exists from openlp.core.lib.ui import UiStrings, create_widget_action from openlp.core.lib.settings import Settings -from openlp.core.utils import AppLocation +from openlp.core.utils import AppLocation, locale_compare from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, \ SongImportForm, SongExportForm from openlp.plugins.songs.lib import OpenLyrics, SongXML, VerseType, \ @@ -263,7 +262,7 @@ class SongMediaItem(MediaManagerItem): # Sort the songs by its title considering language specific characters. # lower() is needed for windows! searchresults.sort( - cmp=locale.strcoll, key=lambda song: song.title.lower()) + cmp=locale_compare, key=lambda song: song.title) for song in searchresults: # Do not display temporary songs if song.temporary: From 2cc18a8fb448f62adc1be25270141bff00475b33 Mon Sep 17 00:00:00 2001 From: Martin Zibricky Date: Fri, 12 Oct 2012 13:55:06 +0200 Subject: [PATCH 04/18] Bug #687638: use locale aware comparison for songs by default. --- openlp/core/utils/__init__.py | 4 ++-- openlp/plugins/songs/forms/songexportform.py | 3 +-- openlp/plugins/songs/lib/db.py | 10 +++++++++- openlp/plugins/songs/lib/mediaitem.py | 7 ++----- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 957fde829..764cab06a 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -490,11 +490,11 @@ def format_time(text, local_time): def locale_compare(string1, string2): """ - Compares two strings according to the current QLocale settings. + Compares two strings according to the current locale settings. As any other compare function, returns a negative, or a positive value, or 0, depending on whether string1 collates before or after string2 or - is equal to it. + is equal to it. Comparison is case insensitive. """ # Function locale.strcol() from standard Python library does not work # properly on Windows and probably somewhere else. diff --git a/openlp/plugins/songs/forms/songexportform.py b/openlp/plugins/songs/forms/songexportform.py index c483c91b6..15239f9c2 100644 --- a/openlp/plugins/songs/forms/songexportform.py +++ b/openlp/plugins/songs/forms/songexportform.py @@ -29,7 +29,6 @@ The :mod:`songexportform` module provides the wizard for exporting songs to the OpenLyrics format. """ -import locale import logging from PyQt4 import QtCore, QtGui @@ -252,7 +251,7 @@ class SongExportForm(OpenLPWizard): # Load the list of songs. Receiver.send_message(u'cursor_busy') songs = self.plugin.manager.get_all_objects(Song) - songs.sort(cmp=locale.strcoll, key=lambda song: song.title.lower()) + songs.sort() for song in songs: # No need to export temporary songs. if song.temporary: diff --git a/openlp/plugins/songs/lib/db.py b/openlp/plugins/songs/lib/db.py index d79d177fd..0d404a235 100644 --- a/openlp/plugins/songs/lib/db.py +++ b/openlp/plugins/songs/lib/db.py @@ -35,6 +35,7 @@ from sqlalchemy.orm import mapper, relation from sqlalchemy.sql.expression import func from openlp.core.lib.db import BaseModel, init_db +from openlp.core.utils import locale_compare class Author(BaseModel): """ @@ -63,7 +64,14 @@ class Song(BaseModel): """ Song model """ - pass + # By default sort the songs by its title considering language specific + # characters. + def __lt__(self, other): + r = locale_compare(self.title, other.title) + return True if r < 0 else False + + def __eq__(self, other): + return 0 == locale_compare(self.title, other.title) class Topic(BaseModel): diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index e338a11d9..0808bcba0 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -39,7 +39,7 @@ from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, \ check_directory_exists from openlp.core.lib.ui import UiStrings, create_widget_action from openlp.core.lib.settings import Settings -from openlp.core.utils import AppLocation, locale_compare +from openlp.core.utils import AppLocation from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, \ SongImportForm, SongExportForm from openlp.plugins.songs.lib import OpenLyrics, SongXML, VerseType, \ @@ -259,10 +259,7 @@ class SongMediaItem(MediaManagerItem): log.debug(u'display results Song') self.saveAutoSelectId() self.listView.clear() - # Sort the songs by its title considering language specific characters. - # lower() is needed for windows! - searchresults.sort( - cmp=locale_compare, key=lambda song: song.title) + searchresults.sort() for song in searchresults: # Do not display temporary songs if song.temporary: From 4427d4168ed2bb2a08b322f97ab81f8f7d06fdf4 Mon Sep 17 00:00:00 2001 From: Martin Zibricky Date: Fri, 12 Oct 2012 15:00:56 +0200 Subject: [PATCH 05/18] Bug #687638: use locale aware comparison in other places too. --- openlp/core/ui/thememanager.py | 9 ++++----- openlp/plugins/bibles/forms/bibleimportform.py | 5 ++--- openlp/plugins/bibles/lib/mediaitem.py | 6 +++--- openlp/plugins/custom/lib/db.py | 11 ++++++++++- openlp/plugins/custom/lib/mediaitem.py | 6 +++--- openlp/plugins/images/lib/mediaitem.py | 12 ++++++------ openlp/plugins/media/lib/mediaitem.py | 14 +++++++------- openlp/plugins/presentations/lib/mediaitem.py | 10 +++++----- openlp/plugins/songs/lib/db.py | 2 +- 9 files changed, 41 insertions(+), 34 deletions(-) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 844ffec8c..a5293e3a8 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -30,7 +30,6 @@ import os import zipfile import shutil import logging -import locale import re from xml.etree.ElementTree import ElementTree, XML @@ -46,7 +45,8 @@ from openlp.core.lib.ui import UiStrings, critical_error_message_box, \ create_widget_action from openlp.core.theme import Theme from openlp.core.ui import FileRenameForm, ThemeForm -from openlp.core.utils import AppLocation, delete_file, get_filesystem_encoding +from openlp.core.utils import AppLocation, delete_file, locale_compare, \ + get_filesystem_encoding log = logging.getLogger(__name__) @@ -457,9 +457,8 @@ class ThemeManager(QtGui.QWidget): self.configUpdated() files = SettingsManager.get_files(self.settingsSection, u'.png') # Sort the themes by its name considering language specific characters. - # lower() is needed for windows! - files.sort(key=lambda file_name: unicode(file_name).lower(), - cmp=locale.strcoll) + files.sort(key=lambda file_name: unicode(file_name), + cmp=locale_compare) # now process the file list of png files for name in files: # check to see file is in theme root directory diff --git a/openlp/plugins/bibles/forms/bibleimportform.py b/openlp/plugins/bibles/forms/bibleimportform.py index 0a1d4cc23..d805ba34f 100644 --- a/openlp/plugins/bibles/forms/bibleimportform.py +++ b/openlp/plugins/bibles/forms/bibleimportform.py @@ -30,7 +30,6 @@ The bible import functions for OpenLP """ import logging import os -import locale from PyQt4 import QtCore, QtGui @@ -39,7 +38,7 @@ from openlp.core.lib.db import delete_database from openlp.core.lib.ui import UiStrings, critical_error_message_box from openlp.core.lib.settings import Settings from openlp.core.ui.wizard import OpenLPWizard, WizardStrings -from openlp.core.utils import AppLocation +from openlp.core.utils import AppLocation, locale_compare from openlp.plugins.bibles.lib.manager import BibleFormat from openlp.plugins.bibles.lib.db import BiblesResourcesDB, clean_filename @@ -523,7 +522,7 @@ class BibleImportForm(OpenLPWizard): """ self.webTranslationComboBox.clear() bibles = self.web_bible_list[index].keys() - bibles.sort(cmp=locale.strcoll) + bibles.sort(cmp=locale_compare) self.webTranslationComboBox.addItems(bibles) def onOsisBrowseButtonClicked(self): diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 5176e7d47..0647076c8 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -27,7 +27,6 @@ ############################################################################### import logging -import locale from PyQt4 import QtCore, QtGui @@ -38,6 +37,7 @@ from openlp.core.lib.settings import Settings from openlp.core.lib.ui import UiStrings, set_case_insensitive_completer, \ create_horizontal_adjusting_combo_box, critical_error_message_box, \ find_and_set_in_combo_box, build_icon +from openlp.core.utils import locale_compare from openlp.plugins.bibles.forms import BibleImportForm, EditBibleForm from openlp.plugins.bibles.lib import LayoutStyle, DisplayStyle, \ VerseReferenceList, get_reference_separator, LanguageSelection, \ @@ -381,7 +381,7 @@ class BibleMediaItem(MediaManagerItem): # Get all bibles and sort the list. bibles = self.plugin.manager.get_bibles().keys() bibles = filter(None, bibles) - bibles.sort(cmp=locale.strcoll) + bibles.sort(cmp=locale_compare) # Load the bibles into the combo boxes. self.quickVersionComboBox.addItems(bibles) self.quickSecondComboBox.addItems(bibles) @@ -538,7 +538,7 @@ class BibleMediaItem(MediaManagerItem): data = BiblesResourcesDB.get_book_by_id( book.book_reference_id) books.append(data[u'name'] + u' ') - books.sort(cmp=locale.strcoll) + books.sort(cmp=locale_compare) set_case_insensitive_completer(books, self.quickSearchEdit) def onImportClick(self): diff --git a/openlp/plugins/custom/lib/db.py b/openlp/plugins/custom/lib/db.py index 6f3155f48..c885562f2 100644 --- a/openlp/plugins/custom/lib/db.py +++ b/openlp/plugins/custom/lib/db.py @@ -34,12 +34,21 @@ from sqlalchemy import Column, Table, types from sqlalchemy.orm import mapper from openlp.core.lib.db import BaseModel, init_db +from openlp.core.utils import locale_compare class CustomSlide(BaseModel): """ CustomSlide model """ - pass + # By default sort the customs by its title considering language specific + # characters. + def __lt__(self, other): + r = locale_compare(self.title, other.title) + return True if r < 0 else False + + def __eq__(self, other): + return 0 == locale_compare(self.title, other.title) + def init_schema(url): """ diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index 663c5489d..01053549f 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -27,7 +27,6 @@ ############################################################################### import logging -import locale from PyQt4 import QtCore, QtGui from sqlalchemy.sql import or_, func @@ -36,6 +35,7 @@ from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, \ check_item_selected, translate from openlp.core.lib.ui import UiStrings from openlp.core.lib.settings import Settings +from openlp.core.utils import locale_compare from openlp.plugins.custom.forms import EditCustomForm from openlp.plugins.custom.lib import CustomXMLParser from openlp.plugins.custom.lib.db import CustomSlide @@ -110,9 +110,9 @@ class CustomMediaItem(MediaManagerItem): self.saveAutoSelectId() self.listView.clear() # Sort the customs by its title considering language specific - # characters. lower() is needed for windows! + # characters. custom_slides.sort( - cmp=locale.strcoll, key=lambda custom: custom.title.lower()) + cmp=locale_compare, key=lambda custom: custom.title) for custom_slide in custom_slides: custom_name = QtGui.QListWidgetItem(custom_slide.title) custom_name.setData( diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 0fdb1537c..9239f8d72 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -28,7 +28,6 @@ import logging import os -import locale from PyQt4 import QtCore, QtGui @@ -37,7 +36,8 @@ from openlp.core.lib import MediaManagerItem, build_icon, ItemCapabilities, \ Receiver, create_thumb, validate_thumb from openlp.core.lib.ui import UiStrings, critical_error_message_box from openlp.core.lib.settings import Settings -from openlp.core.utils import AppLocation, delete_file, get_images_filter +from openlp.core.utils import AppLocation, delete_file, locale_compare, \ + get_images_filter log = logging.getLogger(__name__) @@ -126,10 +126,10 @@ class ImageMediaItem(MediaManagerItem): if not initialLoad: Receiver.send_message(u'cursor_busy') self.plugin.formParent.displayProgressBar(len(images)) - # Sort the themes by its filename considering language specific - # characters. lower() is needed for windows! - images.sort(cmp=locale.strcoll, - key=lambda filename: os.path.split(unicode(filename))[1].lower()) + # Sort the images by its filename considering language specific + # characters. + images.sort(cmp=locale_compare, + key=lambda filename: os.path.split(unicode(filename))[1]) for imageFile in images: filename = os.path.split(unicode(imageFile))[1] thumb = os.path.join(self.servicePath, filename) diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index bd987e79d..9f661149b 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -28,7 +28,6 @@ import logging import os -import locale from PyQt4 import QtCore, QtGui @@ -39,6 +38,7 @@ from openlp.core.lib.ui import UiStrings, critical_error_message_box, \ create_horizontal_adjusting_combo_box from openlp.core.ui import Controller, Display from openlp.core.ui.media import get_media_players, set_media_players +from openlp.core.utils import locale_compare log = logging.getLogger(__name__) @@ -285,10 +285,10 @@ class MediaMediaItem(MediaManagerItem): u'media', self.getFileList()) def loadList(self, media): - # Sort the themes by its filename considering language specific - # characters. lower() is needed for windows! - media.sort(cmp=locale.strcoll, - key=lambda filename: os.path.split(unicode(filename))[1].lower()) + # Sort the media by its filename considering language specific + # characters. + media.sort(cmp=locale_compare, + key=lambda filename: os.path.split(unicode(filename))[1]) for track in media: track_info = QtCore.QFileInfo(track) if track_info.isFile(): @@ -307,8 +307,8 @@ class MediaMediaItem(MediaManagerItem): def getList(self, type=MediaType.Audio): media = SettingsManager.load_list(self.settingsSection, u'media') - media.sort(cmp=locale.strcoll, - key=lambda filename: os.path.split(unicode(filename))[1].lower()) + media.sort(cmp=locale_compare, + key=lambda filename: os.path.split(unicode(filename))[1]) ext = [] if type == MediaType.Audio: ext = self.plugin.audio_extensions_list diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 290882e26..9cfed177c 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -28,7 +28,6 @@ import logging import os -import locale from PyQt4 import QtCore, QtGui @@ -38,6 +37,7 @@ from openlp.core.lib import MediaManagerItem, build_icon, SettingsManager, \ from openlp.core.lib.ui import UiStrings, critical_error_message_box, \ create_horizontal_adjusting_combo_box from openlp.core.lib.settings import Settings +from openlp.core.utils import locale_compare from openlp.plugins.presentations.lib import MessageListener log = logging.getLogger(__name__) @@ -169,10 +169,10 @@ class PresentationMediaItem(MediaManagerItem): if not initialLoad: Receiver.send_message(u'cursor_busy') self.plugin.formParent.displayProgressBar(len(files)) - # Sort the themes by its filename considering language specific - # characters. lower() is needed for windows! - files.sort(cmp=locale.strcoll, - key=lambda filename: os.path.split(unicode(filename))[1].lower()) + # Sort the presentations by its filename considering language specific + # characters. + files.sort(cmp=locale_compare, + key=lambda filename: os.path.split(unicode(filename))[1]) for file in files: if not initialLoad: self.plugin.formParent.incrementProgressBar() diff --git a/openlp/plugins/songs/lib/db.py b/openlp/plugins/songs/lib/db.py index 0d404a235..36b6d53ad 100644 --- a/openlp/plugins/songs/lib/db.py +++ b/openlp/plugins/songs/lib/db.py @@ -69,7 +69,7 @@ class Song(BaseModel): def __lt__(self, other): r = locale_compare(self.title, other.title) return True if r < 0 else False - + def __eq__(self, other): return 0 == locale_compare(self.title, other.title) From 83de6bb99f23e97ccfbfd549f08c5b1c07b9b980 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Fri, 12 Oct 2012 20:51:47 +0200 Subject: [PATCH 06/18] Fixed bug #851706: The song import dialog now shows individual songs being imported. Also tried to make the progress page of the FTW work better, pity it is only slightly... Fixes: https://launchpad.net/bugs/851706 --- openlp/core/ui/firsttimeform.py | 14 +++++++++++- openlp/plugins/songs/lib/olpimport.py | 15 +++++++++--- openlp/plugins/songs/songsplugin.py | 33 +++++++++++++++++++++------ 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index 1bd746759..0461e49d1 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -177,8 +177,10 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): return FirstTimePage.Progress elif self.currentId() == FirstTimePage.Themes: Receiver.send_message(u'cursor_busy') + Receiver.send_message(u'openlp_process_events') while not self.themeScreenshotThread.isFinished(): time.sleep(0.1) + Receiver.send_message(u'openlp_process_events') # Build the screenshot icons, as this can not be done in the thread. self._buildThemeScreenshots() Receiver.send_message(u'cursor_normal') @@ -188,10 +190,11 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): def onCurrentIdChanged(self, pageId): """ - Detects Page changes and updates as approprate. + Detects Page changes and updates as appropriate. """ # Keep track of the page we are at. Triggering "Cancel" causes pageId # to be a -1. + Receiver.send_message(u'openlp_process_events') if pageId != -1: self.lastId = pageId if pageId == FirstTimePage.Plugins: @@ -227,6 +230,10 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): self.cancelButton.setVisible(False) elif pageId == FirstTimePage.Progress: Receiver.send_message(u'cursor_busy') + self.update() + Receiver.send_message(u'openlp_process_events') + time.sleep(0.5) + Receiver.send_message(u'openlp_process_events') self._preWizard() Receiver.send_message(u'openlp_process_events') self._performWizard() @@ -342,8 +349,10 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): self.max_progress = 0 self.finishButton.setVisible(False) Receiver.send_message(u'openlp_process_events') + time.sleep(0.1) # Loop through the songs list and increase for each selected item for i in xrange(self.songsListWidget.count()): + Receiver.send_message(u'openlp_process_events') item = self.songsListWidget.item(i) if item.checkState() == QtCore.Qt.Checked: filename = item.data(QtCore.Qt.UserRole).toString() @@ -352,6 +361,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): # Loop through the Bibles list and increase for each selected item iterator = QtGui.QTreeWidgetItemIterator(self.biblesTreeWidget) while iterator.value(): + Receiver.send_message(u'openlp_process_events') item = iterator.value() if item.parent() and item.checkState(0) == QtCore.Qt.Checked: filename = item.data(0, QtCore.Qt.UserRole).toString() @@ -360,6 +370,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): iterator += 1 # Loop through the themes list and increase for each selected item for i in xrange(self.themesListWidget.count()): + Receiver.send_message(u'openlp_process_events') item = self.themesListWidget.item(i) if item.checkState() == QtCore.Qt.Checked: filename = item.data(QtCore.Qt.UserRole).toString() @@ -381,6 +392,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): self.progressPage.setTitle(translate('OpenLP.FirstTimeWizard', 'Setting Up')) self.progressPage.setSubTitle(u'Setup complete.') + Receiver.send_message(u'openlp_process_events') def _postWizard(self): """ diff --git a/openlp/plugins/songs/lib/olpimport.py b/openlp/plugins/songs/lib/olpimport.py index 7a9d98c98..4b97fdafe 100644 --- a/openlp/plugins/songs/lib/olpimport.py +++ b/openlp/plugins/songs/lib/olpimport.py @@ -63,10 +63,14 @@ class OpenLPSongImport(SongImport): SongImport.__init__(self, manager, **kwargs) self.sourceSession = None - def doImport(self): + def doImport(self, progressDialog=None): """ Run the import for an OpenLP version 2 song database. + + ``progressDialog`` + The QProgressDialog used when importing songs from the FRW. """ + class OldAuthor(BaseModel): """ Author model @@ -101,13 +105,14 @@ class OpenLPSongImport(SongImport): """ pass - + # Check the file type if not self.importSource.endswith(u'.sqlite'): self.logError(self.importSource, translate('SongsPlugin.OpenLPSongImport', 'Not a valid OpenLP 2.0 song database.')) return self.importSource = u'sqlite:///%s' % self.importSource + # Load the db file engine = create_engine(self.importSource) source_meta = MetaData() source_meta.reflect(engine) @@ -224,7 +229,11 @@ class OpenLPSongImport(SongImport): file_name=media_file.file_name)) clean_song(self.manager, new_song) self.manager.save_object(new_song) - if self.importWizard: + if progressDialog: + progressDialog.setValue(progressDialog.value() + 1) + progressDialog.setLabelText( + WizardStrings.ImportingType % new_song.title) + else: self.importWizard.incrementProgressBar( WizardStrings.ImportingType % new_song.title) if self.stopImportFlag: diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index 8b7bd36e8..46506a478 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -29,6 +29,7 @@ import logging import os from tempfile import gettempdir +import sqlite3 from PyQt4 import QtCore, QtGui @@ -82,7 +83,7 @@ class SongsPlugin(Plugin): unicode(UiStrings().Tools)) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'servicemanager_new_service'), - self.clearTemporarySongs) + self.clearTemporarySongs) def addImportMenuItem(self, import_menu): @@ -235,31 +236,37 @@ class SongsPlugin(Plugin): If the first time wizard has run, this function is run to import all the new songs into the database. """ + Receiver.send_message(u'openlp_process_events') self.onToolsReindexItemTriggered() + Receiver.send_message(u'openlp_process_events') db_dir = unicode(os.path.join( unicode(gettempdir(), get_filesystem_encoding()), u'openlp')) if not os.path.exists(db_dir): return song_dbs = [] + song_count = 0 for sfile in os.listdir(db_dir): if sfile.startswith(u'songs_') and sfile.endswith(u'.sqlite'): + Receiver.send_message(u'openlp_process_events') song_dbs.append(os.path.join(db_dir, sfile)) + song_count += self._countSongs(os.path.join(db_dir, sfile)) if not song_dbs: return + Receiver.send_message(u'openlp_process_events') progress = QtGui.QProgressDialog(self.formParent) progress.setWindowModality(QtCore.Qt.WindowModal) progress.setWindowTitle(translate('OpenLP.Ui', 'Importing Songs')) progress.setLabelText(translate('OpenLP.Ui', 'Starting import...')) progress.setCancelButton(None) - progress.setRange(0, len(song_dbs)) + progress.setRange(0, song_count) progress.setMinimumDuration(0) progress.forceShow() - for idx, db in enumerate(song_dbs): - progress.setValue(idx) - Receiver.send_message(u'openlp_process_events') + Receiver.send_message(u'openlp_process_events') + for db in song_dbs: importer = OpenLPSongImport(self.manager, filename=db) - importer.doImport() - progress.setValue(len(song_dbs)) + importer.doImport(progress) + Receiver.send_message(u'openlp_process_events') + progress.setValue(song_count) self.mediaItem.onSearchTextButtonClicked() def finalise(self): @@ -287,3 +294,15 @@ class SongsPlugin(Plugin): songs = self.manager.get_all_objects(Song, Song.temporary == True) for song in songs: self.manager.delete_object(Song, song.id) + + def _countSongs(self, db_file): + connection = sqlite3.connect(db_file) + cursor = connection.cursor() + cursor.execute(u'SELECT COUNT(id) AS song_count FROM songs') + song_count = cursor.fetchone()[0] + connection.close() + try: + song_count = int(song_count) + except (TypeError, ValueError): + song_count = 0 + return song_count From efef105c3facf0e02bb39202a846581b08321eb1 Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Fri, 12 Oct 2012 20:15:36 +0100 Subject: [PATCH 07/18] ppt problems --- openlp/plugins/presentations/lib/powerpointcontroller.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/openlp/plugins/presentations/lib/powerpointcontroller.py b/openlp/plugins/presentations/lib/powerpointcontroller.py index 63183e7b5..c00c6d559 100644 --- a/openlp/plugins/presentations/lib/powerpointcontroller.py +++ b/openlp/plugins/presentations/lib/powerpointcontroller.py @@ -210,6 +210,13 @@ class PowerpointDocument(PresentationDocument): self.presentation.SlideShowSettings.Run() self.presentation.SlideShowWindow.View.State = 1 self.presentation.SlideShowWindow.Activate() + if self.presentation.Application.Version == u'14.0': + # Unblanking is broken in PowerPoint 2010, need to redisplay + slide = self.presentation.SlideShowWindow.View.CurrentShowPosition + click = self.presentation.SlideShowWindow.View.GetClickIndex() + self.presentation.SlideShowWindow.View.GotoSlide(slide) + if click: + self.presentation.SlideShowWindow.View.GotoClick(click) def blank_screen(self): """ From e26cd9ca6bc63b31cbe75b5660f81a8b52cd538a Mon Sep 17 00:00:00 2001 From: Martin Zibricky Date: Fri, 12 Oct 2012 21:40:15 +0200 Subject: [PATCH 08/18] Bug #687638: for customs cmp method in sort not necessary. --- openlp/plugins/custom/lib/mediaitem.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index 01053549f..10a3ec056 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -35,7 +35,6 @@ from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, \ check_item_selected, translate from openlp.core.lib.ui import UiStrings from openlp.core.lib.settings import Settings -from openlp.core.utils import locale_compare from openlp.plugins.custom.forms import EditCustomForm from openlp.plugins.custom.lib import CustomXMLParser from openlp.plugins.custom.lib.db import CustomSlide @@ -109,10 +108,7 @@ class CustomMediaItem(MediaManagerItem): # Sort out what custom we want to select after loading the list. self.saveAutoSelectId() self.listView.clear() - # Sort the customs by its title considering language specific - # characters. - custom_slides.sort( - cmp=locale_compare, key=lambda custom: custom.title) + custom_slides.sort() for custom_slide in custom_slides: custom_name = QtGui.QListWidgetItem(custom_slide.title) custom_name.setData( From c7e555e0e8660d71ae1edece85f981f9c807c32f Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Fri, 12 Oct 2012 22:33:10 +0100 Subject: [PATCH 09/18] Various end of show issues --- openlp/plugins/presentations/lib/impresscontroller.py | 10 ++++++++-- .../plugins/presentations/lib/powerpointcontroller.py | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index ceb793cb2..b1c0bcc82 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -363,7 +363,9 @@ class ImpressDocument(PresentationDocument): log.debug(u'is active OpenOffice') if not self.is_loaded(): return False - return self.control is not None + if not self.control: + return False + return self.control.isRunning() def unblank_screen(self): """ @@ -384,7 +386,7 @@ class ImpressDocument(PresentationDocument): Returns true if screen is blank """ log.debug(u'is blank OpenOffice') - if self.control: + if self.control and self.control.isRunning(): return self.control.isPaused() else: return False @@ -440,7 +442,11 @@ class ImpressDocument(PresentationDocument): """ Triggers the next effect of slide on the running presentation """ + is_paused = self.control.isPaused() self.control.gotoNextEffect() + time.sleep(0.1) + if not is_paused and self.control.isPaused(): + self.control.gotoPreviousEffect() def previous_step(self): """ diff --git a/openlp/plugins/presentations/lib/powerpointcontroller.py b/openlp/plugins/presentations/lib/powerpointcontroller.py index c00c6d559..7da9a95d7 100644 --- a/openlp/plugins/presentations/lib/powerpointcontroller.py +++ b/openlp/plugins/presentations/lib/powerpointcontroller.py @@ -295,6 +295,8 @@ class PowerpointDocument(PresentationDocument): """ log.debug(u'next_step') self.presentation.SlideShowWindow.View.Next() + if self.get_slide_number() > self.get_slide_count(): + self.previous_step() def previous_step(self): """ From 0ddeef9d8ff19218e27b9d111918b9622819cea6 Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Fri, 12 Oct 2012 23:13:58 +0100 Subject: [PATCH 10/18] Blank desktop issues --- .../presentations/lib/messagelistener.py | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/openlp/plugins/presentations/lib/messagelistener.py b/openlp/plugins/presentations/lib/messagelistener.py index dc8ac79d1..fdceda4ab 100644 --- a/openlp/plugins/presentations/lib/messagelistener.py +++ b/openlp/plugins/presentations/lib/messagelistener.py @@ -49,6 +49,7 @@ class Controller(object): """ self.is_live = live self.doc = None + self.hide_mode = None log.info(u'%s controller loaded' % live) def add_handler(self, controller, file, hide_mode, slide_no): @@ -67,6 +68,7 @@ class Controller(object): # Inform slidecontroller that the action failed? return self.doc.slidenumber = slide_no + self.hide_mode = hide_mode if self.is_live: if hide_mode == HideMode.Screen: Receiver.send_message(u'live_display_hide', HideMode.Screen) @@ -117,7 +119,7 @@ class Controller(object): return if not self.is_live: return - if self.doc.is_blank(): + if self.hide_mode: self.doc.slidenumber = int(slide) + 1 return if not self.activate(): @@ -134,7 +136,7 @@ class Controller(object): return if not self.is_live: return - if self.doc.is_blank(): + if self.hide_mode: self.doc.slidenumber = 1 return if not self.activate(): @@ -151,7 +153,7 @@ class Controller(object): return if not self.is_live: return - if self.doc.is_blank(): + if self.hide_mode: self.doc.slidenumber = self.doc.get_slide_count() return if not self.activate(): @@ -168,7 +170,7 @@ class Controller(object): return if not self.is_live: return - if self.doc.is_blank(): + if self.hide_mode: if self.doc.slidenumber < self.doc.get_slide_count(): self.doc.slidenumber = self.doc.slidenumber + 1 return @@ -191,7 +193,7 @@ class Controller(object): return if not self.is_live: return - if self.doc.is_blank(): + if self.hide_mode: if self.doc.slidenumber > 1: self.doc.slidenumber = self.doc.slidenumber - 1 return @@ -215,23 +217,28 @@ class Controller(object): Instruct the controller to blank the presentation """ log.debug(u'Live = %s, blank' % self.is_live) + self.hide_mode = hide_mode if not self.doc: return if not self.is_live: return - if not self.doc.is_loaded(): - return - if not self.doc.is_active(): - return if hide_mode == HideMode.Theme: + if not self.doc.is_loaded(): + return + if not self.doc.is_active(): + return Receiver.send_message(u'live_display_hide', HideMode.Theme) - self.doc.blank_screen() + elif hide_mode == HideMode.Blank: + if not self.activate(): + return + self.doc.blank_screen() def stop(self): """ Instruct the controller to stop and hide the presentation """ log.debug(u'Live = %s, stop' % self.is_live) + self.hide_mode = HideMode.Screen if not self.doc: return if not self.is_live: @@ -247,6 +254,7 @@ class Controller(object): Instruct the controller to unblank the presentation """ log.debug(u'Live = %s, unblank' % self.is_live) + self.hide_mode = None if not self.doc: return if not self.is_live: From 43e41b2688d63926479164c8b60078fcf2c1d310 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sat, 13 Oct 2012 19:05:55 +0200 Subject: [PATCH 11/18] Try to lessen the number of superfluous process events signals --- openlp/core/ui/firsttimeform.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index 0461e49d1..14f1299de 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -230,14 +230,12 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): self.cancelButton.setVisible(False) elif pageId == FirstTimePage.Progress: Receiver.send_message(u'cursor_busy') - self.update() - Receiver.send_message(u'openlp_process_events') - time.sleep(0.5) + self.repaint() Receiver.send_message(u'openlp_process_events') + # Try to give the wizard a chance to redraw itself + time.sleep(0.2) self._preWizard() - Receiver.send_message(u'openlp_process_events') self._performWizard() - Receiver.send_message(u'openlp_process_events') self._postWizard() Receiver.send_message(u'cursor_normal') Receiver.send_message(u'openlp_process_events') @@ -270,8 +268,8 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): """ Receiver.send_message(u'cursor_busy') self._performWizard() - Receiver.send_message(u'openlp_process_events') Receiver.send_message(u'cursor_normal') + Receiver.send_message(u'openlp_process_events') Settings().setValue(u'general/has run wizard', QtCore.QVariant(True)) self.close() @@ -349,7 +347,6 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): self.max_progress = 0 self.finishButton.setVisible(False) Receiver.send_message(u'openlp_process_events') - time.sleep(0.1) # Loop through the songs list and increase for each selected item for i in xrange(self.songsListWidget.count()): Receiver.send_message(u'openlp_process_events') @@ -392,7 +389,10 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): self.progressPage.setTitle(translate('OpenLP.FirstTimeWizard', 'Setting Up')) self.progressPage.setSubTitle(u'Setup complete.') + self.repaint() Receiver.send_message(u'openlp_process_events') + # Try to give the wizard a chance to repaint itself + time.sleep(0.1) def _postWizard(self): """ From 4c1fe14fd2f018292eb15e2eff05c96fb94a86e6 Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Sat, 13 Oct 2012 19:32:32 +0100 Subject: [PATCH 12/18] Raoul's kicks --- openlp/plugins/presentations/lib/impresscontroller.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index b1c0bcc82..3d78f7bdb 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -153,9 +153,7 @@ class ImpressController(PresentationController): desktop = None try: desktop = self.manager.createInstance(u'com.sun.star.frame.Desktop') - except AttributeError: - log.warn(u'Failure to find desktop - Impress may have closed') - except pywintypes.com_error: + except (AttributeError, pywintypes.com_error): log.warn(u'Failure to find desktop - Impress may have closed') return desktop if desktop else None @@ -363,9 +361,7 @@ class ImpressDocument(PresentationDocument): log.debug(u'is active OpenOffice') if not self.is_loaded(): return False - if not self.control: - return False - return self.control.isRunning() + return self.control.isRunning() if self.control else False def unblank_screen(self): """ From 9f5ed9589bdd08ab4361f540275ba1901f028441 Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Sat, 13 Oct 2012 20:07:30 +0100 Subject: [PATCH 13/18] Slide counts can only be got if active --- openlp/plugins/presentations/lib/messagelistener.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/presentations/lib/messagelistener.py b/openlp/plugins/presentations/lib/messagelistener.py index fdceda4ab..bf46191ac 100644 --- a/openlp/plugins/presentations/lib/messagelistener.py +++ b/openlp/plugins/presentations/lib/messagelistener.py @@ -171,16 +171,18 @@ class Controller(object): if not self.is_live: return if self.hide_mode: + if not self.doc.is_active(): + return if self.doc.slidenumber < self.doc.get_slide_count(): self.doc.slidenumber = self.doc.slidenumber + 1 return + if not self.activate(): + return # The "End of slideshow" screen is after the last slide # Note, we can't just stop on the last slide, since it may # contain animations that need to be stepped through. if self.doc.slidenumber > self.doc.get_slide_count(): return - if not self.activate(): - return self.doc.next_step() self.doc.poll_slidenumber(self.is_live) @@ -194,6 +196,8 @@ class Controller(object): if not self.is_live: return if self.hide_mode: + if not self.doc.is_active(): + return if self.doc.slidenumber > 1: self.doc.slidenumber = self.doc.slidenumber - 1 return From bbbf426cf2a9c19a5d6632f259bf40acfd8c69ae Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Sat, 13 Oct 2012 20:48:58 +0100 Subject: [PATCH 14/18] If change slides whilst blank, update slidecontroller --- .../presentations/lib/messagelistener.py | 19 ++++++++++++------- .../lib/presentationcontroller.py | 11 ++++++----- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/openlp/plugins/presentations/lib/messagelistener.py b/openlp/plugins/presentations/lib/messagelistener.py index bf46191ac..7cc12c7f9 100644 --- a/openlp/plugins/presentations/lib/messagelistener.py +++ b/openlp/plugins/presentations/lib/messagelistener.py @@ -80,7 +80,7 @@ class Controller(object): else: self.doc.start_presentation() Receiver.send_message(u'live_display_hide', HideMode.Screen) - self.doc.slidenumber = 0 + self.doc.slidenumber = 1 if slide_no > 1: self.slide(slide_no) @@ -121,11 +121,12 @@ class Controller(object): return if self.hide_mode: self.doc.slidenumber = int(slide) + 1 + self.poll() return if not self.activate(): return self.doc.goto_slide(int(slide) + 1) - self.doc.poll_slidenumber(self.is_live) + self.poll() def first(self): """ @@ -138,11 +139,12 @@ class Controller(object): return if self.hide_mode: self.doc.slidenumber = 1 + self.poll() return if not self.activate(): return self.doc.start_presentation() - self.doc.poll_slidenumber(self.is_live) + self.poll() def last(self): """ @@ -155,11 +157,12 @@ class Controller(object): return if self.hide_mode: self.doc.slidenumber = self.doc.get_slide_count() + self.poll() return if not self.activate(): return self.doc.goto_slide(self.doc.get_slide_count()) - self.doc.poll_slidenumber(self.is_live) + self.poll() def next(self): """ @@ -175,6 +178,7 @@ class Controller(object): return if self.doc.slidenumber < self.doc.get_slide_count(): self.doc.slidenumber = self.doc.slidenumber + 1 + self.poll() return if not self.activate(): return @@ -184,7 +188,7 @@ class Controller(object): if self.doc.slidenumber > self.doc.get_slide_count(): return self.doc.next_step() - self.doc.poll_slidenumber(self.is_live) + self.poll() def previous(self): """ @@ -200,11 +204,12 @@ class Controller(object): return if self.doc.slidenumber > 1: self.doc.slidenumber = self.doc.slidenumber - 1 + self.poll() return if not self.activate(): return self.doc.previous_step() - self.doc.poll_slidenumber(self.is_live) + self.poll() def shutdown(self): """ @@ -274,7 +279,7 @@ class Controller(object): def poll(self): if not self.doc: return - self.doc.poll_slidenumber(self.is_live) + self.doc.poll_slidenumber(self.is_live, self.hide_mode) class MessageListener(object): diff --git a/openlp/plugins/presentations/lib/presentationcontroller.py b/openlp/plugins/presentations/lib/presentationcontroller.py index b72e1e9d4..4006cbc3e 100644 --- a/openlp/plugins/presentations/lib/presentationcontroller.py +++ b/openlp/plugins/presentations/lib/presentationcontroller.py @@ -260,16 +260,17 @@ class PresentationDocument(object): else: return None - def poll_slidenumber(self, is_live): + def poll_slidenumber(self, is_live, hide_mode): """ Check the current slide number """ if not self.is_active(): return - current = self.get_slide_number() - if current == self.slidenumber: - return - self.slidenumber = current + if not hide_mode: + current = self.get_slide_number() + if current == self.slidenumber: + return + self.slidenumber = current if is_live: prefix = u'live' else: From 0f18ec43a060b7f4f7bfe99ddee2bf5d2a4eb583 Mon Sep 17 00:00:00 2001 From: Martin Zibricky Date: Sun, 14 Oct 2012 13:11:48 +0200 Subject: [PATCH 15/18] Bug #687638: improved performance of local aware sorting. --- openlp/core/utils/__init__.py | 12 ++++++--- openlp/plugins/songs/forms/songexportform.py | 4 ++- openlp/plugins/songs/lib/db.py | 26 +++++++++++++------- openlp/plugins/songs/lib/mediaitem.py | 5 ++-- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 764cab06a..742b1e4bc 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -498,8 +498,13 @@ def locale_compare(string1, string2): """ # Function locale.strcol() from standard Python library does not work # properly on Windows and probably somewhere else. - return int(QtCore.QString.localeAwareCompare( - QtCore.QString(string1).toLower(), QtCore.QString(string2).toLower())) + return QtCore.QString.localeAwareCompare(string1.lower(), string2.lower()) + + +# For performance reasons provide direct reference to compare function +# without wrapping it in another function making te string lowercase. +# This is needed for sorting songs. +locale_direct_compare = QtCore.QString.localeAwareCompare from languagemanager import LanguageManager @@ -508,4 +513,5 @@ from actions import ActionList __all__ = [u'AppLocation', u'get_application_version', u'check_latest_version', u'add_actions', u'get_filesystem_encoding', u'LanguageManager', u'ActionList', u'get_web_page', u'get_uno_command', u'get_uno_instance', - u'delete_file', u'clean_filename', u'format_time', u'locale_compare'] + u'delete_file', u'clean_filename', u'format_time', u'locale_compare', + u'locale_direct_compare'] diff --git a/openlp/plugins/songs/forms/songexportform.py b/openlp/plugins/songs/forms/songexportform.py index 15239f9c2..1f2988568 100644 --- a/openlp/plugins/songs/forms/songexportform.py +++ b/openlp/plugins/songs/forms/songexportform.py @@ -37,6 +37,7 @@ from openlp.core.lib import build_icon, Receiver, SettingsManager, translate, \ create_separated_list from openlp.core.lib.ui import UiStrings, critical_error_message_box from openlp.core.ui.wizard import OpenLPWizard, WizardStrings +from openlp.core.utils import locale_direct_compare from openlp.plugins.songs.lib.db import Song from openlp.plugins.songs.lib.openlyricsexport import OpenLyricsExport @@ -251,7 +252,8 @@ class SongExportForm(OpenLPWizard): # Load the list of songs. Receiver.send_message(u'cursor_busy') songs = self.plugin.manager.get_all_objects(Song) - songs.sort() + songs.sort( + cmp=locale_direct_compare, key=lambda song: song.sort_string) for song in songs: # No need to export temporary songs. if song.temporary: diff --git a/openlp/plugins/songs/lib/db.py b/openlp/plugins/songs/lib/db.py index 36b6d53ad..122d29859 100644 --- a/openlp/plugins/songs/lib/db.py +++ b/openlp/plugins/songs/lib/db.py @@ -31,11 +31,11 @@ the Songs plugin """ from sqlalchemy import Column, ForeignKey, Table, types -from sqlalchemy.orm import mapper, relation +from sqlalchemy.orm import mapper, relation, reconstructor from sqlalchemy.sql.expression import func +from PyQt4 import QtCore from openlp.core.lib.db import BaseModel, init_db -from openlp.core.utils import locale_compare class Author(BaseModel): """ @@ -64,14 +64,22 @@ class Song(BaseModel): """ Song model """ - # By default sort the songs by its title considering language specific - # characters. - def __lt__(self, other): - r = locale_compare(self.title, other.title) - return True if r < 0 else False + def __init__(self): + self.sort_string = '' - def __eq__(self, other): - return 0 == locale_compare(self.title, other.title) + # This decorator tells sqlalchemy to call this method everytime + # any data on this object are updated. + @reconstructor + def init_on_load(self): + """ + Precompute string to be used for sorting. + + Song sorting is performance sensitive operation. + To get maximum speed lets precompute the string + used for comparison. + """ + # Avoid the overhead of converting string to lowercase and to QString + self.sort_string = QtCore.QString(self.title.lower()) class Topic(BaseModel): diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 0808bcba0..05da69f61 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -39,7 +39,7 @@ from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, \ check_directory_exists from openlp.core.lib.ui import UiStrings, create_widget_action from openlp.core.lib.settings import Settings -from openlp.core.utils import AppLocation +from openlp.core.utils import AppLocation, locale_direct_compare from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, \ SongImportForm, SongExportForm from openlp.plugins.songs.lib import OpenLyrics, SongXML, VerseType, \ @@ -259,7 +259,8 @@ class SongMediaItem(MediaManagerItem): log.debug(u'display results Song') self.saveAutoSelectId() self.listView.clear() - searchresults.sort() + searchresults.sort( + cmp=locale_direct_compare, key=lambda song: song.sort_string) for song in searchresults: # Do not display temporary songs if song.temporary: From 7321f5fb2d7cc1c061b3062a2962c9b00c0236ed Mon Sep 17 00:00:00 2001 From: Martin Zibricky Date: Sun, 14 Oct 2012 20:42:20 +0200 Subject: [PATCH 16/18] Bug #1002038: Disable and hide presentation plugin on osx. --- openlp/core/lib/pluginmanager.py | 8 ++++++++ openlp/core/ui/firsttimewizard.py | 20 +++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index 8899f5846..b90375506 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -85,6 +85,14 @@ class PluginManager(object): log.debug(u'finding plugins in %s at depth %d', unicode(plugin_dir), startdepth) for root, dirs, files in os.walk(plugin_dir): + # TODO Presentation plugin is not yet working on Mac OS X. + # For now just ignore it. The following code will hide it + # in settings dialog. + if sys.platform == 'darwin': + present_plugin_dir = os.path.join(plugin_dir, 'presentations') + # Ignore files from the presentation plugin directory. + if root.startswith(present_plugin_dir): + continue for name in files: if name.endswith(u'.py') and not name.startswith(u'__'): path = os.path.abspath(os.path.join(root, name)) diff --git a/openlp/core/ui/firsttimewizard.py b/openlp/core/ui/firsttimewizard.py index 1ce523cbc..92204a583 100644 --- a/openlp/core/ui/firsttimewizard.py +++ b/openlp/core/ui/firsttimewizard.py @@ -82,13 +82,13 @@ class Ui_FirstTimeWizard(object): self.imageCheckBox.setChecked(True) self.imageCheckBox.setObjectName(u'imageCheckBox') self.pluginLayout.addWidget(self.imageCheckBox) - self.presentationCheckBox = QtGui.QCheckBox(self.pluginPage) - if sys.platform == "darwin": - self.presentationCheckBox.setChecked(False) - else: + # TODO Presentation plugin is not yet working on Mac OS X. + # For now just ignore it. + if sys.platform != 'darwin': + self.presentationCheckBox = QtGui.QCheckBox(self.pluginPage) self.presentationCheckBox.setChecked(True) - self.presentationCheckBox.setObjectName(u'presentationCheckBox') - self.pluginLayout.addWidget(self.presentationCheckBox) + self.presentationCheckBox.setObjectName(u'presentationCheckBox') + self.pluginLayout.addWidget(self.presentationCheckBox) self.mediaCheckBox = QtGui.QCheckBox(self.pluginPage) self.mediaCheckBox.setChecked(True) self.mediaCheckBox.setObjectName(u'mediaCheckBox') @@ -214,9 +214,11 @@ class Ui_FirstTimeWizard(object): self.bibleCheckBox.setText(translate('OpenLP.FirstTimeWizard', 'Bible')) self.imageCheckBox.setText(translate('OpenLP.FirstTimeWizard', 'Images')) - self.presentationCheckBox.setText(translate('OpenLP.FirstTimeWizard', - 'Presentations')) - if sys.platform == "darwin": + # TODO Presentation plugin is not yet working on Mac OS X. + # For now just ignore it. + if sys.platform != 'darwin': + self.presentationCheckBox.setText(translate('OpenLP.FirstTimeWizard', + 'Presentations')) self.presentationCheckBox.setEnabled(False) self.mediaCheckBox.setText(translate('OpenLP.FirstTimeWizard', 'Media (Audio and Video)')) From 16c0ec482e5db0fbe0335ec09c9041e60d9b6e88 Mon Sep 17 00:00:00 2001 From: Martin Zibricky Date: Mon, 15 Oct 2012 10:25:42 +0200 Subject: [PATCH 17/18] Bug #1002038: Fix enabling presentation plugin if no osx os. --- openlp/core/ui/firsttimewizard.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openlp/core/ui/firsttimewizard.py b/openlp/core/ui/firsttimewizard.py index 92204a583..4477dd4cb 100644 --- a/openlp/core/ui/firsttimewizard.py +++ b/openlp/core/ui/firsttimewizard.py @@ -219,7 +219,6 @@ class Ui_FirstTimeWizard(object): if sys.platform != 'darwin': self.presentationCheckBox.setText(translate('OpenLP.FirstTimeWizard', 'Presentations')) - self.presentationCheckBox.setEnabled(False) self.mediaCheckBox.setText(translate('OpenLP.FirstTimeWizard', 'Media (Audio and Video)')) self.remoteCheckBox.setText(translate('OpenLP.FirstTimeWizard', From f84c0899389cb8444f7615306012935e928af61c Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 16 Oct 2012 10:25:54 +0200 Subject: [PATCH 18/18] fixed bug #1066296 (Renaming theme keeps old/new theme in Theme manager) Fixes: https://launchpad.net/bugs/1066296 --- openlp/core/ui/thememanager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index a5293e3a8..70bf78b29 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -284,6 +284,7 @@ class ThemeManager(QtGui.QWidget): plugin.renameTheme(old_theme_name, new_theme_name) self.mainwindow.renderer.update_theme( new_theme_name, old_theme_name) + self.loadThemes() def onCopyTheme(self): """