Mediamanager and DND classes

This commit is contained in:
Tim Bentley 2013-12-24 07:19:57 +00:00
parent 7e18ced2c4
commit 85da26684c
3 changed files with 79 additions and 73 deletions

View File

@ -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()

View File

@ -171,7 +171,7 @@ class MediaManagerItem(QtGui.QWidget):
## Import Button ## ## Import Button ##
if self.has_import_icon: if self.has_import_icon:
toolbar_actions.append(['Import', StringContent.Import, toolbar_actions.append(['Import', StringContent.Import,
':/general/general_import.png', self.on_import_click]) ':/general/general_import.png', self.on_import_click])
## Load Button ## ## Load Button ##
if self.has_file_icon: if self.has_file_icon:
toolbar_actions.append(['Load', StringContent.Load, ':/general/general_open.png', self.on_file_click]) toolbar_actions.append(['Load', StringContent.Load, ':/general/general_open.png', self.on_file_click])
@ -184,10 +184,10 @@ class MediaManagerItem(QtGui.QWidget):
## Delete Button ## ## Delete Button ##
if self.has_delete_icon: if self.has_delete_icon:
toolbar_actions.append(['Delete', StringContent.Delete, toolbar_actions.append(['Delete', StringContent.Delete,
':/general/general_delete.png', self.on_delete_click]) ':/general/general_delete.png', self.on_delete_click])
## Preview ## ## Preview ##
toolbar_actions.append(['Preview', StringContent.Preview, toolbar_actions.append(['Preview', StringContent.Preview,
':/general/general_preview.png', self.on_preview_click]) ':/general/general_preview.png', self.on_preview_click])
## Live Button ## ## Live Button ##
toolbar_actions.append(['Live', StringContent.Live, ':/general/general_live.png', self.on_live_click]) toolbar_actions.append(['Live', StringContent.Live, ':/general/general_live.png', self.on_live_click])
## Add to service Button ## ## Add to service Button ##
@ -196,9 +196,9 @@ class MediaManagerItem(QtGui.QWidget):
if action[0] == StringContent.Preview: if action[0] == StringContent.Preview:
self.toolbar.addSeparator() self.toolbar.addSeparator()
self.toolbar.add_toolbar_action('%s%sAction' % (self.plugin.name, action[0]), self.toolbar.add_toolbar_action('%s%sAction' % (self.plugin.name, action[0]),
text=self.plugin.get_string(action[1])['title'], icon=action[2], text=self.plugin.get_string(action[1])['title'], icon=action[2],
tooltip=self.plugin.get_string(action[1])['tooltip'], tooltip=self.plugin.get_string(action[1])['tooltip'],
triggers=action[3]) triggers=action[3])
def add_list_view_to_toolbar(self): def add_list_view_to_toolbar(self):
""" """
@ -216,41 +216,41 @@ class MediaManagerItem(QtGui.QWidget):
self.list_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.list_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
if self.has_edit_icon: if self.has_edit_icon:
create_widget_action(self.list_view, create_widget_action(self.list_view,
text=self.plugin.get_string(StringContent.Edit)['title'], text=self.plugin.get_string(StringContent.Edit)['title'],
icon=':/general/general_edit.png', icon=':/general/general_edit.png',
triggers=self.on_edit_click) triggers=self.on_edit_click)
create_widget_action(self.list_view, separator=True) create_widget_action(self.list_view, separator=True)
if self.has_delete_icon: if self.has_delete_icon:
create_widget_action(self.list_view, create_widget_action(self.list_view,
'listView%s%sItem' % (self.plugin.name.title(), StringContent.Delete.title()), 'listView%s%sItem' % (self.plugin.name.title(), StringContent.Delete.title()),
text=self.plugin.get_string(StringContent.Delete)['title'], text=self.plugin.get_string(StringContent.Delete)['title'],
icon=':/general/general_delete.png', icon=':/general/general_delete.png',
can_shortcuts=True, triggers=self.on_delete_click) can_shortcuts=True, triggers=self.on_delete_click)
create_widget_action(self.list_view, separator=True) create_widget_action(self.list_view, separator=True)
create_widget_action(self.list_view, create_widget_action(self.list_view,
'listView%s%sItem' % (self.plugin.name.title(), StringContent.Preview.title()), 'listView%s%sItem' % (self.plugin.name.title(), StringContent.Preview.title()),
text=self.plugin.get_string(StringContent.Preview)['title'], text=self.plugin.get_string(StringContent.Preview)['title'],
icon=':/general/general_preview.png', icon=':/general/general_preview.png',
can_shortcuts=True, can_shortcuts=True,
triggers=self.on_preview_click) triggers=self.on_preview_click)
create_widget_action(self.list_view, create_widget_action(self.list_view,
'listView%s%sItem' % (self.plugin.name.title(), StringContent.Live.title()), 'listView%s%sItem' % (self.plugin.name.title(), StringContent.Live.title()),
text=self.plugin.get_string(StringContent.Live)['title'], text=self.plugin.get_string(StringContent.Live)['title'],
icon=':/general/general_live.png', icon=':/general/general_live.png',
can_shortcuts=True, can_shortcuts=True,
triggers=self.on_live_click) triggers=self.on_live_click)
create_widget_action(self.list_view, create_widget_action(self.list_view,
'listView%s%sItem' % (self.plugin.name.title(), StringContent.Service.title()), 'listView%s%sItem' % (self.plugin.name.title(), StringContent.Service.title()),
can_shortcuts=True, can_shortcuts=True,
text=self.plugin.get_string(StringContent.Service)['title'], text=self.plugin.get_string(StringContent.Service)['title'],
icon=':/general/general_add.png', icon=':/general/general_add.png',
triggers=self.on_add_click) triggers=self.on_add_click)
if self.add_to_service_item: if self.add_to_service_item:
create_widget_action(self.list_view, separator=True) create_widget_action(self.list_view, separator=True)
create_widget_action(self.list_view, create_widget_action(self.list_view,
text=translate('OpenLP.MediaManagerItem', '&Add to selected Service Item'), text=translate('OpenLP.MediaManagerItem', '&Add to selected Service Item'),
icon=':/general/general_add.png', icon=':/general/general_add.png',
triggers=self.on_add_edit_click) triggers=self.on_add_edit_click)
self.add_custom_context_actions() self.add_custom_context_actions()
# Create the context menu and add all actions from the list_view. # Create the context menu and add all actions from the list_view.
self.menu = QtGui.QMenu() self.menu = QtGui.QMenu()
@ -291,21 +291,21 @@ 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
def add_start_header_bar(self): 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 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.
""" """
@ -448,7 +451,7 @@ class MediaManagerItem(QtGui.QWidget):
pass pass
def generate_slide_data(self, service_item, item=None, xml_version=False, remote=False, def generate_slide_data(self, service_item, item=None, xml_version=False, remote=False,
context=ServiceItemContext.Live): context=ServiceItemContext.Live):
""" """
Generate the slide data. Needs to be implemented by the plugin. Generate the slide data. 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?
@ -572,20 +578,22 @@ 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.')) translate('OpenLP.MediaManagerItem', 'You must select one or more items.'))
else: else:
log.debug('%s Add requested', self.plugin.name) log.debug('%s Add requested', self.plugin.name)
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):
""" """

View File

@ -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()