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
|
Initialise the list widget
|
||||||
"""
|
"""
|
||||||
super(ListWidgetWithDnD, self).__init__(parent)
|
super(ListWidgetWithDnD, self).__init__(parent)
|
||||||
self.mimeDataText = name
|
self.mime_data_text = name
|
||||||
assert(self.mimeDataText)
|
|
||||||
|
|
||||||
def activateDnD(self):
|
def activateDnD(self):
|
||||||
"""
|
"""
|
||||||
@ -54,7 +53,7 @@ class ListWidgetWithDnD(QtGui.QListWidget):
|
|||||||
"""
|
"""
|
||||||
self.setAcceptDrops(True)
|
self.setAcceptDrops(True)
|
||||||
self.setDragDropMode(QtGui.QAbstractItemView.DragDrop)
|
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):
|
def mouseMoveEvent(self, event):
|
||||||
"""
|
"""
|
||||||
@ -68,9 +67,9 @@ class ListWidgetWithDnD(QtGui.QListWidget):
|
|||||||
event.ignore()
|
event.ignore()
|
||||||
return
|
return
|
||||||
drag = QtGui.QDrag(self)
|
drag = QtGui.QDrag(self)
|
||||||
mimeData = QtCore.QMimeData()
|
mime_data = QtCore.QMimeData()
|
||||||
drag.setMimeData(mimeData)
|
drag.setMimeData(mime_data)
|
||||||
mimeData.setText(self.mimeDataText)
|
mime_data.setText(self.mime_data_text)
|
||||||
drag.start(QtCore.Qt.CopyAction)
|
drag.start(QtCore.Qt.CopyAction)
|
||||||
|
|
||||||
def dragEnterEvent(self, event):
|
def dragEnterEvent(self, event):
|
||||||
@ -104,13 +103,13 @@ class ListWidgetWithDnD(QtGui.QListWidget):
|
|||||||
event.accept()
|
event.accept()
|
||||||
files = []
|
files = []
|
||||||
for url in event.mimeData().urls():
|
for url in event.mimeData().urls():
|
||||||
localFile = url.toLocalFile()
|
local_file = url.toLocalFile()
|
||||||
if os.path.isfile(localFile):
|
if os.path.isfile(local_file):
|
||||||
files.append(localFile)
|
files.append(local_file)
|
||||||
elif os.path.isdir(localFile):
|
elif os.path.isdir(local_file):
|
||||||
listing = os.listdir(localFile)
|
listing = os.listdir(local_file)
|
||||||
for file in listing:
|
for file in listing:
|
||||||
files.append(os.path.join(localFile, file))
|
files.append(os.path.join(local_file, file))
|
||||||
Registry().execute('%s_dnd' % self.mimeDataText, files)
|
Registry().execute('%s_dnd' % self.mime_data_text, files)
|
||||||
else:
|
else:
|
||||||
event.ignore()
|
event.ignore()
|
||||||
|
@ -291,15 +291,15 @@ class MediaManagerItem(QtGui.QWidget):
|
|||||||
|
|
||||||
def add_custom_context_actions(self):
|
def add_custom_context_actions(self):
|
||||||
"""
|
"""
|
||||||
Implement this method in your descendent media manager item to
|
Implement this method in your descendant media manager item to add any context menu items.
|
||||||
add any context menu items. This method is called automatically.
|
This method is called automatically.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def initialise(self):
|
def initialise(self):
|
||||||
"""
|
"""
|
||||||
Implement this method in your descendent media manager item to
|
Implement this method in your descendant media manager item to do any UI or other initialisation.
|
||||||
do any UI or other initialisation. This method is called automatically.
|
This method is called automatically.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -320,8 +320,9 @@ class MediaManagerItem(QtGui.QWidget):
|
|||||||
Add a file to the list widget to make it available for showing
|
Add a file to the list widget to make it available for showing
|
||||||
"""
|
"""
|
||||||
files = FileDialog.getOpenFileNames(self, self.on_new_prompt,
|
files = FileDialog.getOpenFileNames(self, self.on_new_prompt,
|
||||||
Settings().value(self.settings_section + '/last directory'), self.on_new_file_masks)
|
Settings().value(self.settings_section + '/last directory'),
|
||||||
log.info('New files(s) %s', files)
|
self.on_new_file_masks)
|
||||||
|
log.info('New files(s) %s' % files)
|
||||||
if files:
|
if files:
|
||||||
self.application.set_busy_cursor()
|
self.application.set_busy_cursor()
|
||||||
self.validate_and_load(files)
|
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 file_type.lower() not in self.on_new_file_masks:
|
||||||
if not error_shown:
|
if not error_shown:
|
||||||
critical_error_message_box(translate('OpenLP.MediaManagerItem', 'Invalid File Type'),
|
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
|
error_shown = True
|
||||||
else:
|
else:
|
||||||
new_files.append(file_name)
|
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())
|
Settings().setValue('%s/%s files' % (self.settings_section, self.settings_section), self.get_file_list())
|
||||||
if duplicates_found:
|
if duplicates_found:
|
||||||
critical_error_message_box(UiStrings().Duplicate,
|
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):
|
def context_menu(self, point):
|
||||||
"""
|
"""
|
||||||
@ -411,12 +414,12 @@ class MediaManagerItem(QtGui.QWidget):
|
|||||||
"""
|
"""
|
||||||
file_list = []
|
file_list = []
|
||||||
for index in range(self.list_view.count()):
|
for index in range(self.list_view.count()):
|
||||||
bitem = self.list_view.item(index)
|
list_item = self.list_view.item(index)
|
||||||
filename = bitem.data(QtCore.Qt.UserRole)
|
filename = list_item.data(QtCore.Qt.UserRole)
|
||||||
file_list.append(filename)
|
file_list.append(filename)
|
||||||
return file_list
|
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.
|
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:
|
if not self.list_view.selectedIndexes() and not self.remote_triggered:
|
||||||
QtGui.QMessageBox.information(self, UiStrings().NISp,
|
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:
|
else:
|
||||||
log.debug('%s Preview requested', self.plugin.name)
|
log.debug('%s Preview requested' % self.plugin.name)
|
||||||
service_item = self.build_service_item()
|
service_item = self.build_service_item()
|
||||||
if service_item:
|
if service_item:
|
||||||
service_item.from_plugin = True
|
service_item.from_plugin = True
|
||||||
@ -493,7 +497,8 @@ class MediaManagerItem(QtGui.QWidget):
|
|||||||
"""
|
"""
|
||||||
if not self.list_view.selectedIndexes():
|
if not self.list_view.selectedIndexes():
|
||||||
QtGui.QMessageBox.information(self, UiStrings().NISp,
|
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:
|
else:
|
||||||
self.go_live()
|
self.go_live()
|
||||||
|
|
||||||
@ -536,7 +541,8 @@ class MediaManagerItem(QtGui.QWidget):
|
|||||||
"""
|
"""
|
||||||
if not self.list_view.selectedIndexes():
|
if not self.list_view.selectedIndexes():
|
||||||
QtGui.QMessageBox.information(self, UiStrings().NISp,
|
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:
|
else:
|
||||||
# Is it possible to process multiple list items to generate
|
# Is it possible to process multiple list items to generate
|
||||||
# multiple service items?
|
# multiple service items?
|
||||||
@ -578,14 +584,16 @@ class MediaManagerItem(QtGui.QWidget):
|
|||||||
service_item = self.service_manager.get_service_item()
|
service_item = self.service_manager.get_service_item()
|
||||||
if not service_item:
|
if not service_item:
|
||||||
QtGui.QMessageBox.information(self, UiStrings().NISs,
|
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:
|
elif self.plugin.name == service_item.name:
|
||||||
self.generate_slide_data(service_item)
|
self.generate_slide_data(service_item)
|
||||||
self.service_manager.add_service_item(service_item, replace=True)
|
self.service_manager.add_service_item(service_item, replace=True)
|
||||||
else:
|
else:
|
||||||
# Turn off the remote edit update message indicator
|
# Turn off the remote edit update message indicator
|
||||||
QtGui.QMessageBox.information(self, translate('OpenLP.MediaManagerItem', 'Invalid Service Item'),
|
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):
|
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
|
Initialise the tree widget
|
||||||
"""
|
"""
|
||||||
super(TreeWidgetWithDnD, self).__init__(parent)
|
super(TreeWidgetWithDnD, self).__init__(parent)
|
||||||
self.mimeDataText = name
|
self.mime_data_text = name
|
||||||
self.allow_internal_dnd = False
|
self.allow_internal_dnd = False
|
||||||
self.header().close()
|
self.header().close()
|
||||||
self.default_indentation = self.indentation()
|
self.default_indentation = self.indentation()
|
||||||
self.setIndentation(0)
|
self.setIndentation(0)
|
||||||
self.setAnimated(True)
|
self.setAnimated(True)
|
||||||
assert(self.mimeDataText)
|
|
||||||
|
|
||||||
def activateDnD(self):
|
def activateDnD(self):
|
||||||
"""
|
"""
|
||||||
@ -59,8 +58,8 @@ class TreeWidgetWithDnD(QtGui.QTreeWidget):
|
|||||||
"""
|
"""
|
||||||
self.setAcceptDrops(True)
|
self.setAcceptDrops(True)
|
||||||
self.setDragDropMode(QtGui.QAbstractItemView.DragDrop)
|
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)
|
||||||
Registry().register_function(('%s_dnd_internal' % self.mimeDataText), self.parent().dnd_move_internal)
|
Registry().register_function(('%s_dnd_internal' % self.mime_data_text), self.parent().dnd_move_internal)
|
||||||
|
|
||||||
def mouseMoveEvent(self, event):
|
def mouseMoveEvent(self, event):
|
||||||
"""
|
"""
|
||||||
@ -77,9 +76,9 @@ class TreeWidgetWithDnD(QtGui.QTreeWidget):
|
|||||||
event.ignore()
|
event.ignore()
|
||||||
return
|
return
|
||||||
drag = QtGui.QDrag(self)
|
drag = QtGui.QDrag(self)
|
||||||
mimeData = QtCore.QMimeData()
|
mime_data = QtCore.QMimeData()
|
||||||
drag.setMimeData(mimeData)
|
drag.setMimeData(mime_data)
|
||||||
mimeData.setText(self.mimeDataText)
|
mime_data.setText(self.mime_data_text)
|
||||||
drag.start(QtCore.Qt.CopyAction)
|
drag.start(QtCore.Qt.CopyAction)
|
||||||
|
|
||||||
def dragEnterEvent(self, event):
|
def dragEnterEvent(self, event):
|
||||||
@ -132,11 +131,11 @@ class TreeWidgetWithDnD(QtGui.QTreeWidget):
|
|||||||
listing = os.listdir(local_file)
|
listing = os.listdir(local_file)
|
||||||
for file_name in listing:
|
for file_name in listing:
|
||||||
files.append(os.path.join(local_file, file_name))
|
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:
|
elif self.allow_internal_dnd:
|
||||||
event.setDropAction(QtCore.Qt.CopyAction)
|
event.setDropAction(QtCore.Qt.CopyAction)
|
||||||
event.accept()
|
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:
|
else:
|
||||||
event.ignore()
|
event.ignore()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user