Latest merge from lp:~meths/openlp/trivialfixes

bzr-revno: 525
This commit is contained in:
Jon Tibble 2009-09-07 20:49:27 +02:00 committed by Raoul Snyman
commit 44e3050577
13 changed files with 1458 additions and 1329 deletions

View File

@ -312,7 +312,7 @@ class Renderer(object):
rectPath.lineTo(max_x, 0) rectPath.lineTo(max_x, 0)
rectPath.closeSubpath() rectPath.closeSubpath()
painter.drawPath(rectPath) painter.drawPath(rectPath)
elif self._theme.background_type== u'image': elif self._theme.background_type == u'image':
# image # image
painter.fillRect(self._frame.rect(), QtCore.Qt.black) painter.fillRect(self._frame.rect(), QtCore.Qt.black)
if self.bg_image is not None: if self.bg_image is not None:

View File

@ -20,6 +20,9 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA Place, Suite 330, Boston, MA 02111-1307 USA
""" """
from openlp.core.lib import str_to_bool
from openlp.core.utils import ConfigHelper
class SettingsManager(object): class SettingsManager(object):
""" """
Class to control the size of the UI components so they size correctly. Class to control the size of the UI components so they size correctly.
@ -31,9 +34,30 @@ class SettingsManager(object):
self.width = self.screen[u'size'].width() self.width = self.screen[u'size'].width()
self.height = self.screen[u'size'].height() self.height = self.screen[u'size'].height()
self.mainwindow_height = self.height * 0.8 self.mainwindow_height = self.height * 0.8
self.mainwindow_docbars = self.width / 5 self.mainwindow_docbars = self.width / 3
if self.mainwindow_docbars > 300: self.mainwindow_slidecontroller = self.width / 6
self.mainwindow_docbars = 300 self.showMediaManager = str_to_bool( ConfigHelper.get_config(
self.slidecontroller = ((self.width - (self.mainwindow_docbars * 3 ) / 2) / 2) -100 u'user interface', u'display mediamanager', True))
self.slidecontroller_image = self.slidecontroller - 50 self.showServiceManager = str_to_bool(ConfigHelper.get_config(
print self.width, self.mainwindow_docbars, self.slidecontroller, self.slidecontroller_image u'user interface', u'display servicemanager', True))
self.showThemeManager = str_to_bool(ConfigHelper.get_config(
u'user interface', u'display thememanager', True))
self.showPreviewPanel = str_to_bool(ConfigHelper.get_config(
u'user interface', u'display previewpanel', True))
def toggleMediaManager(self, isVisible):
ConfigHelper.set_config(u'user interface', u'display mediamanager',
isVisible)
def toggleServiceManager(self, isVisible):
ConfigHelper.set_config(u'user interface', u'display servicemanager',
isVisible)
def toggleThemeManager(self, isVisible):
ConfigHelper.set_config(u'user interface', u'display thememanager',
isVisible)
def togglePreviewPanel(self, isVisible):
ConfigHelper.set_config(u'user interface', u'display previewpanel',
isVisible)

View File

@ -24,23 +24,24 @@ sys.path.insert(0,(os.path.join(mypath, '..' ,'..', '..')))
# test the plugin manager with some plugins in the test_plugins directory # test the plugin manager with some plugins in the test_plugins directory
class TestPluginManager: class TestPluginManager:
def test_init(self): def test_init(self):
self.p=PluginManager(u'./testplugins') self.p = PluginManager(u'./testplugins')
p=self.p p = self.p
p.find_plugins(u'./testplugins', None, None) p.find_plugins(u'./testplugins', None, None)
assert (len(p.plugins)==2); assert(len(p.plugins) == 2)
# get list of the names of the plugins # get list of the names of the plugins
names=[plugin.name for plugin in p.plugins] names = [plugin.name for plugin in p.plugins]
# see which ones we've got # see which ones we've got
assert (u'testplugin1' in names) assert(u'testplugin1' in names)
assert (u'testplugin2' in names) assert(u'testplugin2' in names)
# and not got - it's too deep in the hierarchy! # and not got - it's too deep in the hierarchy!
assert (u'testplugin3' not in names) assert(u'testplugin3' not in names)
# test that the weighting is done right # test that the weighting is done right
assert p.plugins[0].name == "testplugin2" assert(p.plugins[0].name == "testplugin2")
assert p.plugins[1].name == "testplugin1" assert(p.plugins[1].name == "testplugin1")
if __name__ == "__main__": if __name__ == "__main__":
log.debug(u'Starting') log.debug(u'Starting')
t=TestPluginManager() t = TestPluginManager()
t.test_init() t.test_init()
log.debug(u'List of plugins found:') log.debug(u'List of plugins found:')
for plugin in t.p.plugins: for plugin in t.p.plugins:

View File

