correct coding rules, some optimizations

This commit is contained in:
rimach 2010-09-14 19:46:21 +02:00
parent 8e8a6e42ff
commit 22304d491d
15 changed files with 41 additions and 44 deletions

View File

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

View File

@ -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 = {}

View File

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

View File

@ -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'])

View File

@ -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,

View File

@ -101,16 +101,16 @@ class AlertsPlugin(Plugin):
'<br />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')
}
}

View File

@ -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')
}
}

View File

@ -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')
}
}

View File

@ -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')
}
}

View File

@ -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')
}
}

View File

@ -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')
}
}

View File

@ -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')
}
}

View File

@ -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')
}
}

View File

@ -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')
}
}

View File

@ -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):
"""