From 9d92f358d4f27bde068c7a451a3deedcb956051b Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Fri, 9 Jul 2010 22:32:32 +0100 Subject: [PATCH 1/4] AdvancedTab: Creation & Recent files --- openlp/core/ui/__init__.py | 1 + openlp/core/ui/advancedtab.py | 162 +++++++++++++++++++++++++++++++++ openlp/core/ui/displaytab.py | 8 +- openlp/core/ui/mainwindow.py | 38 ++++++-- openlp/core/ui/settingsform.py | 7 +- 5 files changed, 200 insertions(+), 16 deletions(-) create mode 100644 openlp/core/ui/advancedtab.py diff --git a/openlp/core/ui/__init__.py b/openlp/core/ui/__init__.py index e104a2ec6..e93108da7 100644 --- a/openlp/core/ui/__init__.py +++ b/openlp/core/ui/__init__.py @@ -49,6 +49,7 @@ from splashscreen import SplashScreen from displaytab import DisplayTab from generaltab import GeneralTab from themestab import ThemesTab +from advancedtab import AdvancedTab from aboutform import AboutForm from pluginform import PluginForm from settingsform import SettingsForm diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py new file mode 100644 index 000000000..d2f0c22b5 --- /dev/null +++ b/openlp/core/ui/advancedtab.py @@ -0,0 +1,162 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2010 Raoul Snyman # +# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael # +# Gorven, Scott Guerrieri, Christian Richter, Maikel Stuivenberg, Martin # +# Thompson, Jon Tibble, Carsten Tinggaard # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### +""" +The :mod:`advancedtab` provides an advanced settings facility. +""" +from PyQt4 import QtCore, QtGui + +from openlp.core.lib import SettingsTab, translate + +class AdvancedTab(SettingsTab): + """ + The :class:`AdvancedTab` manages the advanced settings tab including the UI + and the loading and saving of the displayed settings. + """ + def __init__(self): + """ + Initialise the settings tab + """ + SettingsTab.__init__(self, u'Advanced') + + def setupUi(self): + """ + Configure the UI elements for the tab. + """ + self.setObjectName(u'AdvancedTab') + self.tabTitleVisible = translate('AdvancedTab', 'Advanced') + self.advancedTabLayout = QtGui.QHBoxLayout(self) + self.advancedTabLayout.setSpacing(8) + self.advancedTabLayout.setMargin(8) + self.leftWidget = QtGui.QWidget(self) + self.leftLayout = QtGui.QVBoxLayout(self.leftWidget) + self.leftLayout.setSpacing(8) + self.leftLayout.setMargin(0) + self.recentGroupBox = QtGui.QGroupBox(self.leftWidget) + self.recentGroupBox.setObjectName(u'recentGroupBox') + self.recentGroupBox.setGeometry(QtCore.QRect(0, 0, 220, 57)) + self.recentGroupBox.setMaximumSize(QtCore.QSize(220, 57)) + self.recentLayout = QtGui.QHBoxLayout(self.recentGroupBox) + self.recentLayout.setSpacing(8) + self.recentLayout.setMargin(6) + self.recentLayout.setObjectName(u'recentLayout') + self.recentLabel = QtGui.QLabel(self.recentGroupBox) + self.recentLabel.setObjectName(u'recentLabel') + self.recentLayout.addWidget(self.recentLabel) + self.recentSpinBox = QtGui.QSpinBox(self.recentGroupBox) + self.recentSpinBox.setMinimum(0) + self.recentSpinBox.setObjectName(u'recentSpinBox') + self.recentLayout.addWidget(self.recentSpinBox) + self.leftLayout.addWidget(self.recentGroupBox) +# self.sharedDirGroupBox = QtGui.QGroupBox(self.leftWidget) +# self.sharedDirGroupBox.setObjectName(u'sharedDirGroupBox') +# self.sharedDirGroupBox.setGeometry(QtCore.QRect(0, 65, 500, 85)) +# self.sharedDirGroupBox.setMaximumSize(QtCore.QSize(500, 85)) +# self.sharedDirLayout = QtGui.QVBoxLayout(self.sharedDirGroupBox) +# self.sharedDirLayout.setSpacing(8) +# self.sharedDirLayout.setMargin(8) +# self.sharedCheckBox = QtGui.QCheckBox(self.sharedDirGroupBox) +# self.sharedCheckBox.setObjectName(u'sharedCheckBox') +# self.sharedDirLayout.addWidget(self.sharedCheckBox) +# self.sharedSubLayout = QtGui.QHBoxLayout() +# self.sharedSubLayout.setSpacing(8) +# self.sharedSubLayout.setMargin(0) +# self.sharedLabel = QtGui.QLabel(self.sharedDirGroupBox) +# self.sharedLabel.setObjectName(u'sharedLabel') +# self.sharedSubLayout.addWidget(self.sharedLabel) +# self.sharedLineEdit = QtGui.QLineEdit(self.sharedDirGroupBox) +# self.sharedLineEdit.setObjectName(u'sharedLineEdit') +# self.sharedSubLayout.addWidget(self.sharedLineEdit) +# self.sharedPushButton = QtGui.QPushButton(self.sharedDirGroupBox) +# self.sharedPushButton.setObjectName(u'sharedPushButton') +# self.sharedSubLayout.addWidget(self.sharedPushButton) +# self.sharedDirLayout.addLayout(self.sharedSubLayout) +# self.leftLayout.addWidget(self.sharedDirGroupBox) + self.leftSpacer = QtGui.QSpacerItem(20, 40, + QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) + self.leftLayout.addItem(self.leftSpacer) + self.advancedTabLayout.addWidget(self.leftWidget) +# self.rightWidget = QtGui.QWidget(self) +# self.rightLayout = QtGui.QVBoxLayout(self.rightWidget) +# self.rightLayout.setSpacing(8) +# self.rightLayout.setMargin(0) +# self.databaseGroupBox = QtGui.QGroupBox(self.rightWidget) +# self.databaseGroupBox.setObjectName(u'databaseGroupBox') +# self.databaseGroupBox.setEnabled(False) +# self.databaseLayout = QtGui.QVBoxLayout(self.databaseGroupBox) +# self.databaseLayout.setSpacing(8) +# self.databaseLayout.setMargin(8) +# self.rightLayout.addWidget(self.databaseGroupBox) +# self.advancedTabLayout.addWidget(self.rightWidget) +# QtCore.QObject.connect(self.sharedCheckBox, +# QtCore.SIGNAL(u'stateChanged(int)'), self.onSharedCheckBoxChanged) + + def retranslateUi(self): + """ + Setup the interface translation strings. + """ + self.recentGroupBox.setTitle(translate('AdvancedTab', 'Recent Files')) + self.recentLabel.setText( + translate('AdvancedTab', 'Number of recent files to list:')) +# self.sharedDirGroupBox.setTitle( +# translate('AdvancedTab', 'Central Data Store')) +# self.sharedCheckBox.setText( +# translate('AdvancedTab', 'Enable a shared data location')) +# self.sharedLabel.setText(translate('AdvancedTab', 'Store location:')) +# self.sharedPushButton.setText(translate('AdvancedTab', 'Browse...')) +# self.databaseGroupBox.setTitle(translate('AdvancedTab', 'Databases')) + + def load(self): + """ + Load settings from disk. + """ + settings = QtCore.QSettings() + settings.beginGroup(self.settingsSection) + # The max recent files value does not have an interface and so never + # gets actually stored in the settings therefore the default value of + # 20 will always be used. + self.recentSpinBox.setMaximum(QtCore.QSettings().value( + u'max recent files', QtCore.QVariant(20)).toInt()[0]) + self.recentSpinBox.setValue(settings.value(u'recent file count', + QtCore.QVariant(4)).toInt()[0]) + settings.endGroup() + + def save(self): + """ + Save settings to disk. + """ + settings = QtCore.QSettings() + settings.beginGroup(self.settingsSection) + settings.setValue(u'recent file count', + QtCore.QVariant(self.recentSpinBox.value())) + settings.endGroup() + + def onSharedCheckBoxChanged(self, checked): + """ + Enables the widgets to allow a shared data location + """ + self.sharedLabel.setEnabled(checked) + self.sharedTextEdit.setEnabled(checked) + self.sharedPushButton.setEnabled(checked) + diff --git a/openlp/core/ui/displaytab.py b/openlp/core/ui/displaytab.py index 0fb16a9f7..32dad1c2b 100644 --- a/openlp/core/ui/displaytab.py +++ b/openlp/core/ui/displaytab.py @@ -44,10 +44,12 @@ class DisplayTab(SettingsTab): """ self.tabTitleVisible = translate('DisplayTab', 'Displays') self.layoutWidget = QtGui.QWidget(self) - self.layoutWidget.setGeometry(QtCore.QRect(0, 40, 241, 79)) self.layoutWidget.setObjectName(u'layoutWidget') self.verticalLayout = QtGui.QVBoxLayout(self.layoutWidget) self.verticalLayout.setObjectName(u'verticalLayout') + self.OverrideCheckBox = QtGui.QCheckBox(self.layoutWidget) + self.OverrideCheckBox.setObjectName(u'OverrideCheckBox') + self.verticalLayout.addWidget(self.OverrideCheckBox) self.CurrentGroupBox = QtGui.QGroupBox(self.layoutWidget) self.CurrentGroupBox.setObjectName(u'CurrentGroupBox') self.horizontalLayout = QtGui.QHBoxLayout(self.CurrentGroupBox) @@ -153,9 +155,7 @@ class DisplayTab(SettingsTab): self.WidthEdit.setObjectName(u'WidthEdit') self.verticalLayout_5.addWidget(self.WidthEdit) self.horizontalLayout_2.addLayout(self.verticalLayout_5) - self.OverrideCheckBox = QtGui.QCheckBox(self) - self.OverrideCheckBox.setGeometry(QtCore.QRect(0, 10, 191, 23)) - self.OverrideCheckBox.setObjectName(u'OverrideCheckBox') + self.verticalLayout.addWidget(self.CurrentGroupBox_2) QtCore.QMetaObject.connectSlotsByName(self) QtCore.QObject.connect(self.OverrideCheckBox, QtCore.SIGNAL(u'stateChanged(int)'), self.onOverrideCheckBoxChanged) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 841a0424b..216284f5d 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -897,6 +897,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.ViewLivePanel.setChecked(visible) def loadSettings(self): + """ + Load the main window settings. + """ log.debug(u'Loading QSettings') settings = QtCore.QSettings() settings.beginGroup(self.generalSettingsSection) @@ -911,6 +914,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): settings.endGroup() def saveSettings(self): + """ + Save the main window settings. + """ log.debug(u'Saving QSettings') settings = QtCore.QSettings() settings.beginGroup(self.generalSettingsSection) @@ -928,15 +934,19 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): settings.endGroup() def updateFileMenu(self): + """ + Updates the file menu with the latest list of service files accessed. + """ + recentFileCount = QtCore.QSettings().value( + u'advanced/recent file count', QtCore.QVariant(4)).toInt()[0] self.FileMenu.clear() add_actions(self.FileMenu, self.FileMenuActions[:-1]) - existingRecentFiles = [] - for file in self.recentFiles: - if QtCore.QFile.exists(file): - existingRecentFiles.append(file) - if existingRecentFiles: + existingRecentFiles = [file for file in self.recentFiles + if QtCore.QFile.exists(file)] + recentFilesToDisplay = existingRecentFiles[0:recentFileCount] + if recentFilesToDisplay: self.FileMenu.addSeparator() - for fileId, filename in enumerate(existingRecentFiles): + for fileId, filename in enumerate(recentFilesToDisplay): action = QtGui.QAction(u'&%d %s' % (fileId +1, QtCore.QFileInfo(filename).fileName()), self) action.setData(QtCore.QVariant(filename)) @@ -947,13 +957,21 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.FileMenu.addAction(self.FileMenuActions[-1]) def addRecentFile(self, filename): - recentFileCount = QtCore.QSettings().value( - self.generalSettingsSection + u'/max recent files', - QtCore.QVariant(4)).toInt()[0] + """ + Adds a service to the list of recently used files. + + ``filename`` + The service filename to add + """ + # The maxRecentFiles value does not have an interface and so never gets + # actually stored in the settings therefore the default value of 20 + # will always be used. + maxRecentFiles = QtCore.QSettings().value(u'advanced/max recent files', + QtCore.QVariant(20)).toInt()[0] if filename: position = self.recentFiles.indexOf(filename) if position != -1: self.recentFiles.removeAt(position) self.recentFiles.insert(0, QtCore.QString(filename)) - while self.recentFiles.count() > recentFileCount: + while self.recentFiles.count() > maxRecentFiles: self.recentFiles.removeLast() diff --git a/openlp/core/ui/settingsform.py b/openlp/core/ui/settingsform.py index dfd1d5a7d..3daa9421a 100644 --- a/openlp/core/ui/settingsform.py +++ b/openlp/core/ui/settingsform.py @@ -29,7 +29,7 @@ import logging from PyQt4 import QtGui -from openlp.core.ui import GeneralTab, ThemesTab, DisplayTab +from openlp.core.ui import AdvancedTab, GeneralTab, ThemesTab, DisplayTab from settingsdialog import Ui_SettingsDialog log = logging.getLogger(__name__) @@ -53,6 +53,9 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): # Display tab self.DisplayTab = DisplayTab(screens) self.addTab(u'Display', self.DisplayTab) + # Advanced tab + self.advancedTab = AdvancedTab() + self.addTab(u'Advanced', self.advancedTab) def addTab(self, name, tab): """ @@ -68,7 +71,7 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): log.debug(u'Inserting %s tab' % tab.tabTitle) #13 : There are 3 tables currently and locations starts at -10 self.SettingsTabWidget.insertTab( - location + 13, tab, tab.tabTitleVisible) + location + 14, tab, tab.tabTitleVisible) def removeTab(self, name): """ From 60b55689794aa38a6680e8ee5847c8d999993f2b Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Sat, 10 Jul 2010 02:01:14 +0100 Subject: [PATCH 2/4] Fix bug then fix fix! (Bug #603798) --- openlp/core/lib/mediamanageritem.py | 2 +- openlp/core/ui/mainwindow.py | 3 ++- openlp/plugins/bibles/bibleplugin.py | 3 ++- openlp/plugins/custom/customplugin.py | 3 ++- openlp/plugins/images/imageplugin.py | 3 ++- openlp/plugins/media/mediaplugin.py | 3 ++- openlp/plugins/presentations/presentationplugin.py | 3 ++- openlp/plugins/songs/songsplugin.py | 3 ++- 8 files changed, 15 insertions(+), 8 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 5e1d5bcc3..1a31efa32 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -521,7 +521,7 @@ class MediaManagerItem(QtGui.QWidget): if self.serviceItemIconName: service_item.add_icon(self.serviceItemIconName) else: - service_item.add_icon(self.parent.icon) + service_item.add_icon(self.parent.icon_path) if self.generateSlideData(service_item, item): return service_item else: diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 841a0424b..f58e01148 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -956,4 +956,5 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.recentFiles.removeAt(position) self.recentFiles.insert(0, QtCore.QString(filename)) while self.recentFiles.count() > recentFileCount: - self.recentFiles.removeLast() + # Don't care what API says takeLast works, removeLast doesn't! + self.recentFiles.takeLast() diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index 994be196a..10a4c9551 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -38,7 +38,8 @@ class BiblePlugin(Plugin): def __init__(self, plugin_helpers): Plugin.__init__(self, u'Bibles', u'1.9.2', plugin_helpers) self.weight = -9 - self.icon = build_icon(u':/plugins/plugin_bibles.png') + self.icon_path = u':/plugins/plugin_bibles.png' + self.icon = build_icon(self.icon_path) #Register the bible Manager self.status = PluginStatus.Active self.manager = None diff --git a/openlp/plugins/custom/customplugin.py b/openlp/plugins/custom/customplugin.py index ecbf1b440..8111841d9 100644 --- a/openlp/plugins/custom/customplugin.py +++ b/openlp/plugins/custom/customplugin.py @@ -50,7 +50,8 @@ class CustomPlugin(Plugin): self.weight = -5 self.custommanager = Manager(u'custom', init_schema) self.edit_custom_form = EditCustomForm(self.custommanager) - self.icon = build_icon(u':/plugins/plugin_custom.png') + self.icon_path = u':/plugins/plugin_custom.png' + self.icon = build_icon(self.icon_path) self.status = PluginStatus.Active def getSettingsTab(self): diff --git a/openlp/plugins/images/imageplugin.py b/openlp/plugins/images/imageplugin.py index cfd0ec90e..adf8e401b 100644 --- a/openlp/plugins/images/imageplugin.py +++ b/openlp/plugins/images/imageplugin.py @@ -36,7 +36,8 @@ class ImagePlugin(Plugin): def __init__(self, plugin_helpers): Plugin.__init__(self, u'Images', u'1.9.2', plugin_helpers) self.weight = -7 - self.icon = build_icon(u':/plugins/plugin_images.png') + self.icon_path = u':/plugins/plugin_images.png' + self.icon = build_icon(self.icon_path) self.status = PluginStatus.Active def getSettingsTab(self): diff --git a/openlp/plugins/media/mediaplugin.py b/openlp/plugins/media/mediaplugin.py index adc5f800f..4162c4d31 100644 --- a/openlp/plugins/media/mediaplugin.py +++ b/openlp/plugins/media/mediaplugin.py @@ -38,7 +38,8 @@ class MediaPlugin(Plugin): def __init__(self, plugin_helpers): Plugin.__init__(self, u'Media', u'1.9.2', plugin_helpers) self.weight = -6 - self.icon = build_icon(u':/plugins/plugin_media.png') + self.icon_path = u':/plugins/plugin_media.png' + self.icon = build_icon(self.icon_path) # passed with drag and drop messages self.dnd_id = u'Media' self.status = PluginStatus.Active diff --git a/openlp/plugins/presentations/presentationplugin.py b/openlp/plugins/presentations/presentationplugin.py index a905a3312..7bb256af7 100644 --- a/openlp/plugins/presentations/presentationplugin.py +++ b/openlp/plugins/presentations/presentationplugin.py @@ -40,7 +40,8 @@ class PresentationPlugin(Plugin): self.controllers = {} Plugin.__init__(self, u'Presentations', u'1.9.2', plugin_helpers) self.weight = -8 - self.icon = build_icon(u':/plugins/plugin_presentations.png') + self.icon_path = u':/plugins/plugin_presentations.png' + self.icon = build_icon(self.icon_path) self.status = PluginStatus.Active def getSettingsTab(self): diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index 0d5cdbd87..f63454e51 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -58,7 +58,8 @@ class SongsPlugin(Plugin): Plugin.__init__(self, u'Songs', u'1.9.2', plugin_helpers) self.weight = -10 self.manager = Manager(u'songs', init_schema) - self.icon = build_icon(u':/plugins/plugin_songs.png') + self.icon_path = u':/plugins/plugin_songs.png' + self.icon = build_icon(self.icon_path) self.status = PluginStatus.Active def getSettingsTab(self): From 4c08162e330e4b3a3413c7368d53e0c57265cb0a Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Sat, 10 Jul 2010 02:21:03 +0100 Subject: [PATCH 3/4] Fix docstring for last commit --- openlp/core/lib/serviceitem.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index a8988aa84..86694e986 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -117,8 +117,7 @@ class ServiceItem(object): service item in the service manager. ``icon`` - An instance of QIcon or a string to an icon in the resource or on - disk. + A string to an icon in the resources or on disk. """ self.icon = icon self.iconic_representation = build_icon(icon) From 4eb067343c03954c2b4a9c62519820b0b7838e35 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Sat, 10 Jul 2010 11:44:23 +0100 Subject: [PATCH 4/4] Fix mismerge --- openlp/core/ui/mainwindow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 6c58e5e64..ccef8a5ea 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -974,6 +974,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): if position != -1: self.recentFiles.removeAt(position) self.recentFiles.insert(0, QtCore.QString(filename)) - while self.recentFiles.count() > recentFileCount: + while self.recentFiles.count() > maxRecentFiles: # Don't care what API says takeLast works, removeLast doesn't! self.recentFiles.takeLast()