Mediamanageritem converted

This commit is contained in:
Tim Bentley 2013-03-19 22:00:50 +00:00
parent f99e22fd4a
commit 90ac714c0d
12 changed files with 475 additions and 451 deletions

View File

@ -54,7 +54,7 @@ class ListWidgetWithDnD(QtGui.QListWidget):
""" """
self.setAcceptDrops(True) self.setAcceptDrops(True)
self.setDragDropMode(QtGui.QAbstractItemView.DragDrop) self.setDragDropMode(QtGui.QAbstractItemView.DragDrop)
Registry().register_function((u'%s_dnd' % self.mimeDataText), self.parent().loadFile) Registry().register_function((u'%s_dnd' % self.mimeDataText), self.parent().load_file)
def mouseMoveEvent(self, event): def mouseMoveEvent(self, event):
""" """

View File

@ -63,11 +63,11 @@ class MediaManagerItem(QtGui.QWidget):
When creating a descendant class from this class for your plugin, the following member variables should be set. When creating a descendant class from this class for your plugin, the following member variables should be set.
``self.onNewPrompt`` ``self.on_new_prompt``
Defaults to *'Select Image(s)'*. Defaults to *'Select Image(s)'*.
``self.onNewFileMasks`` ``self.on_new_file_masks``
Defaults to *'Images (*.jpg *jpeg *.gif *.png *.bmp)'*. This assumes that the new action is to load a file. If Defaults to *'Images (*.jpg *jpeg *.gif *.png *.bmp)'*. This assumes that the new action is to load a file. If
not, you need to override the ``OnNew`` method. not, you need to override the ``OnNew`` method.
@ -91,30 +91,30 @@ class MediaManagerItem(QtGui.QWidget):
Registry().register(self.plugin.name, self) Registry().register(self.plugin.name, self)
self.settings_section = self.plugin.name self.settings_section = self.plugin.name
self.toolbar = None self.toolbar = None
self.remoteTriggered = None self.remote_triggered = None
self.singleServiceItem = True self.single_service_item = True
self.quickPreviewAllowed = False self.quick_preview_allowed = False
self.hasSearch = False self.hasSearch = False
self.pageLayout = QtGui.QVBoxLayout(self) self.page_layout = QtGui.QVBoxLayout(self)
self.pageLayout.setSpacing(0) self.page_layout.setSpacing(0)
self.pageLayout.setMargin(0) self.page_layout.setMargin(0)
self.requiredIcons() self.required_icons()
self.setupUi() self.setupUi()
self.retranslateUi() self.retranslateUi()
self.autoSelectId = -1 self.autoSelectId = -1
Registry().register_function(u'%s_service_load' % self.plugin.name, self.serviceLoad) Registry().register_function(u'%s_service_load' % self.plugin.name, self.service_load)
def requiredIcons(self): def required_icons(self):
""" """
This method is called to define the icons for the plugin. It provides a default set and the plugin is able to This method is called to define the icons for the plugin. It provides a default set and the plugin is able to
override the if required. override the if required.
""" """
self.hasImportIcon = False self.has_import_icon = False
self.hasNewIcon = True self.has_new_icon = True
self.hasEditIcon = True self.has_edit_icon = True
self.hasFileIcon = False self.has_file_icon = False
self.hasDeleteIcon = True self.has_delete_icon = True
self.addToServiceItem = False self.add_to_service_item = False
def retranslateUi(self): def retranslateUi(self):
""" """
@ -123,13 +123,13 @@ class MediaManagerItem(QtGui.QWidget):
""" """
pass pass
def addToolbar(self): def add_toolbar(self):
""" """
A method to help developers easily add a toolbar to the media manager item. A method to help developers easily add a toolbar to the media manager item.
""" """
if self.toolbar is None: if self.toolbar is None:
self.toolbar = OpenLPToolbar(self) self.toolbar = OpenLPToolbar(self)
self.pageLayout.addWidget(self.toolbar) self.page_layout.addWidget(self.toolbar)
def setupUi(self): def setupUi(self):
""" """
@ -137,45 +137,45 @@ class MediaManagerItem(QtGui.QWidget):
rest of the interface of the media manager item. rest of the interface of the media manager item.
""" """
# Add a toolbar # Add a toolbar
self.addToolbar() self.add_toolbar()
# Allow the plugin to define buttons at start of bar # Allow the plugin to define buttons at start of bar
self.addStartHeaderBar() self.add_start_header_bar()
# Add the middle of the tool bar (pre defined) # Add the middle of the tool bar (pre defined)
self.addMiddleHeaderBar() self.add_middle_header_bar()
# Allow the plugin to define buttons at end of bar # Allow the plugin to define buttons at end of bar
self.addEndHeaderBar() self.add_end_header_bar()
# Add the list view # Add the list view
self.addListViewToToolBar() self.add_list_view_to_toolbar()
def addMiddleHeaderBar(self): def add_middle_header_bar(self):
""" """
Create buttons for the media item toolbar Create buttons for the media item toolbar
""" """
toolbar_actions = [] toolbar_actions = []
## Import Button ## ## Import Button ##
if self.hasImportIcon: if self.has_import_icon:
toolbar_actions.append([u'Import', StringContent.Import, toolbar_actions.append([u'Import', StringContent.Import,
u':/general/general_import.png', self.on_import_click]) u':/general/general_import.png', self.on_import_click])
## Load Button ## ## Load Button ##
if self.hasFileIcon: if self.has_file_icon:
toolbar_actions.append([u'Load', StringContent.Load, u':/general/general_open.png', self.onFileClick]) toolbar_actions.append([u'Load', StringContent.Load, u':/general/general_open.png', self.on_file_click])
## New Button ## ## New Button ##
if self.hasNewIcon: if self.has_new_icon:
toolbar_actions.append([u'New', StringContent.New, u':/general/general_new.png', self.onNewClick]) toolbar_actions.append([u'New', StringContent.New, u':/general/general_new.png', self.on_new_click])
## Edit Button ## ## Edit Button ##
if self.hasEditIcon: if self.has_edit_icon:
toolbar_actions.append([u'Edit', StringContent.Edit, u':/general/general_edit.png', self.onEditClick]) toolbar_actions.append([u'Edit', StringContent.Edit, u':/general/general_edit.png', self.on_edit_click])
## Delete Button ## ## Delete Button ##
if self.hasDeleteIcon: if self.has_delete_icon:
toolbar_actions.append([u'Delete', StringContent.Delete, toolbar_actions.append([u'Delete', StringContent.Delete,
u':/general/general_delete.png', self.onDeleteClick]) u':/general/general_delete.png', self.on_delete_click])
## Preview ## ## Preview ##
toolbar_actions.append([u'Preview', StringContent.Preview, toolbar_actions.append([u'Preview', StringContent.Preview,
u':/general/general_preview.png', self.onPreviewClick]) u':/general/general_preview.png', self.on_preview_click])
## Live Button ## ## Live Button ##
toolbar_actions.append([u'Live', StringContent.Live, u':/general/general_live.png', self.onLiveClick]) toolbar_actions.append([u'Live', StringContent.Live, u':/general/general_live.png', self.on_live_click])
## Add to service Button ## ## Add to service Button ##
toolbar_actions.append([u'Service', StringContent.Service, u':/general/general_add.png', self.onAddClick]) toolbar_actions.append([u'Service', StringContent.Service, u':/general/general_add.png', self.on_add_click])
for action in toolbar_actions: for action in toolbar_actions:
if action[0] == StringContent.Preview: if action[0] == StringContent.Preview:
self.toolbar.addSeparator() self.toolbar.addSeparator()
@ -184,96 +184,96 @@ class MediaManagerItem(QtGui.QWidget):
tooltip=self.plugin.get_string(action[1])[u'tooltip'], tooltip=self.plugin.get_string(action[1])[u'tooltip'],
triggers=action[3]) triggers=action[3])
def addListViewToToolBar(self): def add_list_view_to_toolbar(self):
""" """
Creates the main widget for listing items the media item is tracking Creates the main widget for listing items the media item is tracking
""" """
# Add the List widget # Add the List widget
self.listView = ListWidgetWithDnD(self, self.plugin.name) self.list_view = ListWidgetWithDnD(self, self.plugin.name)
self.listView.setSpacing(1) self.list_view.setSpacing(1)
self.listView.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) self.list_view.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
self.listView.setAlternatingRowColors(True) self.list_view.setAlternatingRowColors(True)
self.listView.setObjectName(u'%sListView' % self.plugin.name) self.list_view.setObjectName(u'%sListView' % self.plugin.name)
# Add to pageLayout # Add to page_layout
self.pageLayout.addWidget(self.listView) self.page_layout.addWidget(self.list_view)
# define and add the context menu # define and add the context menu
self.listView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.list_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
if self.hasEditIcon: if self.has_edit_icon:
create_widget_action(self.listView, create_widget_action(self.list_view,
text=self.plugin.get_string(StringContent.Edit)[u'title'], text=self.plugin.get_string(StringContent.Edit)[u'title'],
icon=u':/general/general_edit.png', icon=u':/general/general_edit.png',
triggers=self.onEditClick) triggers=self.on_edit_click)
create_widget_action(self.listView, separator=True) create_widget_action(self.list_view, separator=True)
if self.hasDeleteIcon: if self.has_delete_icon:
create_widget_action(self.listView, create_widget_action(self.list_view,
u'listView%s%sItem' % (self.plugin.name.title(), StringContent.Delete.title()), u'listView%s%sItem' % (self.plugin.name.title(), StringContent.Delete.title()),
text=self.plugin.get_string(StringContent.Delete)[u'title'], text=self.plugin.get_string(StringContent.Delete)[u'title'],
icon=u':/general/general_delete.png', icon=u':/general/general_delete.png',
can_shortcuts=True, triggers=self.onDeleteClick) can_shortcuts=True, triggers=self.on_delete_click)
create_widget_action(self.listView, separator=True) create_widget_action(self.list_view, separator=True)
create_widget_action(self.listView, create_widget_action(self.list_view,
u'listView%s%sItem' % (self.plugin.name.title(), StringContent.Preview.title()), u'listView%s%sItem' % (self.plugin.name.title(), StringContent.Preview.title()),
text=self.plugin.get_string(StringContent.Preview)[u'title'], text=self.plugin.get_string(StringContent.Preview)[u'title'],
icon=u':/general/general_preview.png', icon=u':/general/general_preview.png',
can_shortcuts=True, can_shortcuts=True,
triggers=self.onPreviewClick) triggers=self.on_preview_click)
create_widget_action(self.listView, create_widget_action(self.list_view,
u'listView%s%sItem' % (self.plugin.name.title(), StringContent.Live.title()), u'listView%s%sItem' % (self.plugin.name.title(), StringContent.Live.title()),
text=self.plugin.get_string(StringContent.Live)[u'title'], text=self.plugin.get_string(StringContent.Live)[u'title'],
icon=u':/general/general_live.png', icon=u':/general/general_live.png',
can_shortcuts=True, can_shortcuts=True,
triggers=self.onLiveClick) triggers=self.on_live_click)
create_widget_action(self.listView, create_widget_action(self.list_view,
u'listView%s%sItem' % (self.plugin.name.title(), StringContent.Service.title()), u'listView%s%sItem' % (self.plugin.name.title(), StringContent.Service.title()),
can_shortcuts=True, can_shortcuts=True,
text=self.plugin.get_string(StringContent.Service)[u'title'], text=self.plugin.get_string(StringContent.Service)[u'title'],
icon=u':/general/general_add.png', icon=u':/general/general_add.png',
triggers=self.onAddClick) triggers=self.on_add_click)
if self.addToServiceItem: if self.add_to_service_item:
create_widget_action(self.listView, separator=True) create_widget_action(self.list_view, separator=True)
create_widget_action(self.listView, 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=u':/general/general_add.png', icon=u':/general/general_add.png',
triggers=self.onAddEditClick) triggers=self.on_add_edit_click)
self.addCustomContextActions() self.add_custom_context_actions()
# Create the context menu and add all actions from the listView. # Create the context menu and add all actions from the list_view.
self.menu = QtGui.QMenu() self.menu = QtGui.QMenu()
self.menu.addActions(self.listView.actions()) self.menu.addActions(self.list_view.actions())
self.listView.doubleClicked.connect(self.onDoubleClicked) self.list_view.doubleClicked.connect(self.on_double_clicked)
self.listView.itemSelectionChanged.connect(self.onSelectionChange) self.list_view.itemSelectionChanged.connect(self.on_selection_change)
self.listView.customContextMenuRequested.connect(self.contextMenu) self.list_view.customContextMenuRequested.connect(self.context_menu)
def addSearchToToolBar(self): def add_search_to_toolbar(self):
""" """
Creates a search field with button and related signal handling. Creates a search field with button and related signal handling.
""" """
self.searchWidget = QtGui.QWidget(self) self.search_widget = QtGui.QWidget(self)
self.searchWidget.setObjectName(u'searchWidget') self.search_widget.setObjectName(u'search_widget')
self.searchLayout = QtGui.QVBoxLayout(self.searchWidget) self.search_layout = QtGui.QVBoxLayout(self.search_widget)
self.searchLayout.setObjectName(u'searchLayout') self.search_layout.setObjectName(u'search_layout')
self.searchTextLayout = QtGui.QFormLayout() self.search_text_layout = QtGui.QFormLayout()
self.searchTextLayout.setObjectName(u'searchTextLayout') self.search_text_layout.setObjectName(u'search_text_layout')
self.searchTextLabel = QtGui.QLabel(self.searchWidget) self.search_text_label = QtGui.QLabel(self.search_widget)
self.searchTextLabel.setObjectName(u'searchTextLabel') self.search_text_label.setObjectName(u'search_text_label')
self.searchTextEdit = SearchEdit(self.searchWidget) self.search_text_edit = SearchEdit(self.search_widget)
self.searchTextEdit.setObjectName(u'searchTextEdit') self.search_text_edit.setObjectName(u'search_text_edit')
self.searchTextLabel.setBuddy(self.searchTextEdit) self.search_text_label.setBuddy(self.search_text_edit)
self.searchTextLayout.addRow(self.searchTextLabel, self.searchTextEdit) self.search_text_layout.addRow(self.search_text_label, self.search_text_edit)
self.searchLayout.addLayout(self.searchTextLayout) self.search_layout.addLayout(self.search_text_layout)
self.searchButtonLayout = QtGui.QHBoxLayout() self.search_button_layout = QtGui.QHBoxLayout()
self.searchButtonLayout.setObjectName(u'searchButtonLayout') self.search_button_layout.setObjectName(u'search_button_layout')
self.searchButtonLayout.addStretch() self.search_button_layout.addStretch()
self.searchTextButton = QtGui.QPushButton(self.searchWidget) self.search_text_button = QtGui.QPushButton(self.search_widget)
self.searchTextButton.setObjectName(u'searchTextButton') self.search_text_button.setObjectName(u'search_text_button')
self.searchButtonLayout.addWidget(self.searchTextButton) self.search_button_layout.addWidget(self.search_text_button)
self.searchLayout.addLayout(self.searchButtonLayout) self.search_layout.addLayout(self.search_button_layout)
self.pageLayout.addWidget(self.searchWidget) self.page_layout.addWidget(self.search_widget)
# Signals and slots # Signals and slots
self.searchTextEdit.returnPressed.connect(self.onSearchTextButtonClicked) self.search_text_edit.returnPressed.connect(self.on_search_text_button_clicked)
self.searchTextButton.clicked.connect(self.onSearchTextButtonClicked) self.search_text_button.clicked.connect(self.on_search_text_button_clicked)
self.searchTextEdit.textChanged.connect(self.onSearchTextEditChanged) self.search_text_edit.textChanged.connect(self.on_search_text_edit_changed)
def addCustomContextActions(self): def add_custom_context_actions(self):
""" """
Implement this method in your descendent media manager item to Implement this method in your descendent media manager item to
add any context menu items. This method is called automatically. add any context menu items. This method is called automatically.
@ -287,31 +287,31 @@ class MediaManagerItem(QtGui.QWidget):
""" """
pass pass
def addStartHeaderBar(self): def add_start_header_bar(self):
""" """
Slot at start of toolbar for plugin to addwidgets Slot at start of toolbar for plugin to addwidgets
""" """
pass pass
def addEndHeaderBar(self): def add_end_header_bar(self):
""" """
Slot at end of toolbar for plugin to add widgets Slot at end of toolbar for plugin to add widgets
""" """
pass pass
def onFileClick(self): def on_file_click(self):
""" """
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 = QtGui.QFileDialog.getOpenFileNames(self, self.onNewPrompt, files = QtGui.QFileDialog.getOpenFileNames(self, self.on_new_prompt,
Settings().value(self.settings_section + u'/last directory'), self.onNewFileMasks) Settings().value(self.settings_section + u'/last directory'), self.on_new_file_masks)
log.info(u'New files(s) %s', files) log.info(u'New files(s) %s', files)
if files: if files:
self.application.set_busy_cursor() self.application.set_busy_cursor()
self.validateAndLoad(files) self.validate_and_load(files)
self.application.set_normal_cursor() self.application.set_normal_cursor()
def loadFile(self, data): def load_file(self, data):
""" """
Turn file from Drag and Drop into an array so the Validate code can run it. Turn file from Drag and Drop into an array so the Validate code can run it.
@ -322,7 +322,7 @@ class MediaManagerItem(QtGui.QWidget):
error_shown = False error_shown = False
for file_name in data['files']: for file_name in data['files']:
file_type = file_name.split(u'.')[-1] file_type = file_name.split(u'.')[-1]
if file_type.lower() not in self.onNewFileMasks: 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)
@ -330,7 +330,7 @@ class MediaManagerItem(QtGui.QWidget):
else: else:
new_files.append(file_name) new_files.append(file_name)
if new_files: if new_files:
self.validateAndLoad(new_files, data['target']) self.validate_and_load(new_files, data['target'])
def dnd_move_internal(self, target): def dnd_move_internal(self, target):
""" """
@ -341,7 +341,7 @@ class MediaManagerItem(QtGui.QWidget):
""" """
pass pass
def validateAndLoad(self, files, target_group=None): def validate_and_load(self, files, target_group=None):
""" """
Process a list for files either from the File Dialog or from Drag and Process a list for files either from the File Dialog or from Drag and
Drop Drop
@ -354,9 +354,9 @@ class MediaManagerItem(QtGui.QWidget):
""" """
names = [] names = []
full_list = [] full_list = []
for count in range(self.listView.count()): for count in range(self.list_view.count()):
names.append(self.listView.item(count).text()) names.append(self.list_view.item(count).text())
full_list.append(self.listView.item(count).data(QtCore.Qt.UserRole)) full_list.append(self.list_view.item(count).data(QtCore.Qt.UserRole))
duplicates_found = False duplicates_found = False
files_added = False files_added = False
for file_path in files: for file_path in files:
@ -368,61 +368,61 @@ class MediaManagerItem(QtGui.QWidget):
full_list.append(filename) full_list.append(filename)
if full_list and files_added: if full_list and files_added:
if target_group is None: if target_group is None:
self.listView.clear() self.list_view.clear()
self.loadList(full_list, target_group) self.load_list(full_list, target_group)
last_dir = os.path.split(unicode(files[0]))[0] last_dir = os.path.split(unicode(files[0]))[0]
Settings().setValue(self.settings_section + u'/last directory', last_dir) Settings().setValue(self.settings_section + u'/last directory', last_dir)
Settings().setValue(u'%s/%s files' % (self.settings_section, self.settings_section), self.getFileList()) Settings().setValue(u'%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 contextMenu(self, point): def context_menu(self, point):
""" """
Display a context menu Display a context menu
""" """
item = self.listView.itemAt(point) item = self.list_view.itemAt(point)
# Decide if we have to show the context menu or not. # Decide if we have to show the context menu or not.
if item is None: if item is None:
return return
if not item.flags() & QtCore.Qt.ItemIsSelectable: if not item.flags() & QtCore.Qt.ItemIsSelectable:
return return
self.menu.exec_(self.listView.mapToGlobal(point)) self.menu.exec_(self.list_view.mapToGlobal(point))
def getFileList(self): def get_file_list(self):
""" """
Return the current list of files Return the current list of files
""" """
file_list = [] file_list = []
for index in xrange(self.listView.count()): for index in xrange(self.list_view.count()):
bitem = self.listView.item(index) bitem = self.list_view.item(index)
filename = bitem.data(QtCore.Qt.UserRole) filename = bitem.data(QtCore.Qt.UserRole)
file_list.append(filename) file_list.append(filename)
return file_list return file_list
def loadList(self, list, target_group): def load_list(self, list, target_group):
""" """
Load a list. Needs to be implemented by the plugin. Load a list. Needs to be implemented by the plugin.
""" """
raise NotImplementedError(u'MediaManagerItem.loadList needs to be defined by the plugin') raise NotImplementedError(u'MediaManagerItem.loadList needs to be defined by the plugin')
def onNewClick(self): def on_new_click(self):
""" """
Hook for plugins to define behaviour for adding new items. Hook for plugins to define behaviour for adding new items.
""" """
pass pass
def onEditClick(self): def on_edit_click(self):
""" """
Hook for plugins to define behaviour for editing items. Hook for plugins to define behaviour for editing items.
""" """
pass pass
def onDeleteClick(self): def on_delete_click(self):
""" """
Delete an item. Needs to be implemented by the plugin. Delete an item. Needs to be implemented by the plugin.
""" """
raise NotImplementedError(u'MediaManagerItem.onDeleteClick needs to be defined by the plugin') raise NotImplementedError(u'MediaManagerItem.on_delete_click needs to be defined by the plugin')
def onFocus(self): def onFocus(self):
""" """
@ -431,65 +431,65 @@ class MediaManagerItem(QtGui.QWidget):
""" """
pass pass
def generateSlideData(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.
""" """
raise NotImplementedError(u'MediaManagerItem.generateSlideData needs to be defined by the plugin') raise NotImplementedError(u'MediaManagerItem.generate_slide_data needs to be defined by the plugin')
def onDoubleClicked(self): def on_double_clicked(self):
""" """
Allows the list click action to be determined dynamically Allows the list click action to be determined dynamically
""" """
if Settings().value(u'advanced/double click live'): if Settings().value(u'advanced/double click live'):
self.onLiveClick() self.on_live_click()
else: else:
self.onPreviewClick() self.on_preview_click()
def onSelectionChange(self): def on_selection_change(self):
""" """
Allows the change of current item in the list to be actioned Allows the change of current item in the list to be actioned
""" """
if Settings().value(u'advanced/single click preview') and self.quickPreviewAllowed \ if Settings().value(u'advanced/single click preview') and self.quick_preview_allowed \
and self.listView.selectedIndexes() and self.autoSelectId == -1: and self.list_view.selectedIndexes() and self.autoSelectId == -1:
self.onPreviewClick(True) self.on_preview_click(True)
def onPreviewClick(self, keepFocus=False): def on_preview_click(self, keepFocus=False):
""" """
Preview an item by building a service item then adding that service item to the preview slide controller. Preview an item by building a service item then adding that service item to the preview slide controller.
""" """
if not self.listView.selectedIndexes() and not self.remoteTriggered: 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(u'%s Preview requested', self.plugin.name) log.debug(u'%s Preview requested', self.plugin.name)
service_item = self.buildServiceItem() service_item = self.build_service_item()
if service_item: if service_item:
service_item.from_plugin = True service_item.from_plugin = True
self.preview_controller.add_service_item(service_item) self.preview_controller.add_service_item(service_item)
if keepFocus: if keepFocus:
self.listView.setFocus() self.list_view.setFocus()
def onLiveClick(self): def on_live_click(self):
""" """
Send an item live by building a service item then adding that service item to the live slide controller. Send an item live by building a service item then adding that service item to the live slide controller.
""" """
if not self.listView.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.goLive() self.go_live()
def goLive(self, item_id=None, remote=False): def go_live(self, item_id=None, remote=False):
""" """
Make the currently selected item go live. Make the currently selected item go live.
""" """
log.debug(u'%s Live requested', self.plugin.name) log.debug(u'%s Live requested', self.plugin.name)
item = None item = None
if item_id: if item_id:
item = self.createItemFromId(item_id) item = self.create_item_from_id(item_id)
service_item = self.buildServiceItem(item, remote=remote) service_item = self.build_service_item(item, remote=remote)
if service_item: if service_item:
if not item_id: if not item_id:
service_item.from_plugin = True service_item.from_plugin = True
@ -497,7 +497,7 @@ class MediaManagerItem(QtGui.QWidget):
service_item.will_auto_start = True service_item.will_auto_start = True
self.live_controller.add_service_item(service_item) self.live_controller.add_service_item(service_item)
def createItemFromId(self, item_id): def create_item_from_id(self, item_id):
""" """
Create a media item from an item id. Create a media item from an item id.
""" """
@ -505,38 +505,38 @@ class MediaManagerItem(QtGui.QWidget):
item.setData(QtCore.Qt.UserRole, item_id) item.setData(QtCore.Qt.UserRole, item_id)
return item return item
def onAddClick(self): def on_add_click(self):
""" """
Add a selected item to the current service Add a selected item to the current service
""" """
if not self.listView.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?
if self.singleServiceItem: if self.single_service_item:
log.debug(u'%s Add requested', self.plugin.name) log.debug(u'%s Add requested', self.plugin.name)
self.addToService(replace=self.remoteTriggered) self.add_to_service(replace=self.remote_triggered)
else: else:
items = self.listView.selectedIndexes() items = self.list_view.selectedIndexes()
for item in items: for item in items:
self.addToService(item) self.add_to_service(item)
def addToService(self, item=None, replace=None, remote=False): def add_to_service(self, item=None, replace=None, remote=False):
""" """
Add this item to the current service. Add this item to the current service.
""" """
service_item = self.buildServiceItem(item, True, remote=remote, context=ServiceItemContext.Service) service_item = self.build_service_item(item, True, remote=remote, context=ServiceItemContext.Service)
if service_item: if service_item:
service_item.from_plugin = False service_item.from_plugin = False
self.service_manager.add_service_item(service_item, replace=replace) self.service_manager.add_service_item(service_item, replace=replace)
def onAddEditClick(self): def on_add_edit_click(self):
""" """
Add a selected item to an existing item in the current service. Add a selected item to an existing item in the current service.
""" """
if not self.listView.selectedIndexes() and not self.remoteTriggered: 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:
@ -546,36 +546,36 @@ class MediaManagerItem(QtGui.QWidget):
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.generateSlideData(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 buildServiceItem(self, item=None, xmlVersion=False, remote=False, context=ServiceItemContext.Live): def build_service_item(self, item=None, xmlVersion=False, remote=False, context=ServiceItemContext.Live):
""" """
Common method for generating a service item Common method for generating a service item
""" """
service_item = ServiceItem(self.plugin) service_item = ServiceItem(self.plugin)
service_item.add_icon(self.plugin.icon_path) service_item.add_icon(self.plugin.icon_path)
if self.generateSlideData(service_item, item, xmlVersion, remote, context): if self.generate_slide_data(service_item, item, xmlVersion, remote, context):
return service_item return service_item
else: else:
return None return None
def serviceLoad(self, message): def service_load(self, message):
""" """
Method to add processing when a service has been loaded and individual service items need to be processed by the Method to add processing when a service has been loaded and individual service items need to be processed by the
plugins. plugins.
""" """
pass pass
def checkSearchResult(self): def check_search_result(self):
""" """
Checks if the listView is empty and adds a "No Search Results" item. Checks if the list_view is empty and adds a "No Search Results" item.
""" """
if self.listView.count(): if self.list_view.count():
return return
message = translate('OpenLP.MediaManagerItem', 'No Search Results') message = translate('OpenLP.MediaManagerItem', 'No Search Results')
item = QtGui.QListWidgetItem(message) item = QtGui.QListWidgetItem(message)
@ -583,9 +583,9 @@ class MediaManagerItem(QtGui.QWidget):
font = QtGui.QFont() font = QtGui.QFont()
font.setItalic(True) font.setItalic(True)
item.setFont(font) item.setFont(font)
self.listView.addItem(item) self.list_view.addItem(item)
def _getIdOfItemToGenerate(self, item, remoteItem): def _get_id_of_item_to_generate(self, item, remoteItem):
""" """
Utility method to check items being submitted for slide generation. Utility method to check items being submitted for slide generation.
@ -596,8 +596,8 @@ class MediaManagerItem(QtGui.QWidget):
The id to assign if the slide generation was remotely triggered. The id to assign if the slide generation was remotely triggered.
""" """
if item is None: if item is None:
if self.remoteTriggered is None: if self.remote_triggered is None:
item = self.listView.currentItem() item = self.list_view.currentItem()
if item is None: if item is None:
return False return False
item_id = item.data(QtCore.Qt.UserRole) item_id = item.data(QtCore.Qt.UserRole)
@ -607,13 +607,13 @@ class MediaManagerItem(QtGui.QWidget):
item_id = item.data(QtCore.Qt.UserRole) item_id = item.data(QtCore.Qt.UserRole)
return item_id return item_id
def saveAutoSelectId(self): def save_auto_select_id(self):
""" """
Sorts out, what item to select after loading a list. Sorts out, what item to select after loading a list.
""" """
# The item to select has not been set. # The item to select has not been set.
if self.autoSelectId == -1: if self.autoSelectId == -1:
item = self.listView.currentItem() item = self.list_view.currentItem()
if item: if item:
self.autoSelectId = item.data(QtCore.Qt.UserRole) self.autoSelectId = item.data(QtCore.Qt.UserRole)

View File

@ -276,9 +276,9 @@ class Plugin(QtCore.QObject):
""" """
log.debug(u'process_add_service_event event called for plugin %s' % self.name) log.debug(u'process_add_service_event event called for plugin %s' % self.name)
if replace: if replace:
self.media_item.onAddEditClick() self.media_item.on_add_edit_click()
else: else:
self.media_item.onAddClick() self.media_item.on_add_click()
def about(self): def about(self):
""" """

View File

@ -59,7 +59,7 @@ class TreeWidgetWithDnD(QtGui.QTreeWidget):
""" """
self.setAcceptDrops(True) self.setAcceptDrops(True)
self.setDragDropMode(QtGui.QAbstractItemView.DragDrop) self.setDragDropMode(QtGui.QAbstractItemView.DragDrop)
Registry().register_function((u'%s_dnd' % self.mimeDataText), self.parent().loadFile) Registry().register_function((u'%s_dnd' % self.mimeDataText), self.parent().load_file)
Registry().register_function((u'%s_dnd_internal' % self.mimeDataText), self.parent().dnd_move_internal) Registry().register_function((u'%s_dnd_internal' % self.mimeDataText), self.parent().dnd_move_internal)
def mouseMoveEvent(self, event): def mouseMoveEvent(self, event):

View File

@ -66,21 +66,21 @@ class BibleMediaItem(MediaManagerItem):
MediaManagerItem.__init__(self, parent, plugin) MediaManagerItem.__init__(self, parent, plugin)
# Place to store the search results for both bibles. # Place to store the search results for both bibles.
self.settings = self.plugin.settings_tab self.settings = self.plugin.settings_tab
self.quickPreviewAllowed = True self.quick_preview_allowed = True
self.hasSearch = True self.hasSearch = True
self.search_results = {} self.search_results = {}
self.second_search_results = {} self.second_search_results = {}
self.checkSearchResult() self.check_search_result()
Registry().register_function(u'bibles_load_list', self.reload_bibles) Registry().register_function(u'bibles_load_list', self.reload_bibles)
def __checkSecondBible(self, bible, second_bible): def __checkSecondBible(self, bible, second_bible):
""" """
Check if the first item is a second bible item or not. Check if the first item is a second bible item or not.
""" """
bitem = self.listView.item(0) bitem = self.list_view.item(0)
if not bitem.flags() & QtCore.Qt.ItemIsSelectable: if not bitem.flags() & QtCore.Qt.ItemIsSelectable:
# The item is the "No Search Results" item. # The item is the "No Search Results" item.
self.listView.clear() self.list_view.clear()
self.displayResults(bible, second_bible) self.displayResults(bible, second_bible)
return return
else: else:
@ -92,7 +92,7 @@ class BibleMediaItem(MediaManagerItem):
'You cannot combine single and dual Bible verse search results. ' 'You cannot combine single and dual Bible verse search results. '
'Do you want to delete your search results and start a new search?'), 'Do you want to delete your search results and start a new search?'),
parent=self, question=True) == QtGui.QMessageBox.Yes: parent=self, question=True) == QtGui.QMessageBox.Yes:
self.listView.clear() self.list_view.clear()
self.displayResults(bible, second_bible) self.displayResults(bible, second_bible)
def _decodeQtObject(self, bitem, key): def _decodeQtObject(self, bitem, key):
@ -100,13 +100,16 @@ class BibleMediaItem(MediaManagerItem):
obj = reference[unicode(key)] obj = reference[unicode(key)]
return unicode(obj).strip() return unicode(obj).strip()
def requiredIcons(self): def required_icons(self):
MediaManagerItem.requiredIcons(self) """
self.hasImportIcon = True Set which icons the media manager tab should show
self.hasNewIcon = False """
self.hasEditIcon = True MediaManagerItem.required_icons(self)
self.hasDeleteIcon = True self.has_import_icon = True
self.addToServiceItem = False self.has_new_icon = False
self.has_edit_icon = True
self.has_delete_icon = True
self.add_to_service_item = False
def addSearchTab(self, prefix, name): def addSearchTab(self, prefix, name):
self.searchTabBar.addTab(name) self.searchTabBar.addTab(name)
@ -152,19 +155,19 @@ class BibleMediaItem(MediaManagerItem):
styleComboBox = create_horizontal_adjusting_combo_box(tab, prefix + u'StyleComboBox') styleComboBox = create_horizontal_adjusting_combo_box(tab, prefix + u'StyleComboBox')
styleComboBox.addItems([u'', u'', u'']) styleComboBox.addItems([u'', u'', u''])
layout.addWidget(styleComboBox, idx + 2, 1, 1, 2) layout.addWidget(styleComboBox, idx + 2, 1, 1, 2)
searchButtonLayout = QtGui.QHBoxLayout() search_button_layout = QtGui.QHBoxLayout()
searchButtonLayout.setObjectName(prefix + u'SearchButtonLayout') search_button_layout.setObjectName(prefix + u'search_button_layout')
searchButtonLayout.addStretch() search_button_layout.addStretch()
lockButton = QtGui.QToolButton(tab) lockButton = QtGui.QToolButton(tab)
lockButton.setIcon(self.unlockIcon) lockButton.setIcon(self.unlockIcon)
lockButton.setCheckable(True) lockButton.setCheckable(True)
lockButton.setObjectName(prefix + u'LockButton') lockButton.setObjectName(prefix + u'LockButton')
searchButtonLayout.addWidget(lockButton) search_button_layout.addWidget(lockButton)
searchButton = QtGui.QPushButton(tab) searchButton = QtGui.QPushButton(tab)
searchButton.setObjectName(prefix + u'SearchButton') searchButton.setObjectName(prefix + u'SearchButton')
searchButtonLayout.addWidget(searchButton) search_button_layout.addWidget(searchButton)
layout.addLayout(searchButtonLayout, idx + 3, 1, 1, 2) layout.addLayout(search_button_layout, idx + 3, 1, 1, 2)
self.pageLayout.addWidget(tab) self.page_layout.addWidget(tab)
tab.setVisible(False) tab.setVisible(False)
lockButton.toggled.connect(self.onLockButtonToggled) lockButton.toggled.connect(self.onLockButtonToggled)
setattr(self, prefix + u'VersionLabel', versionLabel) setattr(self, prefix + u'VersionLabel', versionLabel)
@ -174,14 +177,14 @@ class BibleMediaItem(MediaManagerItem):
setattr(self, prefix + u'StyleLabel', styleLabel) setattr(self, prefix + u'StyleLabel', styleLabel)
setattr(self, prefix + u'StyleComboBox', styleComboBox) setattr(self, prefix + u'StyleComboBox', styleComboBox)
setattr(self, prefix + u'LockButton', lockButton) setattr(self, prefix + u'LockButton', lockButton)
setattr(self, prefix + u'SearchButtonLayout', searchButtonLayout) setattr(self, prefix + u'SearchButtonLayout', search_button_layout)
setattr(self, prefix + u'SearchButton', searchButton) setattr(self, prefix + u'SearchButton', searchButton)
def addEndHeaderBar(self): def add_end_header_bar(self):
self.searchTabBar = QtGui.QTabBar(self) self.searchTabBar = QtGui.QTabBar(self)
self.searchTabBar.setExpanding(False) self.searchTabBar.setExpanding(False)
self.searchTabBar.setObjectName(u'searchTabBar') self.searchTabBar.setObjectName(u'searchTabBar')
self.pageLayout.addWidget(self.searchTabBar) self.page_layout.addWidget(self.searchTabBar)
# Add the Quick Search tab. # Add the Quick Search tab.
self.addSearchTab(u'quick', translate('BiblesPlugin.MediaItem', 'Quick')) self.addSearchTab(u'quick', translate('BiblesPlugin.MediaItem', 'Quick'))
self.quickSearchLabel = QtGui.QLabel(self.quickTab) self.quickSearchLabel = QtGui.QLabel(self.quickTab)
@ -468,7 +471,7 @@ class BibleMediaItem(MediaManagerItem):
if self.import_wizard.exec_(): if self.import_wizard.exec_():
self.reload_bibles() self.reload_bibles()
def onEditClick(self): def on_edit_click(self):
if self.quickTab.isVisible(): if self.quickTab.isVisible():
bible = self.quickVersionComboBox.currentText() bible = self.quickVersionComboBox.currentText()
elif self.advancedTab.isVisible(): elif self.advancedTab.isVisible():
@ -479,7 +482,7 @@ class BibleMediaItem(MediaManagerItem):
if self.editBibleForm.exec_(): if self.editBibleForm.exec_():
self.reload_bibles() self.reload_bibles()
def onDeleteClick(self): def on_delete_click(self):
if self.quickTab.isVisible(): if self.quickTab.isVisible():
bible = self.quickVersionComboBox.currentText() bible = self.quickVersionComboBox.currentText()
elif self.advancedTab.isVisible(): elif self.advancedTab.isVisible():
@ -628,13 +631,13 @@ class BibleMediaItem(MediaManagerItem):
if second_bible: if second_bible:
self.second_search_results = self.plugin.manager.get_verses(second_bible, versetext, book_ref_id) self.second_search_results = self.plugin.manager.get_verses(second_bible, versetext, book_ref_id)
if not self.advancedLockButton.isChecked(): if not self.advancedLockButton.isChecked():
self.listView.clear() self.list_view.clear()
if self.listView.count() != 0: if self.list_view.count() != 0:
self.__checkSecondBible(bible, second_bible) self.__checkSecondBible(bible, second_bible)
elif self.search_results: elif self.search_results:
self.displayResults(bible, second_bible) self.displayResults(bible, second_bible)
self.advancedSearchButton.setEnabled(True) self.advancedSearchButton.setEnabled(True)
self.checkSearchResult() self.check_search_result()
self.application.set_normal_cursor() self.application.set_normal_cursor()
def onQuickSearchButton(self): def onQuickSearchButton(self):
@ -684,13 +687,13 @@ class BibleMediaItem(MediaManagerItem):
self.search_results = new_search_results self.search_results = new_search_results
self.second_search_results = bibles[second_bible].get_verses(text) self.second_search_results = bibles[second_bible].get_verses(text)
if not self.quickLockButton.isChecked(): if not self.quickLockButton.isChecked():
self.listView.clear() self.list_view.clear()
if self.listView.count() != 0 and self.search_results: if self.list_view.count() != 0 and self.search_results:
self.__checkSecondBible(bible, second_bible) self.__checkSecondBible(bible, second_bible)
elif self.search_results: elif self.search_results:
self.displayResults(bible, second_bible) self.displayResults(bible, second_bible)
self.quickSearchButton.setEnabled(True) self.quickSearchButton.setEnabled(True)
self.checkSearchResult() self.check_search_result()
self.application.set_normal_cursor() self.application.set_normal_cursor()
def displayResults(self, bible, second_bible=u''): def displayResults(self, bible, second_bible=u''):
@ -700,8 +703,8 @@ class BibleMediaItem(MediaManagerItem):
""" """
items = self.buildDisplayResults(bible, second_bible, self.search_results) items = self.buildDisplayResults(bible, second_bible, self.search_results)
for bible_verse in items: for bible_verse in items:
self.listView.addItem(bible_verse) self.list_view.addItem(bible_verse)
self.listView.selectAll() self.list_view.selectAll()
self.search_results = {} self.search_results = {}
self.second_search_results = {} self.second_search_results = {}
@ -764,7 +767,7 @@ class BibleMediaItem(MediaManagerItem):
items.append(bible_verse) items.append(bible_verse)
return items return items
def generateSlideData(self, service_item, item=None, xmlVersion=False, def generate_slide_data(self, service_item, item=None, xmlVersion=False,
remote=False, context=ServiceItemContext.Service): remote=False, context=ServiceItemContext.Service):
""" """
Generates and formats the slides for the service item as well as the Generates and formats the slides for the service item as well as the
@ -774,7 +777,7 @@ class BibleMediaItem(MediaManagerItem):
if item: if item:
items = item items = item
else: else:
items = self.listView.selectedItems() items = self.list_view.selectedItems()
if not items: if not items:
return False return False
bible_text = u'' bible_text = u''
@ -963,7 +966,10 @@ class BibleMediaItem(MediaManagerItem):
return [[string, versetext]] return [[string, versetext]]
return [] return []
def createItemFromId(self, item_id): def create_item_from_id(self, item_id):
"""
Create a media item from an item id.
"""
item = QtGui.QListWidgetItem() item = QtGui.QListWidgetItem()
bible = self.quickVersionComboBox.currentText() bible = self.quickVersionComboBox.currentText()
search_results = self.plugin.manager.get_verses(bible, item_id, False) search_results = self.plugin.manager.get_verses(bible, item_id, False)

