Lots of code style fixes

This commit is contained in:
Arjan Schrijver 2013-01-30 11:57:06 +01:00
parent dbcd1080ea
commit 260a6815c2
11 changed files with 109 additions and 102 deletions

View File

@ -43,6 +43,7 @@ from openlp.core.lib.ui import create_widget_action, critical_error_message_box
log = logging.getLogger(__name__)
class MediaManagerItem(QtGui.QWidget):
"""
MediaManagerItem is a helper widget for plugins.
@ -344,19 +345,19 @@ class MediaManagerItem(QtGui.QWidget):
"""
new_files = []
error_shown = False
for file in data['files']:
type = file.split(u'.')[-1]
for file_name in data['files']:
type = file_name.split(u'.')[-1]
if type.lower() not in self.onNewFileMasks:
if not error_shown:
critical_error_message_box(translate('OpenLP.MediaManagerItem', 'Invalid File Type'),
translate('OpenLP.MediaManagerItem', 'Invalid File %s.\nSuffix not supported') % file)
translate('OpenLP.MediaManagerItem', 'Invalid File %s.\nSuffix not supported') % file_name)
error_shown = True
else:
new_files.append(file)
new_files.append(file_name)
if new_files:
self.validateAndLoad(new_files, data['target'])
def dndMoveInternal(self, target):
def dnd_move_internal(self, target):
"""
Handle internal moving of media manager items
"""
@ -377,8 +378,8 @@ class MediaManagerItem(QtGui.QWidget):
full_list.append(self.listView.topLevelItem(count).data(0, QtCore.Qt.UserRole))
duplicates_found = False
files_added = False
for file in files:
filename = os.path.split(unicode(file))[1]
for file_path in files:
filename = os.path.split(unicode(file_path))[1]
if filename in names:
duplicates_found = True
else:

View File

