forked from openlp/openlp
fileRenameForm/Dialog: code standards
This commit is contained in:
parent
9add95d2a5
commit
3a9908345a
@ -39,28 +39,28 @@ class Ui_FileRenameDialog(object):
|
||||
"""
|
||||
The UI widgets for the rename dialog
|
||||
"""
|
||||
def setupUi(self, fileRenameDialog):
|
||||
def setupUi(self, file_rename_dialog):
|
||||
"""
|
||||
Set up the UI
|
||||
"""
|
||||
fileRenameDialog.setObjectName(u'fileRenameDialog')
|
||||
fileRenameDialog.resize(300, 10)
|
||||
self.dialogLayout = QtGui.QGridLayout(fileRenameDialog)
|
||||
self.dialogLayout.setObjectName(u'dialog_layout')
|
||||
self.fileNameLabel = QtGui.QLabel(fileRenameDialog)
|
||||
self.fileNameLabel.setObjectName(u'fileNameLabel')
|
||||
self.dialogLayout.addWidget(self.fileNameLabel, 0, 0)
|
||||
self.fileNameEdit = QtGui.QLineEdit(fileRenameDialog)
|
||||
self.fileNameEdit.setValidator(QtGui.QRegExpValidator(QtCore.QRegExp(r'[^/\\?*|<>\[\]":+%]+'), self))
|
||||
self.fileNameEdit.setObjectName(u'fileNameEdit')
|
||||
self.dialogLayout.addWidget(self.fileNameEdit, 0, 1)
|
||||
self.button_box = create_button_box(fileRenameDialog, u'button_box', [u'cancel', u'ok'])
|
||||
self.dialogLayout.addWidget(self.button_box, 1, 0, 1, 2)
|
||||
self.retranslateUi(fileRenameDialog)
|
||||
file_rename_dialog.setObjectName(u'fileRenameDialog')
|
||||
file_rename_dialog.resize(300, 10)
|
||||
self.dialog_layout = QtGui.QGridLayout(file_rename_dialog)
|
||||
self.dialog_layout.setObjectName(u'dialogLayout')
|
||||
self.file_name_label = QtGui.QLabel(file_rename_dialog)
|
||||
self.file_name_label.setObjectName(u'fileNameLabel')
|
||||
self.dialog_layout.addWidget(self.file_name_label, 0, 0)
|
||||
self.file_name_edit = QtGui.QLineEdit(file_rename_dialog)
|
||||
self.file_name_edit.setValidator(QtGui.QRegExpValidator(QtCore.QRegExp(r'[^/\\?*|<>\[\]":+%]+'), self))
|
||||
self.file_name_edit.setObjectName(u'fileNameEdit')
|
||||
self.dialog_layout.addWidget(self.file_name_edit, 0, 1)
|
||||
self.button_box = create_button_box(file_rename_dialog, u'button_box', [u'cancel', u'ok'])
|
||||
self.dialog_layout.addWidget(self.button_box, 1, 0, 1, 2)
|
||||
self.retranslateUi(file_rename_dialog)
|
||||
self.setMaximumHeight(self.sizeHint().height())
|
||||
|
||||
def retranslateUi(self, fileRenameDialog):
|
||||
def retranslateUi(self, file_rename_dialog):
|
||||
"""
|
||||
Translate the UI on the fly.
|
||||
"""
|
||||
self.fileNameLabel.setText(translate('OpenLP.FileRenameForm', 'New File Name:'))
|
||||
self.file_name_label.setText(translate('OpenLP.FileRenameForm', 'New File Name:'))
|
||||
|
@ -56,7 +56,7 @@ class FileRenameForm(QtGui.QDialog, Ui_FileRenameDialog):
|
||||
self.setWindowTitle(translate('OpenLP.FileRenameForm', 'File Copy'))
|
||||
else:
|
||||
self.setWindowTitle(translate('OpenLP.FileRenameForm', 'File Rename'))
|
||||
self.fileNameEdit.setFocus()
|
||||
self.file_name_edit.setFocus()
|
||||
return QtGui.QDialog.exec_(self)
|
||||
|
||||
def _get_main_window(self):
|
||||
|
@ -254,9 +254,9 @@ class ThemeManager(QtGui.QWidget):
|
||||
translate('OpenLP.ThemeManager', 'Rename %s theme?'), False, False):
|
||||
item = self.theme_list_widget.currentItem()
|
||||
old_theme_name = item.data(QtCore.Qt.UserRole)
|
||||
self.fileRenameForm.fileNameEdit.setText(old_theme_name)
|
||||
self.fileRenameForm.file_name_edit.setText(old_theme_name)
|
||||
if self.fileRenameForm.exec_():
|
||||
new_theme_name = self.fileRenameForm.fileNameEdit.text()
|
||||
new_theme_name = self.fileRenameForm.file_name_edit.text()
|
||||
if old_theme_name == new_theme_name:
|
||||
return
|
||||
if self.check_if_theme_exists(new_theme_name):
|
||||
@ -275,10 +275,10 @@ class ThemeManager(QtGui.QWidget):
|
||||
"""
|
||||
item = self.theme_list_widget.currentItem()
|
||||
old_theme_name = item.data(QtCore.Qt.UserRole)
|
||||
self.fileRenameForm.fileNameEdit.setText(translate('OpenLP.ThemeManager',
|
||||
self.fileRenameForm.file_name_edit.setText(translate('OpenLP.ThemeManager',
|
||||
'Copy of %s', 'Copy of <theme name>') % old_theme_name)
|
||||
if self.fileRenameForm.exec_(True):
|
||||
new_theme_name = self.fileRenameForm.fileNameEdit.text()
|
||||
new_theme_name = self.fileRenameForm.file_name_edit.text()
|
||||
if self.check_if_theme_exists(new_theme_name):
|
||||
theme_data = self.get_theme_data(old_theme_name)
|
||||
self.cloneThemeData(theme_data, new_theme_name)
|
||||
|
@ -56,28 +56,28 @@ class TestStartFileRenameForm(TestCase):
|
||||
def line_edit_focus_test(self):
|
||||
"""
|
||||
Regression test for bug1067251
|
||||
Test that the fileNameEdit setFocus has called with True when executed
|
||||
Test that the file_name_edit setFocus has called with True when executed
|
||||
"""
|
||||
# GIVEN: A mocked QDialog.exec_() method and mocked fileNameEdit.setFocus() method.
|
||||
# GIVEN: A mocked QDialog.exec_() method and mocked file_name_edit.setFocus() method.
|
||||
with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec:
|
||||
mocked_set_focus = MagicMock()
|
||||
self.form.fileNameEdit.setFocus = mocked_set_focus
|
||||
self.form.file_name_edit.setFocus = mocked_set_focus
|
||||
|
||||
# WHEN: The form is executed
|
||||
self.form.exec_()
|
||||
|
||||
# THEN: the setFocus method of the fileNameEdit has been called with True
|
||||
# THEN: the setFocus method of the file_name_edit has been called with True
|
||||
mocked_set_focus.assert_called_with()
|
||||
|
||||
def file_name_validation_test(self):
|
||||
"""
|
||||
Test the fileNameEdit validation
|
||||
Test the file_name_edit validation
|
||||
"""
|
||||
# GIVEN: QLineEdit with a validator set with illegal file name characters.
|
||||
|
||||
# WHEN: 'Typing' a string containing invalid file characters.
|
||||
QtTest.QTest.keyClicks(self.form.fileNameEdit, u'I/n\\v?a*l|i<d> \F[i\l]e" :N+a%me')
|
||||
QtTest.QTest.keyClicks(self.form.file_name_edit, u'I/n\\v?a*l|i<d> \F[i\l]e" :N+a%me')
|
||||
|
||||
# THEN: The text in the QLineEdit should be the same as the input string with the invalid characters filtered
|
||||
# out.
|
||||
self.assertEqual(self.form.fileNameEdit.text(), u'Invalid File Name')
|
||||
self.assertEqual(self.form.file_name_edit.text(), u'Invalid File Name')
|
||||
|
Loading…
Reference in New Issue
Block a user