From ff2ac445f06214be828595767be466eeb6c09e9b Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 20 Jan 2011 17:12:07 +0100 Subject: [PATCH 1/5] fix for Bug #598393 --- openlp/core/ui/servicemanager.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 1acf8b8a0..f9adca9d7 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -801,10 +801,10 @@ class ServiceManager(QtGui.QWidget): and when regenerating all the items due to theme changes. ``serviceItem`` - The item which changed. + The item which changed. (int) ``serviceItemCount`` - The number of items in the service. + The child of the ``serviceItem``, which will be selected. (int) """ # Correct order of items in array count = 1 @@ -837,6 +837,7 @@ class ServiceManager(QtGui.QWidget): treewidgetitem.setToolTip(0, serviceitem.notes) treewidgetitem.setData(0, QtCore.Qt.UserRole, QtCore.QVariant(item[u'order'])) + # Add the children to their parent treewidgetitem. for count, frame in enumerate(serviceitem.get_frames()): treewidgetitem1 = QtGui.QTreeWidgetItem(treewidgetitem) text = frame[u'title'].replace(u'\n', u' ') @@ -844,9 +845,13 @@ class ServiceManager(QtGui.QWidget): treewidgetitem1.setData(0, QtCore.Qt.UserRole, QtCore.QVariant(count)) if serviceItem == itemcount and serviceItemCount == count: - #preserve expanding status as setCurrentItem sets it to True + # Preserve expanding status as setCurrentItem sets it to + # True. temp = item[u'expanded'] - self.serviceManagerList.setCurrentItem(treewidgetitem1) + if item[u'expanded']: + self.serviceManagerList.setCurrentItem(treewidgetitem1) + else: + self.serviceManagerList.setCurrentItem(treewidgetitem) item[u'expanded'] = temp treewidgetitem.setExpanded(item[u'expanded']) @@ -958,7 +963,7 @@ class ServiceManager(QtGui.QWidget): if replace: item.merge(self.serviceItems[sitem][u'service_item']) self.serviceItems[sitem][u'service_item'] = item - self.repaintServiceList(sitem + 1, 0) + self.repaintServiceList(sitem, 0) self.mainwindow.liveController.replaceServiceManagerItem(item) else: # nothing selected for dnd @@ -1046,7 +1051,12 @@ class ServiceManager(QtGui.QWidget): def findServiceItem(self): """ - Finds a ServiceItem in the list + Finds a ServiceItem in the list and returns the position of the + serviceitem and its selected child item. For example, if the third child + item (in the Slidecontroller known as slide) in the second service item + is selected this will return:: + + (1, 2) """ items = self.serviceManagerList.selectedItems() pos = 0 From 7e57fa2f954df0783b6bfed5042978be75be69b6 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 20 Jan 2011 17:43:29 +0100 Subject: [PATCH 2/5] Don't select the child item if not selected --- openlp/core/ui/servicemanager.py | 8 ++++---- openlp/core/ui/slidecontroller.py | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index f9adca9d7..3bdda5516 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -844,13 +844,13 @@ class ServiceManager(QtGui.QWidget): treewidgetitem1.setText(0, text[:40]) treewidgetitem1.setData(0, QtCore.Qt.UserRole, QtCore.QVariant(count)) - if serviceItem == itemcount and serviceItemCount == count: + if serviceItem == itemcount: # Preserve expanding status as setCurrentItem sets it to # True. temp = item[u'expanded'] - if item[u'expanded']: + if item[u'expanded'] and serviceItemCount == count: self.serviceManagerList.setCurrentItem(treewidgetitem1) - else: + elif serviceItemCount == -1: self.serviceManagerList.setCurrentItem(treewidgetitem) item[u'expanded'] = temp treewidgetitem.setExpanded(item[u'expanded']) @@ -1060,7 +1060,7 @@ class ServiceManager(QtGui.QWidget): """ items = self.serviceManagerList.selectedItems() pos = 0 - count = 0 + count = -1 for item in items: parentitem = item.parent() if parentitem is None: diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 28b419616..3e3438100 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -525,6 +525,9 @@ class SlideController(QtGui.QWidget): Called by ServiceManager """ log.debug(u'addServiceManagerItem live = %s' % self.isLive) + # If no valid slide number is specified we take the first one. + if slideno == -1: + slideno = 0 # If service item is the same as the current on only change slide if item.__eq__(self.serviceItem): if slideno + 1 < self.PreviewListWidget.rowCount(): From 2d21d0163cb7832fb05a286b0c497ba22072b4e2 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Fri, 21 Jan 2011 21:21:09 +0000 Subject: [PATCH 3/5] Small EasiSlides refactor --- openlp/plugins/songs/lib/easislidesimport.py | 62 ++++++++------------ 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/openlp/plugins/songs/lib/easislidesimport.py b/openlp/plugins/songs/lib/easislidesimport.py index 93bf2a01d..56349fc5a 100644 --- a/openlp/plugins/songs/lib/easislidesimport.py +++ b/openlp/plugins/songs/lib/easislidesimport.py @@ -81,44 +81,43 @@ class EasiSlidesImport(SongImport): def _parse_song(self, song): self._success = True - self._add_title(song) - self._add_alttitle(song) - self._add_number(song) + self._add_title(self.title, song.Title1, True) + self._add_alttitle(self.alternate_title, song.Title2) + self._add_number(self.song_number, song.SongNumber) + if self.song_number = u'0': + self.song_number = u'' self._add_authors(song) self._add_copyright(song) - self._add_book(song) + self._add_book(self.song_book_name, song.BookReference) self._parse_and_add_lyrics(song) return self._success - def _add_title(self, song): - try: - self.title = unicode(song.Title1).strip() - except UnicodeDecodeError: - log.exception(u'Unicode decode error while decoding Title1') - self._success = False - except AttributeError: - log.exception(u'no Title1') - self._success = False + def _add_unicode_attribute(self, self_attribute, import_attribute, + mandatory=False): + """ + Add imported values to the song model converting them to unicode at the + same time. If the unicode decode fails or a mandatory attribute is not + present _success is set to False so the importer can react + appropriately. - def _add_alttitle(self, song): - try: - self.alternate_title = unicode(song.Title2).strip() - except UnicodeDecodeError: - log.exception(u'Unicode decode error while decoding Title2') - self._success = False - except AttributeError: - pass + ``self_attribute`` + The attribute in the song model to populate. - def _add_number(self, song): + ``import_attribute`` + The imported value to convert to unicode and save to the song. + + ``mandatory`` + Signals that this attribute must exist in a valid song. + """ try: - number = unicode(song.SongNumber) - if number != u'0': - self.song_number = number + self_attribute = unicode(import_attribute).strip() except UnicodeDecodeError: - log.exception(u'Unicode decode error while decoding SongNumber') + log.exception(u'UnicodeDecodeError decoding %s' % import_attribute) self._success = False except AttributeError: - pass + log.exception(u'No attribute %s' % import_attribute) + if mandatory: + self._success = False def _add_authors(self, song): try: @@ -158,15 +157,6 @@ class EasiSlidesImport(SongImport): pass self.add_copyright(u' '.join(copyright)) - def _add_book(self, song): - try: - self.song_book_name = unicode(song.BookReference).strip() - except UnicodeDecodeError: - log.exception(u'Unicode decode error while decoding BookReference') - self._success = False - except AttributeError: - pass - def _parse_and_add_lyrics(self, song): try: lyrics = unicode(song.Contents).strip() From ab17e6aaf0902b2783d631a38b5bf0d7bab36ef7 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Fri, 21 Jan 2011 22:28:34 +0000 Subject: [PATCH 4/5] Small OOo refactor, fix last commit --- openlp/core/utils/__init__.py | 32 ++++++++++++++++++- .../presentations/lib/impresscontroller.py | 30 ++++------------- .../songs/forms/songmaintenanceform.py | 1 - openlp/plugins/songs/lib/easislidesimport.py | 2 +- openlp/plugins/songs/lib/oooimport.py | 32 ++++++------------- 5 files changed, 48 insertions(+), 49 deletions(-) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 9117a8e19..be5b2813b 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -47,6 +47,8 @@ from openlp.core.lib import Receiver, translate log = logging.getLogger(__name__) IMAGES_FILTER = None +UNO_CONNECTION_TYPE = u'pipe' +#UNO_CONNECTION_TYPE = u'socket' class VersionThread(QtCore.QThread): """ @@ -375,9 +377,37 @@ def string_is_unicode(test_string): log.exception("Error encoding string to unicode") return return_string +def get_uno_command(): + """ + Returns the UNO command to launch an openoffice.org instance. + """ + if UNO_CONNECTION_TYPE == u'pipe': + return u'openoffice.org -nologo -norestore -minimized -invisible ' \ + + u'-nofirststartwizard -accept=pipe,name=openlp_pipe;urp;' + else: + return u'openoffice.org -nologo -norestore -minimized ' \ + + u'-invisible -nofirststartwizard ' \ + + u'-accept=socket,host=localhost,port=2002;urp;' + +def get_uno_instance(resolver): + """ + Returns a running openoffice.org instance. + + ``resolver`` + The UNO resolver to use to find a running instance. + """ + log.debug(u'get UNO Desktop Openoffice - resolve') + if UNO_CONNECTION_TYPE == u'pipe': + return resolver.resolve(u'uno:pipe,name=openlp_pipe;' \ + + u'urp;StarOffice.ComponentContext') + else: + return resolver.resolve(u'uno:socket,host=localhost,port=2002;' \ + + u'urp;StarOffice.ComponentContext') + from languagemanager import LanguageManager from actions import ActionList __all__ = [u'AppLocation', u'check_latest_version', u'add_actions', u'get_filesystem_encoding', u'LanguageManager', u'ActionList', - u'get_web_page', u'file_is_unicode', u'string_is_unicode'] + u'get_web_page', u'file_is_unicode', u'string_is_unicode', + u'get_uno_command', u'get_uno_instance', u'delete_file'] diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index 516c595c7..6ca67c2ae 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -51,7 +51,7 @@ else: from PyQt4 import QtCore -from openlp.core.utils import delete_file +from openlp.core.utils import delete_file, get_uno_command, get_uno_instance from presentationcontroller import PresentationController, PresentationDocument log = logging.getLogger(__name__) @@ -75,7 +75,6 @@ class ImpressController(PresentationController): self.process = None self.desktop = None self.manager = None - self.uno_connection_type = u'pipe' #u'socket' def check_available(self): """ @@ -100,14 +99,7 @@ class ImpressController(PresentationController): self.manager._FlagAsMethod(u'Bridge_GetValueObject') else: # -headless - if self.uno_connection_type == u'pipe': - cmd = u'openoffice.org -nologo -norestore -minimized ' \ - + u'-invisible -nofirststartwizard ' \ - + u'-accept=pipe,name=openlp_pipe;urp;' - else: - cmd = u'openoffice.org -nologo -norestore -minimized ' \ - + u'-invisible -nofirststartwizard ' \ - + u'-accept=socket,host=localhost,port=2002;urp;' + cmd = get_uno_command() self.process = QtCore.QProcess() self.process.startDetached(cmd) self.process.waitForStarted() @@ -118,7 +110,7 @@ class ImpressController(PresentationController): which will be used to manage impress """ log.debug(u'get UNO Desktop Openoffice') - ctx = None + uno_instance = None loop = 0 log.debug(u'get UNO Desktop Openoffice - getComponentContext') context = uno.getComponentContext() @@ -126,27 +118,19 @@ class ImpressController(PresentationController): u'UnoUrlResolver') resolver = context.ServiceManager.createInstanceWithContext( u'com.sun.star.bridge.UnoUrlResolver', context) - while ctx is None and loop < 3: + while uno_instance is None and loop < 3: try: - log.debug(u'get UNO Desktop Openoffice - resolve') - if self.uno_connection_type == u'pipe': - ctx = resolver.resolve(u'uno:' \ - + u'pipe,name=openlp_pipe;' \ - + u'urp;StarOffice.ComponentContext') - else: - ctx = resolver.resolve(u'uno:' \ - + u'socket,host=localhost,port=2002;' \ - + u'urp;StarOffice.ComponentContext') + uno_instance = get_uno_instance(resolver) except: log.exception(u'Unable to find running instance ') self.start_process() loop += 1 try: - self.manager = ctx.ServiceManager + self.manager = uno_instance.ServiceManager log.debug(u'get UNO Desktop Openoffice - createInstanceWithContext' u' - Desktop') desktop = self.manager.createInstanceWithContext( - "com.sun.star.frame.Desktop", ctx ) + "com.sun.star.frame.Desktop", uno_instance) return desktop except: log.exception(u'Failed to get UNO desktop') diff --git a/openlp/plugins/songs/forms/songmaintenanceform.py b/openlp/plugins/songs/forms/songmaintenanceform.py index 7da8ddd81..93a01623e 100644 --- a/openlp/plugins/songs/forms/songmaintenanceform.py +++ b/openlp/plugins/songs/forms/songmaintenanceform.py @@ -535,4 +535,3 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): else: self.booksDeleteButton.setEnabled(True) self.booksEditButton.setEnabled(True) - diff --git a/openlp/plugins/songs/lib/easislidesimport.py b/openlp/plugins/songs/lib/easislidesimport.py index 56349fc5a..64523fd3a 100644 --- a/openlp/plugins/songs/lib/easislidesimport.py +++ b/openlp/plugins/songs/lib/easislidesimport.py @@ -84,7 +84,7 @@ class EasiSlidesImport(SongImport): self._add_title(self.title, song.Title1, True) self._add_alttitle(self.alternate_title, song.Title2) self._add_number(self.song_number, song.SongNumber) - if self.song_number = u'0': + if self.song_number == u'0': self.song_number = u'' self._add_authors(song) self._add_copyright(song) diff --git a/openlp/plugins/songs/lib/oooimport.py b/openlp/plugins/songs/lib/oooimport.py index be33cb8fb..45d1ce5b9 100644 --- a/openlp/plugins/songs/lib/oooimport.py +++ b/openlp/plugins/songs/lib/oooimport.py @@ -29,6 +29,7 @@ import os from PyQt4 import QtCore from openlp.core.lib import Receiver +from openlp.core.utils import get_uno_command, get_uno_instance from songimport import SongImport log = logging.getLogger(__name__) @@ -61,7 +62,6 @@ class OooImport(SongImport): self.document = None self.process_started = False self.filenames = kwargs[u'filenames'] - self.uno_connection_type = u'pipe' #u'socket' QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'openlp_stop_wizard'), self.stop_import) @@ -105,25 +105,18 @@ class OooImport(SongImport): context = uno.getComponentContext() resolver = context.ServiceManager.createInstanceWithContext( u'com.sun.star.bridge.UnoUrlResolver', context) - ctx = None + uno_instance = None loop = 0 - while ctx is None and loop < 5: + while uno_instance is None and loop < 5: try: - if self.uno_connection_type == u'pipe': - ctx = resolver.resolve(u'uno:' \ - + u'pipe,name=openlp_pipe;' \ - + u'urp;StarOffice.ComponentContext') - else: - ctx = resolver.resolve(u'uno:' \ - + u'socket,host=localhost,port=2002;' \ - + u'urp;StarOffice.ComponentContext') + uno_instance = get_uno_instance(resolver) except: log.exception("Failed to resolve uno connection") - self.start_ooo_process() - loop += 1 - manager = ctx.ServiceManager + self.start_ooo_process() + loop += 1 + manager = uno_instance.ServiceManager self.desktop = manager.createInstanceWithContext( - "com.sun.star.frame.Desktop", ctx) + "com.sun.star.frame.Desktop", uno_instance) def start_ooo_process(self): try: @@ -132,14 +125,7 @@ class OooImport(SongImport): self.manager._FlagAsMethod(u'Bridge_GetStruct') self.manager._FlagAsMethod(u'Bridge_GetValueObject') else: - if self.uno_connection_type == u'pipe': - cmd = u'openoffice.org -nologo -norestore -minimized ' \ - + u'-invisible -nofirststartwizard ' \ - + u'-accept=pipe,name=openlp_pipe;urp;' - else: - cmd = u'openoffice.org -nologo -norestore -minimized ' \ - + u'-invisible -nofirststartwizard ' \ - + u'-accept=socket,host=localhost,port=2002;urp;' + cmd = get_uno_command() process = QtCore.QProcess() process.startDetached(cmd) process.waitForStarted() From 4263182290d90c00c905ba8aa5a22cea093e247a Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 22 Jan 2011 08:31:32 +0100 Subject: [PATCH 5/5] name change --- openlp/core/ui/servicemanager.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 3bdda5516..738849599 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -794,7 +794,7 @@ class ServiceManager(QtGui.QWidget): self.repaintServiceList(0, 0) self.setModified(True) - def repaintServiceList(self, serviceItem, serviceItemCount): + def repaintServiceList(self, serviceItem, serviceItemChild): """ Clear the existing service list and prepaint all the items. This is used when moving items as the move takes place in a supporting list, @@ -803,7 +803,7 @@ class ServiceManager(QtGui.QWidget): ``serviceItem`` The item which changed. (int) - ``serviceItemCount`` + ``serviceItemChild`` The child of the ``serviceItem``, which will be selected. (int) """ # Correct order of items in array @@ -839,20 +839,15 @@ class ServiceManager(QtGui.QWidget): QtCore.QVariant(item[u'order'])) # Add the children to their parent treewidgetitem. for count, frame in enumerate(serviceitem.get_frames()): - treewidgetitem1 = QtGui.QTreeWidgetItem(treewidgetitem) + child = QtGui.QTreeWidgetItem(treewidgetitem) text = frame[u'title'].replace(u'\n', u' ') - treewidgetitem1.setText(0, text[:40]) - treewidgetitem1.setData(0, QtCore.Qt.UserRole, - QtCore.QVariant(count)) + child.setText(0, text[:40]) + child.setData(0, QtCore.Qt.UserRole, QtCore.QVariant(count)) if serviceItem == itemcount: - # Preserve expanding status as setCurrentItem sets it to - # True. - temp = item[u'expanded'] - if item[u'expanded'] and serviceItemCount == count: - self.serviceManagerList.setCurrentItem(treewidgetitem1) - elif serviceItemCount == -1: + if item[u'expanded'] and serviceItemChild == count: + self.serviceManagerList.setCurrentItem(child) + elif serviceItemChild == -1: self.serviceManagerList.setCurrentItem(treewidgetitem) - item[u'expanded'] = temp treewidgetitem.setExpanded(item[u'expanded']) def validateItem(self, serviceItem):