Review Fixes

This commit is contained in:
Tim Bentley 2011-01-09 08:17:17 +00:00
parent ead2daeed4
commit 23990c168a
7 changed files with 31 additions and 49 deletions

View File

@ -34,7 +34,7 @@ from subprocess import Popen, PIPE
from PyQt4 import QtCore, QtGui
from openlp.core.lib import Receiver, checkDirectoryExists
from openlp.core.lib import Receiver, check_directory_exists
from openlp.core.resources import qInitResources
from openlp.core.ui.mainwindow import MainWindow
from openlp.core.ui.exceptionform import ExceptionForm
@ -243,7 +243,7 @@ def main():
help='Set the Qt4 style (passed directly to Qt4).')
# Set up logging
log_path = AppLocation.get_directory(AppLocation.CacheDir)
checkDirectoryExists(log_path)
check_directory_exists(log_path)
filename = os.path.join(log_path, u'openlp.log')
logfile = logging.FileHandler(filename, u'w')
logfile.setFormatter(logging.Formatter(
@ -280,4 +280,4 @@ if __name__ == u'__main__':
"""
Instantiate and run the application.
"""
main()
main()

View File

@ -306,14 +306,14 @@ def expand_tags(text):
text = text.replace(tag[u'end tag'], tag[u'end html'])
return text
def checkDirectoryExists(dir):
def check_directory_exists(dir):
"""
Check a theme directory exists and if not create it
``dir``
Theme directory to make sure exists
"""
log.debug(u'checkDirectoryExists')
log.debug(u'check_directory_exists')
if not os.path.exists(dir):
os.mkdir(dir)
@ -337,4 +337,4 @@ from dockwidget import OpenLPDockWidget
from renderer import Renderer
from rendermanager import RenderManager
from mediamanageritem import MediaManagerItem
from baselistwithdnd import BaseListWithDnD
from baselistwithdnd import BaseListWithDnD

View File

@ -29,57 +29,39 @@ Provide Html Tag management and Display Tag access class
from openlp.core.lib import base_html_expands
class HtmlTags(object):
"""
"""
def __init__(self):
self.html_expands = []
self.reset_list()
def reset_list(self):
"""
"""
self.html_expands = []
for html in base_html_expands:
self.html_expands.append(html)
def add_tag(self, html):
"""
"""
self.html_expands.append(html)
class DisplayTags(object):
"""
Static Class to HTML Tags to be access around the code the list is managed
by the Options Tab.
"""
html_tags = HtmlTags()
html_expands = []
@staticmethod
def get_html_tags():
"""
Provide access to the html_expands list.
"""
return DisplayTags.html_tags.html_expands
return DisplayTags.html_expands
@staticmethod
def reset_html_tags():
"""
Resets the html_expands list.
"""
return DisplayTags.html_tags.reset_list()
DisplayTags.html_expands = []
for html in base_html_expands:
DisplayTags.html_expands.append(html)
@staticmethod
def add_html_tag(tag):
"""
Add a new tag to the list
"""
return DisplayTags.html_tags.add_tag(tag)
DisplayTags.html_expands.append(tag)
@staticmethod
def remove_html_tag(id):
"""
Removes amd individual html_expands list.
"""
return DisplayTags.html_tags.html_expands.pop(id)
DisplayTags.html_expands.pop(id)

View File

@ -88,7 +88,7 @@ class SpellTextEdit(QtGui.QPlainTextEdit):
popupMenu.insertMenu(popupMenu.actions()[0], spell_menu)
tagMenu = QtGui.QMenu(translate('OpenLP.SpellTextEdit',
'Formatting Tags'))
for html in DisplayTags.get_html_tags().html_expands:
for html in DisplayTags.get_html_tags():
action = SpellAction( html[u'desc'], tagMenu)
action.correct.connect(self.htmlTag)
tagMenu.addAction(action)
@ -110,7 +110,7 @@ class SpellTextEdit(QtGui.QPlainTextEdit):
"""
Replaces the selected text with word.
"""
for html in DisplayTags.get_html_tags().html_expands:
for html in DisplayTags.get_html_tags():
if tag == html[u'desc']:
cursor = self.textCursor()
if self.textCursor().hasSelection():
@ -158,4 +158,4 @@ class SpellAction(QtGui.QAction):
def __init__(self, *args):
QtGui.QAction.__init__(self, *args)
self.triggered.connect(lambda x: self.correct.emit(
unicode(self.text())))
unicode(self.text())))

View File

@ -57,7 +57,7 @@ class DisplayTagTab(SettingsTab):
user_expands = QtCore.QSettings().value(u'displayTags/html_tags',
QtCore.QVariant(u'')).toString()
# cPickle only accepts str not unicode strings
user_tags = cPickle.loads(str(user_expands))
user_tags = cPickle.loads(str(unicode(user_expands).encode(u'utf8')))
# If we have some user ones added them as well
for t in user_tags:
DisplayTags.add_html_tag(t)

View File

