forked from openlp/openlp
Mediamanager and DND classes
This commit is contained in:
parent
7e18ced2c4
commit
85da26684c
@ -45,8 +45,7 @@ class ListWidgetWithDnD(QtGui.QListWidget):
|
||||
Initialise the list widget
|
||||
"""
|
||||
super(ListWidgetWithDnD, self).__init__(parent)
|
||||
self.mimeDataText = name
|
||||
assert(self.mimeDataText)
|
||||
self.mime_data_text = name
|
||||
|
||||
def activateDnD(self):
|
||||
"""
|
||||
@ -54,7 +53,7 @@ class ListWidgetWithDnD(QtGui.QListWidget):
|
||||
"""
|
||||
self.setAcceptDrops(True)
|
||||
self.setDragDropMode(QtGui.QAbstractItemView.DragDrop)
|
||||
Registry().register_function(('%s_dnd' % self.mimeDataText), self.parent().load_file)
|
||||
Registry().register_function(('%s_dnd' % self.mime_data_text), self.parent().load_file)
|
||||
|
||||
def mouseMoveEvent(self, event):
|
||||
"""
|
||||
@ -68,9 +67,9 @@ class ListWidgetWithDnD(QtGui.QListWidget):
|
||||
event.ignore()
|
||||
return
|
||||
drag = QtGui.QDrag(self)
|
||||
mimeData = QtCore.QMimeData()
|
||||
drag.setMimeData(mimeData)
|
||||
mimeData.setText(self.mimeDataText)
|
||||
mime_data = QtCore.QMimeData()
|
||||
drag.setMimeData(mime_data)
|
||||
mime_data.setText(self.mime_data_text)
|
||||
drag.start(QtCore.Qt.CopyAction)
|
||||
|
||||
def dragEnterEvent(self, event):
|
||||
@ -104,13 +103,13 @@ class ListWidgetWithDnD(QtGui.QListWidget):
|
||||
event.accept()
|
||||
files = []
|
||||
for url in event.mimeData().urls():
|
||||
localFile = url.toLocalFile()
|
||||
if os.path.isfile(localFile):
|
||||
files.append(localFile)
|
||||
elif os.path.isdir(localFile):
|
||||
listing = os.listdir(localFile)
|
||||
local_file = url.toLocalFile()
|
||||
if os.path.isfile(local_file):
|
||||
files.append(local_file)
|
||||
elif os.path.isdir(local_file):
|
||||
listing = os.listdir(local_file)
|
||||
for file in listing:
|
||||
files.append(os.path.join(localFile, file))
|
||||
Registry().execute('%s_dnd' % self.mimeDataText, files)
|
||||
files.append(os.path.join(local_file, file))
|
||||
Registry().execute('%s_dnd' % self.mime_data_text, files)
|
||||
else:
|
||||
event.ignore()
|
||||
|
@ -291,21 +291,21 @@ class MediaManagerItem(QtGui.QWidget):
|
||||
|
||||
def add_custom_context_actions(self):
|
||||
"""
|
||||
Implement this method in your descendent media manager item to
|
||||
add any context menu items. This method is called automatically.
|
||||
Implement this method in your descendant media manager item to add any context menu items.
|
||||
This method is called automatically.
|
||||
"""
|
||||
pass
|
||||
|
||||
def initialise(self):
|
||||
"""
|
||||
Implement this method in your descendent media manager item to
|
||||
do any UI or other initialisation. This method is called automatically.
|
||||
Implement this method in your descendant media manager item to do any UI or other initialisation.
|
||||
This method is called automatically.
|
||||
"""
|
||||
pass
|
||||
|
||||
def add_start_header_bar(self):
|
||||
"""
|
||||
Slot at start of toolbar for plugin to addwidgets
|
||||
Slot at start of toolbar for plugin to add widgets
|
||||
"""
|
||||
pass
|
||||
|
||||
@ -320,8 +320,9 @@ class MediaManagerItem(QtGui.QWidget):
|
||||
Add a file to the list widget to make it available for showing
|
||||
"""
|
||||
files = FileDialog.getOpenFileNames(self, self.on_new_prompt,
|
||||
Settings().value(self.settings_section + '/last directory'), self.on_new_file_masks)
|
||||
log.info('New files(s) %s', files)
|
||||
Settings().value(self.settings_section + '/last directory'),
|
||||
self.on_new_file_masks)
|
||||
log.info('New files(s) %s' % files)
|
||||
if files:
|
||||
self.application.set_busy_cursor()
|
||||
self.validate_and_load(files)
|
||||
@ -341,7 +342,8 @@ class MediaManagerItem(QtGui.QWidget):
|
||||
if file_type.lower() not in self.on_new_file_masks:
|
||||
if not error_shown:
|
||||
critical_error_message_box(translate('OpenLP.MediaManagerItem', 'Invalid File Type'),
|
||||
translate('OpenLP.MediaManagerItem', 'Invalid File %s.\nSuffix not supported') % file_name)
|
||||
translate('OpenLP.MediaManagerItem',
|
||||
'Invalid File %s.\nSuffix not supported') % file_name)
|
||||
error_shown = True
|
||||
else:
|
||||
new_files.append(file_name)
|
||||
@ -391,7 +393,8 @@ class MediaManagerItem(QtGui.QWidget):
|
||||
Settings().setValue('%s/%s files' % (self.settings_section, self.settings_section), self.get_file_list())
|
||||
if duplicates_found:
|
||||
critical_error_message_box(UiStrings().Duplicate,
|
||||
translate('OpenLP.MediaManagerItem', 'Duplicate files were found on import and were ignored.'))
|
||||
translate('OpenLP.MediaManagerItem',
|
||||
'Duplicate files were found on import and were ignored.'))
|
||||
|
||||
def context_menu(self, point):
|
||||
"""
|
||||
@ -411,12 +414,12 @@ class MediaManagerItem(QtGui.QWidget):
|
||||
"""
|
||||
file_list = []
|
||||
for index in range(self.list_view.count()):
|
||||
bitem = self.list_view.item(index)
|
||||
filename = bitem.data(QtCore.Qt.UserRole)
|
||||
list_item = self.list_view.item(index)
|
||||
filename = list_item.data(QtCore.Qt.UserRole)
|
||||
file_list.append(filename)
|
||||
return file_list
|
||||
|
||||
def load_list(self, list, target_group):
|
||||
def load_list(self, load_list, target_group):
|
||||
"""
|
||||
Load a list. Needs to be implemented by the plugin.
|
||||
"""
|
||||
@ -477,9 +480,10 @@ class MediaManagerItem(QtGui.QWidget):
|
||||
"""
|
||||
if not self.list_view.selectedIndexes() and not self.remote_triggered:
|
||||
QtGui.QMessageBox.information(self, UiStrings().NISp,
|
||||
translate('OpenLP.MediaManagerItem', 'You must select one or more items to preview.'))
|
||||
translate('OpenLP.MediaManagerItem',
|
||||
'You must select one or more items to preview.'))
|
||||
else:
|
||||
log.debug('%s Preview requested', self.plugin.name)
|
||||
log.debug('%s Preview requested' % self.plugin.name)
|
||||
service_item = self.build_service_item()
|
||||
if service_item:
|
||||
service_item.from_plugin = True
|
||||
@ -493,7 +497,8 @@ class MediaManagerItem(QtGui.QWidget):
|
||||
"""
|
||||
if not self.list_view.selectedIndexes():
|
||||
QtGui.QMessageBox.information(self, UiStrings().NISp,
|
||||
translate('OpenLP.MediaManagerItem', 'You must select one or more items to send live.'))
|
||||
translate('OpenLP.MediaManagerItem',
|
||||
'You must select one or more items to send live.'))
|
||||
else:
|
||||
self.go_live()
|
||||
|
||||
@ -536,7 +541,8 @@ class MediaManagerItem(QtGui.QWidget):
|
||||
"""
|
||||
if not self.list_view.selectedIndexes():
|
||||
QtGui.QMessageBox.information(self, UiStrings().NISp,
|
||||
translate('OpenLP.MediaManagerItem', 'You must select one or more items to add.'))
|
||||
translate('OpenLP.MediaManagerItem',
|
||||
'You must select one or more items to add.'))
|
||||
else:
|
||||
# Is it possible to process multiple list items to generate
|
||||
# multiple service items?
|
||||
@ -578,14 +584,16 @@ class MediaManagerItem(QtGui.QWidget):
|
||||
service_item = self.service_manager.get_service_item()
|
||||
if not service_item:
|
||||
QtGui.QMessageBox.information(self, UiStrings().NISs,
|
||||
translate('OpenLP.MediaManagerItem', 'You must select an existing service item to add to.'))
|
||||
translate('OpenLP.MediaManagerItem',
|
||||
'You must select an existing service item to add to.'))
|
||||
elif self.plugin.name == service_item.name:
|
||||
self.generate_slide_data(service_item)
|
||||
self.service_manager.add_service_item(service_item, replace=True)
|
||||
else:
|
||||
# Turn off the remote edit update message indicator
|
||||
QtGui.QMessageBox.information(self, translate('OpenLP.MediaManagerItem', 'Invalid Service Item'),
|
||||
translate('OpenLP.MediaManagerItem', 'You must select a %s service item.') % self.title)
|
||||
translate('OpenLP.MediaManagerItem',
|
||||
'You must select a %s service item.') % self.title)
|
||||
|
||||
def build_service_item(self, item=None, xml_version=False, remote=False, context=ServiceItemContext.Live):
|
||||
"""
|
||||
|
@ -45,13 +45,12 @@ class TreeWidgetWithDnD(QtGui.QTreeWidget):
|
||||
Initialise the tree widget
|
||||
"""
|
||||
super(TreeWidgetWithDnD, self).__init__(parent)
|
||||
self.mimeDataText = name
|
||||
self.mime_data_text = name
|
||||
self.allow_internal_dnd = False
|
||||
self.header().close()
|
||||
self.default_indentation = self.indentation()
|
||||
self.setIndentation(0)
|
||||
self.setAnimated(True)
|
||||
assert(self.mimeDataText)
|
||||
|
||||
def activateDnD(self):
|
||||
"""
|
||||
@ -59,8 +58,8 @@ class TreeWidgetWithDnD(QtGui.QTreeWidget):
|
||||
"""
|
||||
self.setAcceptDrops(True)
|
||||
self.setDragDropMode(QtGui.QAbstractItemView.DragDrop)
|
||||
Registry().register_function(('%s_dnd' % self.mimeDataText), self.parent().load_file)
|
||||
Registry().register_function(('%s_dnd_internal' % self.mimeDataText), self.parent().dnd_move_internal)
|
||||
Registry().register_function(('%s_dnd' % self.mime_data_text), self.parent().load_file)
|
||||
Registry().register_function(('%s_dnd_internal' % self.mime_data_text), self.parent().dnd_move_internal)
|
||||
|
||||
def mouseMoveEvent(self, event):
|
||||
"""
|
||||
@ -77,9 +76,9 @@ class TreeWidgetWithDnD(QtGui.QTreeWidget):
|
||||
event.ignore()
|
||||
return
|
||||
drag = QtGui.QDrag(self)
|
||||
mimeData = QtCore.QMimeData()
|
||||
drag.setMimeData(mimeData)
|
||||
mimeData.setText(self.mimeDataText)
|
||||
mime_data = QtCore.QMimeData()
|
||||
drag.setMimeData(mime_data)
|
||||
mime_data.setText(self.mime_data_text)
|
||||
drag.start(QtCore.Qt.CopyAction)
|
||||
|
||||
def dragEnterEvent(self, event):
|
||||
@ -132,11 +131,11 @@ class TreeWidgetWithDnD(QtGui.QTreeWidget):
|
||||
listing = os.listdir(local_file)
|
||||
for file_name in listing:
|
||||
files.append(os.path.join(local_file, file_name))
|
||||
Registry().execute('%s_dnd' % self.mimeDataText, {'files': files, 'target': self.itemAt(event.pos())})
|
||||
Registry().execute('%s_dnd' % self.mime_Data_Text, {'files': files, 'target': self.itemAt(event.pos())})
|
||||
elif self.allow_internal_dnd:
|
||||
event.setDropAction(QtCore.Qt.CopyAction)
|
||||
event.accept()
|
||||
Registry().execute('%s_dnd_internal' % self.mimeDataText, self.itemAt(event.pos()))
|
||||
Registry().execute('%s_dnd_internal' % self.mime_data_text, self.itemAt(event.pos()))
|
||||
else:
|
||||
event.ignore()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user