@ -21,10 +21,12 @@ import sys
import os, os.path import os, os.path
from PyQt4 import QtGui, QtCore from PyQt4 import QtGui, QtCore
mypath=os.path.split(os.path.abspath(__file__))[0]
sys.path.insert(0,(os.path.join(mypath, '..', '..','..')))
from openlp.core.theme import Theme from openlp.core.theme import Theme
from openlp.core import Renderer from openlp.core import Renderer
mypath = os.path.split(os.path.abspath(__file__))[0]
sys.path.insert(0, (os.path.join(mypath, '..', '..', '..')))
# from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66062 # from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66062
def whoami(depth=1): def whoami(depth=1):
return sys._getframe(depth).f_code.co_name return sys._getframe(depth).f_code.co_name
@ -34,8 +36,8 @@ class TstFrame:
def __init__(self, size): def __init__(self, size):
"""Create the DemoPanel.""" """Create the DemoPanel."""
self.width=size.width(); self.width = size.width();
self.height=size.height(); self.height = size.height();
# create something to be painted into # create something to be painted into
self._Buffer = QtGui.QPixmap(self.width, self.height) self._Buffer = QtGui.QPixmap(self.width, self.height)
def GetPixmap(self): def GetPixmap(self):
@ -47,10 +49,10 @@ class TestRender_base:
def __init__(self): def __init__(self):
if not os.path.exists(u'test_results'): if not os.path.exists(u'test_results'):
os.mkdir(u'test_results') os.mkdir(u'test_results')
self.app=None self.app = None
def write_to_file(self, pixmap, name): def write_to_file(self, pixmap, name):
im=pixmap.toImage() im=pixmap.toImage()
testpathname=os.path.join(u'test_results', name+'.bmp') testpathname = os.path.join(u'test_results', name+'.bmp')
if os.path.exists(testpathname): if os.path.exists(testpathname):
os.unlink(testpathname) os.unlink(testpathname)
im.save(testpathname, 'bmp') im.save(testpathname, 'bmp')
@ -85,7 +87,7 @@ class TestRender_base:
def setup_method(self, method): def setup_method(self, method):
print "SSsetup", method print "SSsetup", method
if not hasattr(self, 'app'): if not hasattr(self, 'app'):
self.app=None self.app = None
try: # see if we already have an app for some reason. try: # see if we already have an app for some reason.
# have to try and so something, cant just test against None # have to try and so something, cant just test against None
print "app", self.app, ";;;" print "app", self.app, ";;;"
@ -98,14 +100,14 @@ class TestRender_base:
# print "App", self.app # print "App", self.app
# self.app = QtGui.QApplication([]) # self.app = QtGui.QApplication([])
print "Application created and sorted" print "Application created and sorted"
self.size=QtCore.QSize(800,600) self.size = QtCore.QSize(800,600)
frame=TstFrame(size=self.size) frame = TstFrame(size = self.size)
self.frame=frame self.frame = frame
self.paintdest=frame.GetPixmap() self.paintdest = frame.GetPixmap()
self.r=Renderer() self.r=Renderer()
self.r.set_paint_dest(self.paintdest) self.r.set_paint_dest(self.paintdest)
self.expected_answer="Don't know yet" self.expected_answer = "Don't know yet"
self.answer=None self.answer = None
print "--------------- Setup Done -------------" print "--------------- Setup Done -------------"
def teardown_method(self, method): def teardown_method(self, method):
@ -118,34 +120,34 @@ class TestRender(TestRender_base):
def setup_method(self, method): def setup_method(self, method):
TestRender_base.setup_method(self, method) TestRender_base.setup_method(self, method)
self.r.set_debug(1) self.r.set_debug(1)
themefile=os.path.abspath(u'data_for_tests/render_theme.xml') themefile = os.path.abspath(u'data_for_tests/render_theme.xml')
self.r.set_theme(Theme(themefile)) # set default theme self.r.set_theme(Theme(themefile)) # set default theme
self.r._render_background() self.r._render_background()
self.r.set_text_rectangle(QtCore.QRect(0,0, self.size.width()-1, self.r.set_text_rectangle(QtCore.QRect(0,0, self.size.width()-1,
self.size.height()-1)) self.size.height()-1))
self.msg=None self.msg = None
def test_easy(self): def test_easy(self):
answer=self.r._render_single_line(u'Test line', tlcorner=(0,100)) answer = self.r._render_single_line(u'Test line', tlcorner = (0,100))
assert (answer==(219,163)) assert(answer == (219,163))
def test_longer(self): def test_longer(self):
answer=self.r._render_single_line( answer = self.r._render_single_line(
u'Test line with more words than fit on one line', u'Test line with more words than fit on one line',
tlcorner=(10,10)) tlcorner = (10,10))
assert (answer==(753,136)) assert(answer == (753,136))
def test_even_longer(self): def test_even_longer(self):
answer=self.r._render_single_line( answer = self.r._render_single_line(
u'Test line with more words than fit on either one or two lines', u'Test line with more words than fit on either one or two lines',
tlcorner=(10,10)) tlcorner = (10,10))
assert(answer==(753,199)) assert(answer == (753,199))
def test_lines(self): def test_lines(self):
lines=[] lines = []
lines.append(u'Line One') lines.append(u'Line One')
lines.append(u'Line Two') lines.append(u'Line Two')
lines.append(u'Line Three and should be long enough to wrap') lines.append(u'Line Three and should be long enough to wrap')
lines.append(u'Line Four and should be long enough to wrap also') lines.append(u'Line Four and should be long enough to wrap also')
answer=self.r._render_lines(lines) answer = self.r._render_lines(lines)
assert(answer==QtCore.QRect(0,0,741,378)) assert(answer == QtCore.QRect(0,0,741,378))
def test_set_words_openlp(self): def test_set_words_openlp(self):
words=""" words="""
@ -158,9 +160,9 @@ Line 2
Verse 3: Line 1 Verse 3: Line 1
Line 2 Line 2
Line 3""" Line 3"""
expected_answer=["Verse 1: Line 1\nLine 2","Verse 2: Line 1\nLine 2","Verse 3: Line 1\nLine 2\nLine 3"] expected_answer = ["Verse 1: Line 1\nLine 2","Verse 2: Line 1\nLine 2","Verse 3: Line 1\nLine 2\nLine 3"]
answer=self.r.set_words_openlp(words) answer = self.r.set_words_openlp(words)
assert (answer==expected_answer) assert(answer == expected_answer)
def test_render_screens(self): def test_render_screens(self):
words=""" words="""
@ -173,15 +175,16 @@ Line 2
Verse 3: Line 1 Verse 3: Line 1
Line 2 Line 2
Line 3""" Line 3"""
verses=self.r.set_words_openlp(words) verses = self.r.set_words_openlp(words)
expected_answer=["Verse 1: Line 1\nLine 2","Verse 2: Line 1\nLine 2","Verse 3: Line 1\nLine 2\nLine 3"] expected_answer = ["Verse 1: Line 1\nLine 2","Verse 2: Line 1\nLine 2","Verse 3: Line 1\nLine 2\nLine 3"]
assert (verses==expected_answer) assert(verses == expected_answer)
expected_answer=[QtCore.QRect(0,0,397,126), QtCore.QRect(0,0,397,126), QtCore.QRect(0,0,397,189)] expected_answer = [QtCore.QRect(0,0,397,126), QtCore.QRect(0,0,397,126),
QtCore.QRect(0,0,397,189)]
for v in range(len(verses)): for v in range(len(verses)):
answer=self.r.render_screen(v) answer=self.r.render_screen(v)
# print v, answer.x(), answer.y(), answer.width(), answer.height() # print v, answer.x(), answer.y(), answer.width(), answer.height()
assert(answer==expected_answer[v]) assert(answer == expected_answer[v])
def split_test(self, number, answer, expected_answers): def split_test(self, number, answer, expected_answers):
lines=[] lines=[]
@ -189,34 +192,37 @@ Line 3"""
for i in range(number): for i in range(number):
extra="" extra=""
if i == 51: # make an extra long line on line 51 to test wrapping if i == 51: # make an extra long line on line 51 to test wrapping
extra="Some more words to make it wrap around don't you know until it wraps so many times we don't know what to do" extra = "Some more words to make it wrap around don't you know until it wraps so many times we don't know what to do"
lines.append(u'Line %d %s' % (i, extra)) lines.append(u'Line %d %s' % (i, extra))
result=self.r.split_set_of_lines(lines) result = self.r.split_set_of_lines(lines)
print "results---------------__", result print "results---------------__", result
for i in range(len(result)): for i in range(len(result)):
self.setup_method(None) self.setup_method(None)
answer=self.r._render_lines(result[i]) answer = self.r._render_lines(result[i])
print answer print answer
self.write_to_file(self.frame.GetPixmap(), "split_test_%03d"% i) self.write_to_file(self.frame.GetPixmap(), "split_test_%03d"% i)
print number, i, answer.x(), answer.y(), answer.width(), answer.height() print number, i, answer.x(), answer.y(), answer.width(), \
answer.height()
e=expected_answers[i] e = expected_answers[i]
assert(answer==QtCore.QRect(e[0],e[1],e[2],e[3])) assert(answer == QtCore.QRect(e[0],e[1],e[2],e[3]))
def test_splits(self): def test_splits(self):
print "Test splits" print "Test splits"
self.split_test(100, 11, [(0,0,180,567), (0,0,214,567), (0,0,214,567), (0,0,214,567), (0,0,214,567), (0,0,214,378), (0,0,759,567), self.split_test(100, 11, [(0,0,180,567), (0,0,214,567), (0,0,214,567),
(0,0,214,567), (0,0,214,567), (0,0,214,567), (0,0,214,567), (0,0,214,567), (0,0,214,567)]) (0,0,214,567), (0,0,214,567), (0,0,214,378), (0,0,759,567),
self.split_test(30, 4, [ (0,0,180,441), (0,0,214,441), (0,0,214,441), (0,0,214,441)]) (0,0,214,567), (0,0,214,567), (0,0,214,567), (0,0,214,567),
(0,0,214,567), (0,0,214,567)])
self.split_test(30, 4, [ (0,0,180,441), (0,0,214,441), (0,0,214,441),
(0,0,214,441)])
self.split_test(20, 3, [(0,0,180,378), (0,0,214,378), (0,0,214,378)]) self.split_test(20, 3, [(0,0,180,378), (0,0,214,378), (0,0,214,378)])
self.split_test(12, 2, [(0,0,180,378), (0,0,214,378)]) self.split_test(12, 2, [(0,0,180,378), (0,0,214,378)])
self.split_test(4, 1, [(0,0,180,252)]) self.split_test(4, 1, [(0,0,180,252)])
self.split_test(6, 1, [(0,0,180,378)]) self.split_test(6, 1, [(0,0,180,378)])
self.split_test(8, 1, [(0,0,180,504)]) self.split_test(8, 1, [(0,0,180,504)])
if __name__=="__main__":
t=TestRender() if __name__ == "__main__":
t = TestRender()
t.setup_class() t.setup_class()
t.setup_method(None) t.setup_method(None)
t.test_easy() t.test_easy()

View File

@ -15,17 +15,18 @@ You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA Place, Suite 330, Boston, MA 02111-1307 USA
""" """
from test_render import TestRender_base, whoami
import sys import sys
import os import os
mypath=os.path.split(os.path.abspath(__file__))[0]
sys.path.insert(0,(os.path.join(mypath, '..', '..','..')))
from openlp.core.theme import Theme
from openlp.core import Renderer
from PyQt4 import QtGui, QtCore from PyQt4 import QtGui, QtCore
from openlp.core.theme import Theme
from openlp.core import Renderer
from test_render import TestRender_base, whoami
pypath = os.path.split(os.path.abspath(__file__))[0]
sys.path.insert(0, (os.path.join(mypath, '..', '..', '..')))
def compare_images(goldenim, testim, threshold=0.01): def compare_images(goldenim, testim, threshold=0.01):
# easy test first # easy test first
if goldenim == testim: if goldenim == testim:
@ -53,22 +54,24 @@ class TestRenderTheme(TestRender_base):
def __init__(self): def __init__(self):
TestRender_base.__init__(self) TestRender_base.__init__(self)
def setup_method(self, method): def setup_method(self, method):
TestRender_base.setup_method(self, method) TestRender_base.setup_method(self, method)
print "Theme setup", method print "Theme setup", method
# print "setup theme" # print "setup theme"
self.r.set_theme(Theme(u'blank_theme.xml')) # set "blank" theme self.r.set_theme(Theme(u'blank_theme.xml')) # set "blank" theme
self.r.set_text_rectangle(QtCore.QRect(0,0, self.size.width(), self.size.height())) self.r.set_text_rectangle(QtCore.QRect(0,0, self.size.width(),
words="""How sweet the name of Jesus sounds self.size.height()))
words = """How sweet the name of Jesus sounds
In a believer's ear! In a believer's ear!
It soothes his sorrows, heals his wounds, It soothes his sorrows, heals his wounds,
And drives away his fear. And drives away his fear.
""" """
verses=self.r.set_words_openlp(words) verses = self.r.set_words_openlp(words)
# usually the same # usually the same
self.expected_answer= QtCore.QRect(0, 0, 559, 342) self.expected_answer = QtCore.QRect(0, 0, 559, 342)
self.msg=None self.msg = None
self.bmpname="Not set a bitmap yet" self.bmpname = "Not set a bitmap yet"
print "------------- setup done --------------" print "------------- setup done --------------"
def teardown_method(self, method): def teardown_method(self, method):
@ -76,20 +79,21 @@ And drives away his fear.
if self.bmpname != None: if self.bmpname != None:
assert (self.compare_DC_to_file(self.bmpname)) assert (self.compare_DC_to_file(self.bmpname))
if self.expected_answer != None: # result=None => No result to check if self.expected_answer != None: # result=None => No result to check
assert self.expected_answer==self.answer assert self.expected_answer == self.answer
print "============ teardown done =========" print "============ teardown done ========="
def compare_DC_to_file(self, name): def compare_DC_to_file(self, name):
"""writes DC out to a bitmap file and then compares it with a golden one """writes DC out to a bitmap file and then compares it with a golden
returns True if OK, False if not (so you can assert on it) one returns True if OK, False if not (so you can assert on it)
""" """
print "--- compare DC to file --- ", name print "--- compare DC to file --- ", name
p=self.frame.GetPixmap() p = self.frame.GetPixmap()
im=self.write_to_file(p, name) im = self.write_to_file(p, name)
print "Compare" print "Compare"
goldenfilename=os.path.join(u'golden_bitmaps",name+".bmp') goldenfilename=os.path.join(u'golden_bitmaps",name+".bmp')
if os.path.exists(goldenfilename): if os.path.exists(goldenfilename):
goldenim=QtGui.QImage(goldenfilename) goldenim = QtGui.QImage(goldenfilename)
else: else:
print "File", goldenfilename, "not found" print "File", goldenfilename, "not found"
return False return False
@ -101,201 +105,210 @@ And drives away his fear.
return False return False
def test_theme_basic(self): def test_theme_basic(self):
self.answer=self.r.render_screen(0) self.answer = self.r.render_screen(0)
self.bmpname=whoami() self.bmpname = whoami()
print self.r._theme.FontProportion print self.r._theme.FontProportion
print self.answer, self.expected_answer, self.answer==self.expected_answer print self.answer, self.expected_answer, \
self.answer == self.expected_answer
# self.msg=self.bmpname # self.msg=self.bmpname
# }}} # }}}
# {{{ Gradients # {{{ Gradients
def test_gradient_h(self): def test_gradient_h(self):
# normally we wouldn't hack with these directly! # normally we wouldn't hack with these directly!
self.r._theme.BackgroundType = 1 self.r._theme.BackgroundType = 1
self.r._theme.BackgroundParameter1 = QtGui.QColor(255,0,0); self.r._theme.BackgroundParameter1 = QtGui.QColor(255,0,0)
self.r._theme.BackgroundParameter2 = QtGui.QColor(255,255,0); self.r._theme.BackgroundParameter2 = QtGui.QColor(255,255,0)
self.r._theme.BackgroundParameter3 = 1 self.r._theme.BackgroundParameter3 = 1
self.answer=self.r.render_screen(0) self.answer = self.r.render_screen(0)
self.bmpname=whoami() self.bmpname = whoami()
def test_gradient_v(self): def test_gradient_v(self):
# normally we wouldn't hack with these directly! # normally we wouldn't hack with these directly!
self.r._theme.BackgroundType = 1 self.r._theme.BackgroundType = 1
self.r._theme.BackgroundParameter1 = QtGui.QColor(255,0,0); self.r._theme.BackgroundParameter1 = QtGui.QColor(255,0,0)
self.r._theme.BackgroundParameter2 = QtGui.QColor(255,255,0); self.r._theme.BackgroundParameter2 = QtGui.QColor(255,255,0)
self.r._theme.BackgroundParameter3 = 0 self.r._theme.BackgroundParameter3 = 0
self.answer=self.r.render_screen(0) self.answer = self.r.render_screen(0)
self.bmpname=whoami() self.bmpname = whoami()
# }}} # }}}
# {{{ backgrounds # {{{ backgrounds
def test_bg_stretch_y(self): def test_bg_stretch_y(self):
t=Theme(u'blank_theme.xml') t = Theme(u'blank_theme.xml')
t.BackgroundType = 2
t.BackgroundParameter1 = os.path.join(u'data_for_tests', 'snowsmall.jpg');
t.BackgroundParameter2 = QtGui.QColor(0,0,64);
t.BackgroundParameter3 = 0
t.Name="stretch y"
self.r.set_theme(t)
print "render"
self.answer=self.r.render_screen(0)
print "whoami"
self.bmpname=whoami()
print "fone"
def test_bg_shrink_y(self):
t=Theme(u'blank_theme.xml')
t.BackgroundType = 2
t.BackgroundParameter1 = os.path.join(u'data_for_tests', 'snowbig.jpg');
t.BackgroundParameter2 = QtGui.QColor(0,0,64);
t.BackgroundParameter3 = 0
t.Name="shrink y"
self.r.set_theme(t)
self.answer=self.r.render_screen(0)
self.bmpname=whoami()
def test_bg_stretch_x(self):
t=Theme(u'blank_theme.xml')
t.BackgroundType = 2 t.BackgroundType = 2
t.BackgroundParameter1 = os.path.join(u'data_for_tests', t.BackgroundParameter1 = os.path.join(u'data_for_tests',
'treessmall.jpg'); 'snowsmall.jpg')
t.BackgroundParameter2 = QtGui.QColor(0,0,64); t.BackgroundParameter2 = QtGui.QColor(0,0,64)
t.BackgroundParameter3 = 0
t.Name = "stretch y"
self.r.set_theme(t)
print "render"
self.answer = self.r.render_screen(0)
print "whoami"
self.bmpname = whoami()
print "fone"
def test_bg_shrink_y(self):
t = Theme(u'blank_theme.xml')
t.BackgroundType = 2
t.BackgroundParameter1 = os.path.join(u'data_for_tests', 'snowbig.jpg')
t.BackgroundParameter2 = QtGui.QColor(0,0,64)
t.BackgroundParameter3 = 0
t.Name = "shrink y"
self.r.set_theme(t)
self.answer = self.r.render_screen(0)
self.bmpname = whoami()
def test_bg_stretch_x(self):
t = Theme(u'blank_theme.xml')
t.BackgroundType = 2
t.BackgroundParameter1 = os.path.join(u'data_for_tests',
'treessmall.jpg')
t.BackgroundParameter2 = QtGui.QColor(0,0,64)
t.BackgroundParameter3 = 0 t.BackgroundParameter3 = 0
t.VerticalAlign = 2 t.VerticalAlign = 2
t.Name="stretch x" t.Name = "stretch x"
self.r.set_theme(t) self.r.set_theme(t)
self.answer=self.r.render_screen(0) self.answer = self.r.render_screen(0)
self.expected_answer= QtCore.QRect(0, 129, 559, 342) self.expected_answer = QtCore.QRect(0, 129, 559, 342)
self.bmpname=whoami() self.bmpname = whoami()
def test_bg_shrink_x(self): def test_bg_shrink_x(self):
t=Theme(u'blank_theme.xml') t = Theme(u'blank_theme.xml')
t.BackgroundType = 2 t.BackgroundType = 2
t.BackgroundParameter1 = os.path.join(u'data_for_tests', 'treesbig.jpg'); t.BackgroundParameter1 = os.path.join(u'data_for_tests',
t.BackgroundParameter2 = QtGui.QColor(0,0,64); 'treesbig.jpg')
t.BackgroundParameter2 = QtGui.QColor(0,0,64)
t.BackgroundParameter3 = 0 t.BackgroundParameter3 = 0
t.VerticalAlign = 2 t.VerticalAlign = 2
t.Name="shrink x" t.Name = "shrink x"
self.r.set_theme(t) self.r.set_theme(t)
self.expected_answer= QtCore.QRect(0, 129, 559, 342) self.expected_answer = QtCore.QRect(0, 129, 559, 342)
self.answer=self.r.render_screen(0) self.answer = self.r.render_screen(0)
self.bmpname=whoami() self.bmpname = whoami()
# }}} # }}}
# {{{ Vertical alignment # {{{ Vertical alignment
def test_theme_vertical_align_top(self): def test_theme_vertical_align_top(self):
t=Theme(u'blank_theme.xml') t = Theme(u'blank_theme.xml')
t.BackgroundType = 0 t.BackgroundType = 0
t.BackgroundParameter1 = QtGui.QColor(0,0,64); t.BackgroundParameter1 = QtGui.QColor(0,0,64)
t.VerticalAlign = 0 t.VerticalAlign = 0
t.Name="valign top" t.Name = "valign top"
self.r.set_theme(t) self.r.set_theme(t)
self.answer=self.r.render_screen(0) self.answer = self.r.render_screen(0)
self.bmpname=whoami() self.bmpname = whoami()
def test_theme_vertical_align_bot(self): def test_theme_vertical_align_bot(self):
t=Theme(u'blank_theme.xml') t = Theme(u'blank_theme.xml')
t.BackgroundType = 0 t.BackgroundType = 0
t.BackgroundParameter1 = QtGui.QColor(0,0,64); t.BackgroundParameter1 = QtGui.QColor(0,0,64)
t.VerticalAlign = 1 t.VerticalAlign = 1
t.Name="valign bot" t.Name = "valign bot"
self.r.set_theme(t) self.r.set_theme(t)
self.answer=self.r.render_screen(0) self.answer = self.r.render_screen(0)
self.expected_answer= QtCore.QRect(0, 257, 559, 342) self.expected_answer = QtCore.QRect(0, 257, 559, 342)
self.bmpname=whoami() self.bmpname = whoami()
def test_theme_vertical_align_cen(self): def test_theme_vertical_align_cen(self):
t=Theme(u'blank_theme.xml') t = Theme(u'blank_theme.xml')
t.BackgroundType = 0 t.BackgroundType = 0
t.BackgroundParameter1 = QtGui.QColor(0,0,64); t.BackgroundParameter1 = QtGui.QColor(0,0,64)
t.VerticalAlign = 2 t.VerticalAlign = 2
t.Name="valign cen" t.Name = "valign cen"
self.r.set_theme(t) self.r.set_theme(t)
self.answer=self.r.render_screen(0) self.answer = self.r.render_screen(0)
self.expected_answer= QtCore.QRect(0, 129, 559, 342) self.expected_answer = QtCore.QRect(0, 129, 559, 342)
self.bmpname=whoami() self.bmpname = whoami()
# }}} # }}}
# {{{ Horzontal alignment # {{{ Horzontal alignment
def test_theme_horizontal_align_left(self): def test_theme_horizontal_align_left(self):
t=Theme(u'blank_theme.xml') t = Theme(u'blank_theme.xml')
t.BackgroundType = 0 t.BackgroundType = 0
t.BackgroundParameter1 = QtGui.QColor(0,0,64); t.BackgroundParameter1 = QtGui.QColor(0,0,64)
t.VerticalAlign = 0 t.VerticalAlign = 0
t.HorizontalAlign = 0 t.HorizontalAlign = 0
t.Name="halign left" t.Name = "halign left"
self.r.set_theme(t) self.r.set_theme(t)
self.answer=self.r.render_screen(0) self.answer = self.r.render_screen(0)
self.bmpname=whoami() self.bmpname = whoami()
def test_theme_horizontal_align_right(self): def test_theme_horizontal_align_right(self):
t=Theme(u'blank_theme.xml') t = Theme(u'blank_theme.xml')
t.BackgroundType = 0 t.BackgroundType = 0
t.BackgroundParameter1 = QtGui.QColor(0,0,64); t.BackgroundParameter1 = QtGui.QColor(0,0,64)
t.VerticalAlign = 0 t.VerticalAlign = 0
t.HorizontalAlign = 1 t.HorizontalAlign = 1
t.Name="halign right" t.Name = "halign right"
self.r.set_theme(t) self.r.set_theme(t)
self.expected_answer= QtCore.QRect(0, 0, 800, 342) self.expected_answer = QtCore.QRect(0, 0, 800, 342)
self.answer=self.r.render_screen(0) self.answer = self.r.render_screen(0)
self.bmpname=whoami() self.bmpname = whoami()
def test_theme_horizontal_align_centre(self): def test_theme_horizontal_align_centre(self):
t=Theme(u'blank_theme.xml') t = Theme(u'blank_theme.xml')
t.BackgroundType = 0 t.BackgroundType = 0
t.BackgroundParameter1 = QtGui.QColor(0,0,64); t.BackgroundParameter1 = QtGui.QColor(0,0,64)
t.VerticalAlign = 0 t.VerticalAlign = 0
t.HorizontalAlign = 2 t.HorizontalAlign = 2
t.Name="halign centre" t.Name = "halign centre"
self.r.set_theme(t) self.r.set_theme(t)
self.answer=self.r.render_screen(0) self.answer = self.r.render_screen(0)
self.expected_answer= QtCore.QRect(0, 0, 679, 342) self.expected_answer = QtCore.QRect(0, 0, 679, 342)
self.bmpname=whoami() self.bmpname = whoami()
def test_theme_horizontal_align_left_lyric(self): def test_theme_horizontal_align_left_lyric(self):
t=Theme(u'blank_theme.xml') t = Theme(u'blank_theme.xml')
t.BackgroundType = 0 t.BackgroundType = 0
t.BackgroundParameter1 = QtGui.QColor(0,0,64); t.BackgroundParameter1 = QtGui.QColor(0,0,64)
t.VerticalAlign = 0 t.VerticalAlign = 0
t.HorizontalAlign = 0 t.HorizontalAlign = 0
t.WrapStyle=1 t.WrapStyle = 1
t.Name="halign left lyric" t.Name = "halign left lyric"
self.r.set_theme(t) self.r.set_theme(t)
self.answer=self.r.render_screen(0) self.answer = self.r.render_screen(0)
self.expected_answer=QtCore.QRect(0, 0, 778, 342) self.expected_answer = QtCore.QRect(0, 0, 778, 342)
self.bmpname=whoami() self.bmpname = whoami()
# }}} # }}}
# {{{ Shadows and outlines # {{{ Shadows and outlines
def test_theme_shadow_outline(self): def test_theme_shadow_outline(self):
t=Theme(u'blank_theme.xml') t = Theme(u'blank_theme.xml')
t.BackgroundType = 0 t.BackgroundType = 0
t.BackgroundParameter1 = QtGui.QColor(0,0,0); t.BackgroundParameter1 = QtGui.QColor(0,0,0);
t.Name="shadow/outline" t.Name="shadow/outline"
t.Shadow=1 t.Shadow = 1
t.Outline=1 t.Outline = 1
t.ShadowColor=QtGui.QColor(64,128,0) t.ShadowColor = QtGui.QColor(64,128,0)
t.OutlineColor=QtGui.QColor(128,0,0) t.OutlineColor = QtGui.QColor(128,0,0)
self.r.set_debug(1) self.r.set_debug(1)
self.r.set_theme(t) self.r.set_theme(t)
self.answer=self.r.render_screen(0) self.answer = self.r.render_screen(0)
hoffset=self.r._shadow_offset+2*(self.r._outline_offset) hoffset = self.r._shadow_offset+2*(self.r._outline_offset)
voffset=hoffset * (len(self.r.words[0])+1) voffset = hoffset * (len(self.r.words[0])+1)
self.expected_answer= QtCore.QRect(0, 0, 559+hoffset, 342+voffset) self.expected_answer = QtCore.QRect(0, 0, 559+hoffset, 342+voffset)
self.bmpname=whoami() self.bmpname = whoami()
# }}} # }}}
def test_theme_font(self): def test_theme_font(self):
t=Theme(u'blank_theme.xml') t = Theme(u'blank_theme.xml')
t.BackgroundType = 0 t.BackgroundType = 0
t.BackgroundParameter1 = QtGui.QColor(0,0,64); t.BackgroundParameter1 = QtGui.QColor(0,0,64)
t.Name="font" t.Name = "font"
t.FontName="Times New Roman" t.FontName = "Times New Roman"
self.r.set_theme(t) self.r.set_theme(t)
self.answer=self.r.render_screen(0) self.answer = self.r.render_screen(0)
self.expected_answer= QtCore.QRect(0, 0, 499, 336) self.expected_answer = QtCore.QRect(0, 0, 499, 336)
self.bmpname=whoami() self.bmpname=whoami()
if __name__=="__main__": if __name__ == "__main__":
t=TestRenderTheme() t = TestRenderTheme()
t.setup_class() t.setup_class()
t.setup_method(None) t.setup_method(None)
t.test_bg_stretch_y() t.test_bg_stretch_y()

View File

@ -50,6 +50,6 @@ def test_theme():
print "Tests passed" print "Tests passed"
if __name__=="__main__": if __name__ == "__main__":
test_read_theme() test_read_theme()
test_theme() test_theme()

File diff suppressed because it is too large Load Diff

View File

@ -26,16 +26,19 @@ from openlp.core.ui import AboutForm, SettingsForm, AlertForm, \
ServiceManager, ThemeManager, MainDisplay, SlideController, \ ServiceManager, ThemeManager, MainDisplay, SlideController, \
PluginForm PluginForm
from openlp.core.lib import translate, Plugin, MediaManagerItem, \ from openlp.core.lib import translate, Plugin, MediaManagerItem, \
SettingsTab, RenderManager, PluginConfig, \ SettingsTab, RenderManager, PluginConfig, str_to_bool, \
SettingsManager, PluginManager, Receiver SettingsManager, PluginManager, Receiver
from openlp.core.utils import ConfigHelper
class Ui_MainWindow(object): class Ui_MainWindow(object):
def setupUi(self, MainWindow): def setupUi(self, MainWindow):
""" """
Set up the user interface Set up the user interface
""" """
MainWindow.setObjectName(u'MainWindow') MainWindow.setObjectName(u'MainWindow')
MainWindow.resize(self.settingsmanager.width, self.settingsmanager.height) MainWindow.resize(self.settingsmanager.width,
self.settingsmanager.height)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding) QtGui.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0) sizePolicy.setHorizontalStretch(0)
@ -118,6 +121,7 @@ class Ui_MainWindow(object):
self.MediaManagerDock.setWidget(self.MediaManagerContents) self.MediaManagerDock.setWidget(self.MediaManagerContents)
MainWindow.addDockWidget( MainWindow.addDockWidget(
QtCore.Qt.DockWidgetArea(1), self.MediaManagerDock) QtCore.Qt.DockWidgetArea(1), self.MediaManagerDock)
self.MediaManagerDock.setVisible(self.settingsmanager.showMediaManager)
# Create the service manager # Create the service manager
self.ServiceManagerDock = QtGui.QDockWidget(MainWindow) self.ServiceManagerDock = QtGui.QDockWidget(MainWindow)
ServiceManagerIcon = QtGui.QIcon() ServiceManagerIcon = QtGui.QIcon()
@ -133,6 +137,8 @@ class Ui_MainWindow(object):
self.ServiceManagerDock.setWidget(self.ServiceManagerContents) self.ServiceManagerDock.setWidget(self.ServiceManagerContents)
MainWindow.addDockWidget( MainWindow.addDockWidget(
QtCore.Qt.DockWidgetArea(2), self.ServiceManagerDock) QtCore.Qt.DockWidgetArea(2), self.ServiceManagerDock)
self.ServiceManagerDock.setVisible(
self.settingsmanager.showServiceManager)
# Create the theme manager # Create the theme manager
self.ThemeManagerDock = QtGui.QDockWidget(MainWindow) self.ThemeManagerDock = QtGui.QDockWidget(MainWindow)
ThemeManagerIcon = QtGui.QIcon() ThemeManagerIcon = QtGui.QIcon()
@ -146,18 +152,22 @@ class Ui_MainWindow(object):
self.ThemeManagerDock.setWidget(self.ThemeManagerContents) self.ThemeManagerDock.setWidget(self.ThemeManagerContents)
MainWindow.addDockWidget( MainWindow.addDockWidget(
QtCore.Qt.DockWidgetArea(2), self.ThemeManagerDock) QtCore.Qt.DockWidgetArea(2), self.ThemeManagerDock)
self.ThemeManagerDock.setVisible(self.settingsmanager.showThemeManager)
# Create the menu items # Create the menu items
self.FileNewItem = QtGui.QAction(MainWindow) self.FileNewItem = QtGui.QAction(MainWindow)
self.FileNewItem.setIcon( self.FileNewItem.setIcon(
self.ServiceManagerContents.Toolbar.getIconFromTitle(u'New Service')) self.ServiceManagerContents.Toolbar.getIconFromTitle(
u'New Service'))
self.FileNewItem.setObjectName(u'FileNewItem') self.FileNewItem.setObjectName(u'FileNewItem')
self.FileOpenItem = QtGui.QAction(MainWindow) self.FileOpenItem = QtGui.QAction(MainWindow)
self.FileOpenItem.setIcon( self.FileOpenItem.setIcon(
self.ServiceManagerContents.Toolbar.getIconFromTitle(u'Open Service')) self.ServiceManagerContents.Toolbar.getIconFromTitle(
u'Open Service'))
self.FileOpenItem.setObjectName(u'FileOpenItem') self.FileOpenItem.setObjectName(u'FileOpenItem')
self.FileSaveItem = QtGui.QAction(MainWindow) self.FileSaveItem = QtGui.QAction(MainWindow)
self.FileSaveItem.setIcon( self.FileSaveItem.setIcon(
self.ServiceManagerContents.Toolbar.getIconFromTitle(u'Save Service')) self.ServiceManagerContents.Toolbar.getIconFromTitle(
u'Save Service'))
self.FileSaveItem.setObjectName(u'FileSaveItem') self.FileSaveItem.setObjectName(u'FileSaveItem')
self.FileSaveAsItem = QtGui.QAction(MainWindow) self.FileSaveAsItem = QtGui.QAction(MainWindow)
self.FileSaveAsItem.setObjectName(u'FileSaveAsItem') self.FileSaveAsItem.setObjectName(u'FileSaveAsItem')
@ -185,17 +195,20 @@ class Ui_MainWindow(object):
self.OptionsSettingsItem.setObjectName(u'OptionsSettingsItem') self.OptionsSettingsItem.setObjectName(u'OptionsSettingsItem')
self.ViewMediaManagerItem = QtGui.QAction(MainWindow) self.ViewMediaManagerItem = QtGui.QAction(MainWindow)
self.ViewMediaManagerItem.setCheckable(True) self.ViewMediaManagerItem.setCheckable(True)
self.ViewMediaManagerItem.setChecked(True) self.ViewMediaManagerItem.setChecked(
self.settingsmanager.showMediaManager)
self.ViewMediaManagerItem.setIcon(icon) self.ViewMediaManagerItem.setIcon(icon)
self.ViewMediaManagerItem.setObjectName(u'ViewMediaManagerItem') self.ViewMediaManagerItem.setObjectName(u'ViewMediaManagerItem')
self.ViewThemeManagerItem = QtGui.QAction(MainWindow) self.ViewThemeManagerItem = QtGui.QAction(MainWindow)
self.ViewThemeManagerItem.setCheckable(True) self.ViewThemeManagerItem.setCheckable(True)
self.ViewThemeManagerItem.setChecked(True) self.ViewThemeManagerItem.setChecked(
self.settingsmanager.showThemeManager)
self.ViewThemeManagerItem.setIcon(ThemeManagerIcon) self.ViewThemeManagerItem.setIcon(ThemeManagerIcon)
self.ViewThemeManagerItem.setObjectName(u'ViewThemeManagerItem') self.ViewThemeManagerItem.setObjectName(u'ViewThemeManagerItem')
self.ViewServiceManagerItem = QtGui.QAction(MainWindow) self.ViewServiceManagerItem = QtGui.QAction(MainWindow)
self.ViewServiceManagerItem.setCheckable(True) self.ViewServiceManagerItem.setCheckable(True)
self.ViewServiceManagerItem.setChecked(True) self.ViewServiceManagerItem.setChecked(
self.settingsmanager.showServiceManager)
self.ViewServiceManagerItem.setIcon(ServiceManagerIcon) self.ViewServiceManagerItem.setIcon(ServiceManagerIcon)
self.ViewServiceManagerItem.setObjectName(u'ViewServiceManagerItem') self.ViewServiceManagerItem.setObjectName(u'ViewServiceManagerItem')
self.ToolsAlertItem = QtGui.QAction(MainWindow) self.ToolsAlertItem = QtGui.QAction(MainWindow)
@ -212,7 +225,8 @@ class Ui_MainWindow(object):
self.PluginItem.setObjectName(u'PluginItem') self.PluginItem.setObjectName(u'PluginItem')
self.HelpDocumentationItem = QtGui.QAction(MainWindow) self.HelpDocumentationItem = QtGui.QAction(MainWindow)
ContentsIcon = QtGui.QIcon() ContentsIcon = QtGui.QIcon()
ContentsIcon.addPixmap(QtGui.QPixmap(u':/system/system_help_contents.png'), ContentsIcon.addPixmap(QtGui.QPixmap(
u':/system/system_help_contents.png'),
QtGui.QIcon.Normal, QtGui.QIcon.Off) QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.HelpDocumentationItem.setIcon(ContentsIcon) self.HelpDocumentationItem.setIcon(ContentsIcon)
self.HelpDocumentationItem.setObjectName(u'HelpDocumentationItem') self.HelpDocumentationItem.setObjectName(u'HelpDocumentationItem')
@ -238,8 +252,11 @@ class Ui_MainWindow(object):
self.ToolsAddToolItem.setObjectName(u'ToolsAddToolItem') self.ToolsAddToolItem.setObjectName(u'ToolsAddToolItem')
self.action_Preview_Panel = QtGui.QAction(MainWindow) self.action_Preview_Panel = QtGui.QAction(MainWindow)
self.action_Preview_Panel.setCheckable(True) self.action_Preview_Panel.setCheckable(True)
self.action_Preview_Panel.setChecked(True) self.action_Preview_Panel.setChecked(
self.settingsmanager.showPreviewPanel)
self.action_Preview_Panel.setObjectName(u'action_Preview_Panel') self.action_Preview_Panel.setObjectName(u'action_Preview_Panel')
self.PreviewController.Panel.setVisible(
self.settingsmanager.showPreviewPanel)
self.ModeLiveItem = QtGui.QAction(MainWindow) self.ModeLiveItem = QtGui.QAction(MainWindow)
self.ModeLiveItem.setObjectName(u'ModeLiveItem') self.ModeLiveItem.setObjectName(u'ModeLiveItem')
self.FileImportMenu.addAction(self.ImportThemeItem) self.FileImportMenu.addAction(self.ImportThemeItem)
@ -296,7 +313,8 @@ class Ui_MainWindow(object):
Set up the translation system Set up the translation system
""" """
MainWindow.mainTitle = translate(u'mainWindow', u'OpenLP 2.0') MainWindow.mainTitle = translate(u'mainWindow', u'OpenLP 2.0')
MainWindow.defaultThemeText = translate(u'mainWindow', 'Default Theme: ') MainWindow.defaultThemeText = translate(u'mainWindow',
'Default Theme: ')
MainWindow.setWindowTitle(MainWindow.mainTitle) MainWindow.setWindowTitle(MainWindow.mainTitle)
self.FileMenu.setTitle(translate(u'mainWindow', u'&File')) self.FileMenu.setTitle(translate(u'mainWindow', u'&File'))
self.FileImportMenu.setTitle(translate(u'mainWindow', u'&Import')) self.FileImportMenu.setTitle(translate(u'mainWindow', u'&Import'))
@ -304,7 +322,8 @@ class Ui_MainWindow(object):
self.OptionsMenu.setTitle(translate(u'mainWindow', u'&Options')) self.OptionsMenu.setTitle(translate(u'mainWindow', u'&Options'))
self.OptionsViewMenu.setTitle(translate(u'mainWindow', u'&View')) self.OptionsViewMenu.setTitle(translate(u'mainWindow', u'&View'))
self.ViewModeMenu.setTitle(translate(u'mainWindow', u'M&ode')) self.ViewModeMenu.setTitle(translate(u'mainWindow', u'M&ode'))
self.OptionsLanguageMenu.setTitle(translate(u'mainWindow', u'&Language')) self.OptionsLanguageMenu.setTitle(translate(u'mainWindow',
u'&Language'))
self.ToolsMenu.setTitle(translate(u'mainWindow', u'&Tools')) self.ToolsMenu.setTitle(translate(u'mainWindow', u'&Tools'))
self.HelpMenu.setTitle(translate(u'mainWindow', u'&Help')) self.HelpMenu.setTitle(translate(u'mainWindow', u'&Help'))
self.MediaManagerDock.setWindowTitle( self.MediaManagerDock.setWindowTitle(
@ -364,6 +383,13 @@ class Ui_MainWindow(object):
self.ViewServiceManagerItem.setStatusTip(translate(u'mainWindow', self.ViewServiceManagerItem.setStatusTip(translate(u'mainWindow',
u'Toggle the visibility of the Service Manager')) u'Toggle the visibility of the Service Manager'))
self.ViewServiceManagerItem.setShortcut(translate(u'mainWindow', u'F9')) self.ViewServiceManagerItem.setShortcut(translate(u'mainWindow', u'F9'))
self.action_Preview_Panel.setText(
translate(u'mainWindow', u'&Preview Panel'))
self.action_Preview_Panel.setToolTip(
translate(u'mainWindow', u'Toggle Preview Panel'))
self.action_Preview_Panel.setStatusTip(translate(u'mainWindow',
u'Toggle the visibility of the Preview Panel'))
self.action_Preview_Panel.setShortcut(translate(u'mainWindow', u'F11'))
self.ToolsAlertItem.setText(translate(u'mainWindow', u'&Alert')) self.ToolsAlertItem.setText(translate(u'mainWindow', u'&Alert'))
self.ToolsAlertItem.setStatusTip( self.ToolsAlertItem.setStatusTip(
translate(u'mainWindow', u'Show an alert message')) translate(u'mainWindow', u'Show an alert message'))
@ -430,23 +456,35 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.setupUi(self) self.setupUi(self)
# Set up signals and slots # Set up signals and slots
QtCore.QObject.connect(self.ImportThemeItem, QtCore.QObject.connect(self.ImportThemeItem,
QtCore.SIGNAL(u'triggered()'), self.ThemeManagerContents.onImportTheme) QtCore.SIGNAL(u'triggered()'),
self.ThemeManagerContents.onImportTheme)
QtCore.QObject.connect(self.ExportThemeItem, QtCore.QObject.connect(self.ExportThemeItem,
QtCore.SIGNAL(u'triggered()'), self.ThemeManagerContents.onExportTheme) QtCore.SIGNAL(u'triggered()'),
self.ThemeManagerContents.onExportTheme)
QtCore.QObject.connect(self.ViewMediaManagerItem, QtCore.QObject.connect(self.ViewMediaManagerItem,
QtCore.SIGNAL(u'triggered(bool)'), self.MediaManagerDock.setVisible) QtCore.SIGNAL(u'triggered(bool)'),
self.toggleMediaManager)
QtCore.QObject.connect(self.ViewServiceManagerItem, QtCore.QObject.connect(self.ViewServiceManagerItem,
QtCore.SIGNAL(u'triggered(bool)'), self.ServiceManagerDock.setVisible) QtCore.SIGNAL(u'triggered(bool)'),
self.toggleServiceManager)
QtCore.QObject.connect(self.ViewThemeManagerItem, QtCore.QObject.connect(self.ViewThemeManagerItem,
QtCore.SIGNAL(u'triggered(bool)'), self.ThemeManagerDock.setVisible) QtCore.SIGNAL(u'triggered(bool)'),
self.toggleThemeManager)
QtCore.QObject.connect(self.action_Preview_Panel, QtCore.QObject.connect(self.action_Preview_Panel,
QtCore.SIGNAL(u'toggled(bool)'), self.PreviewController.Panel.setVisible) QtCore.SIGNAL(u'toggled(bool)'),
self.togglePreviewPanel)
QtCore.QObject.connect(self.MediaManagerDock, QtCore.QObject.connect(self.MediaManagerDock,
QtCore.SIGNAL(u'visibilityChanged(bool)'), self.ViewMediaManagerItem.setChecked) QtCore.SIGNAL(u'visibilityChanged(bool)'),
self.ViewMediaManagerItem.setChecked)
QtCore.QObject.connect(self.ServiceManagerDock, QtCore.QObject.connect(self.ServiceManagerDock,
QtCore.SIGNAL(u'visibilityChanged(bool)'), self.ViewServiceManagerItem.setChecked) QtCore.SIGNAL(u'visibilityChanged(bool)'),
self.ViewServiceManagerItem.setChecked)
QtCore.QObject.connect(self.ThemeManagerDock, QtCore.QObject.connect(self.ThemeManagerDock,
QtCore.SIGNAL(u'visibilityChanged(bool)'), self.ViewThemeManagerItem.setChecked) QtCore.SIGNAL(u'visibilityChanged(bool)'),
self.ViewThemeManagerItem.setChecked)
QtCore.QObject.connect(self.PreviewController.Panel,
QtCore.SIGNAL(u'visibilityChanged(bool)'),
self.action_Preview_Panel.setChecked)
QtCore.QObject.connect(self.HelpAboutItem, QtCore.QObject.connect(self.HelpAboutItem,
QtCore.SIGNAL(u'triggered()'), self.onHelpAboutItemClicked) QtCore.SIGNAL(u'triggered()'), self.onHelpAboutItemClicked)
QtCore.QObject.connect(self.ToolsAlertItem, QtCore.QObject.connect(self.ToolsAlertItem,
@ -472,7 +510,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.plugin_manager.find_plugins(pluginpath, self.plugin_helpers) self.plugin_manager.find_plugins(pluginpath, self.plugin_helpers)
# hook methods have to happen after find_plugins. Find plugins needs the # hook methods have to happen after find_plugins. Find plugins needs the
# controllers hence the hooks have moved from setupUI() to here # controllers hence the hooks have moved from setupUI() to here
# Find and insert settings tabs # Find and insert settings tabs
log.info(u'hook settings') log.info(u'hook settings')
self.plugin_manager.hook_settings_tabs(self.settingsForm) self.plugin_manager.hook_settings_tabs(self.settingsForm)
@ -555,7 +592,10 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
ret = QtGui.QMessageBox.question(None, ret = QtGui.QMessageBox.question(None,
translate(u'mainWindow', u'Save Changes to Service?'), translate(u'mainWindow', u'Save Changes to Service?'),
translate(u'mainWindow', u'Your service has been changed, do you want to save those changes?'), translate(u'mainWindow', u'Your service has been changed, do you want to save those changes?'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Cancel | QtGui.QMessageBox.Discard | QtGui.QMessageBox.Save), QtGui.QMessageBox.StandardButtons(
QtGui.QMessageBox.Cancel | \
QtGui.QMessageBox.Discard | \
QtGui.QMessageBox.Save),
QtGui.QMessageBox.Save) QtGui.QMessageBox.Save)
if ret == QtGui.QMessageBox.Save: if ret == QtGui.QMessageBox.Save:
self.ServiceManagerContents.onSaveService() self.ServiceManagerContents.onSaveService()
@ -598,3 +638,23 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def defaultThemeChanged(self, theme): def defaultThemeChanged(self, theme):
self.DefaultThemeLabel.setText(self.defaultThemeText + theme) self.DefaultThemeLabel.setText(self.defaultThemeText + theme)
def toggleMediaManager(self):
mediaBool = self.MediaManagerDock.isVisible()
self.MediaManagerDock.setVisible(not mediaBool)
self.settingsmanager.toggleMediaManager(not mediaBool)
def toggleServiceManager(self):
serviceBool = self.ServiceManagerDock.isVisible()
self.ServiceManagerDock.setVisible(not serviceBool)
self.settingsmanager.toggleServiceManager(not serviceBool)
def toggleThemeManager(self):
themeBool = self.ThemeManagerDock.isVisible()
self.ThemeManagerDock.setVisible(not themeBool)
self.settingsmanager.toggleThemeManager(not themeBool)
def togglePreviewPanel(self):
previewBool = self.PreviewController.Panel.isVisible()
self.PreviewController.Panel.setVisible(not previewBool)
self.settingsmanager.togglePreviewPanel(not previewBool)

View File

@ -136,7 +136,8 @@ class TestServiceManager_base:
# new and save as # new and save as
# deleting items # deleting items
if __name__=="__main__":
if __name__ == "__main__":
t=TestServiceManager_base() t=TestServiceManager_base()
t.setup_class() t.setup_class()

View File

@ -1,380 +1,449 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 # vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
""" """
OpenLP - Open Source Lyrics Projection OpenLP - Open Source Lyrics Projection
Copyright (c) 2009 Raoul Snyman Copyright (c) 2009 Raoul Snyman
Portions copyright (c) 2009 Martin Thompson, Tim Bentley, Portions copyright (c) 2009 Martin Thompson, Tim Bentley,
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License. Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details. PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA Place, Suite 330, Boston, MA 02111-1307 USA
""" """
import os import os
import sys import sys
import zipfile import zipfile
import shutil import shutil
import logging import logging
from xml.etree.ElementTree import ElementTree, XML from xml.etree.ElementTree import ElementTree, XML
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.ui import AmendThemeForm, ServiceManager from openlp.core.ui import AmendThemeForm, ServiceManager
from openlp.core.theme import Theme from openlp.core.theme import Theme
from openlp.core.lib import PluginConfig, \ from openlp.core.lib import PluginConfig, OpenLPToolbar, ThemeXML, Renderer, \
OpenLPToolbar, ThemeXML, Renderer, translate, \ translate, str_to_bool, file_to_xml, buildIcon, Receiver
file_to_xml, buildIcon, Receiver from openlp.core.utils import ConfigHelper
from openlp.core.utils import ConfigHelper
class ThemeManager(QtGui.QWidget):
class ThemeManager(QtGui.QWidget): """
""" Manages the orders of Theme.
Manages the orders of Theme. """
""" global log
global log log = logging.getLogger(u'ThemeManager')
log = logging.getLogger(u'ThemeManager')
def __init__(self, parent):
def __init__(self, parent): QtGui.QWidget.__init__(self, parent)
QtGui.QWidget.__init__(self, parent) self.parent = parent
self.parent = parent self.Layout = QtGui.QVBoxLayout(self)
self.Layout = QtGui.QVBoxLayout(self) self.Layout.setSpacing(0)
self.Layout.setSpacing(0) self.Layout.setMargin(0)
self.Layout.setMargin(0) self.amendThemeForm = AmendThemeForm(self)
self.amendThemeForm = AmendThemeForm(self) self.Toolbar = OpenLPToolbar(self)
self.Toolbar = OpenLPToolbar(self) self.Toolbar.addToolbarButton(
self.Toolbar.addToolbarButton( translate(u'ThemeManager', u'New Theme'), u':/themes/theme_new.png',
translate(u'ThemeManager', u'New Theme'), u':/themes/theme_new.png', translate(u'ThemeManager', u'Create a new theme'), self.onAddTheme)
translate(u'ThemeManager', u'Create a new theme'), self.onAddTheme) self.Toolbar.addToolbarButton(
self.Toolbar.addToolbarButton( translate(u'ThemeManager', u'Edit Theme'),
translate(u'ThemeManager', u'Edit Theme'), u':/themes/theme_edit.png', u':/themes/theme_edit.png',
translate(u'ThemeManager', u'Edit a theme'), self.onEditTheme) translate(u'ThemeManager', u'Edit a theme'), self.onEditTheme)
self.Toolbar.addToolbarButton( self.Toolbar.addToolbarButton(
translate(u'ThemeManager', u'Delete Theme'), u':/themes/theme_delete.png', translate(u'ThemeManager', u'Delete Theme'),
translate(u'ThemeManager', u'Delete a theme'), self.onDeleteTheme) u':/themes/theme_delete.png',
self.Toolbar.addSeparator() translate(u'ThemeManager', u'Delete a theme'), self.onDeleteTheme)
self.Toolbar.addToolbarButton( self.Toolbar.addSeparator()
translate(u'ThemeManager', u'Import Theme'), u':/themes/theme_import.png', self.Toolbar.addToolbarButton(
translate(u'ThemeManager', u'Import a theme'), self.onImportTheme) translate(u'ThemeManager', u'Import Theme'),
self.Toolbar.addToolbarButton( u':/themes/theme_import.png',
translate(u'ThemeManager', u'Export Theme'), u':/themes/theme_export.png', translate(u'ThemeManager', u'Import a theme'), self.onImportTheme)
translate(u'ThemeManager', u'Export a theme'), self.onExportTheme) self.Toolbar.addToolbarButton(
self.ThemeWidget = QtGui.QWidgetAction(self.Toolbar) translate(u'ThemeManager', u'Export Theme'),
self.Layout.addWidget(self.Toolbar) u':/themes/theme_export.png',
self.ThemeListWidget = QtGui.QListWidget(self) translate(u'ThemeManager', u'Export a theme'), self.onExportTheme)
self.ThemeListWidget.setAlternatingRowColors(True) self.ThemeWidget = QtGui.QWidgetAction(self.Toolbar)
self.ThemeListWidget.setIconSize(QtCore.QSize(88,50)) self.Layout.addWidget(self.Toolbar)
self.Layout.addWidget(self.ThemeListWidget) self.ThemeListWidget = QtGui.QListWidget(self)
#Signals self.ThemeListWidget.setAlternatingRowColors(True)
QtCore.QObject.connect(self.ThemeListWidget, self.ThemeListWidget.setIconSize(QtCore.QSize(88,50))
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), self.changeGlobalFromScreen) self.Layout.addWidget(self.ThemeListWidget)
QtCore.QObject.connect(Receiver.get_receiver(), #Signals
QtCore.SIGNAL(u'update_global_theme'), self.changeGlobalFromTab) QtCore.QObject.connect(self.ThemeListWidget,
#Variables QtCore.SIGNAL(u'doubleClicked(QModelIndex)'),
self.themelist = [] self.changeGlobalFromScreen)
self.path = os.path.join(ConfigHelper.get_data_path(), u'themes') QtCore.QObject.connect(Receiver.get_receiver(),
self.checkThemesExists(self.path) QtCore.SIGNAL(u'update_global_theme'), self.changeGlobalFromTab)
self.amendThemeForm.path = self.path #Variables
# Last little bits of setting up self.themelist = []
self.config = PluginConfig(u'themes') self.path = os.path.join(ConfigHelper.get_data_path(), u'themes')
self.servicePath = self.config.get_data_path() self.checkThemesExists(self.path)
self.global_theme = unicode(self.config.get_config(u'theme global theme', u'')) self.amendThemeForm.path = self.path
# Last little bits of setting up
def changeGlobalFromTab(self, themeName): self.config = PluginConfig(u'themes')
log.debug(u'changeGlobalFromTab %s', themeName) self.servicePath = self.config.get_data_path()
for count in range (0, self.ThemeListWidget.count()): self.global_theme = unicode(
#reset the old name self.config.get_config(u'theme global theme', u''))
item = self.ThemeListWidget.item(count)
oldName = item.text() def changeGlobalFromTab(self, themeName):
newName = unicode(item.data(QtCore.Qt.UserRole).toString()) log.debug(u'changeGlobalFromTab %s', themeName)
if oldName != newName: for count in range (0, self.ThemeListWidget.count()):
self.ThemeListWidget.item(count).setText(newName) #reset the old name
#Set the new name item = self.ThemeListWidget.item(count)
if themeName == newName: oldName = item.text()
name = u'%s (%s)' % (newName, translate(u'ThemeManager', u'default')) newName = unicode(item.data(QtCore.Qt.UserRole).toString())
self.ThemeListWidget.item(count).setText(name) if oldName != newName:
self.ThemeListWidget.item(count).setText(newName)
def changeGlobalFromScreen(self, index): #Set the new name
log.debug(u'changeGlobalFromScreen %s', index) if themeName == newName:
for count in range (0, self.ThemeListWidget.count()): name = u'%s (%s)' % (newName, translate(u'ThemeManager',
item = self.ThemeListWidget.item(count) u'default'))
oldName = item.text() self.ThemeListWidget.item(count).setText(name)
#reset the old name
if oldName != unicode(item.data(QtCore.Qt.UserRole).toString()): def changeGlobalFromScreen(self, index):
self.ThemeListWidget.item(count).setText(unicode(item.data(QtCore.Qt.UserRole).toString())) log.debug(u'changeGlobalFromScreen %s', index)
#Set the new name for count in range (0, self.ThemeListWidget.count()):
if count == index.row(): item = self.ThemeListWidget.item(count)
self.global_theme = unicode(self.ThemeListWidget.item(count).text()) oldName = item.text()
name = u'%s (%s)' % (self.global_theme, translate(u'ThemeManager', u'default')) #reset the old name
self.ThemeListWidget.item(count).setText(name) if oldName != unicode(item.data(QtCore.Qt.UserRole).toString()):
self.config.set_config(u'theme global theme', self.global_theme) self.ThemeListWidget.item(count).setText(
Receiver().send_message(u'update_global_theme', self.global_theme ) unicode(item.data(QtCore.Qt.UserRole).toString()))
self.pushThemes() #Set the new name
if count == index.row():
def onAddTheme(self): self.global_theme = unicode(
self.amendThemeForm.loadTheme(None) self.ThemeListWidget.item(count).text())
self.amendThemeForm.exec_() name = u'%s (%s)' % (self.global_theme,
translate(u'ThemeManager', u'default'))
def onEditTheme(self): self.ThemeListWidget.item(count).setText(name)
item = self.ThemeListWidget.currentItem() self.config.set_config(u'theme global theme', self.global_theme)
if item is not None: Receiver().send_message(u'update_global_theme',
self.amendThemeForm.loadTheme(unicode(item.data(QtCore.Qt.UserRole).toString())) self.global_theme)
self.amendThemeForm.exec_() self.pushThemes()
def onDeleteTheme(self): def onAddTheme(self):
self.global_theme = unicode(self.config.get_config(u'theme global theme', u'')) self.amendThemeForm.theme.parse(self.baseTheme())
item = self.ThemeListWidget.currentItem() self.amendThemeForm.loadTheme()
if item is not None: self.amendThemeForm.exec_()
theme = unicode(item.text())
# should be the same unless default def onEditTheme(self):
if theme != unicode(item.data(QtCore.Qt.UserRole).toString()): item = self.ThemeListWidget.currentItem()
QtGui.QMessageBox.critical(self, if item is not None:
translate(u'ThemeManager', u'Error'), self.amendThemeForm.setTheme(self.getThemeData(
translate(u'ThemeManager', u'You are unable to delete the default theme!'), item.data(QtCore.Qt.UserRole).toString()))
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) self.amendThemeForm.loadTheme()
else: self.amendThemeForm.exec_()
self.themelist.remove(theme)
th = theme + u'.png' def onDeleteTheme(self):
row = self.ThemeListWidget.row(item) self.global_theme = unicode(
self.ThemeListWidget.takeItem(row) self.config.get_config(u'theme global theme', u''))
try: item = self.ThemeListWidget.currentItem()
os.remove(os.path.join(self.path, th)) if item is not None:
except: theme = unicode(item.text())
#if not present do not worry # should be the same unless default
pass if theme != unicode(item.data(QtCore.Qt.UserRole).toString()):
try: QtGui.QMessageBox.critical(self,
shutil.rmtree(os.path.join(self.path, theme)) translate(u'ThemeManager', u'Error'),
except: translate(u'ThemeManager',
#if not present do not worry u'You are unable to delete the default theme!'),
pass QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
#As we do not reload the themes push out the change else:
#Reaload the list as the internal lists and events need to be triggered self.themelist.remove(theme)
self.pushThemes() th = theme + u'.png'
row = self.ThemeListWidget.row(item)
def onExportTheme(self): self.ThemeListWidget.takeItem(row)
pass try:
os.remove(os.path.join(self.path, th))
def onImportTheme(self): except:
files = QtGui.QFileDialog.getOpenFileNames(None, #if not present do not worry
translate(u'ThemeManager', u'Select Theme Import File'), pass
self.path, u'Theme (*.*)') try:
log.info(u'New Themes %s', unicode(files)) shutil.rmtree(os.path.join(self.path, theme))
if len(files) > 0: except:
for file in files: #if not present do not worry
self.unzipTheme(file, self.path) pass
self.loadThemes() # As we do not reload the themes push out the change
# Reaload the list as the internal lists and events need
def loadThemes(self): # to be triggered
""" self.pushThemes()
Loads the theme lists and triggers updates accross
the whole system using direct calls or core functions def onExportTheme(self):
and events for the plugins. pass
The plugins will call back in to get the real list if they want it.
""" def onImportTheme(self):
log.debug(u'Load themes from dir') files = QtGui.QFileDialog.getOpenFileNames(None,
self.themelist = [] translate(u'ThemeManager', u'Select Theme Import File'),
self.ThemeListWidget.clear() self.path, u'Theme (*.*)')
for root, dirs, files in os.walk(self.path): log.info(u'New Themes %s', unicode(files))
for name in files: if len(files) > 0:
if name.endswith(u'.png'): for file in files:
#check to see file is in theme root directory self.unzipTheme(file, self.path)
theme = os.path.join(self.path, name) self.loadThemes()
if os.path.exists(theme):
(path, filename) = os.path.split(unicode(file)) def loadThemes(self):
textName = os.path.splitext(name)[0] """
if textName == self.global_theme: Loads the theme lists and triggers updates accross
name = u'%s (%s)' % (textName, translate(u'ThemeManager', u'default')) the whole system using direct calls or core functions
else: and events for the plugins.
name = textName The plugins will call back in to get the real list if they want it.
item_name = QtGui.QListWidgetItem(name) """
item_name.setIcon(buildIcon(theme)) log.debug(u'Load themes from dir')
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(textName)) self.themelist = []
self.ThemeListWidget.addItem(item_name) self.ThemeListWidget.clear()
self.themelist.append(textName) for root, dirs, files in os.walk(self.path):
self.pushThemes() for name in files:
if name.endswith(u'.png'):
def pushThemes(self): #check to see file is in theme root directory
Receiver().send_message(u'update_themes', self.getThemes() ) theme = os.path.join(self.path, name)
if os.path.exists(theme):
def getThemes(self): (path, filename) = os.path.split(unicode(file))
return self.themelist textName = os.path.splitext(name)[0]
if textName == self.global_theme:
def getThemeData(self, themename): name = u'%s (%s)' % (textName,
log.debug(u'getthemedata for theme %s', themename) translate(u'ThemeManager', u'default'))
xml_file = os.path.join(self.path, unicode(themename), unicode(themename) + u'.xml') else:
try: name = textName
xml = file_to_xml(xml_file) item_name = QtGui.QListWidgetItem(name)
except: item_name.setIcon(buildIcon(theme))
newtheme = ThemeXML() item_name.setData(QtCore.Qt.UserRole,
newtheme.new_document(u'New Theme') QtCore.QVariant(textName))
newtheme.add_background_solid(unicode(u'#000000')) self.ThemeListWidget.addItem(item_name)
newtheme.add_font(unicode(QtGui.QFont().family()), unicode(u'#FFFFFF'), unicode(30), u'False') self.themelist.append(textName)
newtheme.add_font(unicode(QtGui.QFont().family()), unicode(u'#FFFFFF'), unicode(12), u'False', u'footer') self.pushThemes()
newtheme.add_display(u'False', unicode(u'#FFFFFF'), u'False', unicode(u'#FFFFFF'),
unicode(0), unicode(0), unicode(0)) def pushThemes(self):
xml = newtheme.extract_xml() Receiver().send_message(u'update_themes', self.getThemes() )
theme = ThemeXML()
theme.parse(xml) def getThemes(self):
theme.extend_image_filename(self.path) return self.themelist
return theme
def getThemeData(self, themename):
def checkThemesExists(self, dir): log.debug(u'getthemedata for theme %s', themename)
log.debug(u'check themes') xml_file = os.path.join(self.path, unicode(themename),
if os.path.exists(dir) == False: unicode(themename) + u'.xml')
os.mkdir(dir) try:
xml = file_to_xml(xml_file)
def unzipTheme(self, filename, dir): except:
""" xml = self.baseTheme()
Unzip the theme, remove the preview file if stored theme = ThemeXML()
Generate a new preview fileCheck the XML theme version and upgrade if theme.parse(xml)
necessary. theme.extend_image_filename(self.path)
""" self.cleanTheme(theme)
log.debug(u'Unzipping theme %s', filename) return theme
zip = zipfile.ZipFile(unicode(filename))
filexml = None def checkThemesExists(self, dir):
themename = None log.debug(u'check themes')
for file in zip.namelist(): if os.path.exists(dir) == False:
if file.endswith(os.path.sep): os.mkdir(dir)
theme_dir = os.path.join(dir, file)
if os.path.exists(theme_dir) == False: def unzipTheme(self, filename, dir):
os.mkdir(os.path.join(dir, file)) """
else: Unzip the theme, remove the preview file if stored
fullpath = os.path.join(dir, file) Generate a new preview fileCheck the XML theme version and upgrade if
names = file.split(os.path.sep) necessary.
if len(names) > 1: """
# not preview file log.debug(u'Unzipping theme %s', filename)
if themename is None: zip = zipfile.ZipFile(unicode(filename))
themename = names[0] filexml = None
xml_data = zip.read(file) themename = None
if os.path.splitext(file)[1].lower() in [u'.xml']: for file in zip.namelist():
if self.checkVersion1(xml_data): if file.endswith(os.path.sep):
# upgrade theme xml theme_dir = os.path.join(dir, file)
filexml = self.migrateVersion122(filename, fullpath, xml_data) if os.path.exists(theme_dir) == False:
else: os.mkdir(os.path.join(dir, file))
filexml = xml_data else:
outfile = open(fullpath, u'w') fullpath = os.path.join(dir, file)
outfile.write(filexml) names = file.split(os.path.sep)
outfile.close() if len(names) > 1:
else: # not preview file
outfile = open(fullpath, u'w') if themename is None:
outfile.write(zip.read(file)) themename = names[0]
outfile.close() xml_data = zip.read(file)
self.generateAndSaveImage(dir, themename, filexml) if os.path.splitext(file)[1].lower() in [u'.xml']:
if self.checkVersion1(xml_data):
def checkVersion1(self, xmlfile): # upgrade theme xml
""" filexml = self.migrateVersion122(filename,
Am I a version 1 theme fullpath, xml_data)
""" else:
log.debug(u'checkVersion1 ') filexml = xml_data
theme = xmlfile outfile = open(fullpath, u'w')
tree = ElementTree(element=XML(theme)).getroot() outfile.write(filexml)
if tree.find(u'BackgroundType') is None: outfile.close()
return False else:
else: outfile = open(fullpath, u'w')
return True outfile.write(zip.read(file))
outfile.close()
def migrateVersion122(self, filename, fullpath, xml_data): self.generateAndSaveImage(dir, themename, filexml)
"""
Called by convert the xml data from version 1 format def checkVersion1(self, xmlfile):
to the current format. """
New fields are defaulted but the new theme is useable Am I a version 1 theme
""" """
log.debug(u'migrateVersion122 %s %s', filename, fullpath) log.debug(u'checkVersion1 ')
theme = Theme(xml_data) theme = xmlfile
newtheme = ThemeXML() tree = ElementTree(element=XML(theme)).getroot()
newtheme.new_document(theme.Name) if tree.find(u'BackgroundType') is None:
if theme.BackgroundType == 0: return False
newtheme.add_background_solid(unicode(theme.BackgroundParameter1.name())) else:
elif theme.BackgroundType == 1: return True
direction = u'vertical'
if theme.BackgroundParameter3.name() == 1: def migrateVersion122(self, filename, fullpath, xml_data):
direction = u'horizontal' """
newtheme.add_background_gradient( Called by convert the xml data from version 1 format
unicode(theme.BackgroundParameter1.name()), to the current format.
unicode(theme.BackgroundParameter2.name()), direction) New fields are defaulted but the new theme is useable
else: """
newtheme.add_background_image(unicode(theme.BackgroundParameter1)) log.debug(u'migrateVersion122 %s %s', filename, fullpath)
theme = Theme(xml_data)
newtheme.add_font(unicode(theme.FontName), newtheme = ThemeXML()
unicode(theme.FontColor.name()), newtheme.new_document(theme.Name)
unicode(theme.FontProportion * 2), u'False') if theme.BackgroundType == 0:
newtheme.add_font(unicode(theme.FontName), newtheme.add_background_solid(unicode(
unicode(theme.FontColor.name()), theme.BackgroundParameter1.name()))
unicode(12), u'False', u'footer') elif theme.BackgroundType == 1:
outline = False direction = u'vertical'
shadow = False if theme.BackgroundParameter3.name() == 1:
if theme.Shadow == 1: direction = u'horizontal'
shadow = True newtheme.add_background_gradient(
if theme.Outline == 1: unicode(theme.BackgroundParameter1.name()),
outline = True unicode(theme.BackgroundParameter2.name()), direction)
newtheme.add_display(unicode(shadow), unicode(theme.ShadowColor.name()), else:
unicode(outline), unicode(theme.OutlineColor.name()), newtheme.add_background_image(unicode(theme.BackgroundParameter1))
unicode(theme.HorizontalAlign), unicode(theme.VerticalAlign),
unicode(theme.WrapStyle)) newtheme.add_font(unicode(theme.FontName),
return newtheme.extract_xml() unicode(theme.FontColor.name()),
unicode(theme.FontProportion * 2), u'False')
def saveTheme(self, name, theme_xml, theme_pretty_xml, image_from, newtheme.add_font(unicode(theme.FontName),
image_to) : unicode(theme.FontColor.name()),
""" unicode(12), u'False', u'footer')
Called by thememaintenance Dialog to save the theme outline = False
and to trigger the reload of the theme list shadow = False
""" if theme.Shadow == 1:
log.debug(u'saveTheme %s %s', name, theme_xml) shadow = True
theme_dir = os.path.join(self.path, name) if theme.Outline == 1:
if os.path.exists(theme_dir) == False: outline = True
os.mkdir(os.path.join(self.path, name)) newtheme.add_display(unicode(shadow), unicode(theme.ShadowColor.name()),
theme_file = os.path.join(theme_dir, name + u'.xml') unicode(outline), unicode(theme.OutlineColor.name()),
log.debug(theme_file) unicode(theme.HorizontalAlign), unicode(theme.VerticalAlign),
unicode(theme.WrapStyle))
result = QtGui.QMessageBox.Yes return newtheme.extract_xml()
if os.path.exists(theme_file):
result = QtGui.QMessageBox.question( def saveTheme(self, name, theme_xml, theme_pretty_xml, image_from,
self, image_to) :
translate(u'ThemeManager',u'Theme Exists'), """
translate(u'ThemeManager',u'A theme with this name already exists, would you like to overwrite it?'), Called by thememaintenance Dialog to save the theme
(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), and to trigger the reload of the theme list
QtGui.QMessageBox.No) """
if result == QtGui.QMessageBox.Yes: log.debug(u'saveTheme %s %s', name, theme_xml)
# Save the theme, overwriting the existing theme if necessary. theme_dir = os.path.join(self.path, name)
outfile = open(theme_file, u'w') if os.path.exists(theme_dir) == False:
outfile.write(theme_pretty_xml) os.mkdir(os.path.join(self.path, name))
outfile.close() theme_file = os.path.join(theme_dir, name + u'.xml')
if image_from is not None and image_from != image_to: log.debug(theme_file)
shutil.copyfile(image_from, image_to)
result = QtGui.QMessageBox.Yes
self.generateAndSaveImage(self.path, name, theme_xml) if os.path.exists(theme_file):
self.loadThemes() result = QtGui.QMessageBox.question(
else: self,
# Don't close the dialog - allow the user to change the name of translate(u'ThemeManager', u'Theme Exists'),
# the theme or to cancel the theme dialog completely. translate(u'ThemeManager', u'A theme with this name already exists, would you like to overwrite it?'),
return False (QtGui.QMessageBox.Yes | QtGui.QMessageBox.No),
QtGui.QMessageBox.No)
def generateAndSaveImage(self, dir, name, theme_xml): if result == QtGui.QMessageBox.Yes:
log.debug(u'generateAndSaveImage %s %s %s', dir, name, theme_xml) # Save the theme, overwriting the existing theme if necessary.
theme = ThemeXML() outfile = open(theme_file, u'w')
theme.parse(theme_xml) outfile.write(theme_pretty_xml)
theme.extend_image_filename(dir) outfile.close()
frame = self.generateImage(theme) if image_from is not None and image_from != image_to:
samplepathname = os.path.join(self.path, name + u'.png') shutil.copyfile(image_from, image_to)
if os.path.exists(samplepathname):
os.unlink(samplepathname) self.generateAndSaveImage(self.path, name, theme_xml)
frame.save(samplepathname, u'png') self.loadThemes()
log.debug(u'Theme image written to %s', samplepathname) else:
# Don't close the dialog - allow the user to change the name of
def generateImage(self, themedata): # the theme or to cancel the theme dialog completely.
""" return False
Call the RenderManager to build a Sample Image
""" def generateAndSaveImage(self, dir, name, theme_xml):
log.debug(u'generateImage %s ', themedata) log.debug(u'generateAndSaveImage %s %s %s', dir, name, theme_xml)
frame = self.parent.RenderManager.generate_preview(themedata) theme = ThemeXML()
return frame theme.parse(theme_xml)
theme.extend_image_filename(dir)
def getPreviewImage(self, theme): frame = self.generateImage(theme)
log.debug(u'getPreviewImage %s ', theme) samplepathname = os.path.join(self.path, name + u'.png')
image = os.path.join(self.path, theme + u'.png') if os.path.exists(samplepathname):
return image os.unlink(samplepathname)
frame.save(samplepathname, u'png')
log.debug(u'Theme image written to %s', samplepathname)
def generateImage(self, themedata):
"""
Call the RenderManager to build a Sample Image
"""
log.debug(u'generateImage %s ', themedata)
frame = self.parent.RenderManager.generate_preview(themedata)
return frame
def getPreviewImage(self, theme):
log.debug(u'getPreviewImage %s ', theme)
image = os.path.join(self.path, theme + u'.png')
return image
def baseTheme(self):
log.debug(u'base theme created')
newtheme = ThemeXML()
newtheme.new_document(u'New Theme')
newtheme.add_background_solid(unicode(u'#000000'))
newtheme.add_font(unicode(QtGui.QFont().family()), unicode(u'#FFFFFF'),
unicode(30), u'False')
newtheme.add_font(unicode(QtGui.QFont().family()), unicode(u'#FFFFFF'),
unicode(12), u'False', u'footer')
newtheme.add_display(u'False', unicode(u'#FFFFFF'), u'False',
unicode(u'#FFFFFF'), unicode(0), unicode(0), unicode(0))
return newtheme.extract_xml()
def cleanTheme(self, theme):
theme.background_color = theme.background_color.strip()
theme.background_direction = theme.background_direction.strip()
theme.background_endColor = theme.background_endColor.strip()
if theme.background_filename:
theme.background_filename = theme.background_filename.strip()
#theme.background_mode
theme.background_startColor = theme.background_startColor.strip()
#theme.background_type
if theme.display_display:
theme.display_display = theme.display_display.strip()
theme.display_horizontalAlign = theme.display_horizontalAlign.strip()
theme.display_outline = str_to_bool(theme.display_outline)
#theme.display_outline_color
theme.display_shadow = str_to_bool(theme.display_shadow)
#theme.display_shadow_color
theme.display_verticalAlign = theme.display_verticalAlign.strip()
theme.display_wrapStyle = theme.display_wrapStyle.strip()
theme.font_footer_color = theme.font_footer_color.strip()
theme.font_footer_height = theme.font_footer_height.strip()
theme.font_footer_italics = str_to_bool(theme.font_footer_italics)
theme.font_footer_name = theme.font_footer_name.strip()
#theme.font_footer_override
theme.font_footer_proportion = theme.font_footer_proportion.strip()
theme.font_footer_weight = theme.font_footer_weight.strip()
theme.font_footer_width = theme.font_footer_width.strip()
theme.font_footer_x = theme.font_footer_x.strip()
theme.font_footer_y = theme.font_footer_y.strip()
theme.font_main_color = theme.font_main_color.strip()
theme.font_main_height = theme.font_main_height.strip()
theme.font_main_italics = str_to_bool(theme.font_main_italics)
theme.font_main_name = theme.font_main_name.strip()
#theme.font_main_override
theme.font_main_proportion = theme.font_main_proportion.strip()
theme.font_main_weight = theme.font_main_weight.strip()
theme.font_main_x = theme.font_main_x.strip()
theme.font_main_y = theme.font_main_y.strip()
#theme.theme_mode
theme.theme_name = theme.theme_name.strip()
#theme.theme_version

View File

@ -28,7 +28,7 @@ from openlp.plugins.bibles.lib.models import *
class BibleDBImpl(BibleCommon): class BibleDBImpl(BibleCommon):
global log global log
log=logging.getLogger(u'BibleDBImpl') log = logging.getLogger(u'BibleDBImpl')
log.info(u'BibleDBimpl loaded') log.info(u'BibleDBimpl loaded')
def __init__(self, biblepath, biblename, config): def __init__(self, biblepath, biblename, config):
@ -122,34 +122,45 @@ class BibleDBImpl(BibleCommon):
def get_max_bible_book_verses(self, bookname, chapter): def get_max_bible_book_verses(self, bookname, chapter):
log.debug(u'get_max_bible_book_verses %s, %s', bookname, chapter) log.debug(u'get_max_bible_book_verses %s, %s', bookname, chapter)
verse = self.session.query(Verse).join(Book).filter(Book.name==bookname).filter(Verse.chapter==chapter).order_by(Verse.verse.desc()).first() verse = self.session.query(Verse).join(Book).filter(
Book.name == bookname).filter(
Verse.chapter == chapter).order_by(Verse.verse.desc()).first()
return verse.verse return verse.verse
def get_max_bible_book_chapter(self, bookname): def get_max_bible_book_chapter(self, bookname):
log.debug(u'get_max_bible_book_chapter %s', bookname) log.debug(u'get_max_bible_book_chapter %s', bookname)
verse = self.session.query(Verse).join(Book).filter(Book.name==bookname).order_by(Verse.chapter.desc()).first() verse = self.session.query(Verse).join(Book).filter(
Book.name == bookname).order_by(Verse.chapter.desc()).first()
return verse.chapter return verse.chapter
def get_bible_book(self, bookname): def get_bible_book(self, bookname):
log.debug(u'get_bible_book %s', bookname) log.debug(u'get_bible_book %s', bookname)
bk = self.session.query(Book).filter(Book.name.like(bookname + u'%')).first() bk = self.session.query(Book).filter(
Book.name.like(bookname + u'%')).first()
if bk == None: if bk == None:
bk = self.session.query(Book).filter(Book.abbreviation.like(bookname + u'%')).first() bk = self.session.query(Book).filter(
Book.abbreviation.like(bookname + u'%')).first()
return bk return bk
def get_bible_chapter(self, id, chapter): def get_bible_chapter(self, id, chapter):
log.debug(u'get_bible_chapter %s, %s', id, chapter) log.debug(u'get_bible_chapter %s, %s', id, chapter)
return self.session.query(Verse).filter_by(chapter=chapter).filter_by(book_id=id).first() return self.session.query(Verse).filter_by(chapter=chapter).filter_by(
book_id=id).first()
def get_bible_text(self, bookname, chapter, sverse, everse): def get_bible_text(self, bookname, chapter, sverse, everse):
log.debug(u'get_bible_text %s, %s, %s, %s', bookname, chapter, sverse, everse) log.debug(u'get_bible_text %s, %s, %s, %s', bookname, chapter, sverse,
verses = self.session.query(Verse).join(Book).filter(Book.name==bookname).filter(Verse.chapter==chapter).filter(Verse.verse>=sverse).filter(Verse.verse<=everse).order_by(Verse.verse).all() everse)
verses = self.session.query(Verse).join(Book).filter(
Book.name == bookname).filter(Verse.chapter == chapter).filter(
Verse.verse>=sverse).filter(Verse.verse<=everse).order_by(
Verse.verse).all()
return verses return verses
def get_verses_from_text(self, versetext): def get_verses_from_text(self, versetext):
log.debug(u'get_verses_from_text %s',versetext) log.debug(u'get_verses_from_text %s',versetext)
versetext = u'%%%s%%' % versetext versetext = u'%%%s%%' % versetext
verses = self.session.query(Verse).filter(Verse.text.like(versetext)).all() verses = self.session.query(Verse).filter(
Verse.text.like(versetext)).all()
return verses return verses
def dump_bible(self): def dump_bible(self):

View File

@ -321,7 +321,8 @@ class BibleMediaItem(MediaManagerItem):
cf = self.AdvancedFromChapter.currentText() cf = self.AdvancedFromChapter.currentText()
self.adjustComboBox(cf, self.chapters_from, self.AdvancedToChapter) self.adjustComboBox(cf, self.chapters_from, self.AdvancedToChapter)
# get the verse count for new chapter # get the verse count for new chapter
vse = self.parent.biblemanager.get_book_verse_count(bible, book, int(cf))[0] vse = self.parent.biblemanager.get_book_verse_count(bible, book,
int(cf))[0]
self.adjustComboBox(1, vse, self.AdvancedFromVerse) self.adjustComboBox(1, vse, self.AdvancedFromVerse)
self.adjustComboBox(1, vse, self.AdvancedToVerse) self.adjustComboBox(1, vse, self.AdvancedToVerse)
@ -332,7 +333,8 @@ class BibleMediaItem(MediaManagerItem):
if self.ClearQuickSearchComboBox.currentIndex() == 0: if self.ClearQuickSearchComboBox.currentIndex() == 0:
self.ListView.clear() self.ListView.clear()
if self.QuickSearchComboBox.currentIndex() == 1: if self.QuickSearchComboBox.currentIndex() == 1:
self.search_results = self.parent.biblemanager.get_verse_from_text(bible, text) self.search_results = self.parent.biblemanager.get_verse_from_text(
bible, text)
else: else:
self.searchByReference(bible, text) self.searchByReference(bible, text)
if self.search_results is not None: if self.search_results is not None:
@ -341,7 +343,7 @@ class BibleMediaItem(MediaManagerItem):
def generateSlideData(self, service_item): def generateSlideData(self, service_item):
log.debug(u'generating slide data') log.debug(u'generating slide data')
items = self.ListView.selectedIndexes() items = self.ListView.selectedIndexes()
if len(items) ==0: if len(items) == 0:
return False return False
old_chapter = u'' old_chapter = u''
raw_slides = [] raw_slides = []
@ -421,8 +423,10 @@ class BibleMediaItem(MediaManagerItem):
def initialiseChapterVerse(self, bible, book): def initialiseChapterVerse(self, bible, book):
log.debug(u'initialiseChapterVerse %s , %s', bible, book) log.debug(u'initialiseChapterVerse %s , %s', bible, book)
self.chapters_from = self.parent.biblemanager.get_book_chapter_count(bible, book) self.chapters_from = self.parent.biblemanager.get_book_chapter_count(
self.verses = self.parent.biblemanager.get_book_verse_count(bible, book, 1) bible, book)
self.verses = self.parent.biblemanager.get_book_verse_count(bible,
book, 1)
self.adjustComboBox(1, self.chapters_from, self.AdvancedFromChapter) self.adjustComboBox(1, self.chapters_from, self.AdvancedFromChapter)
self.adjustComboBox(1, self.chapters_from, self.AdvancedToChapter) self.adjustComboBox(1, self.chapters_from, self.AdvancedToChapter)
self.adjustComboBox(1, self.verses, self.AdvancedFromVerse) self.adjustComboBox(1, self.verses, self.AdvancedFromVerse)
@ -517,15 +521,19 @@ class BibleMediaItem(MediaManagerItem):
if start_chapter == u'': if start_chapter == u'':
message = u'No chapter found for search criteria' message = u'No chapter found for search criteria'
log.debug(u'results = %s @ %s : %s @ %s : %s'% \ log.debug(u'results = %s @ %s : %s @ %s : %s'% \
(unicode(book), unicode(start_chapter), unicode(end_chapter), unicode(start_verse), unicode(end_verse))) (unicode(book), unicode(start_chapter), unicode(end_chapter),
unicode(start_verse), unicode(end_verse)))
if message == None: if message == None:
self.search_results = None self.search_results = None
self.search_results = self.parent.biblemanager.get_verse_text(bible, book, self.search_results = self.parent.biblemanager.get_verse_text(
int(start_chapter), int(end_chapter), int(start_verse), bible, book, int(start_chapter), int(end_chapter),
int(end_verse)) int(start_verse), int(end_verse))
self.copyright = unicode(self.parent.biblemanager.get_meta_data(bible, u'Copyright').value) self.copyright = unicode(self.parent.biblemanager.get_meta_data(
self.permissions = unicode(self.parent.biblemanager.get_meta_data(bible, u'Permissions').value) bible, u'Copyright').value)
self.version = unicode(self.parent.biblemanager.get_meta_data(bible, u'Version').value) self.permissions = unicode(self.parent.biblemanager.get_meta_data(
bible, u'Permissions').value)
self.version = unicode(self.parent.biblemanager.get_meta_data(
bible, u'Version').value)
else: else:
reply = QtGui.QMessageBox.information(self, reply = QtGui.QMessageBox.information(self,
translate(u'BibleMediaItem', u'Information'), translate(u'BibleMediaItem', u'Information'),

View File

@ -32,7 +32,7 @@ class FileListData(QAbstractListModel):
def __init__(self): def __init__(self):
QAbstractListModel.__init__(self) QAbstractListModel.__init__(self)
self.items=[] # will be a list of (full filename shortname) tuples self.items = [] # will be a list of (full filename shortname) tuples
def rowCount(self, parent): def rowCount(self, parent):
return len(self.items) return len(self.items)
@ -56,10 +56,10 @@ class FileListData(QAbstractListModel):
self.insertRow(len(self.items), filename) self.insertRow(len(self.items), filename)
def data(self, index, role): def data(self, index, role):
row=index.row() row = index.row()
if row > len(self.items): # if the last row is selected and deleted, we then get called with an empty row! if row > len(self.items): # if the last row is selected and deleted, we then get called with an empty row!
return QVariant() return QVariant()
if role==Qt.DisplayRole: if role == Qt.DisplayRole:
retval= self.items[row][1] retval= self.items[row][1]
# elif role == Qt.DecorationRole: # elif role == Qt.DecorationRole:
# retval= self.items[row][1] # retval= self.items[row][1]