From 9d92f358d4f27bde068c7a451a3deedcb956051b Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Fri, 9 Jul 2010 22:32:32 +0100 Subject: [PATCH] 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): """