View File

@ -58,23 +58,23 @@ class CustomMediaItem(MediaManagerItem):
self.icon_path = u'custom/custom' self.icon_path = u'custom/custom'
MediaManagerItem.__init__(self, parent, plugin) MediaManagerItem.__init__(self, parent, plugin)
self.edit_custom_form = EditCustomForm(self, self.main_window, self.plugin.manager) self.edit_custom_form = EditCustomForm(self, self.main_window, self.plugin.manager)
self.singleServiceItem = False self.single_service_item = False
self.quickPreviewAllowed = True self.quick_preview_allowed = True
self.hasSearch = True self.hasSearch = True
# Holds information about whether the edit is remotely triggered and # Holds information about whether the edit is remotely triggered and
# which Custom is required. # which Custom is required.
self.remoteCustom = -1 self.remoteCustom = -1
self.manager = plugin.manager self.manager = plugin.manager
def addEndHeaderBar(self): def add_end_header_bar(self):
self.toolbar.addSeparator() self.toolbar.addSeparator()
self.addSearchToToolBar() self.add_search_to_toolbar()
# Signals and slots # Signals and slots
QtCore.QObject.connect(self.searchTextEdit, QtCore.SIGNAL(u'cleared()'), self.onClearTextButtonClick) QtCore.QObject.connect(self.search_text_edit, QtCore.SIGNAL(u'cleared()'), self.onClearTextButtonClick)
QtCore.QObject.connect(self.searchTextEdit, QtCore.SIGNAL(u'searchTypeChanged(int)'), QtCore.QObject.connect(self.search_text_edit, QtCore.SIGNAL(u'searchTypeChanged(int)'),
self.onSearchTextButtonClicked) self.on_search_text_button_clicked)
Registry().register_function(u'custom_load_list', self.loadList) Registry().register_function(u'custom_load_list', self.load_list)
Registry().register_function(u'custom_preview', self.onPreviewClick) Registry().register_function(u'custom_preview', self.on_preview_click)
Registry().register_function(u'custom_create_from_service', self.create_from_service_item) Registry().register_function(u'custom_create_from_service', self.create_from_service_item)
def config_update(self): def config_update(self):
@ -85,42 +85,42 @@ class CustomMediaItem(MediaManagerItem):
self.add_custom_from_service = Settings().value(self.settings_section + u'/add custom from service') self.add_custom_from_service = Settings().value(self.settings_section + u'/add custom from service')
def retranslateUi(self): def retranslateUi(self):
self.searchTextLabel.setText(u'%s:' % UiStrings().Search) self.search_text_label.setText(u'%s:' % UiStrings().Search)
self.searchTextButton.setText(UiStrings().Search) self.search_text_button.setText(UiStrings().Search)
def initialise(self): def initialise(self):
self.searchTextEdit.set_search_types([ self.search_text_edit.set_search_types([
(CustomSearch.Titles, u':/songs/song_search_title.png', (CustomSearch.Titles, u':/songs/song_search_title.png',
translate('SongsPlugin.MediaItem', 'Titles'), translate('SongsPlugin.MediaItem', 'Titles'),
translate('SongsPlugin.MediaItem', 'Search Titles...')), translate('SongsPlugin.MediaItem', 'Search Titles...')),
(CustomSearch.Themes, u':/slides/slide_theme.png', UiStrings().Themes, UiStrings().SearchThemes) (CustomSearch.Themes, u':/slides/slide_theme.png', UiStrings().Themes, UiStrings().SearchThemes)
]) ])
self.searchTextEdit.set_current_search_type(Settings().value(u'%s/last search type' % self.settings_section)) self.search_text_edit.set_current_search_type(Settings().value(u'%s/last search type' % self.settings_section))
self.loadList(self.manager.get_all_objects(CustomSlide, order_by_ref=CustomSlide.title)) self.load_list(self.manager.get_all_objects(CustomSlide, order_by_ref=CustomSlide.title))
self.config_update() self.config_update()
def loadList(self, custom_slides, target_group=None): def load_list(self, custom_slides, target_group=None):
# Sort out what custom we want to select after loading the list. # Sort out what custom we want to select after loading the list.
self.saveAutoSelectId() self.save_auto_select_id()
self.listView.clear() self.list_view.clear()
custom_slides.sort() custom_slides.sort()
for custom_slide in custom_slides: for custom_slide in custom_slides:
custom_name = QtGui.QListWidgetItem(custom_slide.title) custom_name = QtGui.QListWidgetItem(custom_slide.title)
custom_name.setData(QtCore.Qt.UserRole, custom_slide.id) custom_name.setData(QtCore.Qt.UserRole, custom_slide.id)
self.listView.addItem(custom_name) self.list_view.addItem(custom_name)
# Auto-select the custom. # Auto-select the custom.
if custom_slide.id == self.autoSelectId: if custom_slide.id == self.autoSelectId:
self.listView.setCurrentItem(custom_name) self.list_view.setCurrentItem(custom_name)
self.autoSelectId = -1 self.autoSelectId = -1
# Called to redisplay the custom list screen edith from a search # Called to redisplay the custom list screen edith from a search
# or from the exit of the Custom edit dialog. If remote editing is # or from the exit of the Custom edit dialog. If remote editing is
# active trigger it and clean up so it will not update again. # active trigger it and clean up so it will not update again.
def onNewClick(self): def on_new_click(self):
self.edit_custom_form.load_custom(0) self.edit_custom_form.load_custom(0)
self.edit_custom_form.exec_() self.edit_custom_form.exec_()
self.onClearTextButtonClick() self.onClearTextButtonClick()
self.onSelectionChange() self.on_selection_change()
def onRemoteEdit(self, custom_id, preview=False): def onRemoteEdit(self, custom_id, preview=False):
""" """
@ -133,35 +133,35 @@ class CustomMediaItem(MediaManagerItem):
if valid: if valid:
self.edit_custom_form.load_custom(custom_id, preview) self.edit_custom_form.load_custom(custom_id, preview)
if self.edit_custom_form.exec_() == QtGui.QDialog.Accepted: if self.edit_custom_form.exec_() == QtGui.QDialog.Accepted:
self.remoteTriggered = True self.remote_triggered = True
self.remoteCustom = custom_id self.remoteCustom = custom_id
self.autoSelectId = -1 self.autoSelectId = -1
self.onSearchTextButtonClicked() self.on_search_text_button_clicked()
item = self.buildServiceItem(remote=True) item = self.build_service_item(remote=True)
self.remoteTriggered = None self.remote_triggered = None
self.remoteCustom = 1 self.remoteCustom = 1
if item: if item:
return item return item
return None return None
def onEditClick(self): def on_edit_click(self):
""" """
Edit a custom item Edit a custom item
""" """
if check_item_selected(self.listView, UiStrings().SelectEdit): if check_item_selected(self.list_view, UiStrings().SelectEdit):
item = self.listView.currentItem() item = self.list_view.currentItem()
item_id = item.data(QtCore.Qt.UserRole) item_id = item.data(QtCore.Qt.UserRole)
self.edit_custom_form.load_custom(item_id, False) self.edit_custom_form.load_custom(item_id, False)
self.edit_custom_form.exec_() self.edit_custom_form.exec_()
self.autoSelectId = -1 self.autoSelectId = -1
self.onSearchTextButtonClicked() self.on_search_text_button_clicked()
def onDeleteClick(self): def on_delete_click(self):
""" """
Remove a custom item from the list and database Remove a custom item from the list and database
""" """
if check_item_selected(self.listView, UiStrings().SelectDelete): if check_item_selected(self.list_view, UiStrings().SelectDelete):
items = self.listView.selectedIndexes() items = self.list_view.selectedIndexes()
if QtGui.QMessageBox.question(self, if QtGui.QMessageBox.question(self,
UiStrings().ConfirmDelete, UiStrings().ConfirmDelete,
translate('CustomPlugin.MediaItem', translate('CustomPlugin.MediaItem',
@ -170,20 +170,23 @@ class CustomMediaItem(MediaManagerItem):
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No),
QtGui.QMessageBox.Yes) == QtGui.QMessageBox.No: QtGui.QMessageBox.Yes) == QtGui.QMessageBox.No:
return return
row_list = [item.row() for item in self.listView.selectedIndexes()] row_list = [item.row() for item in self.list_view.selectedIndexes()]
row_list.sort(reverse=True) row_list.sort(reverse=True)
id_list = [(item.data(QtCore.Qt.UserRole)) id_list = [(item.data(QtCore.Qt.UserRole))
for item in self.listView.selectedIndexes()] for item in self.list_view.selectedIndexes()]
for id in id_list: for id in id_list:
self.plugin.manager.delete_object(CustomSlide, id) self.plugin.manager.delete_object(CustomSlide, id)
self.onSearchTextButtonClicked() self.on_search_text_button_clicked()
def onFocus(self): def onFocus(self):
self.searchTextEdit.setFocus() self.search_text_edit.setFocus()
def generateSlideData(self, service_item, item=None, xmlVersion=False, def generate_slide_data(self, service_item, item=None, xmlVersion=False,
remote=False, context=ServiceItemContext.Service): remote=False, context=ServiceItemContext.Service):
item_id = self._getIdOfItemToGenerate(item, self.remoteCustom) """
Generate the slide data. Needs to be implemented by the plugin.
"""
item_id = self._get_id_of_item_to_generate(item, self.remoteCustom)
service_item.add_capability(ItemCapabilities.CanEdit) service_item.add_capability(ItemCapabilities.CanEdit)
service_item.add_capability(ItemCapabilities.CanPreview) service_item.add_capability(ItemCapabilities.CanPreview)
service_item.add_capability(ItemCapabilities.CanLoop) service_item.add_capability(ItemCapabilities.CanLoop)
@ -208,28 +211,28 @@ class CustomMediaItem(MediaManagerItem):
service_item.raw_footer.append(u'') service_item.raw_footer.append(u'')
return True return True
def onSearchTextButtonClicked(self): def on_search_text_button_clicked(self):
# Save the current search type to the configuration. # Save the current search type to the configuration.
Settings().setValue(u'%s/last search type' % self.settings_section, self.searchTextEdit.current_search_type()) Settings().setValue(u'%s/last search type' % self.settings_section, self.search_text_edit.current_search_type())
# Reload the list considering the new search type. # Reload the list considering the new search type.
search_keywords = self.searchTextEdit.displayText() search_keywords = self.search_text_edit.displayText()
search_results = [] search_results = []
search_type = self.searchTextEdit.current_search_type() search_type = self.search_text_edit.current_search_type()
if search_type == CustomSearch.Titles: if search_type == CustomSearch.Titles:
log.debug(u'Titles Search') log.debug(u'Titles Search')
search_results = self.plugin.manager.get_all_objects(CustomSlide, search_results = self.plugin.manager.get_all_objects(CustomSlide,
CustomSlide.title.like(u'%' + self.whitespace.sub(u' ', search_keywords) + u'%'), CustomSlide.title.like(u'%' + self.whitespace.sub(u' ', search_keywords) + u'%'),
order_by_ref=CustomSlide.title) order_by_ref=CustomSlide.title)
self.loadList(search_results) self.load_list(search_results)
elif search_type == CustomSearch.Themes: elif search_type == CustomSearch.Themes:
log.debug(u'Theme Search') log.debug(u'Theme Search')
search_results = self.plugin.manager.get_all_objects(CustomSlide, search_results = self.plugin.manager.get_all_objects(CustomSlide,
CustomSlide.theme_name.like(u'%' + self.whitespace.sub(u' ', search_keywords) + u'%'), CustomSlide.theme_name.like(u'%' + self.whitespace.sub(u' ', search_keywords) + u'%'),
order_by_ref=CustomSlide.title) order_by_ref=CustomSlide.title)
self.loadList(search_results) self.load_list(search_results)
self.checkSearchResult() self.check_search_result()
def onSearchTextEditChanged(self, text): def on_search_text_edit_changed(self, text):
""" """
If search as type enabled invoke the search on each key press. If search as type enabled invoke the search on each key press.
If the Title is being searched do not start until 2 characters If the Title is being searched do not start until 2 characters
@ -237,15 +240,15 @@ class CustomMediaItem(MediaManagerItem):
""" """
search_length = 2 search_length = 2
if len(text) > search_length: if len(text) > search_length:
self.onSearchTextButtonClicked() self.on_search_text_button_clicked()
elif not text: elif not text:
self.onClearTextButtonClick() self.onClearTextButtonClick()
def serviceLoad(self, item): def service_load(self, item):
""" """
Triggered by a song being loaded by the service manager. Triggered by a song being loaded by the service manager.
""" """
log.debug(u'serviceLoad') log.debug(u'service_load')
if self.plugin.status != PluginStatus.Active: if self.plugin.status != PluginStatus.Active:
return return
custom = self.plugin.manager.get_object_filtered(CustomSlide, custom = self.plugin.manager.get_object_filtered(CustomSlide,
@ -280,7 +283,7 @@ class CustomMediaItem(MediaManagerItem):
custom_xml.add_verse_to_lyrics(u'custom', unicode(idx + 1), slide['raw_slide']) custom_xml.add_verse_to_lyrics(u'custom', unicode(idx + 1), slide['raw_slide'])
custom.text = unicode(custom_xml.extract_xml(), u'utf-8') custom.text = unicode(custom_xml.extract_xml(), u'utf-8')
self.plugin.manager.save_object(custom) self.plugin.manager.save_object(custom)
self.onSearchTextButtonClicked() self.on_search_text_button_clicked()
if item.name.lower() == u'custom': if item.name.lower() == u'custom':
Registry().execute(u'service_item_update', u'%s:%s:%s' % (custom.id, item.unique_identifier, False)) Registry().execute(u'service_item_update', u'%s:%s:%s' % (custom.id, item.unique_identifier, False))
@ -288,8 +291,8 @@ class CustomMediaItem(MediaManagerItem):
""" """
Clear the search text. Clear the search text.
""" """
self.searchTextEdit.clear() self.search_text_edit.clear()
self.onSearchTextButtonClicked() self.on_search_text_button_clicked()
def search(self, string, showError): def search(self, string, showError):
search_results = self.manager.get_all_objects(CustomSlide, search_results = self.manager.get_all_objects(CustomSlide,

View File

@ -52,7 +52,7 @@ class ImageMediaItem(MediaManagerItem):
def __init__(self, parent, plugin): def __init__(self, parent, plugin):
self.icon_path = u'images/image' self.icon_path = u'images/image'
MediaManagerItem.__init__(self, parent, plugin) MediaManagerItem.__init__(self, parent, plugin)
self.quickPreviewAllowed = True self.quick_preview_allowed = True
self.hasSearch = True self.hasSearch = True
self.manager = plugin.manager self.manager = plugin.manager
self.choose_group_form = ChooseGroupForm(self) self.choose_group_form = ChooseGroupForm(self)
@ -61,13 +61,13 @@ class ImageMediaItem(MediaManagerItem):
self.fill_groups_combobox(self.add_group_form.parent_group_combobox) self.fill_groups_combobox(self.add_group_form.parent_group_combobox)
Registry().register_function(u'live_theme_changed', self.live_theme_changed) Registry().register_function(u'live_theme_changed', self.live_theme_changed)
# Allow DnD from the desktop # Allow DnD from the desktop
self.listView.activateDnD() self.list_view.activateDnD()
def retranslateUi(self): def retranslateUi(self):
self.onNewPrompt = translate('ImagePlugin.MediaItem', self.on_new_prompt = translate('ImagePlugin.MediaItem',
'Select Image(s)') 'Select Image(s)')
file_formats = get_images_filter() file_formats = get_images_filter()
self.onNewFileMasks = u'%s;;%s (*.*) (*)' % (file_formats, UiStrings().AllFiles) self.on_new_file_masks = u'%s;;%s (*.*) (*)' % (file_formats, UiStrings().AllFiles)
self.addGroupAction.setText(UiStrings().AddGroup) self.addGroupAction.setText(UiStrings().AddGroup)
self.addGroupAction.setToolTip(UiStrings().AddGroup) self.addGroupAction.setToolTip(UiStrings().AddGroup)
self.replaceAction.setText(UiStrings().ReplaceBG) self.replaceAction.setText(UiStrings().ReplaceBG)
@ -75,104 +75,107 @@ class ImageMediaItem(MediaManagerItem):
self.resetAction.setText(UiStrings().ResetBG) self.resetAction.setText(UiStrings().ResetBG)
self.resetAction.setToolTip(UiStrings().ResetLiveBG) self.resetAction.setToolTip(UiStrings().ResetLiveBG)
def requiredIcons(self): def required_icons(self):
MediaManagerItem.requiredIcons(self) """
self.hasFileIcon = True Set which icons the media manager tab should show
self.hasNewIcon = False """
self.hasEditIcon = False MediaManagerItem.required_icons(self)
self.addToServiceItem = True self.has_file_icon = True
self.has_new_icon = False
self.has_edit_icon = False
self.add_to_service_item = True
def initialise(self): def initialise(self):
log.debug(u'initialise') log.debug(u'initialise')
self.listView.clear() self.list_view.clear()
self.listView.setIconSize(QtCore.QSize(88, 50)) self.list_view.setIconSize(QtCore.QSize(88, 50))
self.listView.setIndentation(self.listView.defaultIndentation) self.list_view.setIndentation(self.list_view.defaultIndentation)
self.listView.allow_internal_dnd = True self.list_view.allow_internal_dnd = True
self.servicePath = os.path.join(AppLocation.get_section_data_path(self.settings_section), u'thumbnails') self.servicePath = os.path.join(AppLocation.get_section_data_path(self.settings_section), u'thumbnails')
check_directory_exists(self.servicePath) check_directory_exists(self.servicePath)
# Load images from the database # Load images from the database
self.loadFullList( self.loadFullList(
self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename), initial_load=True) self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename), initial_load=True)
def addListViewToToolBar(self): def add_list_view_to_toolbar(self):
""" """
Creates the main widget for listing items the media item is tracking. Creates the main widget for listing items the media item is tracking.
This method overloads MediaManagerItem.addListViewToToolBar This method overloads MediaManagerItem.add_list_view_to_toolbar
""" """
# Add the List widget # Add the List widget
self.listView = TreeWidgetWithDnD(self, self.plugin.name) self.list_view = TreeWidgetWithDnD(self, self.plugin.name)
self.listView.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) self.list_view.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
self.listView.setAlternatingRowColors(True) self.list_view.setAlternatingRowColors(True)
self.listView.setObjectName(u'%sTreeView' % self.plugin.name) self.list_view.setObjectName(u'%sTreeView' % self.plugin.name)
# Add to pageLayout # Add to pageLayout
self.pageLayout.addWidget(self.listView) self.page_layout.addWidget(self.list_view)
# define and add the context menu # define and add the context menu
self.listView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.list_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
if self.hasEditIcon: if self.has_edit_icon:
create_widget_action(self.listView, create_widget_action(self.list_view,
text=self.plugin.get_string(StringContent.Edit)[u'title'], text=self.plugin.get_string(StringContent.Edit)[u'title'],
icon=u':/general/general_edit.png', icon=u':/general/general_edit.png',
triggers=self.onEditClick) triggers=self.on_edit_click)
create_widget_action(self.listView, separator=True) create_widget_action(self.list_view, separator=True)
if self.hasDeleteIcon: if self.has_delete_icon:
create_widget_action(self.listView, create_widget_action(self.list_view,
text=self.plugin.get_string(StringContent.Delete)[u'title'], text=self.plugin.get_string(StringContent.Delete)[u'title'],
icon=u':/general/general_delete.png', icon=u':/general/general_delete.png',
shortcuts=[QtCore.Qt.Key_Delete], triggers=self.onDeleteClick) shortcuts=[QtCore.Qt.Key_Delete], triggers=self.on_delete_click)
create_widget_action(self.listView, separator=True) create_widget_action(self.list_view, separator=True)
create_widget_action(self.listView, create_widget_action(self.list_view,
text=self.plugin.get_string(StringContent.Preview)[u'title'], text=self.plugin.get_string(StringContent.Preview)[u'title'],
icon=u':/general/general_preview.png', icon=u':/general/general_preview.png',
shortcuts=[QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return], shortcuts=[QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return],
triggers=self.onPreviewClick) triggers=self.on_preview_click)
create_widget_action(self.listView, create_widget_action(self.list_view,
text=self.plugin.get_string(StringContent.Live)[u'title'], text=self.plugin.get_string(StringContent.Live)[u'title'],
icon=u':/general/general_live.png', icon=u':/general/general_live.png',
shortcuts=[QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Enter, shortcuts=[QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Enter,
QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Return], QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Return],
triggers=self.onLiveClick) triggers=self.on_live_click)
create_widget_action(self.listView, create_widget_action(self.list_view,
text=self.plugin.get_string(StringContent.Service)[u'title'], text=self.plugin.get_string(StringContent.Service)[u'title'],
icon=u':/general/general_add.png', icon=u':/general/general_add.png',
shortcuts=[QtCore.Qt.Key_Plus, QtCore.Qt.Key_Equal], shortcuts=[QtCore.Qt.Key_Plus, QtCore.Qt.Key_Equal],
triggers=self.onAddClick) triggers=self.on_add_click)
if self.addToServiceItem: if self.add_to_service_item:
create_widget_action(self.listView, separator=True) create_widget_action(self.list_view, separator=True)
create_widget_action(self.listView, 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=u':/general/general_add.png', icon=u':/general/general_add.png',
triggers=self.onAddEditClick) triggers=self.on_add_edit_click)
self.addCustomContextActions() self.add_custom_context_actions()
# Create the context menu and add all actions from the listView. # Create the context menu and add all actions from the list_view.
self.menu = QtGui.QMenu() self.menu = QtGui.QMenu()
self.menu.addActions(self.listView.actions()) self.menu.addActions(self.list_view.actions())
self.listView.doubleClicked.connect(self.onDoubleClicked) self.list_view.doubleClicked.connect(self.on_double_clicked)
self.listView.itemSelectionChanged.connect(self.onSelectionChange) self.list_view.itemSelectionChanged.connect(self.on_selection_change)
self.listView.customContextMenuRequested.connect(self.contextMenu) self.list_view.customContextMenuRequested.connect(self.context_menu)
self.listView.addAction(self.replaceAction) self.list_view.addAction(self.replaceAction)
def addCustomContextActions(self): def add_custom_context_actions(self):
""" """
Add custom actions to the context menu Add custom actions to the context menu
""" """
create_widget_action(self.listView, separator=True) create_widget_action(self.list_view, separator=True)
create_widget_action(self.listView, create_widget_action(self.list_view,
text=UiStrings().AddGroup, text=UiStrings().AddGroup,
icon=u':/images/image_new_group.png', icon=u':/images/image_new_group.png',
triggers=self.onAddGroupClick) triggers=self.onAddGroupClick)
create_widget_action(self.listView, create_widget_action(self.list_view,
text=self.plugin.get_string(StringContent.Load)[u'tooltip'], text=self.plugin.get_string(StringContent.Load)[u'tooltip'],
icon=u':/general/general_open.png', icon=u':/general/general_open.png',
triggers=self.onFileClick) triggers=self.on_file_click)
def addStartHeaderBar(self): def add_start_header_bar(self):
""" """
Add custom buttons to the start of the toolbar Add custom buttons to the start of the toolbar
""" """
self.addGroupAction = self.toolbar.add_toolbar_action(u'addGroupAction', self.addGroupAction = self.toolbar.add_toolbar_action(u'addGroupAction',
icon=u':/images/image_new_group.png', triggers=self.onAddGroupClick) icon=u':/images/image_new_group.png', triggers=self.onAddGroupClick)
def addEndHeaderBar(self): def add_end_header_bar(self):
""" """
Add custom buttons to the end of the toolbar Add custom buttons to the end of the toolbar
""" """
@ -197,15 +200,15 @@ class ImageMediaItem(MediaManagerItem):
self.recursively_delete_group(group) self.recursively_delete_group(group)
self.manager.delete_object(ImageGroups, group.id) self.manager.delete_object(ImageGroups, group.id)
def onDeleteClick(self): def on_delete_click(self):
""" """
Remove an image item from the list Remove an image item from the list
""" """
# Turn off auto preview triggers. # Turn off auto preview triggers.
self.listView.blockSignals(True) self.list_view.blockSignals(True)
if check_item_selected(self.listView, translate('ImagePlugin.MediaItem', if check_item_selected(self.list_view, translate('ImagePlugin.MediaItem',
'You must select an image or group to delete.')): 'You must select an image or group to delete.')):
item_list = self.listView.selectedItems() item_list = self.list_view.selectedItems()
self.application.set_busy_cursor() self.application.set_busy_cursor()
self.main_window.display_progress_bar(len(item_list)) self.main_window.display_progress_bar(len(item_list))
for row_item in item_list: for row_item in item_list:
@ -214,12 +217,12 @@ class ImageMediaItem(MediaManagerItem):
if isinstance(item_data, ImageFilenames): if isinstance(item_data, ImageFilenames):
delete_file(os.path.join(self.servicePath, row_item.text(0))) delete_file(os.path.join(self.servicePath, row_item.text(0)))
if item_data.group_id == 0: if item_data.group_id == 0:
self.listView.takeTopLevelItem(self.listView.indexOfTopLevelItem(row_item)) self.list_view.takeTopLevelItem(self.list_view.indexOfTopLevelItem(row_item))
else: else:
row_item.parent().removeChild(row_item) row_item.parent().removeChild(row_item)
self.manager.delete_object(ImageFilenames, row_item.data(0, QtCore.Qt.UserRole).id) self.manager.delete_object(ImageFilenames, row_item.data(0, QtCore.Qt.UserRole).id)
elif isinstance(item_data, ImageGroups): elif isinstance(item_data, ImageGroups):
if QtGui.QMessageBox.question(self.listView.parent(), if QtGui.QMessageBox.question(self.list_view.parent(),
translate('ImagePlugin.MediaItem', 'Remove group'), translate('ImagePlugin.MediaItem', 'Remove group'),
translate('ImagePlugin.MediaItem', translate('ImagePlugin.MediaItem',
'Are you sure you want to remove "%s" and everything in it?') % item_data.group_name, 'Are you sure you want to remove "%s" and everything in it?') % item_data.group_name,
@ -228,7 +231,7 @@ class ImageMediaItem(MediaManagerItem):
self.recursively_delete_group(item_data) self.recursively_delete_group(item_data)
self.manager.delete_object(ImageGroups, row_item.data(0, QtCore.Qt.UserRole).id) self.manager.delete_object(ImageGroups, row_item.data(0, QtCore.Qt.UserRole).id)
if item_data.parent_id == 0: if item_data.parent_id == 0:
self.listView.takeTopLevelItem(self.listView.indexOfTopLevelItem(row_item)) self.list_view.takeTopLevelItem(self.list_view.indexOfTopLevelItem(row_item))
else: else:
row_item.parent().removeChild(row_item) row_item.parent().removeChild(row_item)
self.fill_groups_combobox(self.choose_group_form.group_combobox) self.fill_groups_combobox(self.choose_group_form.group_combobox)
@ -236,7 +239,7 @@ class ImageMediaItem(MediaManagerItem):
self.main_window.increment_progress_bar() self.main_window.increment_progress_bar()
self.main_window.finished_progress_bar() self.main_window.finished_progress_bar()
self.application.set_normal_cursor() self.application.set_normal_cursor()
self.listView.blockSignals(False) self.list_view.blockSignals(False)
def add_sub_groups(self, group_list, parent_group_id): def add_sub_groups(self, group_list, parent_group_id):
""" """
@ -257,7 +260,7 @@ class ImageMediaItem(MediaManagerItem):
group.setData(0, QtCore.Qt.UserRole, image_group) group.setData(0, QtCore.Qt.UserRole, image_group)
group.setIcon(0, folder_icon) group.setIcon(0, folder_icon)
if parent_group_id == 0: if parent_group_id == 0:
self.listView.addTopLevelItem(group) self.list_view.addTopLevelItem(group)
else: else:
group_list[parent_group_id].addChild(group) group_list[parent_group_id].addChild(group)
group_list[image_group.id] = group group_list[image_group.id] = group
@ -297,7 +300,7 @@ class ImageMediaItem(MediaManagerItem):
""" """
return_value = False return_value = False
if root_item is None: if root_item is None:
root_item = self.listView.invisibleRootItem() root_item = self.list_view.invisibleRootItem()
for i in range(root_item.childCount()): for i in range(root_item.childCount()):
child = root_item.child(i) child = root_item.child(i)
if self.expand_group(group_id, child): if self.expand_group(group_id, child):
@ -324,7 +327,7 @@ class ImageMediaItem(MediaManagerItem):
if not initial_load: if not initial_load:
self.application.set_busy_cursor() self.application.set_busy_cursor()
self.main_window.display_progress_bar(len(images)) self.main_window.display_progress_bar(len(images))
self.listView.clear() self.list_view.clear()
# Load the list of groups and add them to the treeView # Load the list of groups and add them to the treeView
group_items = {} group_items = {}
self.add_sub_groups(group_items, parent_group_id=0) self.add_sub_groups(group_items, parent_group_id=0)
@ -350,7 +353,7 @@ class ImageMediaItem(MediaManagerItem):
item_name.setToolTip(0, imageFile.filename) item_name.setToolTip(0, imageFile.filename)
item_name.setData(0, QtCore.Qt.UserRole, imageFile) item_name.setData(0, QtCore.Qt.UserRole, imageFile)
if imageFile.group_id == 0: if imageFile.group_id == 0:
self.listView.addTopLevelItem(item_name) self.list_view.addTopLevelItem(item_name)
else: else:
group_items[imageFile.group_id].addChild(item_name) group_items[imageFile.group_id].addChild(item_name)
if not initial_load: if not initial_load:
@ -359,7 +362,7 @@ class ImageMediaItem(MediaManagerItem):
self.main_window.finished_progress_bar() self.main_window.finished_progress_bar()
self.application.set_normal_cursor() self.application.set_normal_cursor()
def validateAndLoad(self, files, target_group=None): def validate_and_load(self, files, target_group=None):
""" """
Process a list for files either from the File Dialog or from Drag and Drop. Process a list for files either from the File Dialog or from Drag and Drop.
This method is overloaded from MediaManagerItem. This method is overloaded from MediaManagerItem.
@ -371,11 +374,11 @@ class ImageMediaItem(MediaManagerItem):
The QTreeWidgetItem of the group that will be the parent of the added files The QTreeWidgetItem of the group that will be the parent of the added files
""" """
self.application.set_normal_cursor() self.application.set_normal_cursor()
self.loadList(files, target_group) self.load_list(files, target_group)
last_dir = os.path.split(unicode(files[0]))[0] last_dir = os.path.split(unicode(files[0]))[0]
Settings().setValue(self.settings_section + u'/last directory', last_dir) Settings().setValue(self.settings_section + u'/last directory', last_dir)
def loadList(self, images, target_group=None, initial_load=False): def load_list(self, images, target_group=None, initial_load=False):
""" """
Add new images to the database. This method is called when adding images using the Add button or DnD. Add new images to the database. This method is called when adding images using the Add button or DnD.
@ -391,7 +394,7 @@ class ImageMediaItem(MediaManagerItem):
if target_group is None: if target_group is None:
# Find out if a group must be pre-selected # Find out if a group must be pre-selected
preselect_group = None preselect_group = None
selected_items = self.listView.selectedItems() selected_items = self.list_view.selectedItems()
if selected_items: if selected_items:
selected_item = selected_items[0] selected_item = selected_items[0]
if isinstance(selected_item.data(0, QtCore.Qt.UserRole), ImageFilenames): if isinstance(selected_item.data(0, QtCore.Qt.UserRole), ImageFilenames):
@ -485,14 +488,14 @@ class ImageMediaItem(MediaManagerItem):
``target`` ``target``
This contains the QTreeWidget that is the target of the DnD action This contains the QTreeWidget that is the target of the DnD action
""" """
items_to_move = self.listView.selectedItems() items_to_move = self.list_view.selectedItems()
# Determine group to move images to # Determine group to move images to
target_group = target target_group = target
if target_group is not None and isinstance(target_group.data(0, QtCore.Qt.UserRole), ImageFilenames): if target_group is not None and isinstance(target_group.data(0, QtCore.Qt.UserRole), ImageFilenames):
target_group = target.parent() target_group = target.parent()
# Move to toplevel # Move to toplevel
if target_group is None: if target_group is None:
target_group = self.listView.invisibleRootItem() target_group = self.list_view.invisibleRootItem()
target_group.setData(0, QtCore.Qt.UserRole, ImageGroups()) target_group.setData(0, QtCore.Qt.UserRole, ImageGroups())
target_group.data(0, QtCore.Qt.UserRole).id = 0 target_group.data(0, QtCore.Qt.UserRole).id = 0
# Move images in the treeview # Move images in the treeview
@ -502,7 +505,7 @@ class ImageMediaItem(MediaManagerItem):
if isinstance(item.parent(), QtGui.QTreeWidgetItem): if isinstance(item.parent(), QtGui.QTreeWidgetItem):
item.parent().removeChild(item) item.parent().removeChild(item)
else: else:
self.listView.invisibleRootItem().removeChild(item) self.list_view.invisibleRootItem().removeChild(item)
target_group.addChild(item) target_group.addChild(item)
item.setSelected(True) item.setSelected(True)
item_data = item.data(0, QtCore.Qt.UserRole) item_data = item.data(0, QtCore.Qt.UserRole)
@ -524,13 +527,16 @@ class ImageMediaItem(MediaManagerItem):
image_items.sort(cmp=locale_compare, key=lambda item: item.text(0)) image_items.sort(cmp=locale_compare, key=lambda item: item.text(0))
target_group.addChildren(image_items) target_group.addChildren(image_items)
def generateSlideData(self, service_item, item=None, xmlVersion=False, def generate_slide_data(self, service_item, item=None, xmlVersion=False,
remote=False, context=ServiceItemContext.Service): remote=False, context=ServiceItemContext.Service):
"""
Generate the slide data. Needs to be implemented by the plugin.
"""
background = QtGui.QColor(Settings().value(self.settings_section + u'/background color')) background = QtGui.QColor(Settings().value(self.settings_section + u'/background color'))
if item: if item:
items = [item] items = [item]
else: else:
items = self.listView.selectedItems() items = self.list_view.selectedItems()
if not items: if not items:
return False return False
# Determine service item title # Determine service item title
@ -605,7 +611,7 @@ class ImageMediaItem(MediaManagerItem):
""" """
# Find out if a group must be pre-selected # Find out if a group must be pre-selected
preselect_group = 0 preselect_group = 0
selected_items = self.listView.selectedItems() selected_items = self.list_view.selectedItems()
if selected_items: if selected_items:
selected_item = selected_items[0] selected_item = selected_items[0]
if isinstance(selected_item.data(0, QtCore.Qt.UserRole), ImageFilenames): if isinstance(selected_item.data(0, QtCore.Qt.UserRole), ImageFilenames):
@ -649,10 +655,10 @@ class ImageMediaItem(MediaManagerItem):
""" """
Called to replace Live backgound with the image selected. Called to replace Live backgound with the image selected.
""" """
if check_item_selected(self.listView, if check_item_selected(self.list_view,
translate('ImagePlugin.MediaItem', 'You must select an image to replace the background with.')): translate('ImagePlugin.MediaItem', 'You must select an image to replace the background with.')):
background = QtGui.QColor(Settings().value(self.settings_section + u'/background color')) background = QtGui.QColor(Settings().value(self.settings_section + u'/background color'))
bitem = self.listView.selectedItems()[0] bitem = self.list_view.selectedItems()[0]
if not isinstance(bitem.data(0, QtCore.Qt.UserRole), ImageFilenames): if not isinstance(bitem.data(0, QtCore.Qt.UserRole), ImageFilenames):
# Only continue when an image is selected # Only continue when an image is selected
return return

View File

@ -58,7 +58,7 @@ class MediaMediaItem(MediaManagerItem):
self.background = False self.background = False
self.automatic = u'' self.automatic = u''
MediaManagerItem.__init__(self, parent, plugin) MediaManagerItem.__init__(self, parent, plugin)
self.singleServiceItem = False self.single_service_item = False
self.hasSearch = True self.hasSearch = True
self.media_object = None self.media_object = None
self.display_controller = DisplayController(parent) self.display_controller = DisplayController(parent)
@ -75,10 +75,10 @@ class MediaMediaItem(MediaManagerItem):
Registry().register_function(u'mediaitem_media_rebuild', self.rebuild_players) Registry().register_function(u'mediaitem_media_rebuild', self.rebuild_players)
Registry().register_function(u'config_screen_changed', self.display_setup) Registry().register_function(u'config_screen_changed', self.display_setup)
# Allow DnD from the desktop # Allow DnD from the desktop
self.listView.activateDnD() self.list_view.activateDnD()
def retranslateUi(self): def retranslateUi(self):
self.onNewPrompt = translate('MediaPlugin.MediaItem', 'Select Media') self.on_new_prompt = translate('MediaPlugin.MediaItem', 'Select Media')
self.replaceAction.setText(UiStrings().ReplaceBG) self.replaceAction.setText(UiStrings().ReplaceBG)
self.replaceAction.setToolTip(UiStrings().ReplaceLiveBG) self.replaceAction.setToolTip(UiStrings().ReplaceLiveBG)
self.resetAction.setText(UiStrings().ResetBG) self.resetAction.setText(UiStrings().ResetBG)
@ -87,17 +87,20 @@ class MediaMediaItem(MediaManagerItem):
self.displayTypeLabel.setText(translate('MediaPlugin.MediaItem', 'Use Player:')) self.displayTypeLabel.setText(translate('MediaPlugin.MediaItem', 'Use Player:'))
self.rebuild_players() self.rebuild_players()
def requiredIcons(self): def required_icons(self):
MediaManagerItem.requiredIcons(self) """
self.hasFileIcon = True Set which icons the media manager tab should show
self.hasNewIcon = False """
self.hasEditIcon = False MediaManagerItem.required_icons(self)
self.has_file_icon = True
self.has_new_icon = False
self.has_edit_icon = False
def addListViewToToolBar(self): def add_list_view_to_toolbar(self):
MediaManagerItem.addListViewToToolBar(self) MediaManagerItem.add_list_view_to_toolbar(self)
self.listView.addAction(self.replaceAction) self.list_view.addAction(self.replaceAction)
def addEndHeaderBar(self): def add_end_header_bar(self):
# Replace backgrounds do not work at present so remove functionality. # Replace backgrounds do not work at present so remove functionality.
self.replaceAction = self.toolbar.add_toolbar_action(u'replaceAction', icon=u':/slides/slide_blank.png', self.replaceAction = self.toolbar.add_toolbar_action(u'replaceAction', icon=u':/slides/slide_blank.png',
triggers=self.onReplaceClick) triggers=self.onReplaceClick)
@ -114,7 +117,7 @@ class MediaMediaItem(MediaManagerItem):
self.displayTypeLabel.setBuddy(self.displayTypeComboBox) self.displayTypeLabel.setBuddy(self.displayTypeComboBox)
self.displayLayout.addRow(self.displayTypeLabel, self.displayTypeComboBox) self.displayLayout.addRow(self.displayTypeLabel, self.displayTypeComboBox)
# Add the Media widget to the page layout # Add the Media widget to the page layout
self.pageLayout.addWidget(self.mediaWidget) self.page_layout.addWidget(self.mediaWidget)
self.displayTypeComboBox.currentIndexChanged.connect(self.overridePlayerChanged) self.displayTypeComboBox.currentIndexChanged.connect(self.overridePlayerChanged)
def overridePlayerChanged(self, index): def overridePlayerChanged(self, index):
@ -141,9 +144,9 @@ class MediaMediaItem(MediaManagerItem):
""" """
Called to replace Live background with the media selected. Called to replace Live background with the media selected.
""" """
if check_item_selected(self.listView, if check_item_selected(self.list_view,
translate('MediaPlugin.MediaItem', 'You must select a media file to replace the background with.')): translate('MediaPlugin.MediaItem', 'You must select a media file to replace the background with.')):
item = self.listView.currentItem() item = self.list_view.currentItem()
filename = item.data(QtCore.Qt.UserRole) filename = item.data(QtCore.Qt.UserRole)
if os.path.exists(filename): if os.path.exists(filename):
service_item = ServiceItem() service_item = ServiceItem()
@ -161,10 +164,13 @@ class MediaMediaItem(MediaManagerItem):
translate('MediaPlugin.MediaItem', translate('MediaPlugin.MediaItem',
'There was a problem replacing your background, the media file "%s" no longer exists.') % filename) 'There was a problem replacing your background, the media file "%s" no longer exists.') % filename)
def generateSlideData(self, service_item, item=None, xmlVersion=False, remote=False, def generate_slide_data(self, service_item, item=None, xmlVersion=False, remote=False,
context=ServiceItemContext.Live): context=ServiceItemContext.Live):
"""
Generate the slide data. Needs to be implemented by the plugin.
"""
if item is None: if item is None:
item = self.listView.currentItem() item = self.list_view.currentItem()
if item is None: if item is None:
return False return False
filename = item.data(QtCore.Qt.UserRole) filename = item.data(QtCore.Qt.UserRole)
@ -194,11 +200,11 @@ class MediaMediaItem(MediaManagerItem):
return True return True
def initialise(self): def initialise(self):
self.listView.clear() self.list_view.clear()
self.listView.setIconSize(QtCore.QSize(88, 50)) self.list_view.setIconSize(QtCore.QSize(88, 50))
self.servicePath = os.path.join(AppLocation.get_section_data_path(self.settings_section), u'thumbnails') self.servicePath = os.path.join(AppLocation.get_section_data_path(self.settings_section), u'thumbnails')
check_directory_exists(self.servicePath) check_directory_exists(self.servicePath)
self.loadList(Settings().value(self.settings_section + u'/media files')) self.load_list(Settings().value(self.settings_section + u'/media files'))
self.populateDisplayTypes() self.populateDisplayTypes()
def rebuild_players(self): def rebuild_players(self):
@ -207,7 +213,7 @@ class MediaMediaItem(MediaManagerItem):
the settings the settings
""" """
self.populateDisplayTypes() self.populateDisplayTypes()
self.onNewFileMasks = translate('MediaPlugin.MediaItem', 'Videos (%s);;Audio (%s);;%s (*)') % ( self.on_new_file_masks = translate('MediaPlugin.MediaItem', 'Videos (%s);;Audio (%s);;%s (*)') % (
u' '.join(self.media_controller.video_extensions_list), u' '.join(self.media_controller.video_extensions_list),
u' '.join(self.media_controller.audio_extensions_list), UiStrings().AllFiles) u' '.join(self.media_controller.audio_extensions_list), UiStrings().AllFiles)
@ -240,19 +246,19 @@ class MediaMediaItem(MediaManagerItem):
self.mediaWidget.hide() self.mediaWidget.hide()
self.displayTypeComboBox.blockSignals(False) self.displayTypeComboBox.blockSignals(False)
def onDeleteClick(self): def on_delete_click(self):
""" """
Remove a media item from the list. Remove a media item from the list.
""" """
if check_item_selected(self.listView, if check_item_selected(self.list_view,
translate('MediaPlugin.MediaItem', 'You must select a media file to delete.')): translate('MediaPlugin.MediaItem', 'You must select a media file to delete.')):
row_list = [item.row() for item in self.listView.selectedIndexes()] row_list = [item.row() for item in self.list_view.selectedIndexes()]
row_list.sort(reverse=True) row_list.sort(reverse=True)
for row in row_list: for row in row_list:
self.listView.takeItem(row) self.list_view.takeItem(row)
Settings().setValue(self.settings_section + u'/media files', self.getFileList()) Settings().setValue(self.settings_section + u'/media files', self.get_file_list())
def loadList(self, media, target_group=None): def load_list(self, media, target_group=None):
# Sort the media by its filename considering language specific # Sort the media by its filename considering language specific
# characters. # characters.
media.sort(cmp=locale_compare, key=lambda filename: os.path.split(unicode(filename))[1]) media.sort(cmp=locale_compare, key=lambda filename: os.path.split(unicode(filename))[1])
@ -277,7 +283,7 @@ class MediaMediaItem(MediaManagerItem):
item_name.setIcon(build_icon(DVDICON)) item_name.setIcon(build_icon(DVDICON))
item_name.setData(QtCore.Qt.UserRole, track) item_name.setData(QtCore.Qt.UserRole, track)
item_name.setToolTip(track) item_name.setToolTip(track)
self.listView.addItem(item_name) self.list_view.addItem(item_name)
def getList(self, type=MediaType.Audio): def getList(self, type=MediaType.Audio):
media = Settings().value(self.settings_section + u'/media files') media = Settings().value(self.settings_section + u'/media files')

View File

@ -59,17 +59,17 @@ class PresentationMediaItem(MediaManagerItem):
MediaManagerItem.__init__(self, parent, plugin) MediaManagerItem.__init__(self, parent, plugin)
self.message_listener = MessageListener(self) self.message_listener = MessageListener(self)
self.hasSearch = True self.hasSearch = True
self.singleServiceItem = False self.single_service_item = False
Registry().register_function(u'mediaitem_presentation_rebuild', self.populate_display_types) Registry().register_function(u'mediaitem_presentation_rebuild', self.populate_display_types)
Registry().register_function(u'mediaitem_suffixes', self.build_file_mask_string) Registry().register_function(u'mediaitem_suffixes', self.build_file_mask_string)
# Allow DnD from the desktop # Allow DnD from the desktop
self.listView.activateDnD() self.list_view.activateDnD()
def retranslateUi(self): def retranslateUi(self):
""" """
The name of the plugin media displayed in UI The name of the plugin media displayed in UI
""" """
self.onNewPrompt = translate('PresentationPlugin.MediaItem', 'Select Presentation(s)') self.on_new_prompt = translate('PresentationPlugin.MediaItem', 'Select Presentation(s)')
self.Automatic = translate('PresentationPlugin.MediaItem', 'Automatic') self.Automatic = translate('PresentationPlugin.MediaItem', 'Automatic')
self.displayTypeLabel.setText(translate('PresentationPlugin.MediaItem', 'Present using:')) self.displayTypeLabel.setText(translate('PresentationPlugin.MediaItem', 'Present using:'))
@ -85,18 +85,18 @@ class PresentationMediaItem(MediaManagerItem):
if fileType.find(type) == -1: if fileType.find(type) == -1:
fileType += u'*.%s ' % type fileType += u'*.%s ' % type
self.service_manager.supported_suffixes(type) self.service_manager.supported_suffixes(type)
self.onNewFileMasks = translate('PresentationPlugin.MediaItem', 'Presentations (%s)') % fileType self.on_new_file_masks = translate('PresentationPlugin.MediaItem', 'Presentations (%s)') % fileType
def requiredIcons(self): def required_icons(self):
""" """
Set which icons the media manager tab should show Set which icons the media manager tab should show
""" """
MediaManagerItem.requiredIcons(self) MediaManagerItem.required_icons(self)
self.hasFileIcon = True self.has_file_icon = True
self.hasNewIcon = False self.has_new_icon = False
self.hasEditIcon = False self.has_edit_icon = False
def addEndHeaderBar(self): def add_end_header_bar(self):
""" """
Display custom media manager items for presentations Display custom media manager items for presentations
""" """
@ -112,15 +112,15 @@ class PresentationMediaItem(MediaManagerItem):
self.displayTypeLabel.setBuddy(self.displayTypeComboBox) self.displayTypeLabel.setBuddy(self.displayTypeComboBox)
self.displayLayout.addRow(self.displayTypeLabel, self.displayTypeComboBox) self.displayLayout.addRow(self.displayTypeLabel, self.displayTypeComboBox)
# Add the Presentation widget to the page layout # Add the Presentation widget to the page layout
self.pageLayout.addWidget(self.presentationWidget) self.page_layout.addWidget(self.presentationWidget)
def initialise(self): def initialise(self):
""" """
Populate the media manager tab Populate the media manager tab
""" """
self.listView.setIconSize(QtCore.QSize(88, 50)) self.list_view.setIconSize(QtCore.QSize(88, 50))
files = Settings().value(self.settings_section + u'/presentations files') files = Settings().value(self.settings_section + u'/presentations files')
self.loadList(files, initialLoad=True) self.load_list(files, initialLoad=True)
self.populate_display_types() self.populate_display_types()
def populate_display_types(self): def populate_display_types(self):
@ -141,13 +141,13 @@ class PresentationMediaItem(MediaManagerItem):
else: else:
self.presentationWidget.hide() self.presentationWidget.hide()
def loadList(self, files, target_group=None, initialLoad=False): def load_list(self, files, target_group=None, initialLoad=False):
""" """
Add presentations into the media manager Add presentations into the media manager
This is called both on initial load of the plugin to populate with This is called both on initial load of the plugin to populate with
existing files, and when the user adds new files via the media manager existing files, and when the user adds new files via the media manager
""" """
currlist = self.getFileList() currlist = self.get_file_list()
titles = [os.path.split(file)[1] for file in currlist] titles = [os.path.split(file)[1] for file in currlist]
self.application.set_busy_cursor() self.application.set_busy_cursor()
if not initialLoad: if not initialLoad:
@ -166,7 +166,7 @@ class PresentationMediaItem(MediaManagerItem):
item_name.setIcon(build_icon(ERROR)) item_name.setIcon(build_icon(ERROR))
item_name.setData(QtCore.Qt.UserRole, file) item_name.setData(QtCore.Qt.UserRole, file)
item_name.setToolTip(file) item_name.setToolTip(file)
self.listView.addItem(item_name) self.list_view.addItem(item_name)
else: else:
if titles.count(filename) > 0: if titles.count(filename) > 0:
if not initialLoad: if not initialLoad:
@ -203,17 +203,17 @@ class PresentationMediaItem(MediaManagerItem):
item_name.setData(QtCore.Qt.UserRole, file) item_name.setData(QtCore.Qt.UserRole, file)
item_name.setIcon(icon) item_name.setIcon(icon)
item_name.setToolTip(file) item_name.setToolTip(file)
self.listView.addItem(item_name) self.list_view.addItem(item_name)
if not initialLoad: if not initialLoad:
self.main_window.finished_progress_bar() self.main_window.finished_progress_bar()
self.application.set_normal_cursor() self.application.set_normal_cursor()
def onDeleteClick(self): def on_delete_click(self):
""" """
Remove a presentation item from the list Remove a presentation item from the list
""" """
if check_item_selected(self.listView, UiStrings().SelectDelete): if check_item_selected(self.list_view, UiStrings().SelectDelete):
items = self.listView.selectedIndexes() items = self.list_view.selectedIndexes()
row_list = [item.row() for item in items] row_list = [item.row() for item in items]
row_list.sort(reverse=True) row_list.sort(reverse=True)
self.application.set_busy_cursor() self.application.set_busy_cursor()
@ -228,10 +228,10 @@ class PresentationMediaItem(MediaManagerItem):
self.main_window.finished_progress_bar() self.main_window.finished_progress_bar()
self.application.set_busy_cursor() self.application.set_busy_cursor()
for row in row_list: for row in row_list:
self.listView.takeItem(row) self.list_view.takeItem(row)
Settings().setValue(self.settings_section + u'/presentations files', self.getFileList()) Settings().setValue(self.settings_section + u'/presentations files', self.get_file_list())
def generateSlideData(self, service_item, item=None, xmlVersion=False, def generate_slide_data(self, service_item, item=None, xmlVersion=False,
remote=False, context=ServiceItemContext.Service): remote=False, context=ServiceItemContext.Service):
""" """
Load the relevant information for displaying the presentation Load the relevant information for displaying the presentation
@ -241,7 +241,7 @@ class PresentationMediaItem(MediaManagerItem):
if item: if item:
items = [item] items = [item]
else: else:
items = self.listView.selectedItems() items = self.list_view.selectedItems()
if len(items) > 1: if len(items) > 1:
return False return False
service_item.title = self.displayTypeComboBox.currentText() service_item.title = self.displayTypeComboBox.currentText()

View File

@ -525,7 +525,7 @@ class HttpConnection(object):
return HttpResponse(code=u'400 Bad Request') return HttpResponse(code=u'400 Bad Request')
plugin = self.plugin_manager.get_plugin_by_name(plugin_name) plugin = self.plugin_manager.get_plugin_by_name(plugin_name)
if plugin.status == PluginStatus.Active and plugin.media_item: if plugin.status == PluginStatus.Active and plugin.media_item:
plugin.media_item.goLive(id, remote=True) plugin.media_item.go_live(id, remote=True)
return HttpResponse(code=u'200 OK') return HttpResponse(code=u'200 OK')
def add_to_service(self, plugin_name): def add_to_service(self, plugin_name):
@ -539,7 +539,7 @@ class HttpConnection(object):
plugin = self.plugin_manager.get_plugin_by_name(plugin_name) plugin = self.plugin_manager.get_plugin_by_name(plugin_name)
if plugin.status == PluginStatus.Active and plugin.media_item: if plugin.status == PluginStatus.Active and plugin.media_item:
item_id = plugin.media_item.createItemFromId(id) item_id = plugin.media_item.createItemFromId(id)
plugin.media_item.addToService(item_id, remote=True) plugin.media_item.add_to_service(item_id, remote=True)
return HttpResponse(code=u'200 OK') return HttpResponse(code=u'200 OK')
def send_response(self, response): def send_response(self, response):

View File

@ -74,13 +74,13 @@ class SongMediaItem(MediaManagerItem):
MediaManagerItem.__init__(self, parent, plugin) MediaManagerItem.__init__(self, parent, plugin)
self.editSongForm = EditSongForm(self, self.main_window, self.plugin.manager) self.editSongForm = EditSongForm(self, self.main_window, self.plugin.manager)
self.openLyrics = OpenLyrics(self.plugin.manager) self.openLyrics = OpenLyrics(self.plugin.manager)
self.singleServiceItem = False self.single_service_item = False
self.songMaintenanceForm = SongMaintenanceForm(self.plugin.manager, self) self.songMaintenanceForm = SongMaintenanceForm(self.plugin.manager, self)
# Holds information about whether the edit is remotely triggered and # Holds information about whether the edit is remotely triggered and
# which Song is required. # which Song is required.
self.remoteSong = -1 self.remoteSong = -1
self.editItem = None self.editItem = None
self.quickPreviewAllowed = True self.quick_preview_allowed = True
self.hasSearch = True self.hasSearch = True
def _updateBackgroundAudio(self, song, item): def _updateBackgroundAudio(self, song, item):
@ -95,28 +95,28 @@ class SongMediaItem(MediaManagerItem):
weight=i, file_name=dest_file)) weight=i, file_name=dest_file))
self.plugin.manager.save_object(song, True) self.plugin.manager.save_object(song, True)
def addEndHeaderBar(self): def add_end_header_bar(self):
self.toolbar.addSeparator() self.toolbar.addSeparator()
## Song Maintenance Button ## ## Song Maintenance Button ##
self.maintenanceAction = self.toolbar.add_toolbar_action('maintenanceAction', self.maintenanceAction = self.toolbar.add_toolbar_action('maintenanceAction',
icon=':/songs/song_maintenance.png', icon=':/songs/song_maintenance.png',
triggers=self.onSongMaintenanceClick) triggers=self.onSongMaintenanceClick)
self.addSearchToToolBar() self.add_search_to_toolbar()
# Signals and slots # Signals and slots
Registry().register_function(u'songs_load_list', self.on_song_list_load) Registry().register_function(u'songs_load_list', self.on_song_list_load)
Registry().register_function(u'songs_preview', self.onPreviewClick) Registry().register_function(u'songs_preview', self.on_preview_click)
QtCore.QObject.connect(self.searchTextEdit, QtCore.SIGNAL(u'cleared()'), self.onClearTextButtonClick) QtCore.QObject.connect(self.search_text_edit, QtCore.SIGNAL(u'cleared()'), self.onClearTextButtonClick)
QtCore.QObject.connect(self.searchTextEdit, QtCore.SIGNAL(u'searchTypeChanged(int)'), QtCore.QObject.connect(self.search_text_edit, QtCore.SIGNAL(u'searchTypeChanged(int)'),
self.onSearchTextButtonClicked) self.on_search_text_button_clicked)
def addCustomContextActions(self): def add_custom_context_actions(self):
create_widget_action(self.listView, separator=True) create_widget_action(self.list_view, separator=True)
create_widget_action(self.listView, create_widget_action(self.list_view,
text=translate('OpenLP.MediaManagerItem', '&Clone'), icon=u':/general/general_clone.png', text=translate('OpenLP.MediaManagerItem', '&Clone'), icon=u':/general/general_clone.png',
triggers=self.onCloneClick) triggers=self.onCloneClick)
def onFocus(self): def onFocus(self):
self.searchTextEdit.setFocus() self.search_text_edit.setFocus()
def config_update(self): def config_update(self):
""" """
@ -128,14 +128,14 @@ class SongMediaItem(MediaManagerItem):
self.addSongFromService = Settings().value(self.settings_section + u'/add song from service',) self.addSongFromService = Settings().value(self.settings_section + u'/add song from service',)
def retranslateUi(self): def retranslateUi(self):
self.searchTextLabel.setText(u'%s:' % UiStrings().Search) self.search_text_label.setText(u'%s:' % UiStrings().Search)
self.searchTextButton.setText(UiStrings().Search) self.search_text_button.setText(UiStrings().Search)
self.maintenanceAction.setText(SongStrings.SongMaintenance) self.maintenanceAction.setText(SongStrings.SongMaintenance)
self.maintenanceAction.setToolTip(translate('SongsPlugin.MediaItem', self.maintenanceAction.setToolTip(translate('SongsPlugin.MediaItem',
'Maintain the lists of authors, topics and books.')) 'Maintain the lists of authors, topics and books.'))
def initialise(self): def initialise(self):
self.searchTextEdit.set_search_types([ self.search_text_edit.set_search_types([
(SongSearch.Entire, u':/songs/song_search_all.png', (SongSearch.Entire, u':/songs/song_search_all.png',
translate('SongsPlugin.MediaItem', 'Entire Song'), translate('SongsPlugin.MediaItem', 'Entire Song'),
translate('SongsPlugin.MediaItem', 'Search Entire Song...')), translate('SongsPlugin.MediaItem', 'Search Entire Song...')),
@ -152,16 +152,16 @@ class SongMediaItem(MediaManagerItem):
(SongSearch.Themes, u':/slides/slide_theme.png', (SongSearch.Themes, u':/slides/slide_theme.png',
UiStrings().Themes, UiStrings().SearchThemes) UiStrings().Themes, UiStrings().SearchThemes)
]) ])
self.searchTextEdit.set_current_search_type(Settings().value(u'%s/last search type' % self.settings_section)) self.search_text_edit.set_current_search_type(Settings().value(u'%s/last search type' % self.settings_section))
self.config_update() self.config_update()
def onSearchTextButtonClicked(self): def on_search_text_button_clicked(self):
# Save the current search type to the configuration. # Save the current search type to the configuration.
Settings().setValue(u'%s/last search type' % self.settings_section, self.searchTextEdit.current_search_type()) Settings().setValue(u'%s/last search type' % self.settings_section, self.search_text_edit.current_search_type())
# Reload the list considering the new search type. # Reload the list considering the new search type.
search_keywords = unicode(self.searchTextEdit.displayText()) search_keywords = unicode(self.search_text_edit.displayText())
search_results = [] search_results = []
search_type = self.searchTextEdit.current_search_type() search_type = self.search_text_edit.current_search_type()
if search_type == SongSearch.Entire: if search_type == SongSearch.Entire:
log.debug(u'Entire Song Search') log.debug(u'Entire Song Search')
search_results = self.searchEntire(search_keywords) search_results = self.searchEntire(search_keywords)
@ -197,7 +197,7 @@ class SongMediaItem(MediaManagerItem):
search_results = self.plugin.manager.get_all_objects(Song, search_results = self.plugin.manager.get_all_objects(Song,
Song.theme_name.like(u'%' + search_keywords + u'%')) Song.theme_name.like(u'%' + search_keywords + u'%'))
self.displayResultsSong(search_results) self.displayResultsSong(search_results)
self.checkSearchResult() self.check_search_result()
def searchEntire(self, search_keywords): def searchEntire(self, search_keywords):
return self.plugin.manager.get_all_objects(Song, return self.plugin.manager.get_all_objects(Song,
@ -215,16 +215,16 @@ class SongMediaItem(MediaManagerItem):
# or from the exit of the Song edit dialog. If remote editing is active # or from the exit of the Song edit dialog. If remote editing is active
# Trigger it and clean up so it will not update again. # Trigger it and clean up so it will not update again.
# Push edits to the service manager to update items # Push edits to the service manager to update items
if self.editItem and self.updateServiceOnEdit and not self.remoteTriggered: if self.editItem and self.updateServiceOnEdit and not self.remote_triggered:
item = self.buildServiceItem(self.editItem) item = self.build_service_item(self.editItem)
self.service_manager.replace_service_item(item) self.service_manager.replace_service_item(item)
self.onSearchTextButtonClicked() self.on_search_text_button_clicked()
log.debug(u'on_song_list_load - finished') log.debug(u'on_song_list_load - finished')
def displayResultsSong(self, searchresults): def displayResultsSong(self, searchresults):
log.debug(u'display results Song') log.debug(u'display results Song')
self.saveAutoSelectId() self.save_auto_select_id()
self.listView.clear() self.list_view.clear()
searchresults.sort(cmp=natcmp, key=lambda song: song.sort_key) searchresults.sort(cmp=natcmp, key=lambda song: song.sort_key)
for song in searchresults: for song in searchresults:
# Do not display temporary songs # Do not display temporary songs
@ -235,15 +235,15 @@ class SongMediaItem(MediaManagerItem):
song_detail = u'%s (%s)' % (song_title, create_separated_list(author_list)) song_detail = u'%s (%s)' % (song_title, create_separated_list(author_list))
song_name = QtGui.QListWidgetItem(song_detail) song_name = QtGui.QListWidgetItem(song_detail)
song_name.setData(QtCore.Qt.UserRole, song.id) song_name.setData(QtCore.Qt.UserRole, song.id)
self.listView.addItem(song_name) self.list_view.addItem(song_name)
# Auto-select the item if name has been set # Auto-select the item if name has been set
if song.id == self.autoSelectId: if song.id == self.autoSelectId:
self.listView.setCurrentItem(song_name) self.list_view.setCurrentItem(song_name)
self.autoSelectId = -1 self.autoSelectId = -1
def displayResultsAuthor(self, searchresults): def displayResultsAuthor(self, searchresults):
log.debug(u'display results Author') log.debug(u'display results Author')
self.listView.clear() self.list_view.clear()
for author in searchresults: for author in searchresults:
for song in author.songs: for song in author.songs:
# Do not display temporary songs # Do not display temporary songs
@ -252,11 +252,11 @@ class SongMediaItem(MediaManagerItem):
song_detail = u'%s (%s)' % (author.display_name, song.title) song_detail = u'%s (%s)' % (author.display_name, song.title)
song_name = QtGui.QListWidgetItem(song_detail) song_name = QtGui.QListWidgetItem(song_detail)
song_name.setData(QtCore.Qt.UserRole, song.id) song_name.setData(QtCore.Qt.UserRole, song.id)
self.listView.addItem(song_name) self.list_view.addItem(song_name)
def displayResultsBook(self, searchresults, song_number=False): def displayResultsBook(self, searchresults, song_number=False):
log.debug(u'display results Book') log.debug(u'display results Book')
self.listView.clear() self.list_view.clear()
for book in searchresults: for book in searchresults:
songs = sorted(book.songs, key=lambda song: songs = sorted(book.songs, key=lambda song:
int(re.match(r'[0-9]+', u'0' + song.song_number).group())) int(re.match(r'[0-9]+', u'0' + song.song_number).group()))
@ -269,16 +269,16 @@ class SongMediaItem(MediaManagerItem):
song_detail = u'%s - %s (%s)' % (book.name, song.song_number, song.title) song_detail = u'%s - %s (%s)' % (book.name, song.song_number, song.title)
song_name = QtGui.QListWidgetItem(song_detail) song_name = QtGui.QListWidgetItem(song_detail)
song_name.setData(QtCore.Qt.UserRole, song.id) song_name.setData(QtCore.Qt.UserRole, song.id)
self.listView.addItem(song_name) self.list_view.addItem(song_name)
def onClearTextButtonClick(self): def onClearTextButtonClick(self):
""" """
Clear the search text. Clear the search text.
""" """
self.searchTextEdit.clear() self.search_text_edit.clear()
self.onSearchTextButtonClicked() self.on_search_text_button_clicked()
def onSearchTextEditChanged(self, text): def on_search_text_edit_changed(self, text):
""" """
If search as type enabled invoke the search on each key press. If search as type enabled invoke the search on each key press.
If the Lyrics are being searched do not start till 7 characters If the Lyrics are being searched do not start till 7 characters
@ -286,12 +286,12 @@ class SongMediaItem(MediaManagerItem):
""" """
if self.searchAsYouType: if self.searchAsYouType:
search_length = 1 search_length = 1
if self.searchTextEdit.current_search_type() == SongSearch.Entire: if self.search_text_edit.current_search_type() == SongSearch.Entire:
search_length = 4 search_length = 4
elif self.searchTextEdit.current_search_type() == SongSearch.Lyrics: elif self.search_text_edit.current_search_type() == SongSearch.Lyrics:
search_length = 3 search_length = 3
if len(text) > search_length: if len(text) > search_length:
self.onSearchTextButtonClicked() self.on_search_text_button_clicked()
elif not text: elif not text:
self.onClearTextButtonClick() self.onClearTextButtonClick()
@ -307,12 +307,12 @@ class SongMediaItem(MediaManagerItem):
self.exportWizard = SongExportForm(self, self.plugin) self.exportWizard = SongExportForm(self, self.plugin)
self.exportWizard.exec_() self.exportWizard.exec_()
def onNewClick(self): def on_new_click(self):
log.debug(u'onNewClick') log.debug(u'on_new_click')
self.editSongForm.new_song() self.editSongForm.new_song()
self.editSongForm.exec_() self.editSongForm.exec_()
self.onClearTextButtonClick() self.onClearTextButtonClick()
self.onSelectionChange() self.on_selection_change()
self.autoSelectId = -1 self.autoSelectId = -1
def onSongMaintenanceClick(self): def onSongMaintenanceClick(self):
@ -333,21 +333,21 @@ class SongMediaItem(MediaManagerItem):
self.autoSelectId = -1 self.autoSelectId = -1
self.on_song_list_load() self.on_song_list_load()
self.remoteSong = song_id self.remoteSong = song_id
self.remoteTriggered = True self.remote_triggered = True
item = self.buildServiceItem(remote=True) item = self.build_service_item(remote=True)
self.remoteSong = -1 self.remoteSong = -1
self.remoteTriggered = None self.remote_triggered = None
if item: if item:
return item return item
return None return None
def onEditClick(self): def on_edit_click(self):
""" """
Edit a song Edit a song
""" """
log.debug(u'onEditClick') log.debug(u'on_edit_click')
if check_item_selected(self.listView, UiStrings().SelectEdit): if check_item_selected(self.list_view, UiStrings().SelectEdit):
self.editItem = self.listView.currentItem() self.editItem = self.list_view.currentItem()
item_id = self.editItem.data(QtCore.Qt.UserRole) item_id = self.editItem.data(QtCore.Qt.UserRole)
self.editSongForm.load_song(item_id, False) self.editSongForm.load_song(item_id, False)
self.editSongForm.exec_() self.editSongForm.exec_()
@ -355,12 +355,12 @@ class SongMediaItem(MediaManagerItem):
self.on_song_list_load() self.on_song_list_load()
self.editItem = None self.editItem = None
def onDeleteClick(self): def on_delete_click(self):
""" """
Remove a song from the list and database Remove a song from the list and database
""" """
if check_item_selected(self.listView, UiStrings().SelectDelete): if check_item_selected(self.list_view, UiStrings().SelectDelete):
items = self.listView.selectedIndexes() items = self.list_view.selectedIndexes()
if QtGui.QMessageBox.question(self, if QtGui.QMessageBox.question(self,
UiStrings().ConfirmDelete, UiStrings().ConfirmDelete,
translate('SongsPlugin.MediaItem', 'Are you sure you want to delete the %n selected song(s)?', '', translate('SongsPlugin.MediaItem', 'Are you sure you want to delete the %n selected song(s)?', '',
@ -388,15 +388,15 @@ class SongMediaItem(MediaManagerItem):
self.main_window.increment_progress_bar() self.main_window.increment_progress_bar()
self.main_window.finished_progress_bar() self.main_window.finished_progress_bar()
self.application.set_normal_cursor() self.application.set_normal_cursor()
self.onSearchTextButtonClicked() self.on_search_text_button_clicked()
def onCloneClick(self): def onCloneClick(self):
""" """
Clone a Song Clone a Song
""" """
log.debug(u'onCloneClick') log.debug(u'onCloneClick')
if check_item_selected(self.listView, UiStrings().SelectEdit): if check_item_selected(self.list_view, UiStrings().SelectEdit):
self.editItem = self.listView.currentItem() self.editItem = self.list_view.currentItem()
item_id = self.editItem.data(QtCore.Qt.UserRole) item_id = self.editItem.data(QtCore.Qt.UserRole)
old_song = self.plugin.manager.get_object(Song, item_id) old_song = self.plugin.manager.get_object(Song, item_id)
song_xml = self.openLyrics.song_to_xml(old_song) song_xml = self.openLyrics.song_to_xml(old_song)
@ -406,10 +406,13 @@ class SongMediaItem(MediaManagerItem):
self.plugin.manager.save_object(new_song) self.plugin.manager.save_object(new_song)
self.on_song_list_load() self.on_song_list_load()
def generateSlideData(self, service_item, item=None, xmlVersion=False, def generate_slide_data(self, service_item, item=None, xmlVersion=False,
remote=False, context=ServiceItemContext.Service): remote=False, context=ServiceItemContext.Service):
log.debug(u'generateSlideData: %s, %s, %s' % (service_item, item, self.remoteSong)) """
item_id = self._getIdOfItemToGenerate(item, self.remoteSong) Generate the slide data. Needs to be implemented by the plugin.
"""
log.debug(u'generate_slide_data: %s, %s, %s' % (service_item, item, self.remoteSong))
item_id = self._get_id_of_item_to_generate(item, self.remoteSong)
service_item.add_capability(ItemCapabilities.CanEdit) service_item.add_capability(ItemCapabilities.CanEdit)
service_item.add_capability(ItemCapabilities.CanPreview) service_item.add_capability(ItemCapabilities.CanPreview)
service_item.add_capability(ItemCapabilities.CanLoop) service_item.add_capability(ItemCapabilities.CanLoop)
@ -478,11 +481,11 @@ class SongMediaItem(MediaManagerItem):
service_item.background_audio = [m.file_name for m in song.media_files] service_item.background_audio = [m.file_name for m in song.media_files]
return True return True
def serviceLoad(self, item): def service_load(self, item):
""" """
Triggered by a song being loaded by the service manager. Triggered by a song being loaded by the service manager.
""" """
log.debug(u'serviceLoad') log.debug(u'service_load')
if self.plugin.status != PluginStatus.Active or not item.data_string: if self.plugin.status != PluginStatus.Active or not item.data_string:
return return
if item.data_string[u'title'].find(u'@') == -1: if item.data_string[u'title'].find(u'@') == -1:
@ -522,7 +525,7 @@ class SongMediaItem(MediaManagerItem):
if item.background_audio: if item.background_audio:
self._updateBackgroundAudio(song, item) self._updateBackgroundAudio(song, item)
editId = song.id editId = song.id
self.onSearchTextButtonClicked() self.on_search_text_button_clicked()
elif add_song and not self.addSongFromService: elif add_song and not self.addSongFromService:
# Make sure we temporary import formatting tags. # Make sure we temporary import formatting tags.
song = self.openLyrics.xml_to_song(item.xml_version, True) song = self.openLyrics.xml_to_song(item.xml_version, True)

View File

@ -167,7 +167,7 @@ class SongsPlugin(Plugin):
clean_song(self.manager, song) clean_song(self.manager, song)
progress_dialog.setValue(number + 1) progress_dialog.setValue(number + 1)
self.manager.save_objects(songs) self.manager.save_objects(songs)
self.media_item.onSearchTextButtonClicked() self.media_item.on_search_text_button_clicked()
def on_song_import_item_clicked(self): def on_song_import_item_clicked(self):
if self.media_item: if self.media_item:
@ -275,7 +275,7 @@ class SongsPlugin(Plugin):
importer.doImport(progress) importer.doImport(progress)
self.application.process_events() self.application.process_events()
progress.setValue(song_count) progress.setValue(song_count)
self.media_item.onSearchTextButtonClicked() self.media_item.on_search_text_button_clicked()
def finalise(self): def finalise(self):
""" """