Head r1218 and fixes

This commit is contained in:
Jon Tibble 2011-01-15 20:06:25 +00:00
commit a064ad1b05
18 changed files with 108 additions and 115 deletions

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<Theme>
<Name>openlp.org 2.0 Demo Theme</Name>
<BackgroundType>2</BackgroundType>
<BackgroundParameter1>./openlp/core/test/data_for_tests/treesbig.jpg</BackgroundParameter1>
<BackgroundParameter2>clBlack</BackgroundParameter2>
<BackgroundParameter3/>
<FontName>Tahoma</FontName>
<FontColor>clWhite</FontColor>
<FontProportion>16</FontProportion>
<Shadow>-1</Shadow>
<ShadowColor>$00000001</ShadowColor>
<Outline>-1</Outline>
<OutlineColor>clRed</OutlineColor>
<HorizontalAlign>2</HorizontalAlign>
<VerticalAlign>2</VerticalAlign>
</Theme>

View File

@ -72,9 +72,6 @@ Song Importers
.. automodule:: openlp.plugins.songs.lib.cclifileimport
:members:
.. autoclass:: openlp.plugins.songs.lib.cclifileimport.CCLIFileImportError
:members:
.. automodule:: openlp.plugins.songs.lib.ewimport
:members:

View File

@ -293,6 +293,7 @@ def clean_tags(text):
Remove Tags from text for display
"""
text = text.replace(u'<br>', u'\n')
text = text.replace(u'&nbsp;', u' ')
for tag in DisplayTags.get_html_tags():
text = text.replace(tag[u'start tag'], u'')
text = text.replace(tag[u'end tag'], u'')

View File

@ -34,7 +34,7 @@ from sqlalchemy import create_engine, MetaData
from sqlalchemy.exceptions import InvalidRequestError
from sqlalchemy.orm import scoped_session, sessionmaker
from openlp.core.utils import AppLocation
from openlp.core.utils import AppLocation, delete_file
log = logging.getLogger(__name__)
@ -75,11 +75,7 @@ def delete_database(plugin_name, db_file_name=None):
else:
db_file_path = os.path.join(
AppLocation.get_section_data_path(plugin_name), plugin_name)
try:
os.remove(db_file_path)
return True
except OSError:
return False
return delete_file(db_file_path)
class BaseModel(object):
"""
@ -295,4 +291,4 @@ class Manager(object):
if self.is_dirty:
engine = create_engine(self.db_url)
if self.db_url.startswith(u'sqlite'):
engine.execute("vacuum")
engine.execute("vacuum")

View File

@ -641,4 +641,4 @@ def build_alert_css(alertTab, width):
align = u'top'
alert = style % (width, align, alertTab.font_face, alertTab.font_size,
alertTab.font_color, alertTab.bg_color)
return alert
return alert

View File

