def load_themes(self): """ Loads the theme lists and triggers updates across the whole system using direct calls or core functions and events for the plugins. The plugins will call back in to get the real list if they want it. """ self.theme_list = [] self.theme_list_widget.clear() files = AppLocation.get_files(self.settings_section, '.png') # Sort the themes by its name considering language specific files.sort(key=lambda file_name: get_locale_key(str(file_name))) # now process the file list of png files for name in files: # check to see file is in theme root directory theme = os.path.join(self.path, name) if os.path.exists(theme): text_name = os.path.splitext(name)[0] if text_name == self.global_theme: name = translate('OpenLP.ThemeManager', '{name} (default)').format(name=text_name) else: name = text_name thumb = os.path.join(self.thumb_path, '{name}.png'.format(name=text_name)) item_name = QtWidgets.QListWidgetItem(name) if validate_thumb(theme, thumb): icon = build_icon(thumb) else: icon = create_thumb(theme, thumb) item_name.setIcon(icon) item_name.setData(QtCore.Qt.UserRole, text_name) self.theme_list_widget.addItem(item_name) self.theme_list.append(text_name) self._push_themes()
def dnd_move_internal(self, target): """ Handle drag-and-drop moving of images within the media manager :param target: This contains the QTreeWidget that is the target of the DnD action """ items_to_move = self.list_view.selectedItems() # Determine group to move images to target_group = target if target_group is not None and isinstance( target_group.data(0, QtCore.Qt.UserRole), ImageFilenames): target_group = target.parent() # Move to toplevel if target_group is None: target_group = self.list_view.invisibleRootItem() target_group.setData(0, QtCore.Qt.UserRole, ImageGroups()) target_group.data(0, QtCore.Qt.UserRole).id = 0 # Move images in the treeview items_to_save = [] for item in items_to_move: if isinstance(item.data(0, QtCore.Qt.UserRole), ImageFilenames): if isinstance(item.parent(), QtWidgets.QTreeWidgetItem): item.parent().removeChild(item) else: self.list_view.invisibleRootItem().removeChild(item) target_group.addChild(item) item.setSelected(True) item_data = item.data(0, QtCore.Qt.UserRole) item_data.group_id = target_group.data(0, QtCore.Qt.UserRole).id items_to_save.append(item_data) target_group.setExpanded(True) # Update the group ID's of the images in the database self.manager.save_objects(items_to_save) # Sort the target group group_items = [] image_items = [] for item in target_group.takeChildren(): if isinstance(item.data(0, QtCore.Qt.UserRole), ImageGroups): group_items.append(item) if isinstance(item.data(0, QtCore.Qt.UserRole), ImageFilenames): image_items.append(item) group_items.sort(key=lambda item: get_locale_key(item.text(0))) target_group.addChildren(group_items) image_items.sort(key=lambda item: get_locale_key(item.text(0))) target_group.addChildren(image_items)
def get_list(self, media_type=MediaType.Audio): """ Get the list of media, optional select media type. :param media_type: Type to get, defaults to audio. :return: The media list """ media = Settings().value(self.settings_section + '/media files') media.sort(key=lambda filename: get_locale_key(os.path.split(str(filename))[1])) if media_type == MediaType.Audio: extension = self.media_controller.audio_extensions_list else: extension = self.media_controller.video_extensions_list extension = [x[1:] for x in extension] media = [x for x in media if os.path.splitext(x)[1] in extension] return media
def load_full_list(self, images, initial_load=False, open_group=None): """ Replace the list of images and groups in the interface. :param images: A List of Image Filenames objects that will be used to reload the mediamanager list. :param initial_load: When set to False, the busy cursor and progressbar will be shown while loading images. :param open_group: ImageGroups object of the group that must be expanded after reloading the list in the interface. """ if not initial_load: self.application.set_busy_cursor() self.main_window.display_progress_bar(len(images)) self.list_view.clear() # Load the list of groups and add them to the treeView. group_items = {} self.add_sub_groups(group_items, parent_group_id=0) if open_group is not None: self.expand_group(open_group.id) # Sort the images by its filename considering language specific. # characters. images.sort(key=lambda image_object: get_locale_key( os.path.split(str(image_object.filename))[1])) for image_file in images: log.debug('Loading image: {name}'.format(name=image_file.filename)) filename = os.path.split(image_file.filename)[1] thumb = self.generate_thumbnail_path(image_file) if not os.path.exists(image_file.filename): icon = build_icon(':/general/general_delete.png') else: if validate_thumb(image_file.filename, thumb): icon = build_icon(thumb) else: icon = create_thumb(image_file.filename, thumb) item_name = QtWidgets.QTreeWidgetItem([filename]) item_name.setText(0, filename) item_name.setIcon(0, icon) item_name.setToolTip(0, image_file.filename) item_name.setData(0, QtCore.Qt.UserRole, image_file) if image_file.group_id == 0: self.list_view.addTopLevelItem(item_name) else: group_items[image_file.group_id].addChild(item_name) if not initial_load: self.main_window.increment_progress_bar() if not initial_load: self.main_window.finished_progress_bar() self.application.set_normal_cursor()
def get_list(self, media_type=MediaType.Audio): """ Get the list of media, optional select media type. :param media_type: Type to get, defaults to audio. :return: The media list """ media = Settings().value(self.settings_section + '/media files') media.sort(key=lambda filename: get_locale_key( os.path.split(str(filename))[1])) if media_type == MediaType.Audio: extension = self.media_controller.audio_extensions_list else: extension = self.media_controller.video_extensions_list extension = [x[1:] for x in extension] media = [x for x in media if os.path.splitext(x)[1] in extension] return media
def load_list(self, media, target_group=None): """ Load the media list :param media: The media :param target_group: """ media.sort(key=lambda file_name: get_locale_key( os.path.split(str(file_name))[1])) for track in media: track_info = QtCore.QFileInfo(track) item_name = None if track.startswith('optical:'): # Handle optical based item (file_name, title, audio_track, subtitle_track, start, end, clip_name) = parse_optical_path(track) item_name = QtWidgets.QListWidgetItem(clip_name) item_name.setIcon(self.optical_icon) item_name.setData(QtCore.Qt.UserRole, track) item_name.setToolTip('{name}@{start}-{end}'.format( name=file_name, start=format_milliseconds(start), end=format_milliseconds(end))) elif not os.path.exists(track): # File doesn't exist, mark as error. file_name = os.path.split(str(track))[1] item_name = QtWidgets.QListWidgetItem(file_name) item_name.setIcon(self.error_icon) item_name.setData(QtCore.Qt.UserRole, track) item_name.setToolTip(track) elif track_info.isFile(): # Normal media file handling. file_name = os.path.split(str(track))[1] item_name = QtWidgets.QListWidgetItem(file_name) search = file_name.split('.')[-1].lower() if '*.{text}'.format( text=search ) in self.media_controller.audio_extensions_list: item_name.setIcon(self.audio_icon) else: item_name.setIcon(self.video_icon) item_name.setData(QtCore.Qt.UserRole, track) item_name.setToolTip(track) if item_name: self.list_view.addItem(item_name)
def fill_groups_combobox(self, combobox, parent_group_id=0, prefix=''): """ Recursively add groups to the combobox in the 'Add group' dialog. :param combobox: The QComboBox to add the options to. :param parent_group_id: The ID of the group that will be added. :param prefix: A string containing the prefix that will be added in front of the groupname for each level of the tree. """ if parent_group_id == 0: combobox.clear() combobox.top_level_group_added = False image_groups = self.manager.get_all_objects( ImageGroups, ImageGroups.parent_id == parent_group_id) image_groups.sort( key=lambda group_object: get_locale_key(group_object.group_name)) for image_group in image_groups: combobox.addItem(prefix + image_group.group_name, image_group.id) self.fill_groups_combobox(combobox, image_group.id, prefix + ' ')
def populate_bible_combo_boxes(self): """ Populate the bible combo boxes with the list of bibles that have been loaded :return: None """ log.debug('Loading Bibles') self.version_combo_box.clear() self.second_combo_box.clear() self.second_combo_box.addItem('', None) # Get all bibles and sort the list. bibles = self.plugin.manager.get_bibles() bibles = [(_f, bibles[_f]) for _f in bibles if _f] bibles.sort(key=lambda k: get_locale_key(k[0])) for bible in bibles: self.version_combo_box.addItem(bible[0], bible[1]) self.second_combo_box.addItem(bible[0], bible[1]) # set the default value bible = Settings().value('{settings_section}/primary bible'.format(settings_section=self.settings_section)) find_and_set_in_combo_box(self.version_combo_box, bible)
def load_list(self, media, target_group=None): """ Load the media list :param media: The media :param target_group: """ media.sort(key=lambda file_name: get_locale_key(os.path.split(str(file_name))[1])) for track in media: track_info = QtCore.QFileInfo(track) item_name = None if track.startswith('optical:'): # Handle optical based item (file_name, title, audio_track, subtitle_track, start, end, clip_name) = parse_optical_path(track) item_name = QtWidgets.QListWidgetItem(clip_name) item_name.setIcon(self.optical_icon) item_name.setData(QtCore.Qt.UserRole, track) item_name.setToolTip('{name}@{start}-{end}'.format(name=file_name, start=format_milliseconds(start), end=format_milliseconds(end))) elif not os.path.exists(track): # File doesn't exist, mark as error. file_name = os.path.split(str(track))[1] item_name = QtWidgets.QListWidgetItem(file_name) item_name.setIcon(self.error_icon) item_name.setData(QtCore.Qt.UserRole, track) item_name.setToolTip(track) elif track_info.isFile(): # Normal media file handling. file_name = os.path.split(str(track))[1] item_name = QtWidgets.QListWidgetItem(file_name) search = file_name.split('.')[-1].lower() if '*.{text}'.format(text=search) in self.media_controller.audio_extensions_list: item_name.setIcon(self.audio_icon) else: item_name.setIcon(self.video_icon) item_name.setData(QtCore.Qt.UserRole, track) item_name.setToolTip(track) if item_name: self.list_view.addItem(item_name)
def add_sub_groups(self, group_list, parent_group_id): """ Recursively add subgroups to the given parent group in a QTreeWidget. :param group_list: The List object that contains all QTreeWidgetItems. :param parent_group_id: The ID of the group that will be added recursively. """ image_groups = self.manager.get_all_objects( ImageGroups, ImageGroups.parent_id == parent_group_id) image_groups.sort( key=lambda group_object: get_locale_key(group_object.group_name)) folder_icon = build_icon(':/images/image_group.png') for image_group in image_groups: group = QtWidgets.QTreeWidgetItem() group.setText(0, image_group.group_name) group.setData(0, QtCore.Qt.UserRole, image_group) group.setIcon(0, folder_icon) if parent_group_id == 0: self.list_view.addTopLevelItem(group) else: group_list[parent_group_id].addChild(group) group_list[image_group.id] = group self.add_sub_groups(group_list, image_group.id)
def load_list(self, files, target_group=None, initial_load=False): """ Add presentations into the media manager. 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. """ current_list = self.get_file_list() titles = [os.path.split(file)[1] for file in current_list] self.application.set_busy_cursor() if not initial_load: self.main_window.display_progress_bar(len(files)) # Sort the presentations by its filename considering language specific characters. files.sort(key=lambda filename: get_locale_key(os.path.split(str(filename))[1])) for file in files: if not initial_load: self.main_window.increment_progress_bar() if current_list.count(file) > 0: continue filename = os.path.split(file)[1] if not os.path.exists(file): item_name = QtWidgets.QListWidgetItem(filename) item_name.setIcon(build_icon(ERROR_IMAGE)) item_name.setData(QtCore.Qt.UserRole, file) item_name.setToolTip(file) self.list_view.addItem(item_name) else: if titles.count(filename) > 0: if not initial_load: critical_error_message_box(translate('PresentationPlugin.MediaItem', 'File Exists'), translate('PresentationPlugin.MediaItem', 'A presentation with that filename already exists.')) continue controller_name = self.find_controller_by_type(filename) if controller_name: controller = self.controllers[controller_name] doc = controller.add_document(file) thumb = os.path.join(doc.get_thumbnail_folder(), 'icon.png') preview = doc.get_thumbnail_path(1, True) if not preview and not initial_load: doc.load_presentation() preview = doc.get_thumbnail_path(1, True) doc.close_presentation() if not (preview and os.path.exists(preview)): icon = build_icon(':/general/general_delete.png') else: if validate_thumb(preview, thumb): icon = build_icon(thumb) else: icon = create_thumb(preview, thumb) else: if initial_load: icon = build_icon(':/general/general_delete.png') else: critical_error_message_box(UiStrings().UnsupportedFile, translate('PresentationPlugin.MediaItem', 'This type of presentation is not supported.')) continue item_name = QtWidgets.QListWidgetItem(filename) item_name.setData(QtCore.Qt.UserRole, file) item_name.setIcon(icon) item_name.setToolTip(file) self.list_view.addItem(item_name) if not initial_load: self.main_window.finished_progress_bar() self.application.set_normal_cursor()
def __eq__(self, other): return get_locale_key(self.title) == get_locale_key(other.title)
def __lt__(self, other): return get_locale_key(self.title) < get_locale_key(other.title)