From 22304d491d742da496a1031a76c656fc2e989fc3 Mon Sep 17 00:00:00 2001 From: rimach Date: Tue, 14 Sep 2010 19:46:21 +0200 Subject: [PATCH] correct coding rules, some optimizations --- openlp/core/lib/mediamanageritem.py | 6 +++--- openlp/core/lib/plugin.py | 3 +-- openlp/core/ui/mediadockmanager.py | 13 ++++++------- openlp/core/ui/pluginform.py | 12 ++++++------ openlp/core/utils/languagemanager.py | 4 ++-- openlp/plugins/alerts/alertsplugin.py | 4 ++-- openlp/plugins/bibles/bibleplugin.py | 4 +--- openlp/plugins/custom/customplugin.py | 4 +--- openlp/plugins/images/imageplugin.py | 4 +--- openlp/plugins/media/mediaplugin.py | 4 +--- openlp/plugins/presentations/presentationplugin.py | 4 +--- openlp/plugins/remotes/remoteplugin.py | 3 +-- openlp/plugins/songs/songsplugin.py | 4 +--- openlp/plugins/songusage/songusageplugin.py | 3 +-- scripts/translation_utils.py | 13 +++++++++++++ 15 files changed, 41 insertions(+), 44 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 0d1c1ccb7..796abaa22 100755 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -92,7 +92,7 @@ class MediaManagerItem(QtGui.QWidget): """ QtGui.QWidget.__init__(self) self.parent = parent - # TODO: may the plugin is not the parent? + # TODO: plugin is not the parent, so add this to the calling plugins self.plugin = parent self.settingsSection = self.plugin.name_lower if isinstance(icon, QtGui.QIcon): @@ -103,8 +103,8 @@ class MediaManagerItem(QtGui.QWidget): else: self.icon = None if title: - nameString = self.plugin.getString(StringType.Name) - self.title = nameString[u'plural'] + name_string = self.plugin.getString(StringType.Name) + self.title = name_string[u'plural'] self.toolbar = None self.remoteTriggered = None self.serviceItemIconName = None diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index 21eebf0cf..82acb2986 100755 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -269,7 +269,7 @@ class Plugin(QtCore.QObject): Called by the plugin to remove toolbar """ if self.mediaItem: - self.mediadock.remove_dock(self.name) + self.mediadock.remove_dock(self.mediaItem) if self.settings_tab: self.settingsForm.removeTab(self.name) @@ -315,5 +315,4 @@ class Plugin(QtCore.QObject): """ self.name = u'Plugin' self.name_lower = u'plugin' - self.strings = {} diff --git a/openlp/core/ui/mediadockmanager.py b/openlp/core/ui/mediadockmanager.py index cbfeea274..172288031 100755 --- a/openlp/core/ui/mediadockmanager.py +++ b/openlp/core/ui/mediadockmanager.py @@ -61,24 +61,23 @@ class MediaDockManager(object): match = False for dock_index in range(0, self.media_dock.count()): if self.media_dock.widget(dock_index).settingsSection == \ - media_item.plugin.name: + media_item.plugin.name_lower: match = True break if not match: self.media_dock.addItem(media_item, icon, media_item.plugin.name) - def remove_dock(self, name): + def remove_dock(self, media_item): """ Removes a MediaManagerItem from the dock - ``name`` - The item to remove + ``media_item`` + The item to add to the dock """ - log.debug(u'remove %s dock' % name) + log.debug(u'remove %s dock' % media_item.plugin.name) for dock_index in range(0, self.media_dock.count()): if self.media_dock.widget(dock_index): - log.debug(u'%s %s' % (name, self.media_dock.widget(dock_index).settingsSection)) if self.media_dock.widget(dock_index).settingsSection == \ - name: + media_item.plugin.name_lower: self.media_dock.widget(dock_index).hide() self.media_dock.removeItem(dock_index) diff --git a/openlp/core/ui/pluginform.py b/openlp/core/ui/pluginform.py index 042ecf49f..a3d1a4dce 100755 --- a/openlp/core/ui/pluginform.py +++ b/openlp/core/ui/pluginform.py @@ -78,8 +78,8 @@ class PluginForm(QtGui.QDialog, Ui_PluginViewDialog): elif plugin.status == PluginStatus.Disabled: status_text = unicode( translate('OpenLP.PluginForm', '%s (Disabled)')) - nameString = plugin.getString(StringType.Name) - item.setText(status_text % nameString[u'plural']) + name_string = plugin.getString(StringType.Name) + item.setText(status_text % name_string[u'plural']) # If the plugin has an icon, set it! if plugin.icon: item.setIcon(plugin.icon) @@ -110,8 +110,8 @@ class PluginForm(QtGui.QDialog, Ui_PluginViewDialog): plugin_name_more = self.pluginListWidget.currentItem().text().split(u' ')[0] self.activePlugin = None for plugin in self.parent.plugin_manager.plugins: - nameString = plugin.getString(StringType.Name) - if nameString[u'plural'] == plugin_name_more: + name_string = plugin.getString(StringType.Name) + if name_string[u'plural'] == plugin_name_more: self.activePlugin = plugin break if self.activePlugin: @@ -139,6 +139,6 @@ class PluginForm(QtGui.QDialog, Ui_PluginViewDialog): elif self.activePlugin.status == PluginStatus.Disabled: status_text = unicode( translate('OpenLP.PluginForm', '%s (Disabled)')) - nameString = self.activePlugin.getString(StringType.Name) + name_string = self.activePlugin.getString(StringType.Name) self.pluginListWidget.currentItem().setText( - status_text % nameString[u'plural']) + status_text % name_string[u'plural']) diff --git a/openlp/core/utils/languagemanager.py b/openlp/core/utils/languagemanager.py index a264e15a9..417082321 100755 --- a/openlp/core/utils/languagemanager.py +++ b/openlp/core/utils/languagemanager.py @@ -57,7 +57,7 @@ class LanguageManager(object): lang_path = AppLocation.get_directory(AppLocation.AppDir) lang_path = os.path.join(lang_path, u'i18n') app_translator = QtCore.QTranslator() - if app_translator.load("openlp_" + language, lang_path): + if app_translator.load(language, lang_path): return app_translator @staticmethod @@ -130,7 +130,7 @@ class LanguageManager(object): LanguageManager.__qmList__ = {} qm_files = LanguageManager.find_qm_files() for i, qmf in enumerate(qm_files): - reg_ex = QtCore.QRegExp("^.*openlp_(.*).qm") + reg_ex = QtCore.QRegExp("^(.*).qm") if reg_ex.exactMatch(qmf): lang_name = reg_ex.cap(1) LanguageManager.__qmList__[u'%#2i %s' % (i+1, diff --git a/openlp/plugins/alerts/alertsplugin.py b/openlp/plugins/alerts/alertsplugin.py index 63f3ed291..b711d583a 100755 --- a/openlp/plugins/alerts/alertsplugin.py +++ b/openlp/plugins/alerts/alertsplugin.py @@ -101,16 +101,16 @@ class AlertsPlugin(Plugin): '
The alert plugin controls the displaying of nursery alerts ' 'on the display screen') return about_text + def setPluginStrings(self): """ Called to define all translatable texts of the plugin """ self.name = u'Alerts' self.name_lower = u'alerts' - self.strings = {} # for names in mediamanagerdock and pluginlist self.strings[StringType.Name] = { u'singular': translate('AlertsPlugin', 'Alert'), u'plural': translate('AlertsPlugin', 'Alerts') - } \ No newline at end of file + } diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index 3bb3138a1..fda395b00 100755 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -123,14 +123,12 @@ class BiblePlugin(Plugin): """ self.name = u'Bibles' self.name_lower = u'Bibles' - self.strings = {} # for names in mediamanagerdock and pluginlist self.strings[StringType.Name] = { u'singular': translate('BiblesPlugin', 'Bible'), u'plural': translate('BiblesPlugin', 'Bibles') } - # Middle Header Bar ## Import Button ## self.strings[StringType.Import] = { @@ -166,4 +164,4 @@ class BiblePlugin(Plugin): self.strings[StringType.Service] = { u'title': translate('BiblesPlugin', 'Service'), u'tooltip': translate('BiblesPlugin', 'Add the selected Bible to the service') - } \ No newline at end of file + } diff --git a/openlp/plugins/custom/customplugin.py b/openlp/plugins/custom/customplugin.py index b6614828e..2e2e4b744 100755 --- a/openlp/plugins/custom/customplugin.py +++ b/openlp/plugins/custom/customplugin.py @@ -102,14 +102,12 @@ class CustomPlugin(Plugin): """ self.name = u'Custom' self.name_lower = u'custom' - self.strings = {} # for names in mediamanagerdock and pluginlist self.strings[StringType.Name] = { u'singular': translate('CustomsPlugin', 'Custom'), u'plural': translate('CustomsPlugin', 'Customs') } - # Middle Header Bar ## Import Button ## self.strings[StringType.Import] = { @@ -150,4 +148,4 @@ class CustomPlugin(Plugin): self.strings[StringType.Service] = { u'title': translate('CustomsPlugin', 'Service'), u'tooltip': translate('CustomsPlugin', 'Add the selected Custom to the service') - } \ No newline at end of file + } diff --git a/openlp/plugins/images/imageplugin.py b/openlp/plugins/images/imageplugin.py index 3163eb2c0..7cba1cc21 100755 --- a/openlp/plugins/images/imageplugin.py +++ b/openlp/plugins/images/imageplugin.py @@ -64,14 +64,12 @@ class ImagePlugin(Plugin): """ self.name = u'Images' self.name_lower = u'images' - self.strings = {} # for names in mediamanagerdock and pluginlist self.strings[StringType.Name] = { u'singular': translate('ImagePlugin', 'Image'), u'plural': translate('ImagePlugin', 'Images') } - # Middle Header Bar ## Load Button ## self.strings[StringType.Load] = { @@ -107,4 +105,4 @@ class ImagePlugin(Plugin): self.strings[StringType.Service] = { u'title': translate('ImagePlugin', 'Service'), u'tooltip': translate('ImagePlugin', 'Add the selected Image to the service') - } \ No newline at end of file + } diff --git a/openlp/plugins/media/mediaplugin.py b/openlp/plugins/media/mediaplugin.py index c7712e722..bb00bbd61 100755 --- a/openlp/plugins/media/mediaplugin.py +++ b/openlp/plugins/media/mediaplugin.py @@ -82,14 +82,12 @@ class MediaPlugin(Plugin): """ self.name = u'Media' self.name_lower = u'media' - self.strings = {} # for names in mediamanagerdock and pluginlist self.strings[StringType.Name] = { u'singular': translate('MediaPlugin', 'Media'), u'plural': translate('MediaPlugin', 'Medias') } - # Middle Header Bar ## Load Button ## self.strings[StringType.Load] = { @@ -125,4 +123,4 @@ class MediaPlugin(Plugin): self.strings[StringType.Service] = { u'title': translate('MediaPlugin', 'Service'), u'tooltip': translate('MediaPlugin', 'Add the selected Media to the service') - } \ No newline at end of file + } diff --git a/openlp/plugins/presentations/presentationplugin.py b/openlp/plugins/presentations/presentationplugin.py index ce8e6aa99..5c32002f6 100755 --- a/openlp/plugins/presentations/presentationplugin.py +++ b/openlp/plugins/presentations/presentationplugin.py @@ -150,14 +150,12 @@ class PresentationPlugin(Plugin): """ self.name = u'Presentations' self.name_lower = u'presentations' - self.strings = {} # for names in mediamanagerdock and pluginlist self.strings[StringType.Name] = { u'singular': translate('PresentationPlugin', 'Presentation'), u'plural': translate('PresentationPlugin', 'Presentations') } - # Middle Header Bar ## Load Button ## self.strings[StringType.Load] = { @@ -183,4 +181,4 @@ class PresentationPlugin(Plugin): self.strings[StringType.Service] = { u'title': translate('PresentationPlugin', 'Service'), u'tooltip': translate('PresentationPlugin', 'Add the selected Presentation to the service') - } \ No newline at end of file + } diff --git a/openlp/plugins/remotes/remoteplugin.py b/openlp/plugins/remotes/remoteplugin.py index 1743c4b98..3f4540ae9 100755 --- a/openlp/plugins/remotes/remoteplugin.py +++ b/openlp/plugins/remotes/remoteplugin.py @@ -83,10 +83,9 @@ class RemotesPlugin(Plugin): """ self.name = u'Remotes' self.name_lower = u'remotes' - self.strings = {} # for names in mediamanagerdock and pluginlist self.strings[StringType.Name] = { u'singular': translate('RemotePlugin', 'Remote'), u'plural': translate('RemotePlugin', 'Remotes') - } \ No newline at end of file + } diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index 2e8ed32ee..3d564806f 100755 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -154,14 +154,12 @@ class SongsPlugin(Plugin): """ self.name = u'Songs' self.name_lower = u'songs' - self.strings = {} # for names in mediamanagerdock and pluginlist self.strings[StringType.Name] = { u'singular': translate('SongsPlugin', 'Song'), u'plural': translate('SongsPlugin', 'Songs') } - # Middle Header Bar ## New Button ## self.strings[StringType.New] = { @@ -192,4 +190,4 @@ class SongsPlugin(Plugin): self.strings[StringType.Service] = { u'title': translate('SongsPlugin', 'Service'), u'tooltip': translate('SongsPlugin', 'Add the selected Song to the service') - } \ No newline at end of file + } diff --git a/openlp/plugins/songusage/songusageplugin.py b/openlp/plugins/songusage/songusageplugin.py index 087818756..92863a403 100755 --- a/openlp/plugins/songusage/songusageplugin.py +++ b/openlp/plugins/songusage/songusageplugin.py @@ -169,10 +169,9 @@ class SongUsagePlugin(Plugin): """ self.name = u'SongUsage' self.name_lower = u'songusage' - self.strings = {} # for names in mediamanagerdock and pluginlist self.strings[StringType.Name] = { u'singular': translate('SongUsagePlugin', 'SongUsage'), u'plural': translate('SongUsagePlugin', 'SongUsage') - } \ No newline at end of file + } diff --git a/scripts/translation_utils.py b/scripts/translation_utils.py index f52af4984..6d8997677 100755 --- a/scripts/translation_utils.py +++ b/scripts/translation_utils.py @@ -52,6 +52,7 @@ This is done easily via the ``-d``, ``-p`` and ``-u`` options:: import os import urllib import re +from shutil import copy from optparse import OptionParser from PyQt4 import QtCore @@ -227,6 +228,7 @@ def update_translations(): else: os.chdir(os.path.abspath(u'..')) run(u'pylupdate4 -verbose -noobsolete openlp.pro') + os.chdir(os.path.abspath(u'scripts')) def generate_binaries(): print u'Generate the related *.qm files' @@ -239,6 +241,17 @@ def generate_binaries(): else: os.chdir(os.path.abspath(u'..')) run(u'lrelease openlp.pro') + os.chdir(os.path.abspath(u'scripts')) + src_path = os.path.join(os.path.abspath(u'..'), u'resources', u'i18n') + dest_path = os.path.join(os.path.abspath(u'..'), u'openlp', u'i18n') + if not os.path.exists(dest_path): + os.makedirs(dest_path) + src_list = os.listdir(src_path) + for file in src_list: + if re.search('.qm$', file): + copy(os.path.join(src_path, u'%s' % file), + os.path.join(dest_path, u'%s' % file)) + def create_translation(language): """