@ -24,6 +24,8 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
The :mod:`maindisplay` module provides the functionality to display screens
and play multimedia within OpenLP.
"""
import logging
import os

View File

@ -38,7 +38,8 @@ from openlp.core.lib import OpenLPToolbar, ServiceItem, context_menu_action, \
ThemeLevel
from openlp.core.ui import criticalErrorMessageBox, ServiceNoteForm, \
ServiceItemEditForm
from openlp.core.utils import AppLocation, file_is_unicode, split_filename
from openlp.core.utils import AppLocation, delete_file, file_is_unicode, \
split_filename
class ServiceManagerList(QtGui.QTreeWidget):
"""
@ -446,11 +447,7 @@ class ServiceManager(QtGui.QWidget):
file.close()
if zip:
zip.close()
try:
os.remove(serviceFileName)
except (IOError, OSError):
# if not present do not worry
pass
delete_file(serviceFileName)
self.mainwindow.addRecentFile(fileName)
self.setModified(False)
return True
@ -515,11 +512,7 @@ class ServiceManager(QtGui.QWidget):
if serviceItem.is_capable(ItemCapabilities.OnLoadUpdate):
Receiver.send_message(u'%s_service_load' %
serviceItem.name.lower(), serviceItem)
try:
if os.path.isfile(p_file):
os.remove(p_file)
except (IOError, OSError):
log.exception(u'Failed to remove osd file')
delete_file(p_file)
else:
criticalErrorMessageBox(
message=translate('OpenLP.ServiceManager',
@ -872,11 +865,7 @@ class ServiceManager(QtGui.QWidget):
"""
for file in os.listdir(self.servicePath):
file_path = os.path.join(self.servicePath, file)
try:
if os.path.isfile(file_path):
os.remove(file_path)
except OSError:
log.exception(u'Failed to clean up servicePath')
delete_file(file_path)
def onThemeComboBoxSelected(self, currentIndex):
"""

View File

@ -687,8 +687,17 @@ class SlideController(QtGui.QWidget):
Allow the main display to blank the main display at startup time
"""
log.debug(u'mainDisplaySetBackground live = %s' % self.isLive)
display_type = QtCore.QSettings().value(
self.parent.generalSettingsSection + u'/screen blank',
QtCore.QVariant(u'')).toString()
if not self.display.primary:
self.onBlankDisplay(True)
# Order done to handle initial conversion
if display_type == u'themed':
self.onThemeDisplay(True)
elif display_type == u'hidden':
self.onHideDisplay(True)
else:
self.onBlankDisplay(True)
def onSlideBlank(self):
"""
@ -712,13 +721,15 @@ class SlideController(QtGui.QWidget):
self.ThemeScreen.setChecked(False)
if self.screens.display_count > 1:
self.DesktopScreen.setChecked(False)
QtCore.QSettings().setValue(
self.parent.generalSettingsSection + u'/screen blank',
QtCore.QVariant(checked))
if checked:
Receiver.send_message(u'maindisplay_hide', HideMode.Blank)
QtCore.QSettings().setValue(
self.parent.generalSettingsSection + u'/screen blank',
QtCore.QVariant(u'blanked'))
else:
Receiver.send_message(u'maindisplay_show')
QtCore.QSettings().remove(
self.parent.generalSettingsSection + u'/screen blank')
self.blankPlugin(checked)
def onThemeDisplay(self, checked):
@ -733,8 +744,13 @@ class SlideController(QtGui.QWidget):
self.DesktopScreen.setChecked(False)
if checked:
Receiver.send_message(u'maindisplay_hide', HideMode.Theme)
QtCore.QSettings().setValue(
self.parent.generalSettingsSection + u'/screen blank',
QtCore.QVariant(u'themed'))
else:
Receiver.send_message(u'maindisplay_show')
QtCore.QSettings().remove(
self.parent.generalSettingsSection + u'/screen blank')
self.blankPlugin(checked)
def onHideDisplay(self, checked):
@ -745,12 +761,19 @@ class SlideController(QtGui.QWidget):
self.HideMenu.setDefaultAction(self.DesktopScreen)
self.BlankScreen.setChecked(False)
self.ThemeScreen.setChecked(False)
if self.screens.display_count > 1:
self.DesktopScreen.setChecked(checked)
# On valid if more than 1 display
if self.screens.display_count <= 1:
return
self.DesktopScreen.setChecked(checked)
if checked:
Receiver.send_message(u'maindisplay_hide', HideMode.Screen)
QtCore.QSettings().setValue(
self.parent.generalSettingsSection + u'/screen blank',
QtCore.QVariant(u'hidden'))
else:
Receiver.send_message(u'maindisplay_show')
QtCore.QSettings().remove(
self.parent.generalSettingsSection + u'/screen blank')
self.hidePlugin(checked)
def blankPlugin(self, blank):
@ -1040,9 +1063,8 @@ class SlideController(QtGui.QWidget):
if self.BlankScreen.isChecked:
self.BlankScreen.setChecked(False)
self.HideMenu.setDefaultAction(self.BlankScreen)
QtCore.QSettings().setValue(
self.parent.generalSettingsSection + u'/screen blank',
QtCore.QVariant(False))
QtCore.QSettings().remove(
self.parent.generalSettingsSection + u'/screen blank')
if self.ThemeScreen.isChecked:
self.ThemeScreen.setChecked(False)
self.HideMenu.setDefaultAction(self.ThemeScreen)

View File

@ -37,7 +37,7 @@ 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, check_directory_exists
from openlp.core.utils import AppLocation, file_is_unicode, \
from openlp.core.utils import AppLocation, delete_file, file_is_unicode, \
get_filesystem_encoding
log = logging.getLogger(__name__)
@ -341,9 +341,9 @@ class ThemeManager(QtGui.QWidget):
"""
self.themelist.remove(theme)
thumb = theme + u'.png'
delete_file(os.path.join(self.path, thumb))
delete_file(os.path.join(self.thumbPath, thumb))
try:
os.remove(os.path.join(self.path, thumb))
os.remove(os.path.join(self.thumbPath, thumb))
encoding = get_filesystem_encoding()
shutil.rmtree(os.path.join(self.path, theme).encode(encoding))
except OSError:
@ -518,13 +518,10 @@ class ThemeManager(QtGui.QWidget):
check_directory_exists(theme_dir)
if os.path.splitext(ucsfile)[1].lower() in [u'.xml']:
xml_data = zip.read(file)
try:
xml_data = xml_data.decode(u'utf-8')
except UnicodeDecodeError:
log.exception(u'Theme XML is not UTF-8 '
u'encoded.')
xml_data = file_is_unicode(xml_data)
if not xml_data:
break
filexml = self.checkVersionAndConvert(xml_data)
filexml = self._checkVersionAndConvert(xml_data)
outfile = open(fullpath, u'w')
outfile.write(filexml.encode(u'utf-8'))
else:
@ -552,22 +549,6 @@ class ThemeManager(QtGui.QWidget):
if outfile:
outfile.close()
def checkVersionAndConvert(self, xml_data):
"""
Check if a theme is from OpenLP version 1
``xml_data``
Theme XML to check the version of
"""
log.debug(u'checkVersion1 ')
theme = xml_data.encode(u'ascii', u'xmlcharrefreplace')
tree = ElementTree(element=XML(theme)).getroot()
# look for old version 1 tags
if tree.find(u'BackgroundType') is None:
return xml_data
else:
return self._migrateVersion122(xml_data)
def checkIfThemeExists(self, themeName):
"""
Check if theme already exists and displays error message
@ -597,10 +578,7 @@ class ThemeManager(QtGui.QWidget):
theme_file = os.path.join(theme_dir, name + u'.xml')
if imageTo and self.oldBackgroundImage and \
imageTo != self.oldBackgroundImage:
try:
os.remove(self.oldBackgroundImage)
except OSError:
log.exception(u'Unable to remove old theme background')
delete_file(self.oldBackgroundImage)
outfile = None
try:
outfile = open(theme_file, u'w')
@ -661,6 +639,22 @@ class ThemeManager(QtGui.QWidget):
image = os.path.join(self.path, theme + u'.png')
return image
def _checkVersionAndConvert(self, xml_data):
"""
Check if a theme is from OpenLP version 1
``xml_data``
Theme XML to check the version of
"""
log.debug(u'checkVersion1 ')
theme = xml_data.encode(u'ascii', u'xmlcharrefreplace')
tree = ElementTree(element=XML(theme)).getroot()
# look for old version 1 tags
if tree.find(u'BackgroundType') is None:
return xml_data
else:
return self._migrateVersion122(xml_data)
def _createThemeFromXml(self, themeXml, path):
"""
Return a theme object using information parsed from XML

View File

@ -282,6 +282,23 @@ def split_filename(path):
else:
return os.path.split(path)
def delete_file(file_path_name):
"""
Deletes a file from the system.
``file_path_name``
The file, including path, to delete.
"""
if not file_path_name:
return False
try:
if os.path.exists(file_path_name):
os.remove(file_path_name)
return True
except (IOError, OSError):
log.exception("Unable to delete file %s" % file_path_name)
return False
def get_web_page(url, header=None, update_openlp=False):
"""
Attempts to download the webpage at url and returns that page or None.

View File

@ -536,7 +536,7 @@ class BibleMediaItem(MediaManagerItem):
message=translate('BiblePlugin.MediaItem',
'You cannot combine single and second bible verses. Do you '
'want to delete your search results and start a new search?'),
question=True) == QtGui.QMessageBox.Yes:
parent=self, question=True) == QtGui.QMessageBox.Yes:
self.listView.clear()
self.displayResults(bible, second_bible)
else:
@ -584,7 +584,7 @@ class BibleMediaItem(MediaManagerItem):
message=translate('BiblePlugin.MediaItem',
'You cannot combine single and second bible verses. Do you '
'want to delete your search results and start a new search?'),
question=True) == QtGui.QMessageBox.Yes:
parent=self, question=True) == QtGui.QMessageBox.Yes:
self.listView.clear()
self.displayResults(bible, second_bible)
elif self.search_results:
@ -710,21 +710,21 @@ class BibleMediaItem(MediaManagerItem):
second_copyright, second_permissions)
if footer not in raw_footer:
raw_footer.append(footer)
bible_text = u'%s\u00a0%s\n\n%s\u00a0%s' % (verse_text, text,
bible_text = u'%s&nbsp;%s\n\n%s&nbsp;%s' % (verse_text, text,
verse_text, second_text)
raw_slides.append(bible_text)
raw_slides.append(bible_text.rstrip())
bible_text = u''
# If we are 'Verse Per Slide' then create a new slide.
elif self.parent.settings_tab.layout_style == 0:
bible_text = u'%s\u00a0%s' % (verse_text, text)
raw_slides.append(bible_text)
bible_text = u'%s&nbsp;%s' % (verse_text, text)
raw_slides.append(bible_text.rstrip())
bible_text = u''
# If we are 'Verse Per Line' then force a new line.
elif self.parent.settings_tab.layout_style == 1:
bible_text = u'%s %s\u00a0%s\n' % (bible_text, verse_text, text)
bible_text = u'%s %s&nbsp;%s\n' % (bible_text, verse_text, text)
# We have to be 'Continuous'.
else:
bible_text = u'%s %s\u00a0%s\n' % (bible_text, verse_text, text)
bible_text = u'%s %s&nbsp;%s\n' % (bible_text, verse_text, text)
if not old_item:
start_item = item
elif self.checkTitle(item, old_item):
@ -735,7 +735,7 @@ class BibleMediaItem(MediaManagerItem):
raw_title.append(self.formatTitle(start_item, item))
# If there are no more items we check whether we have to add bible_text.
if bible_text:
raw_slides.append(bible_text)
raw_slides.append(bible_text.lstrip())
bible_text = u''
# Service Item: Capabilities
if self.parent.settings_tab.layout_style == 2 and not second_bible:

View File

@ -33,7 +33,7 @@ from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \
ItemCapabilities, SettingsManager, translate, check_item_selected, \
check_directory_exists
from openlp.core.ui import criticalErrorMessageBox
from openlp.core.utils import AppLocation, get_images_filter
from openlp.core.utils import AppLocation, delete_file, get_images_filter
log = logging.getLogger(__name__)
@ -116,12 +116,8 @@ class ImageMediaItem(MediaManagerItem):
for row in row_list:
text = self.listView.item(row)
if text:
try:
os.remove(os.path.join(self.servicePath,
unicode(text.text())))
except OSError:
# if not present do not worry
pass
delete_file(os.path.join(self.servicePath,
unicode(text.text())))
self.listView.takeItem(row)
SettingsManager.set_list(self.settingsSection,
self.settingsSection, self.getFileList())

View File

@ -51,6 +51,7 @@ else:
from PyQt4 import QtCore
from openlp.core.utils import delete_file
from presentationcontroller import PresentationController, PresentationDocument
log = logging.getLogger(__name__)
@ -292,8 +293,7 @@ class ImpressDocument(PresentationDocument):
try:
doc.storeToURL(urlpath, props)
self.convert_thumbnail(path, idx + 1)
if os.path.exists(path):
os.remove(path)
delete_file(path)
except:
log.exception(u'%s - Unable to store openoffice preview' % path)

View File

@ -94,7 +94,7 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
message=translate('SongsPlugin.AuthorsForm',
'You have not set a display name for the '
'author, combine the first and last names?'),
question=True) == QtGui.QMessageBox.Yes:
parent=self, question=True) == QtGui.QMessageBox.Yes:
self.displayEdit.setText(self.firstNameEdit.text() + \
u' ' + self.lastNameEdit.text())
return QtGui.QDialog.accept(self)

