fileRenameForm/Dialog: code standards

This commit is contained in:
Andreas Preikschat 2013-03-01 12:12:23 +01:00
parent 9add95d2a5
commit 3a9908345a
4 changed files with 29 additions and 29 deletions

View File

@ -39,28 +39,28 @@ class Ui_FileRenameDialog(object):
""" """
The UI widgets for the rename dialog The UI widgets for the rename dialog
""" """
def setupUi(self, fileRenameDialog): def setupUi(self, file_rename_dialog):
""" """
Set up the UI Set up the UI
""" """
fileRenameDialog.setObjectName(u'fileRenameDialog') file_rename_dialog.setObjectName(u'fileRenameDialog')
fileRenameDialog.resize(300, 10) file_rename_dialog.resize(300, 10)
self.dialogLayout = QtGui.QGridLayout(fileRenameDialog) self.dialog_layout = QtGui.QGridLayout(file_rename_dialog)
self.dialogLayout.setObjectName(u'dialog_layout') self.dialog_layout.setObjectName(u'dialogLayout')
self.fileNameLabel = QtGui.QLabel(fileRenameDialog) self.file_name_label = QtGui.QLabel(file_rename_dialog)
self.fileNameLabel.setObjectName(u'fileNameLabel') self.file_name_label.setObjectName(u'fileNameLabel')
self.dialogLayout.addWidget(self.fileNameLabel, 0, 0) self.dialog_layout.addWidget(self.file_name_label, 0, 0)
self.fileNameEdit = QtGui.QLineEdit(fileRenameDialog) self.file_name_edit = QtGui.QLineEdit(file_rename_dialog)
self.fileNameEdit.setValidator(QtGui.QRegExpValidator(QtCore.QRegExp(r'[^/\\?*|<>\[\]":+%]+'), self)) self.file_name_edit.setValidator(QtGui.QRegExpValidator(QtCore.QRegExp(r'[^/\\?*|<>\[\]":+%]+'), self))
self.fileNameEdit.setObjectName(u'fileNameEdit') self.file_name_edit.setObjectName(u'fileNameEdit')
self.dialogLayout.addWidget(self.fileNameEdit, 0, 1) self.dialog_layout.addWidget(self.file_name_edit, 0, 1)
self.button_box = create_button_box(fileRenameDialog, u'button_box', [u'cancel', u'ok']) self.button_box = create_button_box(file_rename_dialog, u'button_box', [u'cancel', u'ok'])
self.dialogLayout.addWidget(self.button_box, 1, 0, 1, 2) self.dialog_layout.addWidget(self.button_box, 1, 0, 1, 2)
self.retranslateUi(fileRenameDialog) self.retranslateUi(file_rename_dialog)
self.setMaximumHeight(self.sizeHint().height()) self.setMaximumHeight(self.sizeHint().height())
def retranslateUi(self, fileRenameDialog): def retranslateUi(self, file_rename_dialog):
""" """
Translate the UI on the fly. 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:'))

View File

@ -56,7 +56,7 @@ class FileRenameForm(QtGui.QDialog, Ui_FileRenameDialog):
self.setWindowTitle(translate('OpenLP.FileRenameForm', 'File Copy')) self.setWindowTitle(translate('OpenLP.FileRenameForm', 'File Copy'))
else: else:
self.setWindowTitle(translate('OpenLP.FileRenameForm', 'File Rename')) self.setWindowTitle(translate('OpenLP.FileRenameForm', 'File Rename'))
self.fileNameEdit.setFocus() self.file_name_edit.setFocus()
return QtGui.QDialog.exec_(self) return QtGui.QDialog.exec_(self)
def _get_main_window(self): def _get_main_window(self):

View File

@ -254,9 +254,9 @@ class ThemeManager(QtGui.QWidget):
translate('OpenLP.ThemeManager', 'Rename %s theme?'), False, False): translate('OpenLP.ThemeManager', 'Rename %s theme?'), False, False):
item = self.theme_list_widget.currentItem() item = self.theme_list_widget.currentItem()
old_theme_name = item.data(QtCore.Qt.UserRole) 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_(): 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: if old_theme_name == new_theme_name:
return return
if self.check_if_theme_exists(new_theme_name): if self.check_if_theme_exists(new_theme_name):
@ -275,10 +275,10 @@ class ThemeManager(QtGui.QWidget):
""" """
item = self.theme_list_widget.currentItem() item = self.theme_list_widget.currentItem()
old_theme_name = item.data(QtCore.Qt.UserRole) 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) 'Copy of %s', 'Copy of <theme name>') % old_theme_name)
if self.fileRenameForm.exec_(True): 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): if self.check_if_theme_exists(new_theme_name):
theme_data = self.get_theme_data(old_theme_name) theme_data = self.get_theme_data(old_theme_name)
self.cloneThemeData(theme_data, new_theme_name) self.cloneThemeData(theme_data, new_theme_name)

View File

@ -56,28 +56,28 @@ class TestStartFileRenameForm(TestCase):
def line_edit_focus_test(self): def line_edit_focus_test(self):
""" """
Regression test for bug1067251 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: with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec:
mocked_set_focus = MagicMock() 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 # WHEN: The form is executed
self.form.exec_() 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() mocked_set_focus.assert_called_with()
def file_name_validation_test(self): 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. # GIVEN: QLineEdit with a validator set with illegal file name characters.
# WHEN: 'Typing' a string containing invalid file 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 # THEN: The text in the QLineEdit should be the same as the input string with the invalid characters filtered
# out. # out.
self.assertEqual(self.form.fileNameEdit.text(), u'Invalid File Name') self.assertEqual(self.form.file_name_edit.text(), u'Invalid File Name')