From b03c3c6f4fc4701dc693147947f2cf6492b9bcff Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 19 Apr 2013 21:03:16 +0200 Subject: [PATCH] code standards --- openlp/plugins/images/__init__.py | 4 +- openlp/plugins/images/forms/__init__.py | 25 ++++---- openlp/plugins/images/forms/addgroupform.py | 10 ++-- .../plugins/images/forms/choosegroupform.py | 8 +-- openlp/plugins/images/imageplugin.py | 10 ++-- openlp/plugins/images/lib/db.py | 6 +- openlp/plugins/images/lib/mediaitem.py | 59 +++++++++---------- openlp/plugins/media/lib/mediaitem.py | 3 + 8 files changed, 60 insertions(+), 65 deletions(-) diff --git a/openlp/plugins/images/__init__.py b/openlp/plugins/images/__init__.py index 12e0cc9e4..9830af231 100644 --- a/openlp/plugins/images/__init__.py +++ b/openlp/plugins/images/__init__.py @@ -27,6 +27,6 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### """ -The :mod:`images` module provides the Images plugin. The Images plugin -provides the facility to display images from OpenLP. +The :mod:`images` module provides the Images plugin. The Images plugin provides the facility to display images from +OpenLP. """ diff --git a/openlp/plugins/images/forms/__init__.py b/openlp/plugins/images/forms/__init__.py index d308a1471..8bb8e966f 100644 --- a/openlp/plugins/images/forms/__init__.py +++ b/openlp/plugins/images/forms/__init__.py @@ -27,20 +27,16 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### """ -Forms in OpenLP are made up of two classes. One class holds all the graphical -elements, like buttons and lists, and the other class holds all the functional -code, like slots and loading and saving. +Forms in OpenLP are made up of two classes. One class holds all the graphical elements, like buttons and lists, and the +other class holds all the functional code, like slots and loading and saving. -The first class, commonly known as the **Dialog** class, is typically named -``Ui_Dialog``. It is a slightly modified version of the class that the -``pyuic4`` command produces from Qt4's .ui file. Typical modifications will be -converting most strings from "" to u'' and using OpenLP's ``translate()`` -function for translating strings. +The first class, commonly known as the **Dialog** class, is typically named ``Ui_Dialog``. It is a slightly +modified version of the class that the ``pyuic4`` command produces from Qt4's .ui file. Typical modifications will be +converting most strings from "" to u'' and using OpenLP's ``translate()`` function for translating strings. -The second class, commonly known as the **Form** class, is typically named -``Form``. This class is the one which is instantiated and used. It uses -dual inheritance to inherit from (usually) QtGui.QDialog and the Ui class -mentioned above, like so:: +The second class, commonly known as the **Form** class, is typically named ``Form``. This class is the one which +is instantiated and used. It uses dual inheritance to inherit from (usually) QtGui.QDialog and the Ui class mentioned +above, like so:: class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog): @@ -48,9 +44,8 @@ mentioned above, like so:: QtGui.QDialog.__init__(self, parent) self.setupUi(self) -This allows OpenLP to use ``self.object`` for all the GUI elements while keeping -them separate from the functionality, so that it is easier to recreate the GUI -from the .ui files later if necessary. +This allows OpenLP to use ``self.object`` for all the GUI elements while keeping them separate from the functionality, +so that it is easier to recreate the GUI from the .ui files later if necessary. """ from addgroupform import AddGroupForm diff --git a/openlp/plugins/images/forms/addgroupform.py b/openlp/plugins/images/forms/addgroupform.py index 7f7986499..f891969c6 100644 --- a/openlp/plugins/images/forms/addgroupform.py +++ b/openlp/plugins/images/forms/addgroupform.py @@ -47,16 +47,16 @@ class AddGroupForm(QtGui.QDialog, Ui_AddGroupDialog): def exec_(self, clear=True, show_top_level_group=False, selected_group=None): """ - Show the form + Show the form, ``clear`` - Set to False if the text input box should not be cleared when showing the dialog (default: True) + Set to False if the text input box should not be cleared when showing the dialog (default: True), ``show_top_level_group`` - Set to True when "-- Top level group --" should be showed as first item (default: False) + Set to True when "-- Top level group --" should be showed as first item (default: False), ``selected_group`` - The ID of the group that should be selected by default when showing the dialog + The ID of the group that should be selected by default when showing the dialog, """ if clear: self.name_edit.clear() @@ -72,7 +72,7 @@ class AddGroupForm(QtGui.QDialog, Ui_AddGroupDialog): def accept(self): """ - Override the accept() method from QDialog to make sure something is entered in the text input box + Override the accept() method from QDialog to make sure something is entered in the text input box. """ if not self.name_edit.text(): critical_error_message_box(message=translate('ImagePlugin.AddGroupForm', diff --git a/openlp/plugins/images/forms/choosegroupform.py b/openlp/plugins/images/forms/choosegroupform.py index bbb57255c..f11c8324c 100644 --- a/openlp/plugins/images/forms/choosegroupform.py +++ b/openlp/plugins/images/forms/choosegroupform.py @@ -48,10 +48,10 @@ class ChooseGroupForm(QtGui.QDialog, Ui_ChooseGroupDialog): Show the form ``selected_group`` - The ID of the group that should be selected by default when showing the dialog + The ID of the group that should be selected by default when showing the dialog. """ if selected_group is not None: - for i in range(self.group_combobox.count()): - if self.group_combobox.itemData(i) == selected_group: - self.group_combobox.setCurrentIndex(i) + for index in range(self.group_combobox.count()): + if self.group_combobox.itemData(index) == selected_group: + self.group_combobox.setCurrentIndex(index) return QtGui.QDialog.exec_(self) diff --git a/openlp/plugins/images/imageplugin.py b/openlp/plugins/images/imageplugin.py index cb25dc375..dfe927a7b 100644 --- a/openlp/plugins/images/imageplugin.py +++ b/openlp/plugins/images/imageplugin.py @@ -70,10 +70,10 @@ class ImagePlugin(Plugin): def app_startup(self): """ - Perform tasks on application startup + Perform tasks on application startup. """ Plugin.app_startup(self) - # Convert old settings-based image list to the database + # Convert old settings-based image list to the database. files_from_config = Settings().get_files_from_config(self) if files_from_config: log.debug(u'Importing images list from old config: %s' % files_from_config) @@ -93,7 +93,7 @@ class ImagePlugin(Plugin): def set_plugin_text_strings(self): """ - Called to define all translatable texts of the plugin + Called to define all translatable texts of the plugin. """ ## Name PluginList ## self.text_strings[StringContent.Name] = { @@ -117,8 +117,8 @@ class ImagePlugin(Plugin): def config_update(self): """ - Triggered by saving and changing the image border. Sets the images in image manager to require updates. - Actual update is triggered by the last part of saving the config. + Triggered by saving and changing the image border. Sets the images in image manager to require updates. Actual + update is triggered by the last part of saving the config. """ log.info(u'Images config_update') background = QtGui.QColor(Settings().value(self.settings_section + u'/background color')) diff --git a/openlp/plugins/images/lib/db.py b/openlp/plugins/images/lib/db.py index bc4a94f15..1d8f473d8 100644 --- a/openlp/plugins/images/lib/db.py +++ b/openlp/plugins/images/lib/db.py @@ -27,7 +27,7 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### """ -The :mod:`db` module provides the database and schema that is the backend for the Images plugin +The :mod:`db` module provides the database and schema that is the backend for the Images plugin. """ from sqlalchemy import Column, ForeignKey, Table, types @@ -38,14 +38,14 @@ from openlp.core.lib.db import BaseModel, init_db class ImageGroups(BaseModel): """ - ImageGroups model + ImageGroups model. """ pass class ImageFilenames(BaseModel): """ - ImageFilenames model + ImageFilenames model. """ pass diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index fc575ec0a..5281070fb 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -40,6 +40,7 @@ from openlp.core.utils import AppLocation, delete_file, get_locale_key, get_imag from openlp.plugins.images.forms import AddGroupForm, ChooseGroupForm from openlp.plugins.images.lib.db import ImageFilenames, ImageGroups + log = logging.getLogger(__name__) @@ -60,12 +61,11 @@ class ImageMediaItem(MediaManagerItem): self.fill_groups_combobox(self.choose_group_form.group_combobox) self.fill_groups_combobox(self.add_group_form.parent_group_combobox) Registry().register_function(u'live_theme_changed', self.live_theme_changed) - # Allow DnD from the desktop + # Allow DnD from the desktop. self.list_view.activateDnD() def retranslateUi(self): - self.on_new_prompt = translate('ImagePlugin.MediaItem', - 'Select Image(s)') + self.on_new_prompt = translate('ImagePlugin.MediaItem', 'Select Image(s)') file_formats = get_images_filter() self.on_new_file_masks = u'%s;;%s (*.*) (*)' % (file_formats, UiStrings().AllFiles) self.addGroupAction.setText(UiStrings().AddGroup) @@ -77,7 +77,7 @@ class ImageMediaItem(MediaManagerItem): def required_icons(self): """ - Set which icons the media manager tab should show + Set which icons the media manager tab should show. """ MediaManagerItem.required_icons(self) self.has_file_icon = True @@ -99,8 +99,8 @@ class ImageMediaItem(MediaManagerItem): def add_list_view_to_toolbar(self): """ - Creates the main widget for listing items the media item is tracking. - This method overloads MediaManagerItem.add_list_view_to_toolbar + Creates the main widget for listing items the media item is tracking. This method overloads + MediaManagerItem.add_list_view_to_toolbar. """ # Add the List widget self.list_view = TreeWidgetWithDnD(self, self.plugin.name) @@ -159,21 +159,18 @@ class ImageMediaItem(MediaManagerItem): def add_custom_context_actions(self): """ - Add custom actions to the context menu + Add custom actions to the context menu. """ create_widget_action(self.list_view, separator=True) create_widget_action(self.list_view, - text=UiStrings().AddGroup, - icon=u':/images/image_new_group.png', - triggers=self.onAddGroupClick) + text=UiStrings().AddGroup, icon=u':/images/image_new_group.png', triggers=self.onAddGroupClick) create_widget_action(self.list_view, text=self.plugin.get_string(StringContent.Load)[u'tooltip'], - icon=u':/general/general_open.png', - triggers=self.on_file_click) + icon=u':/general/general_open.png', triggers=self.on_file_click) 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', icon=u':/images/image_new_group.png', triggers=self.onAddGroupClick) @@ -189,10 +186,10 @@ class ImageMediaItem(MediaManagerItem): def recursively_delete_group(self, image_group): """ - Recursively deletes a group and all groups and images in it + Recursively deletes a group and all groups and images in it. ``image_group`` - The ImageGroups instance of the group that will be deleted + The ImageGroups instance of the group that will be deleted. """ images = self.manager.get_all_objects(ImageFilenames, ImageFilenames.group_id == image_group.id) for image in images: @@ -205,7 +202,7 @@ class ImageMediaItem(MediaManagerItem): def on_delete_click(self): """ - Remove an image item from the list + Remove an image item from the list. """ # Turn off auto preview triggers. self.list_view.blockSignals(True) @@ -226,11 +223,11 @@ class ImageMediaItem(MediaManagerItem): self.manager.delete_object(ImageFilenames, row_item.data(0, QtCore.Qt.UserRole).id) elif isinstance(item_data, ImageGroups): if QtGui.QMessageBox.question(self.list_view.parent(), - translate('ImagePlugin.MediaItem', 'Remove group'), - translate('ImagePlugin.MediaItem', - 'Are you sure you want to remove "%s" and everything in it?') % item_data.group_name, - QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | - QtGui.QMessageBox.No)) == QtGui.QMessageBox.Yes: + translate('ImagePlugin.MediaItem', 'Remove group'), + translate('ImagePlugin.MediaItem', + 'Are you sure you want to remove "%s" and everything in it?') % item_data.group_name, + QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | + QtGui.QMessageBox.No)) == QtGui.QMessageBox.Yes: self.recursively_delete_group(item_data) self.manager.delete_object(ImageGroups, row_item.data(0, QtCore.Qt.UserRole).id) if item_data.parent_id == 0: @@ -246,13 +243,13 @@ class ImageMediaItem(MediaManagerItem): def add_sub_groups(self, group_list, parent_group_id): """ - Recursively add subgroups to the given parent group in a QTreeWidget + Recursively add subgroups to the given parent group in a QTreeWidget. ``group_list`` - The List object that contains all QTreeWidgetItems + The List object that contains all QTreeWidgetItems. ``parent_group_id`` - The ID of the group that will be added recursively + 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)) @@ -271,16 +268,16 @@ class ImageMediaItem(MediaManagerItem): def fill_groups_combobox(self, combobox, parent_group_id=0, prefix=''): """ - Recursively add groups to the combobox in the 'Add group' dialog + Recursively add groups to the combobox in the 'Add group' dialog. ``combobox`` - The QComboBox to add the options to + The QComboBox to add the options to. ``parent_group_id`` - The ID of the group that will be added + The ID of the group that will be added. ``prefix`` - A string containing the prefix that will be added in front of the groupname for each level of the tree + 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() @@ -293,13 +290,13 @@ class ImageMediaItem(MediaManagerItem): def expand_group(self, group_id, root_item=None): """ - Expand groups in the widget recursively + Expand groups in the widget recursively. ``group_id`` - The ID of the group that will be expanded + The ID of the group that will be expanded. ``root_item`` - This option is only used for recursion purposes + This option is only used for recursion purposes. """ return_value = False if root_item is None: diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 7d492bc69..751d7a202 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -39,14 +39,17 @@ from openlp.core.ui import DisplayController, Display, DisplayControllerType from openlp.core.ui.media import get_media_players, set_media_players from openlp.core.utils import AppLocation, get_locale_key + log = logging.getLogger(__name__) + CLAPPERBOARD = u':/media/slidecontroller_multimedia.png' VIDEO = build_icon(QtGui.QImage(u':/media/media_video.png')) AUDIO = build_icon(QtGui.QImage(u':/media/media_audio.png')) DVDICON = build_icon(QtGui.QImage(u':/media/media_video.png')) ERROR = build_icon(QtGui.QImage(u':/general/general_delete.png')) + class MediaMediaItem(MediaManagerItem): """ This is the custom media manager item for Media Slides.