forked from openlp/openlp
Completed refactor of songimportform.py
This commit is contained in:
parent
e882607360
commit
504145d454
@ -36,8 +36,8 @@ from PyQt4 import QtCore, QtGui
|
|||||||
from openlp.core.lib import Receiver, SettingsManager, translate
|
from openlp.core.lib import Receiver, SettingsManager, translate
|
||||||
from openlp.core.lib.ui import UiStrings, critical_error_message_box
|
from openlp.core.lib.ui import UiStrings, critical_error_message_box
|
||||||
from openlp.core.ui.wizard import OpenLPWizard, WizardStrings
|
from openlp.core.ui.wizard import OpenLPWizard, WizardStrings
|
||||||
from openlp.plugins.songs.lib.importer import (SongFormat, SongFormatAttr,
|
from openlp.plugins.songs.lib.importer import SongFormat, SongFormatAttr, \
|
||||||
SongFormatSelect)
|
SongFormatSelect
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -59,8 +59,6 @@ class SongImportForm(OpenLPWizard):
|
|||||||
The songs plugin.
|
The songs plugin.
|
||||||
"""
|
"""
|
||||||
self.clipboard = plugin.formParent.clipboard
|
self.clipboard = plugin.formParent.clipboard
|
||||||
self.activeFormat = None
|
|
||||||
self.formatWidgets = dict([(f, {}) for f in SongFormat.get_format_list()])
|
|
||||||
OpenLPWizard.__init__(self, parent, plugin, u'songImportWizard',
|
OpenLPWizard.__init__(self, parent, plugin, u'songImportWizard',
|
||||||
u':/wizards/wizard_importsong.bmp')
|
u':/wizards/wizard_importsong.bmp')
|
||||||
|
|
||||||
@ -68,6 +66,8 @@ class SongImportForm(OpenLPWizard):
|
|||||||
"""
|
"""
|
||||||
Set up the song wizard UI.
|
Set up the song wizard UI.
|
||||||
"""
|
"""
|
||||||
|
self.formatWidgets = dict([(format, {}) for format in
|
||||||
|
SongFormat.get_format_list()])
|
||||||
OpenLPWizard.setupUi(self, image)
|
OpenLPWizard.setupUi(self, image)
|
||||||
self.activeFormat = SongFormat.OpenLyrics
|
self.activeFormat = SongFormat.OpenLyrics
|
||||||
self.formatStack.setCurrentIndex(self.activeFormat)
|
self.formatStack.setCurrentIndex(self.activeFormat)
|
||||||
@ -82,7 +82,7 @@ class SongImportForm(OpenLPWizard):
|
|||||||
button.
|
button.
|
||||||
"""
|
"""
|
||||||
self.activeFormat = index
|
self.activeFormat = index
|
||||||
self.formatStack.setCurrentIndex(self.activeFormat)
|
self.formatStack.setCurrentIndex(index)
|
||||||
next_button = self.button(QtGui.QWizard.NextButton)
|
next_button = self.button(QtGui.QWizard.NextButton)
|
||||||
next_button.setEnabled(SongFormatAttr.get(self.activeFormat,
|
next_button.setEnabled(SongFormatAttr.get(self.activeFormat,
|
||||||
SongFormatAttr.availability))
|
SongFormatAttr.availability))
|
||||||
@ -92,8 +92,7 @@ class SongImportForm(OpenLPWizard):
|
|||||||
Song wizard specific initialisation.
|
Song wizard specific initialisation.
|
||||||
"""
|
"""
|
||||||
for format in SongFormat.get_format_list():
|
for format in SongFormat.get_format_list():
|
||||||
if not SongFormatAttr.get(format,
|
if not SongFormatAttr.get(format, SongFormatAttr.availability):
|
||||||
SongFormatAttr.availability):
|
|
||||||
self.formatWidgets[format][u'disabledWidget'].setVisible(True)
|
self.formatWidgets[format][u'disabledWidget'].setVisible(True)
|
||||||
self.formatWidgets[format][u'importWidget'].setVisible(False)
|
self.formatWidgets[format][u'importWidget'].setVisible(False)
|
||||||
|
|
||||||
@ -102,8 +101,7 @@ class SongImportForm(OpenLPWizard):
|
|||||||
Song wizard specific signals.
|
Song wizard specific signals.
|
||||||
"""
|
"""
|
||||||
for format in SongFormat.get_format_list():
|
for format in SongFormat.get_format_list():
|
||||||
select_mode = SongFormatAttr.get(format,
|
select_mode = SongFormatAttr.get(format, SongFormatAttr.select_mode)
|
||||||
SongFormatAttr.select_mode)
|
|
||||||
if select_mode == SongFormatSelect.MultipleFiles:
|
if select_mode == SongFormatSelect.MultipleFiles:
|
||||||
QtCore.QObject.connect(self.formatWidgets[format][u'addButton'],
|
QtCore.QObject.connect(self.formatWidgets[format][u'addButton'],
|
||||||
QtCore.SIGNAL(u'clicked()'), self.onAddButtonClicked)
|
QtCore.SIGNAL(u'clicked()'), self.onAddButtonClicked)
|
||||||
@ -162,7 +160,6 @@ class SongImportForm(OpenLPWizard):
|
|||||||
self.sourcePage.setTitle(WizardStrings.ImportSelect)
|
self.sourcePage.setTitle(WizardStrings.ImportSelect)
|
||||||
self.sourcePage.setSubTitle(WizardStrings.ImportSelectLong)
|
self.sourcePage.setSubTitle(WizardStrings.ImportSelectLong)
|
||||||
self.formatLabel.setText(WizardStrings.FormatLabel)
|
self.formatLabel.setText(WizardStrings.FormatLabel)
|
||||||
|
|
||||||
for format in SongFormat.get_format_list():
|
for format in SongFormat.get_format_list():
|
||||||
format_name, custom_combo_text, select_mode = SongFormatAttr.get(
|
format_name, custom_combo_text, select_mode = SongFormatAttr.get(
|
||||||
format, SongFormatAttr.name, SongFormatAttr.combo_box_text,
|
format, SongFormatAttr.name, SongFormatAttr.combo_box_text,
|
||||||
@ -176,19 +173,17 @@ class SongImportForm(OpenLPWizard):
|
|||||||
self.formatWidgets[format][u'removeButton'].setText(
|
self.formatWidgets[format][u'removeButton'].setText(
|
||||||
translate('SongsPlugin.ImportWizardForm', 'Remove File(s)'))
|
translate('SongsPlugin.ImportWizardForm', 'Remove File(s)'))
|
||||||
else:
|
else:
|
||||||
|
self.formatWidgets[format][u'browseButton'].setText(
|
||||||
|
UiStrings().Browse)
|
||||||
if select_mode == SongFormatSelect.SingleFile:
|
if select_mode == SongFormatSelect.SingleFile:
|
||||||
f_label = 'Filename:'
|
f_label = 'Filename:'
|
||||||
elif select_mode == SongFormatSelect.SingleFolder:
|
elif select_mode == SongFormatSelect.SingleFolder:
|
||||||
f_label = 'Folder:'
|
f_label = 'Folder:'
|
||||||
self.formatWidgets[format][u'browseButton'].setText(
|
|
||||||
UiStrings().Browse)
|
|
||||||
self.formatWidgets[format][u'filepathLabel'].setText(
|
self.formatWidgets[format][u'filepathLabel'].setText(
|
||||||
translate('SongsPlugin.ImportWizardForm', f_label))
|
translate('SongsPlugin.ImportWizardForm', f_label))
|
||||||
for format in self.disablableFormats:
|
for format in self.disablableFormats:
|
||||||
self.formatWidgets[format][u'disabledLabel'].setText(
|
self.formatWidgets[format][u'disabledLabel'].setText(
|
||||||
SongFormatAttr.get(format,
|
SongFormatAttr.get(format, SongFormatAttr.disabled_label_text))
|
||||||
SongFormatAttr.disabled_label_text))
|
|
||||||
|
|
||||||
self.progressPage.setTitle(WizardStrings.Importing)
|
self.progressPage.setTitle(WizardStrings.Importing)
|
||||||
self.progressPage.setSubTitle(
|
self.progressPage.setSubTitle(
|
||||||
translate('SongsPlugin.ImportWizardForm',
|
translate('SongsPlugin.ImportWizardForm',
|
||||||
@ -200,8 +195,9 @@ class SongImportForm(OpenLPWizard):
|
|||||||
self.errorSaveToButton.setText(translate('SongsPlugin.ImportWizardForm',
|
self.errorSaveToButton.setText(translate('SongsPlugin.ImportWizardForm',
|
||||||
'Save to File'))
|
'Save to File'))
|
||||||
# Align all QFormLayouts towards each other.
|
# Align all QFormLayouts towards each other.
|
||||||
|
filepathLabel = self.formatWidgets[SongFormat.OpenLP2][u'filepathLabel']
|
||||||
width = max(self.formatLabel.minimumSizeHint().width(),
|
width = max(self.formatLabel.minimumSizeHint().width(),
|
||||||
self.openLP2FilenameLabel.minimumSizeHint().width())
|
filepathLabel.minimumSizeHint().width())
|
||||||
self.formatSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed,
|
self.formatSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed,
|
||||||
QtGui.QSizePolicy.Fixed)
|
QtGui.QSizePolicy.Fixed)
|
||||||
|
|
||||||
@ -233,7 +229,6 @@ class SongImportForm(OpenLPWizard):
|
|||||||
fileListWidget = self.formatWidgets[format][u'fileListWidget']
|
fileListWidget = self.formatWidgets[format][u'fileListWidget']
|
||||||
if fileListWidget.count() == 0 or not class_.isValidSource(
|
if fileListWidget.count() == 0 or not class_.isValidSource(
|
||||||
filenames=self.getListOfFiles(fileListWidget)):
|
filenames=self.getListOfFiles(fileListWidget)):
|
||||||
error_msg = error_msg if error_msg else WizardStrings.YouSpecifyFiles % format_name
|
|
||||||
critical_error_message_box(UiStrings().NFSp,
|
critical_error_message_box(UiStrings().NFSp,
|
||||||
error_msg(WizardStrings.YouSpecifyFiles))
|
error_msg(WizardStrings.YouSpecifyFiles))
|
||||||
self.formatWidgets[format][u'addButton'].setFocus()
|
self.formatWidgets[format][u'addButton'].setFocus()
|
||||||
@ -301,25 +296,22 @@ class SongImportForm(OpenLPWizard):
|
|||||||
|
|
||||||
def onBrowseButtonClicked(self):
|
def onBrowseButtonClicked(self):
|
||||||
format = self.activeFormat
|
format = self.activeFormat
|
||||||
select_mode = SongFormatAttr.get(format,
|
select_mode, format_name, filter = SongFormatAttr.get(format,
|
||||||
SongFormatAttr.select_mode)
|
SongFormatAttr.select_mode, SongFormatAttr.name,
|
||||||
name = SongFormatAttr.get(format,
|
|
||||||
SongFormatAttr.name)
|
|
||||||
filter = SongFormatAttr.get(format,
|
|
||||||
SongFormatAttr.filter)
|
SongFormatAttr.filter)
|
||||||
filepathEdit = self.formatWidgets[format][u'filepathEdit']
|
filepathEdit = self.formatWidgets[format][u'filepathEdit']
|
||||||
if select_mode == SongFormatSelect.SingleFile:
|
if select_mode == SongFormatSelect.SingleFile:
|
||||||
self.getFileName(WizardStrings.OpenTypeFile % name, filepathEdit,
|
self.getFileName(WizardStrings.OpenTypeFile % format_name,
|
||||||
filter)
|
filepathEdit, filter)
|
||||||
elif select_mode == SongFormatSelect.SingleFolder:
|
elif select_mode == SongFormatSelect.SingleFolder:
|
||||||
self.getFolder(WizardStrings.OpenTypeFile % name, filepathEdit)
|
self.getFolder(WizardStrings.OpenTypeFolder % format_name,
|
||||||
|
filepathEdit)
|
||||||
|
|
||||||
def onAddButtonClicked(self):
|
def onAddButtonClicked(self):
|
||||||
format = self.activeFormat
|
format = self.activeFormat
|
||||||
select_mode, format_name, filter, custom_title = \
|
select_mode, format_name, filter, custom_title = SongFormatAttr.get(
|
||||||
SongFormatAttr.get(format, SongFormatAttr.select_mode,
|
format, SongFormatAttr.select_mode, SongFormatAttr.name,
|
||||||
SongFormatAttr.name, SongFormatAttr.filter,
|
SongFormatAttr.filter, SongFormatAttr.get_files_title)
|
||||||
SongFormatAttr.get_files_title)
|
|
||||||
title = custom_title if custom_title \
|
title = custom_title if custom_title \
|
||||||
else WizardStrings.OpenTypeFile % format_name
|
else WizardStrings.OpenTypeFile % format_name
|
||||||
if select_mode == SongFormatSelect.MultipleFiles:
|
if select_mode == SongFormatSelect.MultipleFiles:
|
||||||
@ -344,8 +336,7 @@ class SongImportForm(OpenLPWizard):
|
|||||||
last_import_type = 0
|
last_import_type = 0
|
||||||
self.formatComboBox.setCurrentIndex(last_import_type)
|
self.formatComboBox.setCurrentIndex(last_import_type)
|
||||||
for format in SongFormat.get_format_list():
|
for format in SongFormat.get_format_list():
|
||||||
select_mode = SongFormatAttr.get(format,
|
select_mode = SongFormatAttr.get(format, SongFormatAttr.select_mode)
|
||||||
SongFormatAttr.select_mode)
|
|
||||||
if select_mode == SongFormatSelect.MultipleFiles:
|
if select_mode == SongFormatSelect.MultipleFiles:
|
||||||
self.formatWidgets[format][u'fileListWidget'].clear()
|
self.formatWidgets[format][u'fileListWidget'].clear()
|
||||||
else:
|
else:
|
||||||
@ -407,13 +398,9 @@ class SongImportForm(OpenLPWizard):
|
|||||||
|
|
||||||
def addFileSelectItem(self):
|
def addFileSelectItem(self):
|
||||||
format = self.activeFormat
|
format = self.activeFormat
|
||||||
prefix = SongFormatAttr.get(format, SongFormatAttr.prefix)
|
prefix, obj_prefix, can_disable, select_mode = SongFormatAttr.get(
|
||||||
obj_prefix = SongFormatAttr.get(format,
|
format, SongFormatAttr.prefix, SongFormatAttr.obj_prefix,
|
||||||
SongFormatAttr.obj_prefix)
|
SongFormatAttr.can_disable, SongFormatAttr.select_mode)
|
||||||
can_disable = SongFormatAttr.get(format,
|
|
||||||
SongFormatAttr.can_disable)
|
|
||||||
select_mode = SongFormatAttr.get(format,
|
|
||||||
SongFormatAttr.select_mode)
|
|
||||||
if not obj_prefix:
|
if not obj_prefix:
|
||||||
obj_prefix = prefix
|
obj_prefix = prefix
|
||||||
page = QtGui.QWidget()
|
page = QtGui.QWidget()
|
||||||
@ -473,7 +460,6 @@ class SongImportForm(OpenLPWizard):
|
|||||||
self.formatComboBox.addItem(u'')
|
self.formatComboBox.addItem(u'')
|
||||||
|
|
||||||
def disablableWidget(self, page, obj_prefix):
|
def disablableWidget(self, page, obj_prefix):
|
||||||
format = self.activeFormat
|
|
||||||
self.disablableFormats.append(format)
|
self.disablableFormats.append(format)
|
||||||
layout = QtGui.QVBoxLayout(page)
|
layout = QtGui.QVBoxLayout(page)
|
||||||
layout.setMargin(0)
|
layout.setMargin(0)
|
||||||
@ -494,6 +480,7 @@ class SongImportForm(OpenLPWizard):
|
|||||||
importWidget = QtGui.QWidget(page)
|
importWidget = QtGui.QWidget(page)
|
||||||
importWidget.setObjectName(obj_prefix + u'ImportWidget')
|
importWidget.setObjectName(obj_prefix + u'ImportWidget')
|
||||||
layout.addWidget(importWidget)
|
layout.addWidget(importWidget)
|
||||||
|
format = self.activeFormat
|
||||||
self.formatWidgets[format][u'layout'] = layout
|
self.formatWidgets[format][u'layout'] = layout
|
||||||
self.formatWidgets[format][u'disabledWidget'] = disabledWidget
|
self.formatWidgets[format][u'disabledWidget'] = disabledWidget
|
||||||
self.formatWidgets[format][u'disabledLayout'] = disabledLayout
|
self.formatWidgets[format][u'disabledLayout'] = disabledLayout
|
||||||
|
@ -130,13 +130,13 @@ class SongFormatAttr(object):
|
|||||||
* ``availability`` Whether song format is available.
|
* ``availability`` Whether song format is available.
|
||||||
* ``select_mode`` Whether format accepts single file, multiple files, or
|
* ``select_mode`` Whether format accepts single file, multiple files, or
|
||||||
single folder.
|
single folder.
|
||||||
* ``filter`` File extension filter for Open File/Folder dialog.
|
* ``filter`` File extension filter for QFileDialog.
|
||||||
|
|
||||||
Optional/custom text values for SongImportForm widgets:
|
Optional/custom text values for SongImportForm widgets:
|
||||||
* ``combo_box_text`` Combo box selector (default is format name).
|
* ``combo_box_text`` Combo box selector (default is format name).
|
||||||
* ``disabled_label_text`` Required for disablable song formats.
|
* ``disabled_label_text`` Required for disablable song formats.
|
||||||
* ``get_files_title`` Title for Open File/Folder dialog (default includes
|
* ``get_files_title`` Title for QFileDialog (default includes format
|
||||||
format name).
|
name).
|
||||||
* ``invalid_source_msg`` Message shown when source does not validate.
|
* ``invalid_source_msg`` Message shown when source does not validate.
|
||||||
"""
|
"""
|
||||||
# Required attributes
|
# Required attributes
|
||||||
@ -339,7 +339,7 @@ class SongFormatAttr(object):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def set(format, attribute, value):
|
def set(format, attribute, value):
|
||||||
"""
|
"""
|
||||||
Set specified song format attribute to supplied value.
|
Set specified song format attribute to the supplied value.
|
||||||
"""
|
"""
|
||||||
SongFormat._attributes[format][attribute] = value
|
SongFormat._attributes[format][attribute] = value
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user