From 209f92439cb9e0655a4757c015ed043c93635795 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Mon, 6 Jul 2009 17:34:13 +0100 Subject: [PATCH 01/14] Remove Not used files and References Fixes from Last Merge ThemeManager Cleanup MVC. --- cnvdb.py | 2 +- openlp/core/lib/plugin.py | 1 - openlp/core/ui/__init__.py | 1 - openlp/core/ui/amendthemeform.py | 4 +- openlp/core/ui/mainwindow.py | 4 +- openlp/core/ui/slidecontroller.py | 10 +- openlp/core/ui/slidecontrollermanager.py | 52 ------ openlp/core/ui/thememanager.py | 159 +++++------------- .../images/lib/imageslidecontroller.py | 17 +- openlp/plugins/images/lib/imagetab.py | 2 +- 10 files changed, 65 insertions(+), 187 deletions(-) delete mode 100644 openlp/core/ui/slidecontrollermanager.py diff --git a/cnvdb.py b/cnvdb.py index a1e200ea8..cf8b899f9 100644 --- a/cnvdb.py +++ b/cnvdb.py @@ -31,7 +31,7 @@ class Convert(): writefile = codecs.open(outname, 'w', encoding='utf-8') for line in infile: #replace the quotes with quotes - line, replace("''", "'") + line = line.replace(u'\'\'', u'\'') writefile.write(line) infile.close() writefile.close() diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index 4db4480cc..bff11c4ed 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -102,7 +102,6 @@ class Plugin(object): self.render_manager = plugin_helpers[u'render'] self.service_manager = plugin_helpers[u'service'] self.settings = plugin_helpers[u'settings'] - self.slideManager = plugin_helpers[u'slideManager'] self.dnd_id=None def check_pre_conditions(self): diff --git a/openlp/core/ui/__init__.py b/openlp/core/ui/__init__.py index 8fcef14ae..10b046748 100644 --- a/openlp/core/ui/__init__.py +++ b/openlp/core/ui/__init__.py @@ -18,7 +18,6 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ from slidecontroller import MasterToolbar -from slidecontrollermanager import SlideControllerManager from maindisplay import MainDisplay from amendthemeform import AmendThemeForm from slidecontroller import SlideController diff --git a/openlp/core/ui/amendthemeform.py b/openlp/core/ui/amendthemeform.py index d120ff3b6..4358f1071 100644 --- a/openlp/core/ui/amendthemeform.py +++ b/openlp/core/ui/amendthemeform.py @@ -128,9 +128,7 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog): unicode(self.theme.display_outline), unicode(self.theme.display_outline_color), unicode(self.theme.display_horizontalAlign), unicode(self.theme.display_verticalAlign), unicode(self.theme.display_wrapStyle)) - theme = new_theme.extract_xml() - self.thememanager.saveTheme(theme_name, theme, save_from, save_to) return QtGui.QDialog.accept(self) @@ -526,4 +524,4 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog): def previewTheme(self, theme): if self.allowPreview: frame = self.thememanager.generateImage(theme) - self.ThemePreview.setPixmap(QtGui.QPixmap.fromImage(frame)) \ No newline at end of file + self.ThemePreview.setPixmap(QtGui.QPixmap.fromImage(frame)) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 7b56a09c8..e4f2dd92e 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -23,7 +23,7 @@ import logging from PyQt4 import QtCore, QtGui from openlp.core.ui import AboutForm, SettingsForm, AlertForm, ServiceManager, \ - ThemeManager, MainDisplay, SlideController, SlideControllerManager + ThemeManager, MainDisplay, SlideController from openlp.core.lib import translate, Plugin, MediaManagerItem, SettingsTab, \ EventManager, RenderManager, PluginConfig from openlp.core import PluginManager @@ -50,7 +50,6 @@ class MainWindow(object): self.alertForm = AlertForm(self) self.aboutForm = AboutForm() self.settingsForm = SettingsForm(self.screenList, self) - self.slideControllerManager = SlideControllerManager(self) # Set up the path with plugins pluginpath = os.path.split(os.path.abspath(__file__))[0] pluginpath = os.path.abspath( @@ -73,7 +72,6 @@ class MainWindow(object): self.plugin_helpers[u'render'] = self.RenderManager self.plugin_helpers[u'service'] = self.ServiceManagerContents self.plugin_helpers[u'settings'] = self.settingsForm - self.plugin_helpers[u'slideManager'] = self.slideControllerManager self.plugin_manager.find_plugins(pluginpath, self.plugin_helpers, self.EventManager) # hook methods have to happen after find_plugins. Find plugins needs the diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 5679b76e1..c87739313 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -183,7 +183,7 @@ class SlideController(QtGui.QWidget): class MasterToolbar(QtCore.QObject): """ - Class from which all tollbars should extend + Class from which all toolbars should extend """ def __init__(self, isLive): self.Toolbar = None @@ -232,6 +232,13 @@ class MasterToolbar(QtCore.QObject): translate(u'SlideController', u'Close Screen'), self.onBlankScreen) + def serviceLoaded(self): + """ + method to allow toolbars to know when the service item + is fully in place + """ + pass + def onSlideSelectedFirst(self): """ Go to the first slide. @@ -325,3 +332,4 @@ class MasterToolbar(QtCore.QObject): else: self.PreviewListWidget.selectRow(slideno) self.onSlideSelected() + self.serviceLoaded() diff --git a/openlp/core/ui/slidecontrollermanager.py b/openlp/core/ui/slidecontrollermanager.py deleted file mode 100644 index 10312ece5..000000000 --- a/openlp/core/ui/slidecontrollermanager.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 -""" -OpenLP - Open Source Lyrics Projection -Copyright (c) 2008 Raoul Snyman -Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley, - -This program is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA -""" -import logging -import os - -class SlideControllerManager(): - """ - This class controls which SlideController is availabe to the - main window - """ - global log - log = logging.getLogger(u'SlideControllerManager') - - def __init__(self, parent): - """ - Set up the Slide Controller. Manager - """ - self.parent = parent - self.live = {} - self.preview = {} - - def add_controllers(self, handle, preview, live): - self.live[handle] = live - self.preview[handle] = preview - print self.live - - def getPreviewController(self, handle): - return self.preview[handle] - - def getLiveController(self, handle): - print "---" - print self.live - print handle - print self.live[handle] - return self.live[handle] diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 602f85bb9..56d4224f5 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -21,109 +21,16 @@ import os import sys import zipfile import shutil +import logging -from time import sleep from xml.etree.ElementTree import ElementTree, XML from PyQt4 import QtCore, QtGui from openlp.core.ui import AmendThemeForm, ServiceManager from openlp.core.theme import Theme -from openlp.core.lib import Event, EventType, EventManager, OpenLPToolbar, ThemeXML, Renderer, translate, file_to_xml +from openlp.core.lib import Event, EventType, EventManager, OpenLPToolbar, ThemeXML, Renderer, translate, file_to_xml, buildIcon from openlp.core.utils import ConfigHelper -import logging - -class ThemeData(QtCore.QAbstractListModel): - """ - Tree of items for an order of Theme. - Includes methods for reading and writing the contents to an OOS file - Root contains a list of ThemeItems - """ - global log - log = logging.getLogger(u'ThemeData') - - def __init__(self): - QtCore.QAbstractListModel.__init__(self) - self.items = [] - self.rowheight = 50 - self.maximagewidth = self.rowheight * 16 / 9.0; - log.info(u'Starting') - - def clearItems(self): - self.items = [] - - def rowCount(self, parent): - return len(self.items) - - def insertRow(self, row, filename): - self.beginInsertRows(QtCore.QModelIndex(), row, row) - log.debug(u'insert row %d:%s' % (row, filename)) - (prefix, shortfilename) = os.path.split(unicode(filename)) - log.debug(u'shortfilename = %s' % shortfilename) - theme = shortfilename.split(u'.') - # create a preview image - if os.path.exists(filename): - preview = QtGui.QImage(unicode(filename)) - width = self.maximagewidth - height = self.rowheight - preview = preview.scaled(width, height, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation) - realwidth = preview.width() - realheight = preview.height() - # and move it to the centre of the preview space - pixmap = QtGui.QImage(width, height, QtGui.QImage.Format_ARGB32_Premultiplied) - pixmap.fill(QtCore.Qt.black) - painter = QtGui.QPainter(pixmap) - painter.drawImage((width - realwidth) / 2, (height - realheight) / 2, preview) - else: - width = self.maximagewidth - height = self.rowheight - pixmap = QtGui.QImage(width, height, QtGui.QImage.Format_ARGB32_Premultiplied) - pixmap.fill(QtCore.Qt.black) - # finally create the row - self.items.insert(row, (filename, pixmap, shortfilename, theme[0])) - log.debug(u'Items: %s' % self.items) - self.endInsertRows() - - def removeRow(self, row): - self.beginRemoveRows(QtCore.QModelIndex(), row, row) - self.items.pop(row) - self.endRemoveRows() - - def addRow(self, item): - self.insertRow(len(self.items), item) - - def data(self, index, role): - row = index.row() - if row > len(self.items): - # if the last row is selected and deleted, we then get called with an empty row! - return QtCore.QVariant() - if role == QtCore.Qt.DisplayRole: - retval = self.items[row][3] - elif role == QtCore.Qt.DecorationRole: - retval = self.items[row][1] - else: - retval = QtCore.QVariant() - if type(retval) is not type(QtCore.QVariant): - return QtCore.QVariant(retval) - else: - return retval - - def __iter__(self): - for item in self.items: - yield item - - def getValue(self, index): - row = index.row() - return self.items[row] - - def getItem(self, row): - log.info(u'Get Item:%d -> %s' % (row, unicode(self.items))) - return self.items[row] - - def getList(self): - filelist = [item[3] for item in self.items] - return filelist - class ThemeManager(QtGui.QWidget): """ Manages the orders of Theme. @@ -157,13 +64,10 @@ class ThemeManager(QtGui.QWidget): translate(u'ThemeManager', u'Export a theme'), self.onExportTheme) self.ThemeWidget = QtGui.QWidgetAction(self.Toolbar) self.Layout.addWidget(self.Toolbar) - - self.ThemeListView = QtGui.QListView(self) - self.themeData = ThemeData() - self.ThemeListView.setModel(self.themeData) - self.ThemeListView.setAlternatingRowColors(True) - self.Layout.addWidget(self.ThemeListView) - + self.ThemeListWidget = QtGui.QListWidget(self) + self.ThemeListWidget.setAlternatingRowColors(True) + self.ThemeListWidget.setIconSize(QtCore.QSize(88,50)) + self.Layout.addWidget(self.ThemeListWidget) self.themelist = [] self.path = os.path.join(ConfigHelper.get_data_path(), u'themes') self.checkThemesExists(self.path) @@ -174,21 +78,18 @@ class ThemeManager(QtGui.QWidget): self.amendThemeForm.exec_() def onEditTheme(self): - items = self.ThemeListView.selectedIndexes() - if len(items) > 0: - for item in items: - data = self.themeData.getValue(item) - self.amendThemeForm.loadTheme(data[3]) + item = self.ThemeListWidget.currentItem() + if item is not None: + self.amendThemeForm.loadTheme(unicode(item.text())) self.amendThemeForm.exec_() def onDeleteTheme(self): - items = self.ThemeListView.selectedIndexes() - if len(items) > 0: - theme = u'' - for item in items: - data = self.themeData.getValue(item) - theme = data[3] + item = self.ThemeListWidget.currentItem() + if item is not None: + theme = unicode(item.text()) th = theme + u'.png' + row = self.ThemeListWidget.row(item) + self.ThemeListWidget.takeItem(row) try: os.remove(os.path.join(self.path, th)) except: @@ -199,8 +100,6 @@ class ThemeManager(QtGui.QWidget): except: #if not present do not worry pass - self.themeData.clearItems() - self.loadThemes() def onExportTheme(self): pass @@ -213,24 +112,37 @@ class ThemeManager(QtGui.QWidget): if len(files) > 0: for file in files: self.unzipTheme(file, self.path) - self.themeData.clearItems() self.loadThemes() def loadThemes(self): + """ + Loads the theme lists and triggers updates accross + the whole system using direct calls or core functions + and events for the plugins. + The plugins will call back in to get the real list if they want it. + """ log.debug(u'Load themes from dir') + self.themelist = [] + self.ThemeListWidget.clear() for root, dirs, files in os.walk(self.path): for name in files: if name.endswith(u'.png'): - #check to see file is in route directory + #check to see file is in theme root directory theme = os.path.join(self.path, name) if os.path.exists(theme): - self.themeData.addRow(theme) + (path, filename) = os.path.split(unicode(file)) + textName = os.path.splitext(name)[0] + item_name = QtGui.QListWidgetItem(textName) + item_name.setIcon(buildIcon(theme)) + item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(textName)) + self.ThemeListWidget.addItem(item_name) + self.themelist.append(textName) self.parent.EventManager.post_event(Event(EventType.ThemeListChanged)) self.parent.ServiceManagerContents.updateThemeList(self.getThemes()) self.parent.settingsForm.ThemesTab.updateThemeList(self.getThemes()) def getThemes(self): - return self.themeData.getList() + return self.themelist def getThemeData(self, themename): log.debug(u'getthemedata for theme %s', themename) @@ -337,6 +249,10 @@ class ThemeManager(QtGui.QWidget): return newtheme.extract_xml() def saveTheme(self, name, theme_xml, image_from, image_to) : + """ + Called by thememaintenance Dialog to save the theme + and to trigger the reload of the theme list + """ log.debug(u'saveTheme %s %s', name, theme_xml) theme_dir = os.path.join(self.path, name) if os.path.exists(theme_dir) == False: @@ -348,7 +264,6 @@ class ThemeManager(QtGui.QWidget): if image_from is not None and image_from != image_to: shutil.copyfile(image_from, image_to) self.generateAndSaveImage(self.path, name, theme_xml) - self.themeData.clearItems() self.loadThemes() def generateAndSaveImage(self, dir, name, theme_xml): @@ -357,7 +272,6 @@ class ThemeManager(QtGui.QWidget): theme.parse(theme_xml) theme.extend_image_filename(dir) frame = self.generateImage(theme) - #im = frame.toImage() samplepathname = os.path.join(self.path, name + u'.png') if os.path.exists(samplepathname): os.unlink(samplepathname) @@ -365,6 +279,9 @@ class ThemeManager(QtGui.QWidget): log.debug(u'Theme image written to %s', samplepathname) def generateImage(self, themedata): + """ + Call the RenderManager to build a Sample Image + """ log.debug(u'generateImage %s ', themedata) frame = self.parent.RenderManager.generate_preview(themedata) return frame diff --git a/openlp/plugins/images/lib/imageslidecontroller.py b/openlp/plugins/images/lib/imageslidecontroller.py index 68f7da815..926955846 100644 --- a/openlp/plugins/images/lib/imageslidecontroller.py +++ b/openlp/plugins/images/lib/imageslidecontroller.py @@ -74,14 +74,26 @@ class ImageToolbar(MasterToolbar): u':/media/media_stop.png', translate(u'SlideController', u'Stop continuous loop'), self.onStopLoop) + self.Toolbar.addSeparator() + self.DelaySpinBox = QtGui.QSpinBox(self.Toolbar) + self.SpinWidget = QtGui.QWidgetAction(self.Toolbar) + self.SpinWidget.setDefaultWidget(self.DelaySpinBox) + self.Toolbar.addAction(self.SpinWidget) + #self.Layout.addWidget(self.Toolbar) self.Toolbar.setSizePolicy(sizeToolbarPolicy) + self.DelaySpinBox.setSuffix(translate(u'ImageSlideController', u's')) + + def serviceLoaded(self): + self.DelaySpinBox.setValue(self.parent.parent.ImageTab.loop_delay) + if self.PreviewListWidget.rowCount() == 1: + self.DelaySpinBox.setEnabled(False) def onStartLoop(self): """ Go to the last slide. """ - delay = self.parent.parent.ImageTab.loop_delay - self.timer_id = self.startTimer(delay * 1000) + if self.PreviewListWidget.rowCount() > 1: + self.timer_id = self.startTimer(int(self.TimeoutSpinBox.value()) * 1000) def onStopLoop(self): """ @@ -92,4 +104,3 @@ class ImageToolbar(MasterToolbar): def timerEvent(self, event): if event.timerId() == self.timer_id: self.onSlideSelectedNext() - diff --git a/openlp/plugins/images/lib/imagetab.py b/openlp/plugins/images/lib/imagetab.py index d1e58c4c6..e9c49a0a3 100644 --- a/openlp/plugins/images/lib/imagetab.py +++ b/openlp/plugins/images/lib/imagetab.py @@ -49,7 +49,6 @@ class ImageTab(SettingsTab): self.TimeoutSpacer = QtGui.QSpacerItem(147, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.TimeoutLayout.addItem(self.TimeoutSpacer) - self.ImageLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.ImageModeGroupBox) # Signals and slots QtCore.QObject.connect(self.TimeoutSpinBox, @@ -57,6 +56,7 @@ class ImageTab(SettingsTab): def retranslateUi(self): self.TimeoutLabel.setText(translate(u'ImageTab', u'Slide Loop Delay:')) + self.TimeoutSpinBox.setSuffix(translate(u'ImageTab', u's')) def onTimeoutSpinBoxChanged(self): self.loop_delay = self.TimeoutSpinBox.value() From a06b8f0b076f3474e636537f266644ac9bbf676b Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 7 Jul 2009 17:35:01 +0100 Subject: [PATCH 02/14] Add saving check to exit so OOS can be saved --- openlp/core/ui/mainwindow.py | 46 ++++++++++++++++++++++++-- openlp/core/ui/servicemanager.py | 17 ++++++++-- openlp/plugins/bibles/lib/mediaitem.py | 2 +- 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index e4f2dd92e..504b351aa 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -41,6 +41,7 @@ class MainWindow(object): This constructor sets up the interface, the various managers, and the plugins. """ + self.oosNotSaved = False self.mainWindow = QtGui.QMainWindow() self.mainWindow.__class__.closeEvent = self.onCloseEvent self.mainDisplay = MainDisplay(None, screens) @@ -127,8 +128,46 @@ class MainWindow(object): """ Hook to close the main window and display windows on exit """ - self.mainDisplay.close() - event.accept() + if self.oosNotSaved == True: + box = QtGui.QMessageBox() + box.setWindowTitle(translate(u'mainWindow', u'Question?')) + box.setText(translate(u'mainWindow', u'Save changes to Order of Service?')) + box.setIcon(QtGui.QMessageBox.Question) + box.setStandardButtons(QtGui.QMessageBox.Save | QtGui.QMessageBox.Discard | QtGui.QMessageBox.Cancel); + box.setDefaultButton(QtGui.QMessageBox.Save); + ret = box.exec_() + if ret == QtGui.QMessageBox.Save: + self.ServiceManagerContents.onSaveService() + self.mainDisplay.close() + event.accept() + elif ret == QtGui.QMessageBox.Discard: + self.mainDisplay.close() + event.accept() + else: + event.ignore() + else: + self.mainDisplay.close() + event.accept() + + def OosChanged(self, reset = False, oosName = None): + """ + Hook to change the title if the OOS has been changed + reset - tells if the OOS has been cleared or saved + oosName - is the name of the OOS (if it has one) + """ + if reset == True: + self.oosNotSaved = False + if oosName is None: + title = self.mainTitle + else: + title = self.mainTitle + u' - (' + oosName + u')' + else: + self.oosNotSaved = True + if oosName is None: + title = self.mainTitle + u' - *' + else: + title = self.mainTitle + u' - *(' + oosName + u')' + self.mainWindow.setWindowTitle(title) def setupUi(self): """ @@ -409,7 +448,8 @@ class MainWindow(object): """ Set up the translation system """ - self.mainWindow.setWindowTitle(translate(u'mainWindow', u'OpenLP 2.0')) + self.mainTitle = translate(u'mainWindow', u'OpenLP 2.0') + self.mainWindow.setWindowTitle(self.mainTitle) self.FileMenu.setTitle(translate(u'mainWindow', u'&File')) self.FileImportMenu.setTitle(translate(u'mainWindow', u'&Import')) self.FileExportMenu.setTitle(translate(u'mainWindow', u'&Export')) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 4c486fe70..3e71fbbee 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -63,6 +63,7 @@ class ServiceManager(QtGui.QWidget): QtGui.QWidget.__init__(self) self.parent = parent self.serviceItems = [] + self.serviceName = u'' self.Layout = QtGui.QVBoxLayout(self) self.Layout.setSpacing(0) self.Layout.setMargin(0) @@ -151,6 +152,7 @@ class ServiceManager(QtGui.QWidget): self.serviceItems.remove(self.serviceItems[item]) self.serviceItems.insert(0, temp) self.repaintServiceList() + self.parent.OosChanged(False, self.serviceName) def onServiceUp(self): """ @@ -163,6 +165,7 @@ class ServiceManager(QtGui.QWidget): self.serviceItems.remove(self.serviceItems[item]) self.serviceItems.insert(item - 1, temp) self.repaintServiceList() + self.parent.OosChanged(False, self.serviceName) def onServiceDown(self): """ @@ -175,6 +178,7 @@ class ServiceManager(QtGui.QWidget): self.serviceItems.remove(self.serviceItems[item]) self.serviceItems.insert(item + 1, temp) self.repaintServiceList() + self.parent.OosChanged(False, self.serviceName) def onServiceEnd(self): """ @@ -186,6 +190,7 @@ class ServiceManager(QtGui.QWidget): self.serviceItems.remove(self.serviceItems[item]) self.serviceItems.insert(len(self.serviceItems), temp) self.repaintServiceList() + self.parent.OosChanged(False, self.serviceName) def onNewService(self): """ @@ -193,6 +198,8 @@ class ServiceManager(QtGui.QWidget): """ self.ServiceManagerList.clear() self.serviceItems = [] + self.serviceName = u'' + self.parent.OosChanged(True, self.serviceName) def onDeleteFromService(self): """ @@ -202,6 +209,7 @@ class ServiceManager(QtGui.QWidget): if item is not -1: self.serviceItems.remove(self.serviceItems[item]) self.repaintServiceList() + self.parent.OosChanged(False, self.serviceName) def repaintServiceList(self): #Correct order of idems in array @@ -252,6 +260,7 @@ class ServiceManager(QtGui.QWidget): os.remove(servicefile) except: pass #if not present do not worry + self.parent.OosChanged(True, self.serviceName) def onLoadService(self): """ @@ -260,6 +269,7 @@ class ServiceManager(QtGui.QWidget): filename = QtGui.QFileDialog.getOpenFileName(self, u'Open Order of Service',self.config.get_last_dir(), u'Services (*.oos)') filename = unicode(filename) + name = filename.split(os.path.sep) if filename != u'': self.config.set_last_dir(filename) zip = zipfile.ZipFile(unicode(filename)) @@ -279,7 +289,6 @@ class ServiceManager(QtGui.QWidget): f.close() self.onNewService() for item in items: - #print item serviceitem = ServiceItem() serviceitem.RenderManager = self.parent.RenderManager serviceitem.set_from_oos(item, self.servicePath ) @@ -287,7 +296,10 @@ class ServiceManager(QtGui.QWidget): try: os.remove(p_file) except: - pass #if not present do not worry + #if not present do not worry + pass + self.serviceName = name[len(name) - 1] + self.parent.OosChanged(True, self.serviceName) def onThemeComboBoxSelected(self, currentIndex): """ @@ -323,6 +335,7 @@ class ServiceManager(QtGui.QWidget): treewidgetitem1.setText(0,text[:40]) treewidgetitem1.setData(0, QtCore.Qt.UserRole,QtCore.QVariant(count)) count = count + 1 + self.parent.OosChanged(False, self.serviceName) def makePreview(self): """ diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index fd7681ae1..f5e58f8f0 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -494,7 +494,7 @@ class BibleMediaItem(MediaManagerItem): if end_verse == '': end_verse = 99 if start_chapter == '': - message = u'No chapter found for search' + message = u'No chapter found for search criteria' #print 'message = ' + unicode(message) #print 'search = ' + unicode(original) #print 'results = ' + unicode(book) + ' @ '+ unicode(start_chapter)+' @ '+ unicode(end_chapter)+' @ '+ unicode(start_verse)+ ' @ '+ unicode(end_verse) From f12949eb0ca70727e8728eba2048c576c6ac3cf5 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 8 Jul 2009 07:12:16 +0200 Subject: [PATCH 03/14] Fixed up a few logging things, a few bits of indentation, and resolved some conflicts from the last update. bzr-revno: 484 --- openlp/core/lib/pluginconfig.py | 2 +- openlp/core/lib/pluginmanager.py | 25 ++++++++++++++----- .../presentations/presentationplugin.py | 5 ++-- openlp/plugins/songs/lib/manager.py | 11 +++++--- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/openlp/core/lib/pluginconfig.py b/openlp/core/lib/pluginconfig.py index e966fb2ed..519e4e255 100644 --- a/openlp/core/lib/pluginconfig.py +++ b/openlp/core/lib/pluginconfig.py @@ -51,7 +51,7 @@ class PluginConfig(object): return ConfigHelper.set_config(self.section, key, value) def get_data_path(self): - app_data = ConfigHelper.get_data_path() + #app_data = ConfigHelper.get_data_path() app_data = ConfigHelper.get_data_path() safe_name = self.section.replace(u' ',u'-') plugin_data = self.get_config(u'data path', safe_name) diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index 38cb9b477..b557400b9 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -53,7 +53,7 @@ class PluginManager(object): """ self.plugin_helpers = plugin_helpers startdepth = len(os.path.abspath(dir).split(os.sep)) - log.debug(u'find plugins %s at depth %d' %( unicode(dir), startdepth)) + log.debug(u'find plugins %s at depth %d', unicode(dir), startdepth) for root, dirs, files in os.walk(dir): for name in files: @@ -69,34 +69,46 @@ class PluginManager(object): modulename = modulename[len(prefix) + 1:] modulename = modulename.replace(os.path.sep, '.') # import the modules - log.debug(u'Importing %s from %s. Depth %d' % (modulename, path, thisdepth)) + log.debug(u'Importing %s from %s. Depth %d', modulename, path, thisdepth) try: __import__(modulename, globals(), locals(), []) except ImportError, e: - log.error(u'Failed to import module %s on path %s for reason %s', modulename, path, sys.exc_info()[1]) + log.error(u'Failed to import module %s on path %s for reason %s', modulename, path, e.args[0]) self.plugin_classes = Plugin.__subclasses__() self.plugins = [] plugin_objects = [] for p in self.plugin_classes: try: plugin = p(self.plugin_helpers) - log.debug(u'loaded plugin %s with helpers'%unicode(p)) + log.debug(u'loaded plugin %s with helpers', unicode(p)) log.debug(u'Plugin: %s', unicode(p)) if plugin.check_pre_conditions(): - log.debug(u'Appending %s ', unicode(p)) + log.debug(u'Appending %s ', unicode(p)) plugin_objects.append(plugin) eventmanager.register(plugin) except TypeError: - log.error(u'loaded plugin %s has no helpers'%unicode(p)) + log.error(u'loaded plugin %s has no helpers', unicode(p)) self.plugins = sorted(plugin_objects, self.order_by_weight) def order_by_weight(self, x, y): + """ + Sort two plugins and order them by their weight. + + ``x`` + The first plugin. + + ``y`` + The second plugin. + """ return cmp(x.weight, y.weight) def hook_media_manager(self, mediatoolbox): """ Loop through all the plugins. If a plugin has a valid media manager item, add it to the media manager. + + ``mediatoolbox`` + The Media Manager itself. """ for plugin in self.plugins: media_manager_item = plugin.get_media_manager_item() @@ -140,3 +152,4 @@ class PluginManager(object): """ for plugin in self.plugins: plugin.initialise() + diff --git a/openlp/plugins/presentations/presentationplugin.py b/openlp/plugins/presentations/presentationplugin.py index 1bc95ef26..42f5930bf 100644 --- a/openlp/plugins/presentations/presentationplugin.py +++ b/openlp/plugins/presentations/presentationplugin.py @@ -42,8 +42,8 @@ class PresentationPlugin(Plugin): QtGui.QIcon.Normal, QtGui.QIcon.Off) def get_settings_tab(self): - self.presentation_tab = PresentationTab() - return self.presentation_tab + #self.presentation_tab = PresentationTab() + return None #self.presentation_tab def get_media_manager_item(self): # Create the MediaManagerItem object @@ -54,3 +54,4 @@ class PresentationPlugin(Plugin): log.debug('check_pre_conditions') self.openoffice = Openoffice() return self.openoffice.checkOoPid() + diff --git a/openlp/plugins/songs/lib/manager.py b/openlp/plugins/songs/lib/manager.py index c4c7a1fa6..bfe795f6e 100644 --- a/openlp/plugins/songs/lib/manager.py +++ b/openlp/plugins/songs/lib/manager.py @@ -47,8 +47,7 @@ class SongManager(): self.db_url = u'' db_type = self.config.get_config(u'db type', u'sqlite') if db_type == u'sqlite': - self.db_url = u'sqlite:///' + self.config.get_data_path() + \ - u'/songs.sqlite' + self.db_url = u'sqlite:///%s/songs.sqlite' % self.config.get_data_path() else: self.db_url = db_type + 'u://' + \ self.config.get_config(u'db username') + u':' + \ @@ -73,13 +72,17 @@ class SongManager(): """ Searches the song title for keywords. """ - return self.session.query(Song).filter(Song.search_title.like(u'%' + keywords + u'%')).order_by(Song.search_title.asc()).all() + return self.session.query(Song).filter( + Song.search_title.like(u'%' + keywords + u'%')).order_by( + Song.search_title.asc()).all() def search_song_lyrics(self, keywords): """ Searches the song lyrics for keywords. """ - return self.session.query(Song).filter(Song.search_lyrics.like(u'%' + keywords + u'%')).order_by(Song.search_lyrics.asc()).all() + return self.session.query(Song).filter( + Song.search_lyrics.like(u'%' + keywords + u'%')).order_by( + Song.search_lyrics.asc()).all() def get_song_from_author(self, keywords): """ From e66fa9b87d690ec36a0a9687c28efeabf60e7a1d Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 8 Jul 2009 08:55:08 +0200 Subject: [PATCH 04/14] Started fixing up docstrings and doing some more of a code cleanup. --- cnvdb.py | 42 +++--- demo.py | 73 +++++++---- openlp.pyw | 18 ++- openlp/core/__init__.py | 1 + openlp/core/lib/themexmlhandler.py | 201 +++++++++++++++++++++-------- openlp/core/lib/toolbar.py | 33 ++++- openlp/core/lib/xmlrootclass.py | 95 +++++++------- openlp/core/settingsmanager.py | 6 +- openlpcnv.pyw | 31 ++++- 9 files changed, 345 insertions(+), 155 deletions(-) diff --git a/cnvdb.py b/cnvdb.py index cf8b899f9..f33b5dc03 100644 --- a/cnvdb.py +++ b/cnvdb.py @@ -21,27 +21,35 @@ Place, Suite 330, Boston, MA 02111-1307 USA import codecs import sys +def convert_file(self, inname, outname): + """ + Convert a file from another encoding into UTF-8. -class Convert(): - def __init__(self): - pass + ``inname`` + The name of the file to be opened and converted. - def process(self, inname, outname): - infile = codecs.open(inname, 'r', encoding='iso-8859-1') - writefile = codecs.open(outname, 'w', encoding='utf-8') - for line in infile: - #replace the quotes with quotes - line = line.replace(u'\'\'', u'\'') - writefile.write(line) - infile.close() - writefile.close() + ``outname`` + The output file name. + """ + infile = codecs.open(inname, 'r', encoding='iso-8859-1') + writefile = codecs.open(outname, 'w', encoding='utf-8') + for line in infile: + #replace the quotes with quotes + line = line.replace(u'\'\'', u'\'') + writefile.write(line) + infile.close() + writefile.close() if __name__ == '__main__': + """ + Run the conversion script. + """ if len(sys.argv) < 2: print 'No action specified.' sys.exit() - print u'Uncode conversion ' - print u'Input file = ', sys.argv[1:] - print u'Output file = ', sys.argv[2:] - mig = Convert() - mig.process(sys.argv[1:],sys.argv[2:]) + print 'Uncode conversion:' + print 'Input file = ', sys.argv[1] + print 'Output file = ', sys.argv[2] + print 'Converting...' + convert_file(sys.argv[1], sys.argv[2]) + print 'Done.' diff --git a/demo.py b/demo.py index c06bbd26a..c6b1cf571 100644 --- a/demo.py +++ b/demo.py @@ -16,12 +16,14 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ -from openlp.core import Renderer -from openlp.theme import Theme import sys import time from PyQt4 import QtGui, QtCore + +from openlp.core import Renderer +from openlp.theme import Theme + words="""How sweet the name of Jesus sounds In a believer's ear! It soothes his sorrows, heals his wounds, @@ -29,53 +31,74 @@ And drives away his fear. """ class TstFrame(QtGui.QMainWindow): - """ We simply derive a new class of QMainWindow""" - - # {{{ init + """ + We simply derive a new class of QMainWindow + """ def __init__(self, *args, **kwargs): - """Create the DemoPanel.""" + """ + Create the DemoPanel. + """ QtGui.QMainWindow.__init__(self) - self.resize(1024,768) - self.size=(1024,768) - - self.v=0 - self._font=QtGui.QFont(u'Decorative', 32) - self.framecount=0 + self.resize(1024, 768) + self.size = (1024, 768) + self.v = 0 + self._font = QtGui.QFont(u'Decorative', 32) + self.framecount = 0 self.totaltime = 0 - self.dir=1 - self.y=1 -# self.startTimer(10) - self.frame=QtGui.QFrame() + self.dir = 1 + self.y = 1 + self.frame = QtGui.QFrame() self.setCentralWidget(self.frame) - self.r=Renderer() + self.r = Renderer() self.r.set_theme(Theme(u'demo_theme.xml')) - self.r.set_text_rectangle(self.frame.frameRect()) self.r.set_paint_dest(self) self.r.set_words_openlp(words) + def timerEvent(self, event): + """ + Update the form on a timer event. + + ``event`` + The event which triggered this update. + """ self.update() + def paintEvent(self, event): + """ + Repaint the canvas. + + ``event`` + The event which triggered this repaint. + """ self.r.set_text_rectangle(self.frame.frameRect()) self.r.scale_bg_image() - t1=time.clock() + t1 = time.clock() self.r.render_screen(0) t2 = time.clock() - deltat=t2-t1 + deltat = t2 - t1 self.totaltime += deltat - self.framecount+=1 + self.framecount += 1 print "Timing result: %5.3ffps" %(self.framecount/float(self.totaltime)) - # }}} -class Demo: +class Demo(object): + """ + The demo application itself. + """ def __init__(self): + """ + Construct the application. + """ app = QtGui.QApplication(sys.argv) - main=TstFrame() + main = TstFrame() main.show() sys.exit(app.exec_()) if __name__=="__main__": - t=Demo() + """ + Run the demo. + """ + t = Demo() diff --git a/openlp.pyw b/openlp.pyw index 33ae56f16..d7e43ede0 100755 --- a/openlp.pyw +++ b/openlp.pyw @@ -23,22 +23,29 @@ import sys import logging from PyQt4 import QtCore, QtGui + from openlp.core.lib import Receiver +from openlp.core.resources import * +from openlp.core.ui import MainWindow, SplashScreen logging.basicConfig(level=logging.DEBUG, format=u'%(asctime)s:%(msecs)3d %(name)-15s %(levelname)-8s %(message)s', datefmt=u'%m-%d %H:%M:%S', filename=u'openlp.log', filemode=u'w') -from openlp.core.resources import * -from openlp.core.ui import MainWindow, SplashScreen - class OpenLP(QtGui.QApplication): + """ + The core application class. This class inherits from Qt's QApplication + class in order to provide the core of the application. + """ global log log = logging.getLogger(u'OpenLP Application') log.info(u'Application Loaded') def run(self): - #set the default string encoding + """ + Run the OpenLP application. + """ + #set the default string encoding try: sys.setappdefaultencoding(u'utf-8') except: @@ -68,5 +75,8 @@ class OpenLP(QtGui.QApplication): sys.exit(app.exec_()) if __name__ == u'__main__': + """ + Instantiate and run the application. + """ app = OpenLP(sys.argv) app.run() diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index e123886b5..f8fbc58a6 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ + from settingsmanager import SettingsManager from openlp.core.lib.pluginmanager import PluginManager diff --git a/openlp/core/lib/themexmlhandler.py b/openlp/core/lib/themexmlhandler.py index 12880bfa6..4c6789193 100644 --- a/openlp/core/lib/themexmlhandler.py +++ b/openlp/core/lib/themexmlhandler.py @@ -19,11 +19,13 @@ Place, Suite 330, Boston, MA 02111-1307 USA For XML Schema see wiki.openlp.org """ -import os, os.path -from openlp.core.lib import str_to_bool -from xml.dom.minidom import Document +import os + +from xml.dom.minidom import Document from xml.etree.ElementTree import ElementTree, XML, dump +from openlp.core.lib import str_to_bool + blankthemexml=\ ''' @@ -62,26 +64,38 @@ blankthemexml=\ ''' -class ThemeXML(): +class ThemeXML(object): + """ + A class to encapsulate the Theme XML. + """ def __init__(self): + """ + Initialise the theme object. + """ # Create the minidom document self.theme_xml = Document() def extend_image_filename(self, path): """ Add the path name to the image name so the background can be rendered. + + ``path`` + The path name to be added. """ - if self.background_filename is not None: - self.background_filename = os.path.join(path, self.theme_name, self.background_filename) + if self.background_filename is not None and path is not None: + self.background_filename = os.path.join(path, self.theme_name, + self.background_filename) def new_document(self, name): + """ + Create a new theme XML document. + """ self.theme = self.theme_xml.createElement(u'theme') self.theme_xml.appendChild(self.theme) self.theme.setAttribute(u'version', u'1.0') - self.name = self.theme_xml.createElement(u'name') - ctn = self.theme_xml.createTextNode(name) - self.name.appendChild(ctn) + text_node = self.theme_xml.createTextNode(name) + self.name.appendChild(text_node) self.theme.appendChild(self.name) def add_background_transparent(self): @@ -95,23 +109,33 @@ class ThemeXML(): def add_background_solid(self, bkcolor): """ Add a Solid background. + + ``bkcolor`` + The color of the background. """ background = self.theme_xml.createElement(u'background') background.setAttribute(u'mode', u'opaque') background.setAttribute(u'type', u'solid') self.theme.appendChild(background) - self.child_element(background, u'color', bkcolor) def add_background_gradient(self, startcolor, endcolor, direction): """ Add a gradient background. + + ``startcolor`` + The gradient's starting colour. + + ``endcolor`` + The gradient's ending colour. + + ``direction`` + The direction of the gradient. """ background = self.theme_xml.createElement(u'background') background.setAttribute(u'mode', u'opaque') background.setAttribute(u'type', u'gradient') self.theme.appendChild(background) - # Create startColor element self.child_element(background, u'startColor', startcolor) # Create endColor element @@ -122,39 +146,63 @@ class ThemeXML(): def add_background_image(self, filename): """ Add a image background. + + ``filename`` + The file name of the image. """ background = self.theme_xml.createElement(u'background') background.setAttribute(u'mode', u'opaque') background.setAttribute(u'type', u'image') self.theme.appendChild(background) - #Create Filename element self.child_element(background, u'filename', filename) - def add_font(self, name, color, proportion, override, fonttype=u'main', xpos=0, ypos=0 ,width=0, height=0): + def add_font(self, name, color, proportion, override, fonttype=u'main', + xpos=0, ypos=0, width=0, height=0): """ Add a Font. + + ``name`` + The name of the font. + + ``color`` + The colour of the font. + + ``proportion`` + The size of the font. + + ``override`` + Whether or not to override the default positioning of the theme. + + ``fonttype`` + The type of font, ``main`` or ``footer``. Defaults to ``main``. + + ``xpos`` + The X position of the text block. + + ``ypos`` + The Y position of the text block. + + ``width`` + The width of the text block. + + ``height`` + The height of the text block. """ background = self.theme_xml.createElement(u'font') background.setAttribute(u'type',fonttype) self.theme.appendChild(background) - #Create Font name element self.child_element(background, u'name', name) - #Create Font color element self.child_element(background, u'color', color) - #Create Proportion name element self.child_element(background, u'proportion', proportion) - #Create Proportion name element self.child_element(background, u'proportion', proportion) - #Create Location element element = self.theme_xml.createElement(u'location') element.setAttribute(u'override',override) - if override == u'True': element.setAttribute(u'x', xpos) element.setAttribute(u'y', ypos) @@ -162,79 +210,120 @@ class ThemeXML(): element.setAttribute(u'height', height) background.appendChild(element) - def add_display(self, shadow, shadowColor, outline, outlineColor, horizontal, vertical, wrap): + def add_display(self, shadow, shadow_color, outline, outline_color, + horizontal, vertical, wrap): """ Add a Display options. + + ``shadow`` + Whether or not to show a shadow. + + ``shadow_color`` + The colour of the shadow. + + ``outline`` + Whether or not to show an outline. + + ``outline_color`` + The colour of the outline. + + ``horizontal`` + The horizontal alignment of the text. + + ``vertical`` + The vertical alignment of the text. + + ``wrap`` + Wrap style. """ background = self.theme_xml.createElement(u'display') self.theme.appendChild(background) - - tagElement = self.theme_xml.createElement(u'shadow') - - tagElement.setAttribute(u'color',shadowColor) - tagValue = self.theme_xml.createTextNode(shadow) - tagElement.appendChild(tagValue) - background.appendChild(tagElement) - - tagElement = self.theme_xml.createElement(u'outline') - tagElement.setAttribute(u'color',outlineColor) - tagValue = self.theme_xml.createTextNode(outline) - tagElement.appendChild(tagValue) - background.appendChild(tagElement) - - tagElement = self.theme_xml.createElement(u'horizontalAlign') - tagValue = self.theme_xml.createTextNode(horizontal) - tagElement.appendChild(tagValue) - background.appendChild(tagElement) - - tagElement = self.theme_xml.createElement(u'verticalAlign') - tagValue = self.theme_xml.createTextNode(vertical) - tagElement.appendChild(tagValue) - background.appendChild(tagElement) - - tagElement = self.theme_xml.createElement(u'wrapStyle') - tagValue = self.theme_xml.createTextNode(wrap) - tagElement.appendChild(tagValue) - background.appendChild(tagElement) + # Shadow + element = self.theme_xml.createElement(u'shadow') + element.setAttribute(u'color', shadow_color) + value = self.theme_xml.createTextNode(shadow) + element.appendChild(value) + background.appendChild(element) + # Outline + element = self.theme_xml.createElement(u'outline') + element.setAttribute(u'color', outline_color) + value = self.theme_xml.createTextNode(outline) + element.appendChild(value) + background.appendChild(element) + # Horizontal alignment + element = self.theme_xml.createElement(u'horizontalAlign') + value = self.theme_xml.createTextNode(horizontal) + element.appendChild(value) + background.appendChild(element) + # Vertical alignment + element = self.theme_xml.createElement(u'verticalAlign') + value = self.theme_xml.createTextNode(vertical) + element.appendChild(value) + background.appendChild(element) + # Wrap style + element = self.theme_xml.createElement(u'wrapStyle') + value = self.theme_xml.createTextNode(wrap) + element.appendChild(value) + background.appendChild(element) def child_element(self, element, tag, value): + """ + Generic child element creator. + """ child = self.theme_xml.createElement(tag) child.appendChild(self.theme_xml.createTextNode(value)) element.appendChild(child) return child def dump_xml(self): + """ + Dump the XML to file. + """ # Debugging aid to see what we have print self.theme_xml.toprettyxml(indent=u' ') def extract_xml(self): + """ + Pull out the XML string. + """ # Print our newly created XML return self.theme_xml.toxml() def parse(self, xml): - self.baseParseXml() + """ + Read in an XML string and parse it. + + ``xml`` + The XML string to parse. + """ + self.base_parse_xml() self.parse_xml(xml) self.theme_filename_extended = False - def baseParseXml(self): + def base_parse_xml(self): + """ + Pull in the blank theme XML as a starting point. + """ self.parse_xml(blankthemexml) def parse_xml(self, xml): + """ + Parse an XML string. + + ``xml`` + The XML string to parse. + """ theme_xml = ElementTree(element=XML(xml)) iter = theme_xml.getiterator() master = u'' for element in iter: - #print element.tag, element.text if len(element.getchildren()) > 0: master = element.tag + u'_' if len(element.attrib) > 0: - #print "D", element.tag , element.attrib for e in element.attrib.iteritems(): - #print "A", master, e[0], e[1] if master == u'font_' and e[0] == u'type': master += e[1] + u'_' elif master == u'display_' and (element.tag == u'shadow' or element.tag == u'outline'): - #print "b", master, element.tag, element.text, e[0], e[1] et = str_to_bool(element.text) setattr(self, master + element.tag , et) setattr(self, master + element.tag + u'_'+ e[0], e[1]) @@ -245,12 +334,14 @@ class ThemeXML(): e1 = str_to_bool(e[1]) setattr(self, field, e1) else: - #print "c", element.tag, element.text if element.tag is not None: field = master + element.tag setattr(self, field, element.text) def __str__(self): + """ + Return a string representation of this object. + """ s = u'' for k in dir(self): if k[0:1] != u'_': diff --git a/openlp/core/lib/toolbar.py b/openlp/core/lib/toolbar.py index 9bd124aa2..0f89abed4 100644 --- a/openlp/core/lib/toolbar.py +++ b/openlp/core/lib/toolbar.py @@ -1,4 +1,3 @@ - # -*- coding: utf-8 -*- # vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 """ @@ -19,15 +18,19 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ import types +import logging from PyQt4 import QtCore, QtGui -import logging class OpenLPToolbar(QtGui.QToolBar): """ - Lots of toolbars around the place, so it makes sense to have a common way to manage them + Lots of toolbars around the place, so it makes sense to have a common way + to manage them. This is the base toolbar class. """ def __init__(self, parent): + """ + Initialise the toolbar. + """ QtGui.QToolBar.__init__(self, None) # useful to be able to reuse button icons... self.icons = {} @@ -37,6 +40,23 @@ class OpenLPToolbar(QtGui.QToolBar): def addToolbarButton(self, title, icon, tooltip=None, slot=None, objectname=None): """ A method to help developers easily add a button to the toolbar. + + ``title`` + The title of the button. + + ``icon`` + The icon of the button. This can be an instance of QIcon, or a + string cotaining either the absolute path to the image, or an + internal resource path starting with ':/'. + + ``tooltip`` + A hint or tooltip for this button. + + ``slot`` + The method to run when this button is clicked. + + ``objectname`` + The name of the object, as used in `