@ -36,7 +36,7 @@ from openlp.core.ui import FileRenameForm, ThemeForm
from openlp.core.theme import Theme
from openlp.core.lib import OpenLPToolbar, ThemeXML, get_text_file_string, \
build_icon, Receiver, SettingsManager, translate, check_item_selected, \
BackgroundType, BackgroundGradientType, checkDirectoryExists
BackgroundType, BackgroundGradientType, check_directory_exists
from openlp.core.utils import AppLocation, get_filesystem_encoding
log = logging.getLogger(__name__)
@ -130,9 +130,9 @@ class ThemeManager(QtGui.QWidget):
# Variables
self.themelist = []
self.path = AppLocation.get_section_data_path(self.settingsSection)
checkDirectoryExists(self.path)
check_directory_exists(self.path)
self.thumbPath = os.path.join(self.path, u'thumbnails')
checkDirectoryExists(self.thumbPath)
check_directory_exists(self.thumbPath)
self.themeForm.path = self.path
self.oldBackgroundImage = None
# Last little bits of setting up
@ -492,7 +492,7 @@ class ThemeManager(QtGui.QWidget):
theme_dir = None
if osfile.endswith(os.path.sep):
theme_dir = os.path.join(dir, osfile)
checkDirectoryExists(theme_dir)
check_directory_exists(theme_dir)
else:
fullpath = os.path.join(dir, osfile)
names = osfile.split(os.path.sep)
@ -502,7 +502,7 @@ class ThemeManager(QtGui.QWidget):
themename = names[0]
if theme_dir is None:
theme_dir = os.path.join(dir, names[0])
checkDirectoryExists(theme_dir)
check_directory_exists(theme_dir)
if os.path.splitext(ucsfile)[1].lower() in [u'.xml']:
xml_data = zip.read(file)
try:
@ -522,7 +522,7 @@ class ThemeManager(QtGui.QWidget):
self.generateAndSaveImage(dir, themename, theme)
else:
Receiver.send_message(u'openlp_error_message', {
u'title': translate('OpenLP.ThemeManager', \
u'title': translate('OpenLP.ThemeManager',
'Validation Error'),
u'message':translate('OpenLP.ThemeManager',
'File is not a valid theme.')})
@ -530,7 +530,7 @@ class ThemeManager(QtGui.QWidget):
filename)
except (IOError, NameError):
Receiver.send_message(u'openlp_error_message', {
u'title': translate('OpenLP.ThemeManager', \
u'title': translate('OpenLP.ThemeManager',
'Validation Error'),
u'message':translate('OpenLP.ThemeManager',
'File is not a valid theme.')})
@ -567,7 +567,7 @@ class ThemeManager(QtGui.QWidget):
theme_dir = os.path.join(self.path, themeName)
if os.path.exists(theme_dir):
Receiver.send_message(u'openlp_error_message', {
u'title': translate('OpenLP.ThemeManager', \
u'title': translate('OpenLP.ThemeManager',
'Validation Error'),
u'message':translate('OpenLP.ThemeManager',
'A theme with this name already exists.')})
@ -583,7 +583,7 @@ class ThemeManager(QtGui.QWidget):
theme_pretty_xml = theme.extract_formatted_xml()
log.debug(u'saveTheme %s %s', name, theme_pretty_xml)
theme_dir = os.path.join(self.path, name)
checkDirectoryExists(theme_dir)
check_directory_exists(theme_dir)
theme_file = os.path.join(theme_dir, name + u'.xml')
if imageTo and self.oldBackgroundImage and \
imageTo != self.oldBackgroundImage:
@ -701,7 +701,7 @@ class ThemeManager(QtGui.QWidget):
for plugin in self.parent.pluginManager.plugins:
if plugin.usesTheme(theme):
Receiver.send_message(u'openlp_error_message', {
u'title': translate('OpenLP.ThemeManager', \
u'title': translate('OpenLP.ThemeManager',
'Validation Error'),
u'message': unicode(translate('OpenLP.ThemeManager',
'Theme %s is used in the %s plugin.')) % \
@ -765,4 +765,4 @@ class ThemeManager(QtGui.QWidget):
vAlignCorrection = 2
newtheme.display_horizontal_align = theme.HorizontalAlign
newtheme.display_vertical_align = vAlignCorrection
return newtheme.extract_xml()
return newtheme.extract_xml()

View File

@ -31,7 +31,7 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \
ItemCapabilities, SettingsManager, translate, check_item_selected, \
Receiver, checkDirectoryExists
Receiver, check_directory_exists
from openlp.core.utils import AppLocation, get_images_filter
log = logging.getLogger(__name__)
@ -88,7 +88,7 @@ class ImageMediaItem(MediaManagerItem):
self.servicePath = os.path.join(
AppLocation.get_section_data_path(self.settingsSection),
u'thumbnails')
checkDirectoryExists(self.servicePath)
check_directory_exists(self.servicePath)
self.loadList(SettingsManager.load_list(
self.settingsSection, self.settingsSection))
@ -216,4 +216,4 @@ class ImageMediaItem(MediaManagerItem):
'the image file "%s" no longer exists.')) % filename})
def onPreviewClick(self):
MediaManagerItem.onPreviewClick(self)
MediaManagerItem.onPreviewClick(self)