forked from openlp/openlp
Lots of small refactors and cleanups
bzr-revno: 1224
This commit is contained in:
commit
e2e75af066
@ -28,9 +28,9 @@ import re
|
|||||||
try:
|
try:
|
||||||
import enchant
|
import enchant
|
||||||
from enchant import DictNotFoundError
|
from enchant import DictNotFoundError
|
||||||
enchant_available = True
|
ENCHANT_AVAILABLE = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
enchant_available = False
|
ENCHANT_AVAILABLE = False
|
||||||
|
|
||||||
# based on code from
|
# based on code from
|
||||||
# http://john.nachtimwald.com/2009/08/22/qplaintextedit-with-in-line-spell-check
|
# http://john.nachtimwald.com/2009/08/22/qplaintextedit-with-in-line-spell-check
|
||||||
@ -45,7 +45,7 @@ class SpellTextEdit(QtGui.QPlainTextEdit):
|
|||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
QtGui.QPlainTextEdit.__init__(self, *args)
|
QtGui.QPlainTextEdit.__init__(self, *args)
|
||||||
# Default dictionary based on the current locale.
|
# Default dictionary based on the current locale.
|
||||||
if enchant_available:
|
if ENCHANT_AVAILABLE:
|
||||||
try:
|
try:
|
||||||
self.dict = enchant.Dict()
|
self.dict = enchant.Dict()
|
||||||
except DictNotFoundError:
|
except DictNotFoundError:
|
||||||
@ -72,7 +72,7 @@ class SpellTextEdit(QtGui.QPlainTextEdit):
|
|||||||
self.setTextCursor(cursor)
|
self.setTextCursor(cursor)
|
||||||
# Check if the selected word is misspelled and offer spelling
|
# Check if the selected word is misspelled and offer spelling
|
||||||
# suggestions if it is.
|
# suggestions if it is.
|
||||||
if enchant_available and self.textCursor().hasSelection():
|
if ENCHANT_AVAILABLE and self.textCursor().hasSelection():
|
||||||
text = unicode(self.textCursor().selectedText())
|
text = unicode(self.textCursor().selectedText())
|
||||||
if not self.dict.check(text):
|
if not self.dict.check(text):
|
||||||
spell_menu = QtGui.QMenu(translate('OpenLP.SpellTextEdit',
|
spell_menu = QtGui.QMenu(translate('OpenLP.SpellTextEdit',
|
||||||
|
@ -163,8 +163,7 @@ class AdvancedTab(SettingsTab):
|
|||||||
settings.value(u'enable exit confirmation',
|
settings.value(u'enable exit confirmation',
|
||||||
QtCore.QVariant(True)).toBool())
|
QtCore.QVariant(True)).toBool())
|
||||||
self.hideMouseCheckBox.setChecked(
|
self.hideMouseCheckBox.setChecked(
|
||||||
settings.value(u'hide mouse',
|
settings.value(u'hide mouse', QtCore.QVariant(False)).toBool())
|
||||||
QtCore.QVariant(False)).toBool())
|
|
||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
"""
|
"""
|
||||||
The :mod:`utils` module provides the utility libraries for OpenLP
|
The :mod:`utils` module provides the utility libraries for OpenLP
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@ -36,12 +35,18 @@ import urllib2
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from PyQt4 import QtGui, QtCore
|
from PyQt4 import QtGui, QtCore
|
||||||
|
if sys.platform != u'win32' and sys.platform != u'darwin':
|
||||||
|
try:
|
||||||
|
from xdg import BaseDirectory
|
||||||
|
XDG_BASE_AVAILABLE = True
|
||||||
|
except ImportError:
|
||||||
|
XDG_BASE_AVAILABLE = False
|
||||||
|
|
||||||
import openlp
|
import openlp
|
||||||
from openlp.core.lib import Receiver, translate
|
from openlp.core.lib import Receiver, translate
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
images_filter = None
|
IMAGES_FILTER = None
|
||||||
|
|
||||||
class VersionThread(QtCore.QThread):
|
class VersionThread(QtCore.QThread):
|
||||||
"""
|
"""
|
||||||
@ -113,77 +118,46 @@ class AppLocation(object):
|
|||||||
The directory type you want, for instance the data directory.
|
The directory type you want, for instance the data directory.
|
||||||
"""
|
"""
|
||||||
if dir_type == AppLocation.AppDir:
|
if dir_type == AppLocation.AppDir:
|
||||||
if hasattr(sys, u'frozen') and sys.frozen == 1:
|
return _get_frozen_path(
|
||||||
app_path = os.path.abspath(os.path.split(sys.argv[0])[0])
|
os.path.abspath(os.path.split(sys.argv[0])[0]),
|
||||||
else:
|
os.path.split(openlp.__file__)[0])
|
||||||
app_path = os.path.split(openlp.__file__)[0]
|
|
||||||
return app_path
|
|
||||||
elif dir_type == AppLocation.ConfigDir:
|
elif dir_type == AppLocation.ConfigDir:
|
||||||
if sys.platform == u'win32':
|
return _get_os_dir_path(u'openlp',
|
||||||
path = os.path.join(os.getenv(u'APPDATA'), u'openlp')
|
os.path.join(os.getenv(u'HOME'), u'Library',
|
||||||
elif sys.platform == u'darwin':
|
u'Application Support', u'openlp'),
|
||||||
path = os.path.join(os.getenv(u'HOME'), u'Library',
|
os.path.join(BaseDirectory.xdg_config_home, u'openlp'),
|
||||||
u'Application Support', u'openlp')
|
os.path.join(os.getenv(u'HOME'), u'.openlp'))
|
||||||
else:
|
|
||||||
try:
|
|
||||||
from xdg import BaseDirectory
|
|
||||||
path = os.path.join(
|
|
||||||
BaseDirectory.xdg_config_home, u'openlp')
|
|
||||||
except ImportError:
|
|
||||||
path = os.path.join(os.getenv(u'HOME'), u'.openlp')
|
|
||||||
return path
|
|
||||||
elif dir_type == AppLocation.DataDir:
|
elif dir_type == AppLocation.DataDir:
|
||||||
if sys.platform == u'win32':
|
return _get_os_dir_path(os.path.join(u'openlp', u'data'),
|
||||||
path = os.path.join(os.getenv(u'APPDATA'), u'openlp', u'data')
|
os.path.join(os.getenv(u'HOME'), u'Library',
|
||||||
elif sys.platform == u'darwin':
|
u'Application Support', u'openlp', u'Data'),
|
||||||
path = os.path.join(os.getenv(u'HOME'), u'Library',
|
os.path.join(BaseDirectory.xdg_data_home, u'openlp'),
|
||||||
u'Application Support', u'openlp', u'Data')
|
os.path.join(os.getenv(u'HOME'), u'.openlp', u'data'))
|
||||||
else:
|
|
||||||
try:
|
|
||||||
from xdg import BaseDirectory
|
|
||||||
path = os.path.join(BaseDirectory.xdg_data_home, u'openlp')
|
|
||||||
except ImportError:
|
|
||||||
path = os.path.join(os.getenv(u'HOME'), u'.openlp', u'data')
|
|
||||||
return path
|
|
||||||
elif dir_type == AppLocation.PluginsDir:
|
elif dir_type == AppLocation.PluginsDir:
|
||||||
plugin_path = None
|
|
||||||
app_path = os.path.abspath(os.path.split(sys.argv[0])[0])
|
app_path = os.path.abspath(os.path.split(sys.argv[0])[0])
|
||||||
if hasattr(sys, u'frozen') and sys.frozen == 1:
|
return _get_frozen_path(os.path.join(app_path, u'plugins'),
|
||||||
plugin_path = os.path.join(app_path, u'plugins')
|
os.path.join(os.path.split(openlp.__file__)[0], u'plugins'))
|
||||||
else:
|
|
||||||
plugin_path = os.path.join(
|
|
||||||
os.path.split(openlp.__file__)[0], u'plugins')
|
|
||||||
return plugin_path
|
|
||||||
elif dir_type == AppLocation.VersionDir:
|
elif dir_type == AppLocation.VersionDir:
|
||||||
if hasattr(sys, u'frozen') and sys.frozen == 1:
|
return _get_frozen_path(
|
||||||
version_path = os.path.abspath(os.path.split(sys.argv[0])[0])
|
os.path.abspath(os.path.split(sys.argv[0])[0]),
|
||||||
else:
|
os.path.split(openlp.__file__)[0])
|
||||||
version_path = os.path.split(openlp.__file__)[0]
|
|
||||||
return version_path
|
|
||||||
elif dir_type == AppLocation.CacheDir:
|
elif dir_type == AppLocation.CacheDir:
|
||||||
if sys.platform == u'win32':
|
return _get_os_dir_path(u'openlp',
|
||||||
path = os.path.join(os.getenv(u'APPDATA'), u'openlp')
|
os.path.join(os.getenv(u'HOME'), u'Library',
|
||||||
elif sys.platform == u'darwin':
|
u'Application Support', u'openlp'),
|
||||||
path = os.path.join(os.getenv(u'HOME'), u'Library',
|
os.path.join(BaseDirectory.xdg_cache_home, u'openlp'),
|
||||||
u'Application Support', u'openlp')
|
os.path.join(os.getenv(u'HOME'), u'.openlp'))
|
||||||
else:
|
|
||||||
try:
|
|
||||||
from xdg import BaseDirectory
|
|
||||||
path = os.path.join(
|
|
||||||
BaseDirectory.xdg_cache_home, u'openlp')
|
|
||||||
except ImportError:
|
|
||||||
path = os.path.join(os.getenv(u'HOME'), u'.openlp')
|
|
||||||
return path
|
|
||||||
if dir_type == AppLocation.LanguageDir:
|
if dir_type == AppLocation.LanguageDir:
|
||||||
if hasattr(sys, u'frozen') and sys.frozen == 1:
|
app_path = _get_frozen_path(
|
||||||
app_path = os.path.abspath(os.path.split(sys.argv[0])[0])
|
os.path.abspath(os.path.split(sys.argv[0])[0]),
|
||||||
else:
|
os.path.split(openlp.__file__)[0])
|
||||||
app_path = os.path.split(openlp.__file__)[0]
|
|
||||||
return os.path.join(app_path, u'i18n')
|
return os.path.join(app_path, u'i18n')
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_data_path():
|
def get_data_path():
|
||||||
|
"""
|
||||||
|
Return the path OpenLP stores all its data under.
|
||||||
|
"""
|
||||||
path = AppLocation.get_directory(AppLocation.DataDir)
|
path = AppLocation.get_directory(AppLocation.DataDir)
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
@ -191,12 +165,38 @@ class AppLocation(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_section_data_path(section):
|
def get_section_data_path(section):
|
||||||
|
"""
|
||||||
|
Return the path a particular module stores its data under.
|
||||||
|
"""
|
||||||
data_path = AppLocation.get_data_path()
|
data_path = AppLocation.get_data_path()
|
||||||
path = os.path.join(data_path, section)
|
path = os.path.join(data_path, section)
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
def _get_os_dir_path(win_option, darwin_option, base_dir_option,
|
||||||
|
non_base_dir_option):
|
||||||
|
"""
|
||||||
|
Return a path based on which OS and environment we are running in.
|
||||||
|
"""
|
||||||
|
if sys.platform == u'win32':
|
||||||
|
return os.path.join(os.getenv(u'APPDATA'), win_option)
|
||||||
|
elif sys.platform == u'darwin':
|
||||||
|
return darwin_option
|
||||||
|
else:
|
||||||
|
if XDG_BASE_AVAILABLE:
|
||||||
|
return base_dir_option
|
||||||
|
else:
|
||||||
|
return non_base_dir_option
|
||||||
|
|
||||||
|
def _get_frozen_path(frozen_option, non_frozen_option):
|
||||||
|
"""
|
||||||
|
Return a path based on the system status.
|
||||||
|
"""
|
||||||
|
if hasattr(sys, u'frozen') and sys.frozen == 1:
|
||||||
|
return frozen_option
|
||||||
|
else:
|
||||||
|
return non_frozen_option
|
||||||
|
|
||||||
def check_latest_version(current_version):
|
def check_latest_version(current_version):
|
||||||
"""
|
"""
|
||||||
@ -225,9 +225,8 @@ def check_latest_version(current_version):
|
|||||||
remote_version = None
|
remote_version = None
|
||||||
try:
|
try:
|
||||||
remote_version = unicode(urllib2.urlopen(req, None).read()).strip()
|
remote_version = unicode(urllib2.urlopen(req, None).read()).strip()
|
||||||
except IOError, e:
|
except IOError:
|
||||||
if hasattr(e, u'reason'):
|
log.exception(u'Failed to download the latest OpenLP version file')
|
||||||
log.exception(u'Reason for failure: %s', e.reason)
|
|
||||||
if remote_version:
|
if remote_version:
|
||||||
version_string = remote_version
|
version_string = remote_version
|
||||||
return version_string
|
return version_string
|
||||||
@ -264,18 +263,21 @@ def get_images_filter():
|
|||||||
Returns a filter string for a file dialog containing all the supported
|
Returns a filter string for a file dialog containing all the supported
|
||||||
image formats.
|
image formats.
|
||||||
"""
|
"""
|
||||||
global images_filter
|
global IMAGES_FILTER
|
||||||
if not images_filter:
|
if not IMAGES_FILTER:
|
||||||
log.debug(u'Generating images filter.')
|
log.debug(u'Generating images filter.')
|
||||||
formats = [unicode(fmt)
|
formats = [unicode(fmt)
|
||||||
for fmt in QtGui.QImageReader.supportedImageFormats()]
|
for fmt in QtGui.QImageReader.supportedImageFormats()]
|
||||||
visible_formats = u'(*.%s)' % u'; *.'.join(formats)
|
visible_formats = u'(*.%s)' % u'; *.'.join(formats)
|
||||||
actual_formats = u'(*.%s)' % u' *.'.join(formats)
|
actual_formats = u'(*.%s)' % u' *.'.join(formats)
|
||||||
images_filter = u'%s %s %s' % (translate('OpenLP', 'Image Files'),
|
IMAGES_FILTER = u'%s %s %s' % (translate('OpenLP', 'Image Files'),
|
||||||
visible_formats, actual_formats)
|
visible_formats, actual_formats)
|
||||||
return images_filter
|
return IMAGES_FILTER
|
||||||
|
|
||||||
def split_filename(path):
|
def split_filename(path):
|
||||||
|
"""
|
||||||
|
Return a list of the parts in a given path.
|
||||||
|
"""
|
||||||
path = os.path.abspath(path)
|
path = os.path.abspath(path)
|
||||||
if not os.path.isfile(path):
|
if not os.path.isfile(path):
|
||||||
return path, u''
|
return path, u''
|
||||||
|
@ -48,49 +48,27 @@ class VerseType(object):
|
|||||||
``verse_type``
|
``verse_type``
|
||||||
The type to return a string for
|
The type to return a string for
|
||||||
"""
|
"""
|
||||||
if verse_type == VerseType.Verse:
|
if not isinstance(verse_type, int):
|
||||||
return translate('SongsPlugin.VerseType', 'Verse')
|
verse_type = verse_type.lower()
|
||||||
elif verse_type == VerseType.Chorus:
|
if verse_type == VerseType.Verse or verse_type == \
|
||||||
return translate('SongsPlugin.VerseType', 'Chorus')
|
|
||||||
elif verse_type == VerseType.Bridge:
|
|
||||||
return translate('SongsPlugin.VerseType', 'Bridge')
|
|
||||||
elif verse_type == VerseType.PreChorus:
|
|
||||||
return translate('SongsPlugin.VerseType', 'Pre-Chorus')
|
|
||||||
elif verse_type == VerseType.Intro:
|
|
||||||
return translate('SongsPlugin.VerseType', 'Intro')
|
|
||||||
elif verse_type == VerseType.Ending:
|
|
||||||
return translate('SongsPlugin.VerseType', 'Ending')
|
|
||||||
elif verse_type == VerseType.Other:
|
|
||||||
return translate('SongsPlugin.VerseType', 'Other')
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def expand_string(verse_type):
|
|
||||||
"""
|
|
||||||
Return the VerseType for a given string
|
|
||||||
|
|
||||||
``verse_type``
|
|
||||||
The string to return a VerseType for
|
|
||||||
"""
|
|
||||||
verse_type = verse_type.lower()
|
|
||||||
if verse_type == \
|
|
||||||
unicode(VerseType.to_string(VerseType.Verse)).lower()[0]:
|
unicode(VerseType.to_string(VerseType.Verse)).lower()[0]:
|
||||||
return translate('SongsPlugin.VerseType', 'Verse')
|
return translate('SongsPlugin.VerseType', 'Verse')
|
||||||
elif verse_type == \
|
elif verse_type == VerseType.Chorus or verse_type == \
|
||||||
unicode(VerseType.to_string(VerseType.Chorus)).lower()[0]:
|
unicode(VerseType.to_string(VerseType.Chorus)).lower()[0]:
|
||||||
return translate('SongsPlugin.VerseType', 'Chorus')
|
return translate('SongsPlugin.VerseType', 'Chorus')
|
||||||
elif verse_type == \
|
elif verse_type == VerseType.Bridge or verse_type == \
|
||||||
unicode(VerseType.to_string(VerseType.Bridge)).lower()[0]:
|
unicode(VerseType.to_string(VerseType.Bridge)).lower()[0]:
|
||||||
return translate('SongsPlugin.VerseType', 'Bridge')
|
return translate('SongsPlugin.VerseType', 'Bridge')
|
||||||
elif verse_type == \
|
elif verse_type == VerseType.PreChorus or verse_type == \
|
||||||
unicode(VerseType.to_string(VerseType.PreChorus)).lower()[0]:
|
unicode(VerseType.to_string(VerseType.PreChorus)).lower()[0]:
|
||||||
return translate('SongsPlugin.VerseType', 'PreChorus')
|
return translate('SongsPlugin.VerseType', 'Pre-Chorus')
|
||||||
elif verse_type == \
|
elif verse_type == VerseType.Intro or verse_type == \
|
||||||
unicode(VerseType.to_string(VerseType.Intro)).lower()[0]:
|
unicode(VerseType.to_string(VerseType.Intro)).lower()[0]:
|
||||||
return translate('SongsPlugin.VerseType', 'Intro')
|
return translate('SongsPlugin.VerseType', 'Intro')
|
||||||
elif verse_type == \
|
elif verse_type == VerseType.Ending or verse_type == \
|
||||||
unicode(VerseType.to_string(VerseType.Ending)).lower()[0]:
|
unicode(VerseType.to_string(VerseType.Ending)).lower()[0]:
|
||||||
return translate('SongsPlugin.VerseType', 'Ending')
|
return translate('SongsPlugin.VerseType', 'Ending')
|
||||||
elif verse_type == \
|
elif verse_type == VerseType.Other or verse_type == \
|
||||||
unicode(VerseType.to_string(VerseType.Other)).lower()[0]:
|
unicode(VerseType.to_string(VerseType.Other)).lower()[0]:
|
||||||
return translate('SongsPlugin.VerseType', 'Other')
|
return translate('SongsPlugin.VerseType', 'Other')
|
||||||
|
|
||||||
@ -163,7 +141,7 @@ def retrieve_windows_encoding(recommendation=None):
|
|||||||
translate('SongsPlugin', 'Character Encoding'),
|
translate('SongsPlugin', 'Character Encoding'),
|
||||||
translate('SongsPlugin', 'The codepage setting is responsible\n'
|
translate('SongsPlugin', 'The codepage setting is responsible\n'
|
||||||
'for the correct character representation.\n'
|
'for the correct character representation.\n'
|
||||||
'Usually you are fine with the preselected choise.'),
|
'Usually you are fine with the preselected choice.'),
|
||||||
[pair[1] for pair in encodings], recommended_index, False)
|
[pair[1] for pair in encodings], recommended_index, False)
|
||||||
else:
|
else:
|
||||||
choice = QtGui.QInputDialog.getItem(None,
|
choice = QtGui.QInputDialog.getItem(None,
|
||||||
|
@ -23,7 +23,9 @@
|
|||||||
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
"""
|
||||||
|
The :mod:`importer` modules provides the general song import functionality.
|
||||||
|
"""
|
||||||
from opensongimport import OpenSongImport
|
from opensongimport import OpenSongImport
|
||||||
from olpimport import OpenLPSongImport
|
from olpimport import OpenLPSongImport
|
||||||
from openlyricsimport import OpenLyricsImport
|
from openlyricsimport import OpenLyricsImport
|
||||||
@ -34,19 +36,19 @@ from songbeamerimport import SongBeamerImport
|
|||||||
# Imports that might fail
|
# Imports that might fail
|
||||||
try:
|
try:
|
||||||
from olp1import import OpenLP1SongImport
|
from olp1import import OpenLP1SongImport
|
||||||
has_openlp1 = True
|
HAS_OPENLP1 = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
has_openlp1 = False
|
HAS_OPENLP1 = False
|
||||||
try:
|
try:
|
||||||
from sofimport import SofImport
|
from sofimport import SofImport
|
||||||
has_sof = True
|
HAS_SOF = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
has_sof = False
|
HAS_SOF = False
|
||||||
try:
|
try:
|
||||||
from oooimport import OooImport
|
from oooimport import OooImport
|
||||||
has_ooo = True
|
HAS_OOO = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
has_ooo = False
|
HAS_OOO = False
|
||||||
|
|
||||||
class SongFormat(object):
|
class SongFormat(object):
|
||||||
"""
|
"""
|
||||||
@ -118,14 +120,20 @@ class SongFormat(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def set_availability(format, available):
|
def set_availability(format, available):
|
||||||
|
"""
|
||||||
|
Set the availability for a given song format.
|
||||||
|
"""
|
||||||
SongFormat._format_availability[format] = available
|
SongFormat._format_availability[format] = available
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_availability(format):
|
def get_availability(format):
|
||||||
|
"""
|
||||||
|
Return the availability of a given song format.
|
||||||
|
"""
|
||||||
return SongFormat._format_availability.get(format, True)
|
return SongFormat._format_availability.get(format, True)
|
||||||
|
|
||||||
SongFormat.set_availability(SongFormat.OpenLP1, has_openlp1)
|
SongFormat.set_availability(SongFormat.OpenLP1, HAS_OPENLP1)
|
||||||
SongFormat.set_availability(SongFormat.SongsOfFellowship, has_sof)
|
SongFormat.set_availability(SongFormat.SongsOfFellowship, HAS_SOF)
|
||||||
SongFormat.set_availability(SongFormat.Generic, has_ooo)
|
SongFormat.set_availability(SongFormat.Generic, HAS_OOO)
|
||||||
|
|
||||||
__all__ = [u'SongFormat']
|
__all__ = [u'SongFormat']
|
||||||
|
@ -194,8 +194,7 @@ class SongMediaItem(MediaManagerItem):
|
|||||||
elif search_type == 5:
|
elif search_type == 5:
|
||||||
log.debug(u'Theme Search')
|
log.debug(u'Theme Search')
|
||||||
search_results = self.parent.manager.get_all_objects(Song,
|
search_results = self.parent.manager.get_all_objects(Song,
|
||||||
Song.theme_name == search_keywords,
|
Song.theme_name == search_keywords, Song.search_lyrics.asc())
|
||||||
Song.search_lyrics.asc())
|
|
||||||
self.displayResultsSong(search_results)
|
self.displayResultsSong(search_results)
|
||||||
|
|
||||||
def onSongListLoad(self):
|
def onSongListLoad(self):
|
||||||
|
@ -83,7 +83,7 @@ class SongBeamerImport(SongImport):
|
|||||||
|
|
||||||
def do_import(self):
|
def do_import(self):
|
||||||
"""
|
"""
|
||||||
Recieve a single file, or a list of files to import.
|
Receive a single file or a list of files to import.
|
||||||
"""
|
"""
|
||||||
if isinstance(self.import_source, list):
|
if isinstance(self.import_source, list):
|
||||||
self.import_wizard.progressBar.setMaximum(
|
self.import_wizard.progressBar.setMaximum(
|
||||||
@ -94,21 +94,21 @@ class SongBeamerImport(SongImport):
|
|||||||
self.current_verse = u''
|
self.current_verse = u''
|
||||||
self.current_verse_type = u'V'
|
self.current_verse_type = u'V'
|
||||||
read_verses = False
|
read_verses = False
|
||||||
self.file_name = os.path.split(file)[1]
|
file_name = os.path.split(file)[1]
|
||||||
self.import_wizard.incrementProgressBar(
|
self.import_wizard.incrementProgressBar(
|
||||||
u'Importing %s' % (self.file_name), 0)
|
u'Importing %s' % (file_name), 0)
|
||||||
if os.path.isfile(file):
|
if os.path.isfile(file):
|
||||||
detect_file = open(file, u'r')
|
detect_file = open(file, u'r')
|
||||||
details = chardet.detect(detect_file.read(2048))
|
details = chardet.detect(detect_file.read(2048))
|
||||||
detect_file.close()
|
detect_file.close()
|
||||||
infile = codecs.open(file, u'r', details['encoding'])
|
infile = codecs.open(file, u'r', details['encoding'])
|
||||||
self.songData = infile.readlines()
|
songData = infile.readlines()
|
||||||
infile.close()
|
infile.close()
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
self.title = self.file_name.split('.sng')[0]
|
self.title = file_name.split('.sng')[0]
|
||||||
read_verses = False
|
read_verses = False
|
||||||
for line in self.songData:
|
for line in songData:
|
||||||
# Just make sure that the line is of the type 'Unicode'.
|
# Just make sure that the line is of the type 'Unicode'.
|
||||||
line = unicode(line).strip()
|
line = unicode(line).strip()
|
||||||
if line.startswith(u'#') and not read_verses:
|
if line.startswith(u'#') and not read_verses:
|
||||||
@ -136,7 +136,7 @@ class SongBeamerImport(SongImport):
|
|||||||
self.finish()
|
self.finish()
|
||||||
self.import_wizard.incrementProgressBar(unicode(translate(
|
self.import_wizard.incrementProgressBar(unicode(translate(
|
||||||
'SongsPlugin.SongBeamerImport', 'Importing %s...')) %
|
'SongsPlugin.SongBeamerImport', 'Importing %s...')) %
|
||||||
self.file_name)
|
file_name)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def replace_html_tags(self):
|
def replace_html_tags(self):
|
||||||
|
@ -62,7 +62,6 @@ class SongImport(QtCore.QObject):
|
|||||||
Create defaults for properties - call this before each song
|
Create defaults for properties - call this before each song
|
||||||
if importing many songs at once to ensure a clean beginning
|
if importing many songs at once to ensure a clean beginning
|
||||||
"""
|
"""
|
||||||
self.authors = []
|
|
||||||
self.title = u''
|
self.title = u''
|
||||||
self.song_number = u''
|
self.song_number = u''
|
||||||
self.alternate_title = u''
|
self.alternate_title = u''
|
||||||
@ -251,17 +250,11 @@ class SongImport(QtCore.QObject):
|
|||||||
|
|
||||||
def finish(self):
|
def finish(self):
|
||||||
"""
|
"""
|
||||||
All fields have been set to this song. Write it away
|
All fields have been set to this song. Write the song to disk.
|
||||||
"""
|
"""
|
||||||
if not self.authors:
|
if not self.authors:
|
||||||
self.authors.append(unicode(translate('SongsPlugin.SongImport',
|
self.authors.append(unicode(translate('SongsPlugin.SongImport',
|
||||||
'Author unknown')))
|
'Author unknown')))
|
||||||
self.commit_song()
|
|
||||||
|
|
||||||
def commit_song(self):
|
|
||||||
"""
|
|
||||||
Write the song and its fields to disk
|
|
||||||
"""
|
|
||||||
log.info(u'commiting song %s to database', self.title)
|
log.info(u'commiting song %s to database', self.title)
|
||||||
song = Song()
|
song = Song()
|
||||||
song.title = self.title
|
song.title = self.title
|
||||||
|
@ -107,63 +107,60 @@ class WowImport(SongImport):
|
|||||||
|
|
||||||
def do_import(self):
|
def do_import(self):
|
||||||
"""
|
"""
|
||||||
Recieve a single file, or a list of files to import.
|
Receive a single file or a list of files to import.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if isinstance(self.import_source, list):
|
if isinstance(self.import_source, list):
|
||||||
self.import_wizard.progressBar.setMaximum(len(self.import_source))
|
self.import_wizard.progressBar.setMaximum(len(self.import_source))
|
||||||
for file in self.import_source:
|
for file in self.import_source:
|
||||||
self.author = u''
|
author = u''
|
||||||
self.copyright = u''
|
copyright = u''
|
||||||
self.file_name = os.path.split(file)[1]
|
file_name = os.path.split(file)[1]
|
||||||
self.import_wizard.incrementProgressBar(
|
self.import_wizard.incrementProgressBar(
|
||||||
u'Importing %s' % (self.file_name), 0)
|
u'Importing %s' % (file_name), 0)
|
||||||
# Get the song title
|
# Get the song title
|
||||||
self.title = self.file_name.rpartition(u'.')[0]
|
self.title = file_name.rpartition(u'.')[0]
|
||||||
self.songData = open(file, 'rb')
|
songData = open(file, 'rb')
|
||||||
if self.songData.read(19) != u'WoW File\nSong Words':
|
if songData.read(19) != u'WoW File\nSong Words':
|
||||||
continue
|
continue
|
||||||
# Seek to byte which stores number of blocks in the song
|
# Seek to byte which stores number of blocks in the song
|
||||||
self.songData.seek(56)
|
songData.seek(56)
|
||||||
self.no_of_blocks = ord(self.songData.read(1))
|
no_of_blocks = ord(songData.read(1))
|
||||||
# Seek to the beging of the first block
|
# Seek to the beging of the first block
|
||||||
self.songData.seek(82)
|
songData.seek(82)
|
||||||
for block in range(self.no_of_blocks):
|
for block in range(no_of_blocks):
|
||||||
self.lines_to_read = ord(self.songData.read(1))
|
self.lines_to_read = ord(songData.read(1))
|
||||||
# Skip 3 nulls to the beginnig of the 1st line
|
# Skip 3 nulls to the beginnig of the 1st line
|
||||||
self.songData.seek(3, os.SEEK_CUR)
|
songData.seek(3, os.SEEK_CUR)
|
||||||
self.block_text = u''
|
block_text = u''
|
||||||
while self.lines_to_read:
|
while self.lines_to_read:
|
||||||
self.length_of_line = ord(self.songData.read(1))
|
|
||||||
self.line_text = unicode(
|
self.line_text = unicode(
|
||||||
self.songData.read(self.length_of_line), u'cp1252')
|
songData.read(ord(songData.read(1))), u'cp1252')
|
||||||
self.songData.seek(1, os.SEEK_CUR)
|
songData.seek(1, os.SEEK_CUR)
|
||||||
if self.block_text != u'':
|
if block_text != u'':
|
||||||
self.block_text += u'\n'
|
block_text += u'\n'
|
||||||
self.block_text += self.line_text
|
block_text += self.line_text
|
||||||
self.lines_to_read -= 1
|
self.lines_to_read -= 1
|
||||||
self.block_type = BLOCK_TYPES[ord(self.songData.read(1))]
|
block_type = BLOCK_TYPES[ord(songData.read(1))]
|
||||||
# Skip 3 nulls at the end of the block
|
# Skip 3 nulls at the end of the block
|
||||||
self.songData.seek(3, os.SEEK_CUR)
|
songData.seek(3, os.SEEK_CUR)
|
||||||
# Blocks are seperated by 2 bytes, skip them, but not if
|
# Blocks are seperated by 2 bytes, skip them, but not if
|
||||||
# this is the last block!
|
# this is the last block!
|
||||||
if (block + 1) < self.no_of_blocks:
|
if (block + 1) < no_of_blocks:
|
||||||
self.songData.seek(2, os.SEEK_CUR)
|
songData.seek(2, os.SEEK_CUR)
|
||||||
self.add_verse(self.block_text, self.block_type)
|
self.add_verse(block_text, block_type)
|
||||||
# Now to extact the author
|
# Now to extract the author
|
||||||
self.author_length = ord(self.songData.read(1))
|
author_length = ord(songData.read(1))
|
||||||
if self.author_length != 0:
|
if author_length != 0:
|
||||||
self.author = unicode(
|
author = unicode(songData.read(author_length), u'cp1252')
|
||||||
self.songData.read(self.author_length), u'cp1252')
|
|
||||||
# Finally the copyright
|
# Finally the copyright
|
||||||
self.copyright_length = ord(self.songData.read(1))
|
copyright_length = ord(songData.read(1))
|
||||||
if self.copyright_length != 0:
|
if copyright_length != 0:
|
||||||
self.copyright = unicode(
|
copyright = unicode(
|
||||||
self.songData.read(self.copyright_length), u'cp1252')
|
songData.read(copyright_length), u'cp1252')
|
||||||
self.parse_author(self.author)
|
self.parse_author(author)
|
||||||
self.add_copyright(self.copyright)
|
self.add_copyright(copyright)
|
||||||
self.songData.close()
|
songData.close()
|
||||||
self.finish()
|
self.finish()
|
||||||
self.import_wizard.incrementProgressBar(
|
self.import_wizard.incrementProgressBar(
|
||||||
u'Importing %s' % (self.file_name))
|
u'Importing %s' % (file_name))
|
||||||
return True
|
return True
|
||||||
|
@ -435,7 +435,7 @@ class OpenLyrics(object):
|
|||||||
text += u'\n'
|
text += u'\n'
|
||||||
text += u'\n'.join([unicode(line) for line in lines.line])
|
text += u'\n'.join([unicode(line) for line in lines.line])
|
||||||
verse_name = self._get(verse, u'name')
|
verse_name = self._get(verse, u'name')
|
||||||
verse_type = unicode(VerseType.expand_string(verse_name[0]))[0]
|
verse_type = unicode(VerseType.to_string(verse_name[0]))[0]
|
||||||
verse_number = re.compile(u'[a-zA-Z]*').sub(u'', verse_name)
|
verse_number = re.compile(u'[a-zA-Z]*').sub(u'', verse_name)
|
||||||
verse_part = re.compile(u'[0-9]*').sub(u'', verse_name[1:])
|
verse_part = re.compile(u'[0-9]*').sub(u'', verse_name[1:])
|
||||||
# OpenLyrics allows e. g. "c", but we need "c1".
|
# OpenLyrics allows e. g. "c", but we need "c1".
|
||||||
|
Loading…
Reference in New Issue
Block a user