@ -35,6 +35,7 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import Receiver
class TreeWidgetWithDnD(QtGui.QTreeWidget):
"""
Provide a tree widget to store objects and handle drag and drop events
@ -60,7 +61,7 @@ class TreeWidgetWithDnD(QtGui.QTreeWidget):
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'%s_dnd' % self.mimeDataText),
self.parent().loadFile)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'%s_dnd_internal' % self.mimeDataText),
self.parent().dndMoveInternal)
self.parent().dnd_move_internal)
def doInternalDnD(self, accept):
self.allowInternalDnD = accept
@ -118,9 +119,9 @@ class TreeWidgetWithDnD(QtGui.QTreeWidget):
files.append(localFile)
elif os.path.isdir(localFile):
listing = os.listdir(localFile)
for file in listing:
files.append(os.path.join(localFile, file))
Receiver.send_message(u'%s_dnd' % self.mimeDataText, {'files':files, 'target':self.itemAt(event.pos())})
for file_name in listing:
files.append(os.path.join(localFile, file_name))
Receiver.send_message(u'%s_dnd' % self.mimeDataText, {'files': files, 'target': self.itemAt(event.pos())})
elif self.allowInternalDnD:
event.setDropAction(QtCore.Qt.CopyAction)
event.accept()

View File

@ -55,4 +55,3 @@ from the .ui files later if necessary.
from addgroupform import AddGroupForm
from choosegroupform import ChooseGroupForm

View File

@ -32,32 +32,33 @@ from PyQt4 import QtGui
from openlp.core.lib import translate
from openlp.core.lib.ui import create_button_box
class Ui_AddGroupDialog(object):
def setupUi(self, addGroupDialog):
addGroupDialog.setObjectName(u'addGroupDialog')
addGroupDialog.resize(300, 10)
self.dialogLayout = QtGui.QVBoxLayout(addGroupDialog)
self.dialogLayout.setObjectName(u'dialogLayout')
self.nameLayout = QtGui.QFormLayout()
self.nameLayout.setObjectName(u'nameLayout')
self.parentGroupLabel = QtGui.QLabel(addGroupDialog)
self.parentGroupLabel.setObjectName(u'parentGroupLabel')
self.parentGroupComboBox = QtGui.QComboBox(addGroupDialog)
self.parentGroupComboBox.setObjectName(u'parentGroupComboBox')
self.nameLayout.addRow(self.parentGroupLabel, self.parentGroupComboBox)
self.nameLabel = QtGui.QLabel(addGroupDialog)
self.nameLabel.setObjectName(u'nameLabel')
self.nameEdit = QtGui.QLineEdit(addGroupDialog)
self.nameEdit.setObjectName(u'nameEdit')
self.nameLabel.setBuddy(self.nameEdit)
self.nameLayout.addRow(self.nameLabel, self.nameEdit)
self.dialogLayout.addLayout(self.nameLayout)
self.buttonBox = create_button_box(addGroupDialog, u'buttonBox', [u'cancel', u'save'])
self.dialogLayout.addWidget(self.buttonBox)
self.retranslateUi(addGroupDialog)
addGroupDialog.setMaximumHeight(addGroupDialog.sizeHint().height())
def retranslateUi(self, addGroupDialog):
addGroupDialog.setWindowTitle(translate('ImagePlugin.AddGroupForm', 'Add group'))
self.parentGroupLabel.setText(translate('ImagePlugin.AddGroupForm', 'Parent group:'))
self.nameLabel.setText(translate('ImagePlugin.AddGroupForm', 'Group name:'))
class Ui_AddGroupDialog(object):
def setupUi(self, add_group_dialog):
add_group_dialog.setObjectName(u'add_group_dialog')
add_group_dialog.resize(300, 10)
self.dialog_layout = QtGui.QVBoxLayout(add_group_dialog)
self.dialog_layout.setObjectName(u'dialog_layout')
self.name_layout = QtGui.QFormLayout()
self.name_layout.setObjectName(u'name_layout')
self.parent_group_label = QtGui.QLabel(add_group_dialog)
self.parent_group_label.setObjectName(u'parent_group_label')
self.parent_group_combobox = QtGui.QComboBox(add_group_dialog)
self.parent_group_combobox.setObjectName(u'parent_group_combobox')
self.name_layout.addRow(self.parent_group_label, self.parent_group_combobox)
self.name_label = QtGui.QLabel(add_group_dialog)
self.name_label.setObjectName(u'name_label')
self.name_edit = QtGui.QLineEdit(add_group_dialog)
self.name_edit.setObjectName(u'name_edit')
self.name_label.setBuddy(self.name_edit)
self.name_layout.addRow(self.name_label, self.name_edit)
self.dialog_layout.addLayout(self.name_layout)
self.button_box = create_button_box(add_group_dialog, u'button_box', [u'cancel', u'save'])
self.dialog_layout.addWidget(self.button_box)
self.retranslateUi(add_group_dialog)
add_group_dialog.setMaximumHeight(add_group_dialog.sizeHint().height())
def retranslateUi(self, add_group_dialog):
add_group_dialog.setWindowTitle(translate('ImagePlugin.AddGroupForm', 'Add group'))
self.parent_group_label.setText(translate('ImagePlugin.AddGroupForm', 'Parent group:'))
self.name_label.setText(translate('ImagePlugin.AddGroupForm', 'Group name:'))

View File

@ -33,6 +33,7 @@ from openlp.core.lib import translate
from openlp.core.lib.ui import critical_error_message_box
from openlp.plugins.images.forms.addgroupdialog import Ui_AddGroupDialog
class AddGroupForm(QtGui.QDialog, Ui_AddGroupDialog):
"""
Class documentation goes here.
@ -44,20 +45,20 @@ class AddGroupForm(QtGui.QDialog, Ui_AddGroupDialog):
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
def exec_(self, clear=True, showTopLevelGroup=False):
def exec_(self, clear=True, show_top_level_group=False):
if clear:
self.nameEdit.clear()
self.nameEdit.setFocus()
if showTopLevelGroup and not self.parentGroupComboBox.topLevelGroupAdded:
self.parentGroupComboBox.insertItem(0, translate('ImagePlugin.MediaItem', '-- Top-level group --'), 0)
self.parentGroupComboBox.topLevelGroupAdded = True
self.name_edit.clear()
self.name_edit.setFocus()
if show_top_level_group and not self.parent_group_combobox.top_level_group_added:
self.parent_group_combobox.insertItem(0, translate('ImagePlugin.MediaItem', '-- Top-level group --'), 0)
self.parent_group_combobox.top_level_group_added = True
return QtGui.QDialog.exec_(self)
def accept(self):
if not self.nameEdit.text():
if not self.name_edit.text():
critical_error_message_box(message=translate('ImagePlugin.AddGroupForm',
'You need to type in a group name.'))
self.nameEdit.setFocus()
self.name_edit.setFocus()
return False
else:
return QtGui.QDialog.accept(self)

