diff --git a/openlp.pyw b/openlp.pyw index 76d334bae..5ecfbe5f5 100755 --- a/openlp.pyw +++ b/openlp.pyw @@ -85,10 +85,13 @@ class OpenLP(QtGui.QApplication): QtGui.QApplication.exec_() self.sharedMemory.detach() - def run(self): + def run(self, args): """ Run the OpenLP application. """ + # On Windows, the args passed into the constructor are + # ignored. Not very handy, so set the ones we want to use. + self.args = args # provide a listener for widgets to reqest a screen update. QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'openlp_process_events'), self.processEvents) @@ -115,7 +118,7 @@ class OpenLP(QtGui.QApplication): # make sure Qt really display the splash screen self.processEvents() # start the main app window - self.mainWindow = MainWindow(self.clipboard(), self.arguments()) + self.mainWindow = MainWindow(self.clipboard(), self.args) self.mainWindow.show() if show_splash: # now kill the splashscreen @@ -250,7 +253,7 @@ def main(): log.debug(u'Could not find default_translator.') if not options.no_error_form: sys.excepthook = app.hookException - sys.exit(app.run()) + sys.exit(app.run(qt_args)) if __name__ == u'__main__': """ diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index f57740fad..b8cb23999 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -515,18 +515,18 @@ class MediaManagerItem(QtGui.QWidget): # multiple service items? if self.singleServiceItem or self.remoteTriggered: log.debug(u'%s Add requested', self.plugin.name) - serviceItem = self.buildServiceItem(None, True) - if serviceItem: - serviceItem.from_plugin = False - self.parent.serviceManager.addServiceItem(serviceItem, - replace=self.remoteTriggered) + self.addToService(replace=self.remoteTriggered) else: items = self.listView.selectedIndexes() for item in items: - serviceItem = self.buildServiceItem(item, True) - if serviceItem: - serviceItem.from_plugin = False - self.parent.serviceManager.addServiceItem(serviceItem) + self.addToService(item) + + def addToService(self, item=None, replace=None): + serviceItem = self.buildServiceItem(item, True) + if serviceItem: + serviceItem.from_plugin = False + self.parent.serviceManager.addServiceItem(serviceItem, + replace=replace) def onAddEditClick(self): """ diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 20d5c3d62..cb65dc057 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -335,7 +335,7 @@ class Renderer(object): styled_text += styled_line html = self.page_shell + styled_text + HTML_END self.web.setHtml(html) - # Text too long so go to next page + # Text too long so go to next page. if self.web_frame.contentsSize().height() > self.page_height: if force_page and line_count > 0: Receiver.send_message(u'theme_line_count', line_count) @@ -366,7 +366,7 @@ class Renderer(object): """ log.debug(u'_paginate_slide_words - Start') - line_end = u'' + line_end = u' ' if line_break: line_end = u'
' formatted = [] @@ -374,10 +374,11 @@ class Renderer(object): previous_raw = u'' lines = text.split(u'\n') for line in lines: + line = line.strip() styled_line = expand_tags(line) html = self.page_shell + previous_html + styled_line + HTML_END self.web.setHtml(html) - # Text too long so go to next page + # Text too long so go to next page. if self.web_frame.contentsSize().height() > self.page_height: # Check if there was a verse before the current one and append # it, when it fits on the page. @@ -401,24 +402,56 @@ class Renderer(object): previous_html = styled_line + line_end previous_raw = line + line_end continue - words = self._words_split(line) - for word in words: - styled_word = expand_tags(word) - html = self.page_shell + previous_html + styled_word + \ - HTML_END + # Figure out how many words of the line will fit on screen by + # using the algorithm known as "binary chop". + raw_words = self._words_split(line) + html_words = [expand_tags(word) for word in raw_words] + smallest_index = 0 + highest_index = len(html_words) - 1 + index = int(highest_index / 2) + while True: + html = self.page_shell + previous_html + \ + u''.join(html_words[:index + 1]).strip() + HTML_END self.web.setHtml(html) - # Text too long so go to next page if self.web_frame.contentsSize().height() > \ self.page_height: - while previous_raw.endswith(u'
'): - previous_raw = previous_raw[:-4] - formatted.append(previous_raw) + # We know that it does not fit, so change/calculate the + # new index and highest_index accordingly. + highest_index = index + index = int(index - (index - smallest_index) / 2) + else: + smallest_index = index + index = int(index + (highest_index - index) / 2) + # We found the number of words which will fit. + if smallest_index == index or highest_index == index: + index = smallest_index + formatted.append(previous_raw.rstrip(u'
') + + u''.join(raw_words[:index + 1])) previous_html = u'' previous_raw = u'' - previous_html += styled_word - previous_raw += word - previous_html += line_end - previous_raw += line_end + else: + continue + # Check if the rest of the line fits on the slide. If it + # does we do not have to do the much more intensive "word by + # word" checking. + html = self.page_shell + \ + u''.join(html_words[index + 1:]).strip() + HTML_END + self.web.setHtml(html) + if self.web_frame.contentsSize().height() <= \ + self.page_height: + previous_html = \ + u''.join(html_words[index + 1:]).strip() + line_end + previous_raw = \ + u''.join(raw_words[index + 1:]).strip() + line_end + break + else: + # The other words do not fit, thus reset the indexes, + # create a new list and continue with "word by word". + raw_words = raw_words[index + 1:] + html_words = html_words[index + 1:] + smallest_index = 0 + highest_index = len(html_words) - 1 + index = int(highest_index / 2) else: previous_html += styled_line + line_end previous_raw += line + line_end diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 167fcdd4a..bf6b7fa98 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -625,11 +625,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): if self.liveController.display.isVisible(): self.liveController.display.setFocus() self.activateWindow() - # On Windows, arguments contains the entire commandline - # So args[0]=='python' args[1]=='openlp.pyw' - # Therefore this approach is not going to work - # Bypass for now. - if len(self.arguments) and os.name != u'nt': + if len(self.arguments): args = [] for a in self.arguments: args.extend([a]) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 358877cc7..94cf621ab 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -757,7 +757,7 @@ class ServiceManager(QtGui.QWidget): """ Called by a signal to select a specific item. """ - self.setItem(int(message[0])) + self.setItem(int(message)) def setItem(self, index): """ diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index 189164b59..85e6e51f2 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -25,6 +25,7 @@ ############################################################################### import logging +import locale from PyQt4 import QtCore, QtGui from sqlalchemy.sql import or_, func @@ -133,15 +134,19 @@ class CustomMediaItem(MediaManagerItem): self.onPreviewClick() self.onRemoteEditClear() - def loadList(self, list): + def loadList(self, custom_slides): self.listView.clear() - for customSlide in list: - custom_name = QtGui.QListWidgetItem(customSlide.title) + # Sort the customs by its title considering language specific + # characters. lower() is needed for windows! + custom_slides.sort( + cmp=locale.strcoll, key=lambda custom: custom.title.lower()) + for custom_slide in custom_slides: + custom_name = QtGui.QListWidgetItem(custom_slide.title) custom_name.setData( - QtCore.Qt.UserRole, QtCore.QVariant(customSlide.id)) + QtCore.Qt.UserRole, QtCore.QVariant(custom_slide.id)) self.listView.addItem(custom_name) # Auto-select the item if name has been set - if customSlide.title == self.autoSelectItem : + if custom_slide.title == self.autoSelectItem: self.listView.setCurrentItem(custom_name) def onNewClick(self): diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 7660c9099..5cc6f1fe1 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -149,20 +149,18 @@ class PresentationMediaItem(MediaManagerItem): else: self.presentationWidget.hide() - def loadList(self, list, initialLoad=False): + def loadList(self, files, initialLoad=False): """ Add presentations into the media manager This is called both on initial load of the plugin to populate with existing files, and when the user adds new files via the media manager """ currlist = self.getFileList() - titles = [] - for file in currlist: - titles.append(os.path.split(file)[1]) + titles = [os.path.split(file)[1] for file in currlist] Receiver.send_message(u'cursor_busy') if not initialLoad: - self.parent.formparent.displayProgressBar(len(list)) - for file in list: + self.parent.formparent.displayProgressBar(len(files)) + for file in files: if not initialLoad: self.parent.formparent.incrementProgressBar() if currlist.count(file) > 0: diff --git a/openlp/plugins/remotes/html/openlp.js b/openlp/plugins/remotes/html/openlp.js index 4eee047a4..09312876c 100644 --- a/openlp/plugins/remotes/html/openlp.js +++ b/openlp/plugins/remotes/html/openlp.js @@ -219,10 +219,11 @@ window.OpenLP = { } else { $.each(data.results.items, function (idx, value) { - var li = $("
  • ").append( - $("").attr("value", value[0]).text(value[1])); - li.children("a").click(OpenLP.goLive); - ul.append(li); + var item = $("
  • ").text(value[1]); + var golive = $("Go Live").attr("value", value[0]).click(OpenLP.goLive); + var additem = $("Add To Service").attr("value", value[0]).click(OpenLP.addToService); + item.append($("