forked from openlp/openlp
Implemented adding images into groups
This commit is contained in:
parent
a770f90320
commit
3c3b7bb294
@ -54,4 +54,5 @@ from the .ui files later if necessary.
|
||||
"""
|
||||
|
||||
from addgroupform import AddGroupForm
|
||||
from choosegroupform import ChooseGroupForm
|
||||
|
||||
|
61
openlp/plugins/images/forms/choosegroupdialog.py
Normal file
61
openlp/plugins/images/forms/choosegroupdialog.py
Normal file
@ -0,0 +1,61 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
||||
|
||||
###############################################################################
|
||||
# OpenLP - Open Source Lyrics Projection #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Copyright (c) 2008-2013 Raoul Snyman #
|
||||
# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
|
||||
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
|
||||
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
|
||||
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
|
||||
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
|
||||
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
|
||||
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# This program is free software; you can redistribute it and/or modify it #
|
||||
# under the terms of the GNU General Public License as published by the Free #
|
||||
# Software Foundation; version 2 of the License. #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
||||
# more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU General Public License along #
|
||||
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||
###############################################################################
|
||||
|
||||
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)
|
||||
|
||||
self.retranslateUi(chooseGroupDialog)
|
||||
QtCore.QMetaObject.connectSlotsByName(chooseGroupDialog)
|
||||
|
||||
def retranslateUi(self, chooseGroupDialog):
|
||||
chooseGroupDialog.setWindowTitle(translate('ImagePlugin.ChooseGroupForm', 'Choose group'))
|
||||
self.groupQuestionLabel.setText(translate('ImagePlugin.ChooseGroupForm',
|
||||
'To which group do you want these images to be added?'))
|
||||
|
46
openlp/plugins/images/forms/choosegroupform.py
Normal file
46
openlp/plugins/images/forms/choosegroupform.py
Normal file
@ -0,0 +1,46 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
||||
|
||||
###############################################################################
|
||||
# OpenLP - Open Source Lyrics Projection #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Copyright (c) 2008-2013 Raoul Snyman #
|
||||
# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
|
||||
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
|
||||
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
|
||||
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
|
||||
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
|
||||
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
|
||||
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# This program is free software; you can redistribute it and/or modify it #
|
||||
# under the terms of the GNU General Public License as published by the Free #
|
||||
# Software Foundation; version 2 of the License. #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
||||
# more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU General Public License along #
|
||||
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||
###############################################################################
|
||||
|
||||
from PyQt4 import QtGui
|
||||
|
||||
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.
|
||||
"""
|
||||
def __init__(self, parent=None):
|
||||
"""
|
||||
Constructor
|
||||
"""
|
||||
QtGui.QDialog.__init__(self, parent)
|
||||
self.setupUi(self)
|
||||
|
@ -37,7 +37,7 @@ from openlp.core.lib import MediaManagerItem, build_icon, ItemCapabilities, Sett
|
||||
UiStrings
|
||||
from openlp.core.lib.ui import critical_error_message_box
|
||||
from openlp.core.utils import AppLocation, delete_file, locale_compare, get_images_filter
|
||||
from openlp.plugins.images.forms import AddGroupForm
|
||||
from openlp.plugins.images.forms import AddGroupForm, ChooseGroupForm
|
||||
from openlp.plugins.images.lib.db import ImageFilenames, ImageGroups
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@ -54,8 +54,9 @@ class ImageMediaItem(MediaManagerItem):
|
||||
self.quickPreviewAllowed = True
|
||||
self.hasSearch = True
|
||||
self.manager = plugin.manager
|
||||
self.choosegroupform = ChooseGroupForm(self)
|
||||
self.addgroupform = AddGroupForm(self)
|
||||
self.fillGroupsComboBox()
|
||||
self.fillGroupsComboBox(self.addgroupform.parentGroupComboBox)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'live_theme_changed'), self.liveThemeChanged)
|
||||
# Allow DnD from the desktop
|
||||
self.listView.activateDnD()
|
||||
@ -153,18 +154,19 @@ class ImageMediaItem(MediaManagerItem):
|
||||
groupList[image_group.id] = group
|
||||
self.addSubGroups(groupList, image_group.id)
|
||||
|
||||
def fillGroupsComboBox(self, parentGroupId=0, prefix=''):
|
||||
def fillGroupsComboBox(self, comboBox, parentGroupId=0, prefix='', showTopLevelGroup=True):
|
||||
"""
|
||||
Recursively add groups to the combobox in the 'Add group' dialog
|
||||
"""
|
||||
if parentGroupId is 0:
|
||||
self.addgroupform.parentGroupComboBox.clear()
|
||||
self.addgroupform.parentGroupComboBox.addItem(translate('ImagePlugin.MediaItem', '-- Top-level group --'), 0)
|
||||
comboBox.clear()
|
||||
if showTopLevelGroup is True:
|
||||
comboBox.addItem(translate('ImagePlugin.MediaItem', '-- Top-level group --'), 0)
|
||||
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:
|
||||
self.addgroupform.parentGroupComboBox.addItem(prefix+image_group.group_name, image_group.id)
|
||||
self.fillGroupsComboBox(image_group.id, prefix+' ')
|
||||
comboBox.addItem(prefix+image_group.group_name, image_group.id)
|
||||
self.fillGroupsComboBox(comboBox, image_group.id, prefix+' ')
|
||||
|
||||
def loadFullList(self, images, initialLoad=False):
|
||||
"""
|
||||
@ -215,11 +217,17 @@ class ImageMediaItem(MediaManagerItem):
|
||||
"""
|
||||
Add new images to the database. This method is called when adding images using the Add button or DnD.
|
||||
"""
|
||||
# Ask which group the images should be saved in
|
||||
self.fillGroupsComboBox(self.choosegroupform.groupComboBox, showTopLevelGroup=False)
|
||||
if self.choosegroupform.exec_():
|
||||
group_id = self.choosegroupform.groupComboBox.itemData(
|
||||
self.choosegroupform.groupComboBox.currentIndex(), QtCore.Qt.UserRole)
|
||||
# Save the new images in the database
|
||||
for filename in images:
|
||||
if filename is None:
|
||||
continue
|
||||
imageFile = ImageFilenames()
|
||||
imageFile.group_id = 0
|
||||
imageFile.group_id = group_id
|
||||
imageFile.filename = unicode(filename)
|
||||
success = self.manager.save_object(imageFile)
|
||||
self.loadFullList(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename),
|
||||
@ -316,7 +324,7 @@ class ImageMediaItem(MediaManagerItem):
|
||||
if self.checkGroupName(new_group):
|
||||
if self.manager.save_object(new_group):
|
||||
self.loadList([])
|
||||
self.fillGroupsComboBox()
|
||||
self.fillGroupsComboBox(self.addgroupform.parentGroupComboBox)
|
||||
else:
|
||||
critical_error_message_box(
|
||||
message=translate('ImagePlugin.AddGroupForm', 'Could not add the new group.'))
|
||||
|
55
resources/forms/imageschoosegroupdialog.ui
Normal file
55
resources/forms/imageschoosegroupdialog.ui
Normal file
@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ChooseGroupDialog</class>
|
||||
<widget class="QDialog" name="ChooseGroupDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>440</width>
|
||||
<height>119</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Choose group</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="addGroupLayout">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::ExpandingFieldsGrow</enum>
|
||||
</property>
|
||||
<property name="horizontalSpacing">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<property name="verticalSpacing">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QLabel" name="groupQuestionLabel">
|
||||
<property name="text">
|
||||
<string>To which group do you want these images to be added?</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="groupComboBox"/>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QDialogButtonBox" name="groupButtonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../images/openlp-2.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in New Issue
Block a user