From a55cdd3a50700fb2e432d692c50d74724a1fbcc1 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 7 Dec 2010 18:55:58 +0000 Subject: [PATCH 1/4] Fix string to int problem --- openlp/core/ui/generaltab.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/openlp/core/ui/generaltab.py b/openlp/core/ui/generaltab.py index d8481e801..0801c91c6 100644 --- a/openlp/core/ui/generaltab.py +++ b/openlp/core/ui/generaltab.py @@ -23,6 +23,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### +import re from PyQt4 import QtCore, QtGui @@ -465,10 +466,10 @@ class GeneralTab(SettingsTab): # Reset screens after initial definition if self.overrideChanged: self.screens.override[u'size'] = QtCore.QRect( - int(self.customXValueEdit.text()), - int(self.customYValueEdit.text()), - int(self.customWidthValueEdit.text()), - int(self.customHeightValueEdit.text())) + self._toInt(self.customXValueEdit.text()), + self._toInt(self.customYValueEdit.text()), + self._toInt(self.customWidthValueEdit.text()), + self._toInt(self.customHeightValueEdit.text())) if self.overrideCheckBox.isChecked(): self.screens.set_override_display() else: @@ -487,3 +488,12 @@ class GeneralTab(SettingsTab): self.customHeightValueEdit.setEnabled(checked) self.customWidthValueEdit.setEnabled(checked) self.overrideChanged = True + + def _toInt(self, value): + """ + Convert text string to a numeric string + """ + try: + return int(value) + except: + return 0 From ccc640bb27b5f28aa2b329f856ffcf409794792b Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 7 Dec 2010 20:47:09 +0000 Subject: [PATCH 2/4] Stop invalid characters being entered --- openlp/core/ui/generaltab.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/openlp/core/ui/generaltab.py b/openlp/core/ui/generaltab.py index 0801c91c6..f932f7ab1 100644 --- a/openlp/core/ui/generaltab.py +++ b/openlp/core/ui/generaltab.py @@ -243,6 +243,7 @@ class GeneralTab(SettingsTab): self.customXLayout.addWidget(self.customXLabel) self.customXValueEdit = QtGui.QLineEdit(self.displayGroupBox) self.customXValueEdit.setObjectName(u'customXValueEdit') + self.customXValueEdit.setInputMask(u'99999') self.customXLayout.addWidget(self.customXValueEdit) self.customLayout.addLayout(self.customXLayout) self.customYLayout = QtGui.QVBoxLayout() @@ -255,6 +256,7 @@ class GeneralTab(SettingsTab): self.customYLayout.addWidget(self.customYLabel) self.customYValueEdit = QtGui.QLineEdit(self.displayGroupBox) self.customYValueEdit.setObjectName(u'customYValueEdit') + self.customYValueEdit.setInputMask(u'99999') self.customYLayout.addWidget(self.customYValueEdit) self.customLayout.addLayout(self.customYLayout) self.customWidthLayout = QtGui.QVBoxLayout() @@ -268,6 +270,7 @@ class GeneralTab(SettingsTab): self.customWidthLayout.addWidget(self.customWidthLabel) self.customWidthValueEdit = QtGui.QLineEdit(self.displayGroupBox) self.customWidthValueEdit.setObjectName(u'customWidthValueEdit') + self.customWidthValueEdit.setInputMask(u'99999') self.customWidthLayout.addWidget(self.customWidthValueEdit) self.customLayout.addLayout(self.customWidthLayout) self.customHeightLayout = QtGui.QVBoxLayout() @@ -280,6 +283,7 @@ class GeneralTab(SettingsTab): self.customHeightLayout.addWidget(self.customHeightLabel) self.customHeightValueEdit = QtGui.QLineEdit(self.displayGroupBox) self.customHeightValueEdit.setObjectName(u'customHeightValueEdit') + self.customHeightValueEdit.setInputMask(u'99999') self.customHeightLayout.addWidget(self.customHeightValueEdit) self.customLayout.addLayout(self.customHeightLayout) self.displayLayout.addLayout(self.customLayout) @@ -491,7 +495,7 @@ class GeneralTab(SettingsTab): def _toInt(self, value): """ - Convert text string to a numeric string + Make sure a Int returns a value. """ try: return int(value) From 2f04bde2aab04197cae2b4e09e2be708d47d7ec2 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 8 Dec 2010 19:00:24 +0000 Subject: [PATCH 3/4] Fix size input validation --- openlp/core/ui/generaltab.py | 53 +++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/openlp/core/ui/generaltab.py b/openlp/core/ui/generaltab.py index f932f7ab1..0ef848410 100644 --- a/openlp/core/ui/generaltab.py +++ b/openlp/core/ui/generaltab.py @@ -23,12 +23,34 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -import re +import logging from PyQt4 import QtCore, QtGui from openlp.core.lib import SettingsTab, Receiver, translate +log = logging.getLogger(__name__) + +class ValidEdit(QtGui.QLineEdit): + """ + Only allow numeric characters to be edited + """ + def __init__(self, parent): + """ + Set up Override and Validator + """ + QtGui.QLineEdit.__init__(self, parent) + self.setValidator(QtGui.QIntValidator(0, 9999, self)) + + def validText(self): + """ + Only return Integers. Space is 0 + """ + if len(self.text()) == 0: + return QtCore.QString(u'0') + else: + return self.text() + class GeneralTab(SettingsTab): """ GeneralTab is the general settings tab in the settings dialog. @@ -241,9 +263,8 @@ class GeneralTab(SettingsTab): self.customXLabel.setAlignment(QtCore.Qt.AlignCenter) self.customXLabel.setObjectName(u'customXLabel') self.customXLayout.addWidget(self.customXLabel) - self.customXValueEdit = QtGui.QLineEdit(self.displayGroupBox) + self.customXValueEdit = ValidEdit(self.displayGroupBox) self.customXValueEdit.setObjectName(u'customXValueEdit') - self.customXValueEdit.setInputMask(u'99999') self.customXLayout.addWidget(self.customXValueEdit) self.customLayout.addLayout(self.customXLayout) self.customYLayout = QtGui.QVBoxLayout() @@ -254,9 +275,8 @@ class GeneralTab(SettingsTab): self.customYLabel.setAlignment(QtCore.Qt.AlignCenter) self.customYLabel.setObjectName(u'customYLabel') self.customYLayout.addWidget(self.customYLabel) - self.customYValueEdit = QtGui.QLineEdit(self.displayGroupBox) + self.customYValueEdit = ValidEdit(self.displayGroupBox) self.customYValueEdit.setObjectName(u'customYValueEdit') - self.customYValueEdit.setInputMask(u'99999') self.customYLayout.addWidget(self.customYValueEdit) self.customLayout.addLayout(self.customYLayout) self.customWidthLayout = QtGui.QVBoxLayout() @@ -268,9 +288,8 @@ class GeneralTab(SettingsTab): self.customWidthLabel.setAlignment(QtCore.Qt.AlignCenter) self.customWidthLabel.setObjectName(u'customWidthLabel') self.customWidthLayout.addWidget(self.customWidthLabel) - self.customWidthValueEdit = QtGui.QLineEdit(self.displayGroupBox) + self.customWidthValueEdit = ValidEdit(self.displayGroupBox) self.customWidthValueEdit.setObjectName(u'customWidthValueEdit') - self.customWidthValueEdit.setInputMask(u'99999') self.customWidthLayout.addWidget(self.customWidthValueEdit) self.customLayout.addLayout(self.customWidthLayout) self.customHeightLayout = QtGui.QVBoxLayout() @@ -281,9 +300,8 @@ class GeneralTab(SettingsTab): self.customHeightLabel.setAlignment(QtCore.Qt.AlignCenter) self.customHeightLabel.setObjectName(u'customHeightLabel') self.customHeightLayout.addWidget(self.customHeightLabel) - self.customHeightValueEdit = QtGui.QLineEdit(self.displayGroupBox) + self.customHeightValueEdit = ValidEdit(self.displayGroupBox) self.customHeightValueEdit.setObjectName(u'customHeightValueEdit') - self.customHeightValueEdit.setInputMask(u'99999') self.customHeightLayout.addWidget(self.customHeightValueEdit) self.customLayout.addLayout(self.customHeightLayout) self.displayLayout.addLayout(self.customLayout) @@ -470,10 +488,10 @@ class GeneralTab(SettingsTab): # Reset screens after initial definition if self.overrideChanged: self.screens.override[u'size'] = QtCore.QRect( - self._toInt(self.customXValueEdit.text()), - self._toInt(self.customYValueEdit.text()), - self._toInt(self.customWidthValueEdit.text()), - self._toInt(self.customHeightValueEdit.text())) + int(self.customXValueEdit.validText()), + int(self.customYValueEdit.validText()), + int(self.customWidthValueEdit.validText()), + int(self.customHeightValueEdit.validText())) if self.overrideCheckBox.isChecked(): self.screens.set_override_display() else: @@ -492,12 +510,3 @@ class GeneralTab(SettingsTab): self.customHeightValueEdit.setEnabled(checked) self.customWidthValueEdit.setEnabled(checked) self.overrideChanged = True - - def _toInt(self, value): - """ - Make sure a Int returns a value. - """ - try: - return int(value) - except: - return 0 From b405195261dea27d8dc6d271c5d4cbf5d6f03920 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 8 Dec 2010 19:12:38 +0000 Subject: [PATCH 4/4] Fix size input validation again --- openlp/core/ui/generaltab.py | 2 +- openlp/plugins/songs/lib/mediaitem.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/core/ui/generaltab.py b/openlp/core/ui/generaltab.py index 0ef848410..b8894fe9a 100644 --- a/openlp/core/ui/generaltab.py +++ b/openlp/core/ui/generaltab.py @@ -46,7 +46,7 @@ class ValidEdit(QtGui.QLineEdit): """ Only return Integers. Space is 0 """ - if len(self.text()) == 0: + if self.text().isEmpty(): return QtCore.QString(u'0') else: return self.text() diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 432eee744..1008df020 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -390,7 +390,7 @@ class SongMediaItem(MediaManagerItem): raw_footer.append(author_list) raw_footer.append(song.copyright ) raw_footer.append(unicode( - translate('SongsPlugin.MediaItem', 'CCLI Licence: ') + + translate('SongsPlugin.MediaItem', 'CCLI License: ') + QtCore.QSettings().value(u'general/ccli number', QtCore.QVariant(u'')).toString())) service_item.raw_footer = raw_footer