View File

@ -332,7 +332,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
else:
author = Author.populate(first_name=text.rsplit(u' ', 1)[0],
last_name=text.rsplit(u' ', 1)[1], display_name=text)
self.manager.save_object(author)
self.manager.save_object(author, False)
author_item = QtGui.QListWidgetItem(
unicode(author.display_name))
author_item.setData(QtCore.Qt.UserRole,
@ -386,7 +386,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
QtGui.QMessageBox.Yes) == QtGui.QMessageBox.Yes:
topic = Topic.populate(name=text)
self.manager.save_object(topic)
self.manager.save_object(topic, False)
topic_item = QtGui.QListWidgetItem(unicode(topic.name))
topic_item.setData(QtCore.Qt.UserRole,
QtCore.QVariant(topic.id))
@ -649,7 +649,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
def accept(self):
"""
Exit Dialog and save soong if valid
Exit Dialog and save song if valid
"""
log.debug(u'accept')
self.clearCaches()
@ -665,7 +665,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
QtGui.QMessageBox.Yes) == QtGui.QMessageBox.Yes:
book = Book.populate(name=text, publisher=u'')
self.manager.save_object(book)
self.manager.save_object(book, False)
else:
return
if self.saveSong():

View File

@ -92,7 +92,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
item = self.manager.get_object(item_class, item_id)
if item and len(item.songs) == 0:
if criticalErrorMessageBox(title=dlg_title, message=del_text,
question=True) == QtGui.QMessageBox.Yes:
parent=self, question=True) == QtGui.QMessageBox.Yes:
self.manager.delete_object(item_class, item.id)
reset_func()
else:
@ -303,7 +303,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
'exists. Would you like to make songs with author %s use '
'the existing author %s?')) % (author.display_name,
temp_display_name, author.display_name),
question=True) == QtGui.QMessageBox.Yes:
parent=self, question=True) == QtGui.QMessageBox.Yes:
self.mergeAuthors(author)
self.resetAuthors()
Receiver.send_message(u'songs_load_list')
@ -339,7 +339,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
'The topic %s already exists. Would you like to make songs '
'with topic %s use the existing topic %s?')) % (topic.name,
temp_name, topic.name),
question=True) == QtGui.QMessageBox.Yes:
parent=self, question=True) == QtGui.QMessageBox.Yes:
self.mergeTopics(topic)
self.resetTopics()
else:
@ -377,7 +377,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
'The book %s already exists. Would you like to make songs '
'with book %s use the existing book %s?')) % (book.name,
temp_name, book.name),
question=True) == QtGui.QMessageBox.Yes:
parent=self, question=True) == QtGui.QMessageBox.Yes:
self.mergeBooks(book)
self.resetBooks()
else:

View File

@ -34,9 +34,6 @@ from songimport import SongImport
log = logging.getLogger(__name__)
class CCLIFileImportError(Exception):
pass
class CCLIFileImport(SongImport):
"""
The :class:`CCLIFileImport` class provides OpenLP with the ability to
@ -152,7 +149,6 @@ class CCLIFileImport(SongImport):
"""
log.debug(u'USR file text: %s', textList)
lyrics = []
self.set_defaults()
for line in textList:
if line.startswith(u'Title='):

View File

@ -72,7 +72,7 @@ def init_schema(url):
``url``
The database to setup
"""
session, metadata = init_db(url)
session, metadata = init_db(url, False)
# Definition of the "authors" table
authors_table = Table(u'authors', metadata,
@ -181,4 +181,4 @@ def init_schema(url):
mapper(Topic, topics_table)
metadata.create_all(checkfirst=True)
return session
return session