View File

@ -32,30 +32,30 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import translate
from openlp.core.lib.ui import create_button_box
class Ui_ChooseGroupDialog(object):
def setupUi(self, chooseGroupDialog):
chooseGroupDialog.setObjectName(u'chooseGroupDialog')
chooseGroupDialog.resize(440, 119)
self.chooseGroupLayout = QtGui.QFormLayout(chooseGroupDialog)
self.chooseGroupLayout.setFieldGrowthPolicy(QtGui.QFormLayout.ExpandingFieldsGrow)
self.chooseGroupLayout.setMargin(8)
self.chooseGroupLayout.setSpacing(8)
self.chooseGroupLayout.setObjectName(u'chooseGroupLayout')
self.groupQuestionLabel = QtGui.QLabel(chooseGroupDialog)
self.groupQuestionLabel.setWordWrap(True)
self.groupQuestionLabel.setObjectName(u'groupQuestionLabel')
self.chooseGroupLayout.setWidget(1, QtGui.QFormLayout.SpanningRole, self.groupQuestionLabel)
self.groupComboBox = QtGui.QComboBox(chooseGroupDialog)
self.groupComboBox.setObjectName(u'groupComboBox')
self.chooseGroupLayout.setWidget(2, QtGui.QFormLayout.FieldRole, self.groupComboBox)
self.groupButtonBox = create_button_box(chooseGroupDialog, u'buttonBox', [u'ok'])
self.chooseGroupLayout.setWidget(3, QtGui.QFormLayout.FieldRole, self.groupButtonBox)
def setupUi(self, choose_group_dialog):
choose_group_dialog.setObjectName(u'choose_group_dialog')
choose_group_dialog.resize(440, 119)
self.choose_group_layout = QtGui.QFormLayout(choose_group_dialog)
self.choose_group_layout.setFieldGrowthPolicy(QtGui.QFormLayout.ExpandingFieldsGrow)
self.choose_group_layout.setMargin(8)
self.choose_group_layout.setSpacing(8)
self.choose_group_layout.setObjectName(u'choose_group_layout')
self.group_question_label = QtGui.QLabel(choose_group_dialog)
self.group_question_label.setWordWrap(True)
self.group_question_label.setObjectName(u'group_question_label')
self.choose_group_layout.setWidget(1, QtGui.QFormLayout.SpanningRole, self.group_question_label)
self.group_combobox = QtGui.QComboBox(choose_group_dialog)
self.group_combobox.setObjectName(u'group_combobox')
self.choose_group_layout.setWidget(2, QtGui.QFormLayout.FieldRole, self.group_combobox)
self.group_button_box = create_button_box(choose_group_dialog, u'buttonBox', [u'ok'])
self.choose_group_layout.setWidget(3, QtGui.QFormLayout.FieldRole, self.group_button_box)
self.retranslateUi(chooseGroupDialog)
QtCore.QMetaObject.connectSlotsByName(chooseGroupDialog)
self.retranslateUi(choose_group_dialog)
QtCore.QMetaObject.connectSlotsByName(choose_group_dialog)
def retranslateUi(self, chooseGroupDialog):
chooseGroupDialog.setWindowTitle(translate('ImagePlugin.ChooseGroupForm', 'Choose group'))
self.groupQuestionLabel.setText(translate('ImagePlugin.ChooseGroupForm',
def retranslateUi(self, choose_group_dialog):
choose_group_dialog.setWindowTitle(translate('ImagePlugin.ChooseGroupForm', 'Choose group'))
self.group_question_label.setText(translate('ImagePlugin.ChooseGroupForm',
'To which group do you want these images to be added?'))

View File

@ -33,6 +33,7 @@ from openlp.core.lib import translate
from openlp.core.lib.ui import critical_error_message_box
from openlp.plugins.images.forms.choosegroupdialog import Ui_ChooseGroupDialog
class ChooseGroupForm(QtGui.QDialog, Ui_ChooseGroupDialog):
"""
Class documentation goes here.
@ -43,4 +44,3 @@ class ChooseGroupForm(QtGui.QDialog, Ui_ChooseGroupDialog):
"""
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)

View File

@ -39,10 +39,10 @@ from openlp.plugins.images.lib.db import init_schema
log = logging.getLogger(__name__)
__default_settings__ = {
u'images/db type': u'sqlite',
u'images/background color': u'#000000',
u'images/images files': []
}
u'images/db type': u'sqlite',
u'images/background color': u'#000000',
u'images/images files': []
}
class ImagePlugin(Plugin):
@ -80,8 +80,7 @@ class ImagePlugin(Plugin):
u'plural': translate('ImagePlugin', 'Images', 'name plural')
}
## Name for MediaDockManager, SettingsManager ##
self.textStrings[StringContent.VisibleName] = {u'title': translate('ImagePlugin', 'Images', 'container title')
}
self.textStrings[StringContent.VisibleName] = {u'title': translate('ImagePlugin', 'Images', 'container title')}
# Middle Header Bar
tooltips = {
u'load': translate('ImagePlugin', 'Load a new image.'),

View File

@ -42,12 +42,14 @@ class ImageGroups(BaseModel):
"""
pass
class ImageFilenames(BaseModel):
"""
ImageFilenames model
"""
pass
def init_schema(url):
"""
Setup the images database connection and initialise the database schema.

View File

@ -31,6 +31,7 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import SettingsTab, translate, Receiver, Settings, UiStrings
class ImageTab(SettingsTab):
"""
ImageTab is the images settings tab in the settings dialog.
@ -92,4 +93,3 @@ class ImageTab(SettingsTab):
settings.endGroup()
if self.initial_color != self.bg_color:
Receiver.send_message(u'image_updated')

View File

@ -42,6 +42,7 @@ from openlp.plugins.images.lib.db import ImageFilenames, ImageGroups
log = logging.getLogger(__name__)
class ImageMediaItem(MediaManagerItem):
"""
This is the custom media manager item for images.
@ -56,8 +57,8 @@ class ImageMediaItem(MediaManagerItem):
self.manager = plugin.manager
self.choosegroupform = ChooseGroupForm(self)
self.addgroupform = AddGroupForm(self)
self.fillGroupsComboBox(self.choosegroupform.groupComboBox)
self.fillGroupsComboBox(self.addgroupform.parentGroupComboBox)
self.fill_groups_combo_box(self.choosegroupform.group_combobox)
self.fill_groups_combo_box(self.addgroupform.parent_group_combobox)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'live_theme_changed'), self.liveThemeChanged)
# Allow DnD from the desktop
self.listView.activateDnD()
@ -90,7 +91,7 @@ class ImageMediaItem(MediaManagerItem):
self.servicePath = os.path.join(AppLocation.get_section_data_path(self.settingsSection), u'thumbnails')
check_directory_exists(self.servicePath)
# Import old images list
images_old = Settings().value(self.settingsSection + u'/images files')
images_old = Settings().value(self.settingsSection + u'/images files')
if len(images_old) > 0:
for imageFile in images_old:
imagefilename = ImageFilenames()
@ -136,7 +137,8 @@ class ImageMediaItem(MediaManagerItem):
"""
# Turn off auto preview triggers.
self.listView.blockSignals(True)
if check_item_selected(self.listView, translate('ImagePlugin.MediaItem','You must select an image to delete.')):
if check_item_selected(self.listView, translate('ImagePlugin.MediaItem',
'You must select an image to delete.')):
item_list = self.listView.selectedItems()
Receiver.send_message(u'cursor_busy')
self.main_window.displayProgressBar(len(item_list))
@ -160,8 +162,8 @@ class ImageMediaItem(MediaManagerItem):
self.listView.takeTopLevelItem(self.listView.indexOfTopLevelItem(row_item))
else:
row_item.parent().removeChild(row_item)
self.fillGroupsComboBox(self.choosegroupform.groupComboBox)
self.fillGroupsComboBox(self.addgroupform.parentGroupComboBox)
self.fill_groups_combo_box(self.choosegroupform.group_combobox)
self.fill_groups_combo_box(self.addgroupform.parent_group_combobox)
self.main_window.incrementProgressBar()
self.main_window.finishedProgressBar()
Receiver.send_message(u'cursor_normal')
@ -184,18 +186,18 @@ class ImageMediaItem(MediaManagerItem):
groupList[image_group.id] = group
self.addSubGroups(groupList, image_group.id)
def fillGroupsComboBox(self, comboBox, parentGroupId=0, prefix=''):
def fill_groups_combo_box(self, comboBox, parentGroupId=0, prefix=''):
"""
Recursively add groups to the combobox in the 'Add group' dialog
"""
if parentGroupId is 0:
comboBox.clear()
comboBox.topLevelGroupAdded = False
comboBox.top_level_group_added = False
image_groups = self.manager.get_all_objects(ImageGroups, ImageGroups.parent_id == parentGroupId)
image_groups.sort(cmp=locale_compare, key=lambda group_object: group_object.group_name)
for image_group in image_groups:
comboBox.addItem(prefix+image_group.group_name, image_group.id)
self.fillGroupsComboBox(comboBox, image_group.id, prefix+' ')
comboBox.addItem(prefix + image_group.group_name, image_group.id)
self.fill_groups_combo_box(comboBox, image_group.id, prefix + ' ')
def loadFullList(self, images, initialLoad=False):
"""
@ -249,8 +251,8 @@ class ImageMediaItem(MediaManagerItem):
if target_group is None:
# Ask which group the images should be saved in
if self.choosegroupform.exec_():
group_id = self.choosegroupform.groupComboBox.itemData(
self.choosegroupform.groupComboBox.currentIndex(), QtCore.Qt.UserRole)
group_id = self.choosegroupform.group_combobox.itemData(
self.choosegroupform.group_combobox.currentIndex(), QtCore.Qt.UserRole)
parent_group = self.manager.get_object_filtered(ImageGroups, ImageGroups.id == group_id)
else:
parent_group = target_group.data(0, QtCore.Qt.UserRole)
@ -271,7 +273,7 @@ class ImageMediaItem(MediaManagerItem):
self.loadFullList(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename),
initialLoad)
def dndMoveInternal(self, target):
def dnd_move_internal(self, target):
"""
Handle drag-and-drop moving of images within the media manager
"""
@ -386,16 +388,16 @@ class ImageMediaItem(MediaManagerItem):
"""
Called to add a new group
"""
if self.addgroupform.exec_(showTopLevelGroup=True):
new_group = ImageGroups.populate(parent_id=self.addgroupform.parentGroupComboBox.itemData(
self.addgroupform.parentGroupComboBox.currentIndex(), QtCore.Qt.UserRole),
group_name=self.addgroupform.nameEdit.text())
if self.addgroupform.exec_(show_top_level_group=True):
new_group = ImageGroups.populate(parent_id=self.addgroupform.parent_group_combobox.itemData(
self.addgroupform.parent_group_combobox.currentIndex(), QtCore.Qt.UserRole),
group_name=self.addgroupform.name_edit.text())
if self.checkGroupName(new_group):
if self.manager.save_object(new_group):
self.loadFullList(self.manager.get_all_objects(ImageFilenames,
order_by_ref=ImageFilenames.filename))
self.fillGroupsComboBox(self.choosegroupform.groupComboBox)
self.fillGroupsComboBox(self.addgroupform.parentGroupComboBox)
self.fill_groups_combo_box(self.choosegroupform.group_combobox)
self.fill_groups_combo_box(self.addgroupform.parent_group_combobox)
else:
critical_error_message_box(
message=translate('ImagePlugin.AddGroupForm', 'Could not add the new group.'))
@ -437,9 +439,10 @@ class ImageMediaItem(MediaManagerItem):
'the image file "%s" no longer exists.') % filename)
def search(self, string, showError):
files = self.manager.get_all_objects(ImageFilenames, filter_clause=ImageFilenames.filename.contains(string), order_by_ref=ImageFilenames.filename)
files = self.manager.get_all_objects(ImageFilenames, filter_clause=ImageFilenames.filename.contains(string),
order_by_ref=ImageFilenames.filename)
results = []
for file in files:
filename = os.path.split(unicode(file.filename))[1]
results.append([file.filename, filename])
for file_object in files:
filename = os.path.split(unicode(file_object.filename))[1]
results.append([file_object.filename, filename])
return results