Head again

This commit is contained in:
Tim Bentley 2009-09-07 20:00:41 +01:00
commit 9ec28564ee
13 changed files with 1458 additions and 1329 deletions

View File

@ -312,7 +312,7 @@ class Renderer(object):
rectPath.lineTo(max_x, 0)
rectPath.closeSubpath()
painter.drawPath(rectPath)
elif self._theme.background_type== u'image':
elif self._theme.background_type == u'image':
# image
painter.fillRect(self._frame.rect(), QtCore.Qt.black)
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
"""
from openlp.core.lib import str_to_bool
from openlp.core.utils import ConfigHelper
class SettingsManager(object):
"""
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.height = self.screen[u'size'].height()
self.mainwindow_height = self.height * 0.8
self.mainwindow_docbars = self.width / 5
if self.mainwindow_docbars > 300:
self.mainwindow_docbars = 300
self.slidecontroller = ((self.width - (self.mainwindow_docbars * 3 ) / 2) / 2) -100
self.slidecontroller_image = self.slidecontroller - 50
print self.width, self.mainwindow_docbars, self.slidecontroller, self.slidecontroller_image
self.mainwindow_docbars = self.width / 3
self.mainwindow_slidecontroller = self.width / 6
self.showMediaManager = str_to_bool( ConfigHelper.get_config(
u'user interface', u'display mediamanager', True))
self.showServiceManager = str_to_bool(ConfigHelper.get_config(
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
class TestPluginManager:
def test_init(self):
self.p=PluginManager(u'./testplugins')
p=self.p
self.p = PluginManager(u'./testplugins')
p = self.p
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
names=[plugin.name for plugin in p.plugins]
names = [plugin.name for plugin in p.plugins]
# see which ones we've got
assert (u'testplugin1' in names)
assert (u'testplugin2' in names)
assert(u'testplugin1' in names)
assert(u'testplugin2' in names)
# 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
assert p.plugins[0].name == "testplugin2"
assert p.plugins[1].name == "testplugin1"
assert(p.plugins[0].name == "testplugin2")
assert(p.plugins[1].name == "testplugin1")
if __name__ == "__main__":
log.debug(u'Starting')
t=TestPluginManager()
t = TestPluginManager()
t.test_init()
log.debug(u'List of plugins found:')
for plugin in t.p.plugins:

View File

@ -21,10 +21,12 @@ import sys
import os, os.path
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 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
def whoami(depth=1):
return sys._getframe(depth).f_code.co_name
@ -34,8 +36,8 @@ class TstFrame:
def __init__(self, size):
"""Create the DemoPanel."""
self.width=size.width();
self.height=size.height();
self.width = size.width();
self.height = size.height();
# create something to be painted into
self._Buffer = QtGui.QPixmap(self.width, self.height)
def GetPixmap(self):
@ -47,10 +49,10 @@ class TestRender_base:
def __init__(self):
if not os.path.exists(u'test_results'):
os.mkdir(u'test_results')
self.app=None
self.app = None
def write_to_file(self, pixmap, name):
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):
os.unlink(testpathname)
im.save(testpathname, 'bmp')
@ -85,7 +87,7 @@ class TestRender_base:
def setup_method(self, method):
print "SSsetup", method
if not hasattr(self, 'app'):
self.app=None
self.app = None
try: # see if we already have an app for some reason.
# have to try and so something, cant just test against None
print "app", self.app, ";;;"
@ -98,14 +100,14 @@ class TestRender_base:
# print "App", self.app
# self.app = QtGui.QApplication([])
print "Application created and sorted"
self.size=QtCore.QSize(800,600)
frame=TstFrame(size=self.size)
self.frame=frame
self.paintdest=frame.GetPixmap()
self.size = QtCore.QSize(800,600)
frame = TstFrame(size = self.size)
self.frame = frame
self.paintdest = frame.GetPixmap()
self.r=Renderer()
self.r.set_paint_dest(self.paintdest)
self.expected_answer="Don't know yet"
self.answer=None
self.expected_answer = "Don't know yet"
self.answer = None
print "--------------- Setup Done -------------"
def teardown_method(self, method):
@ -118,34 +120,34 @@ class TestRender(TestRender_base):
def setup_method(self, method):
TestRender_base.setup_method(self, method)
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._render_background()
self.r.set_text_rectangle(QtCore.QRect(0,0, self.size.width()-1,
self.size.height()-1))
self.msg=None
self.msg = None
def test_easy(self):
answer=self.r._render_single_line(u'Test line', tlcorner=(0,100))
assert (answer==(219,163))
answer = self.r._render_single_line(u'Test line', tlcorner = (0,100))
assert(answer == (219,163))
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',
tlcorner=(10,10))
assert (answer==(753,136))
tlcorner = (10,10))
assert(answer == (753,136))
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',
tlcorner=(10,10))
assert(answer==(753,199))
tlcorner = (10,10))
assert(answer == (753,199))
def test_lines(self):
lines=[]
lines = []
lines.append(u'Line One')
lines.append(u'Line Two')
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')
answer=self.r._render_lines(lines)
assert(answer==QtCore.QRect(0,0,741,378))
answer = self.r._render_lines(lines)
assert(answer == QtCore.QRect(0,0,741,378))
def test_set_words_openlp(self):
words="""
@ -158,9 +160,9 @@ Line 2
Verse 3: Line 1
Line 2
Line 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)
assert (answer==expected_answer)
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)
assert(answer == expected_answer)
def test_render_screens(self):
words="""
@ -173,15 +175,16 @@ Line 2
Verse 3: Line 1
Line 2
Line 3"""
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"]
assert (verses==expected_answer)
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"]
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)):
answer=self.r.render_screen(v)
# 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):
lines=[]
@ -189,34 +192,37 @@ Line 3"""
for i in range(number):
extra=""
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))
result=self.r.split_set_of_lines(lines)
result = self.r.split_set_of_lines(lines)
print "results---------------__", result
for i in range(len(result)):
self.setup_method(None)
answer=self.r._render_lines(result[i])
answer = self.r._render_lines(result[i])
print answer
self.write_to_file(self.frame.GetPixmap(), "split_test_%03d"% i)
print number, i, answer.x(), answer.y(), answer.width(), answer.height()
e=expected_answers[i]
assert(answer==QtCore.QRect(e[0],e[1],e[2],e[3]))
print number, i, answer.x(), answer.y(), answer.width(), \
answer.height()
e = expected_answers[i]
assert(answer == QtCore.QRect(e[0],e[1],e[2],e[3]))
def test_splits(self):
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),
(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(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),
(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(12, 2, [(0,0,180,378), (0,0,214,378)])
self.split_test(4, 1, [(0,0,180,252)])
self.split_test(6, 1, [(0,0,180,378)])
self.split_test(8, 1, [(0,0,180,504)])
if __name__=="__main__":
t=TestRender()
if __name__ == "__main__":
t = TestRender()
t.setup_class()
t.setup_method(None)
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
Place, Suite 330, Boston, MA 02111-1307 USA
"""
from test_render import TestRender_base, whoami
import sys
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 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):
# easy test first
if goldenim == testim:
@ -53,22 +54,24 @@ class TestRenderTheme(TestRender_base):
def __init__(self):
TestRender_base.__init__(self)
def setup_method(self, method):
TestRender_base.setup_method(self, method)
print "Theme setup", method
# print "setup 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()))
words="""How sweet the name of Jesus sounds
self.r.set_text_rectangle(QtCore.QRect(0,0, self.size.width(),
self.size.height()))
words = """How sweet the name of Jesus sounds
In a believer's ear!
It soothes his sorrows, heals his wounds,
And drives away his fear.
"""
verses=self.r.set_words_openlp(words)
verses = self.r.set_words_openlp(words)
# usually the same
self.expected_answer= QtCore.QRect(0, 0, 559, 342)
self.msg=None
self.bmpname="Not set a bitmap yet"
self.expected_answer = QtCore.QRect(0, 0, 559, 342)
self.msg = None
self.bmpname = "Not set a bitmap yet"
print "------------- setup done --------------"
def teardown_method(self, method):
@ -76,20 +79,21 @@ And drives away his fear.
if self.bmpname != None:
assert (self.compare_DC_to_file(self.bmpname))
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 ========="
def compare_DC_to_file(self, name):
"""writes DC out to a bitmap file and then compares it with a golden one
returns True if OK, False if not (so you can assert on it)
"""writes DC out to a bitmap file and then compares it with a golden
one returns True if OK, False if not (so you can assert on it)
"""
print "--- compare DC to file --- ", name
p=self.frame.GetPixmap()
im=self.write_to_file(p, name)
p = self.frame.GetPixmap()
im = self.write_to_file(p, name)
print "Compare"
goldenfilename=os.path.join(u'golden_bitmaps",name+".bmp')
if os.path.exists(goldenfilename):
goldenim=QtGui.QImage(goldenfilename)
goldenim = QtGui.QImage(goldenfilename)
else:
print "File", goldenfilename, "not found"
return False
@ -101,201 +105,210 @@ And drives away his fear.
return False
def test_theme_basic(self):
self.answer=self.r.render_screen(0)
self.bmpname=whoami()
self.answer = self.r.render_screen(0)
self.bmpname = whoami()
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
# }}}
# {{{ Gradients
def test_gradient_h(self):
# normally we wouldn't hack with these directly!
self.r._theme.BackgroundType = 1
self.r._theme.BackgroundParameter1 = QtGui.QColor(255,0,0);
self.r._theme.BackgroundParameter2 = QtGui.QColor(255,255,0);
self.r._theme.BackgroundParameter1 = QtGui.QColor(255,0,0)
self.r._theme.BackgroundParameter2 = QtGui.QColor(255,255,0)
self.r._theme.BackgroundParameter3 = 1
self.answer=self.r.render_screen(0)
self.bmpname=whoami()
self.answer = self.r.render_screen(0)
self.bmpname = whoami()
def test_gradient_v(self):
# normally we wouldn't hack with these directly!
self.r._theme.BackgroundType = 1
self.r._theme.BackgroundParameter1 = QtGui.QColor(255,0,0);
self.r._theme.BackgroundParameter2 = QtGui.QColor(255,255,0);
self.r._theme.BackgroundParameter1 = QtGui.QColor(255,0,0)
self.r._theme.BackgroundParameter2 = QtGui.QColor(255,255,0)
self.r._theme.BackgroundParameter3 = 0
self.answer=self.r.render_screen(0)
self.bmpname=whoami()
self.answer = self.r.render_screen(0)
self.bmpname = whoami()
# }}}
# {{{ backgrounds
def test_bg_stretch_y(self):
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 = 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);
'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.BackgroundParameter1 = os.path.join(u'data_for_tests',
'treessmall.jpg')
t.BackgroundParameter2 = QtGui.QColor(0,0,64)
t.BackgroundParameter3 = 0
t.VerticalAlign = 2
t.Name="stretch x"
t.Name = "stretch x"
self.r.set_theme(t)
self.answer=self.r.render_screen(0)
self.expected_answer= QtCore.QRect(0, 129, 559, 342)
self.bmpname=whoami()
self.answer = self.r.render_screen(0)
self.expected_answer = QtCore.QRect(0, 129, 559, 342)
self.bmpname = whoami()
def test_bg_shrink_x(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', 'treesbig.jpg');
t.BackgroundParameter2 = QtGui.QColor(0,0,64);
t.BackgroundParameter1 = os.path.join(u'data_for_tests',
'treesbig.jpg')
t.BackgroundParameter2 = QtGui.QColor(0,0,64)
t.BackgroundParameter3 = 0
t.VerticalAlign = 2
t.Name="shrink x"
t.Name = "shrink x"
self.r.set_theme(t)
self.expected_answer= QtCore.QRect(0, 129, 559, 342)
self.answer=self.r.render_screen(0)
self.bmpname=whoami()
self.expected_answer = QtCore.QRect(0, 129, 559, 342)
self.answer = self.r.render_screen(0)
self.bmpname = whoami()
# }}}
# {{{ Vertical alignment
def test_theme_vertical_align_top(self):
t=Theme(u'blank_theme.xml')
t = Theme(u'blank_theme.xml')
t.BackgroundType = 0
t.BackgroundParameter1 = QtGui.QColor(0,0,64);
t.BackgroundParameter1 = QtGui.QColor(0,0,64)
t.VerticalAlign = 0
t.Name="valign top"
t.Name = "valign top"
self.r.set_theme(t)
self.answer=self.r.render_screen(0)
self.bmpname=whoami()
self.answer = self.r.render_screen(0)
self.bmpname = whoami()
def test_theme_vertical_align_bot(self):
t=Theme(u'blank_theme.xml')
t = Theme(u'blank_theme.xml')
t.BackgroundType = 0
t.BackgroundParameter1 = QtGui.QColor(0,0,64);
t.BackgroundParameter1 = QtGui.QColor(0,0,64)
t.VerticalAlign = 1
t.Name="valign bot"
t.Name = "valign bot"
self.r.set_theme(t)
self.answer=self.r.render_screen(0)
self.expected_answer= QtCore.QRect(0, 257, 559, 342)
self.bmpname=whoami()
self.answer = self.r.render_screen(0)
self.expected_answer = QtCore.QRect(0, 257, 559, 342)
self.bmpname = whoami()
def test_theme_vertical_align_cen(self):
t=Theme(u'blank_theme.xml')
t = Theme(u'blank_theme.xml')
t.BackgroundType = 0
t.BackgroundParameter1 = QtGui.QColor(0,0,64);
t.BackgroundParameter1 = QtGui.QColor(0,0,64)
t.VerticalAlign = 2
t.Name="valign cen"
t.Name = "valign cen"
self.r.set_theme(t)
self.answer=self.r.render_screen(0)
self.expected_answer= QtCore.QRect(0, 129, 559, 342)
self.bmpname=whoami()
self.answer = self.r.render_screen(0)
self.expected_answer = QtCore.QRect(0, 129, 559, 342)
self.bmpname = whoami()
# }}}
# {{{ Horzontal alignment
def test_theme_horizontal_align_left(self):
t=Theme(u'blank_theme.xml')
t = Theme(u'blank_theme.xml')
t.BackgroundType = 0
t.BackgroundParameter1 = QtGui.QColor(0,0,64);
t.BackgroundParameter1 = QtGui.QColor(0,0,64)
t.VerticalAlign = 0
t.HorizontalAlign = 0
t.Name="halign left"
t.Name = "halign left"
self.r.set_theme(t)
self.answer=self.r.render_screen(0)
self.bmpname=whoami()
self.answer = self.r.render_screen(0)
self.bmpname = whoami()
def test_theme_horizontal_align_right(self):
t=Theme(u'blank_theme.xml')
t = Theme(u'blank_theme.xml')
t.BackgroundType = 0
t.BackgroundParameter1 = QtGui.QColor(0,0,64);
t.BackgroundParameter1 = QtGui.QColor(0,0,64)
t.VerticalAlign = 0
t.HorizontalAlign = 1
t.Name="halign right"
t.Name = "halign right"
self.r.set_theme(t)
self.expected_answer= QtCore.QRect(0, 0, 800, 342)
self.answer=self.r.render_screen(0)
self.bmpname=whoami()
self.expected_answer = QtCore.QRect(0, 0, 800, 342)
self.answer = self.r.render_screen(0)
self.bmpname = whoami()
def test_theme_horizontal_align_centre(self):
t=Theme(u'blank_theme.xml')
t = Theme(u'blank_theme.xml')
t.BackgroundType = 0
t.BackgroundParameter1 = QtGui.QColor(0,0,64);
t.BackgroundParameter1 = QtGui.QColor(0,0,64)
t.VerticalAlign = 0
t.HorizontalAlign = 2
t.Name="halign centre"
t.Name = "halign centre"
self.r.set_theme(t)
self.answer=self.r.render_screen(0)
self.expected_answer= QtCore.QRect(0, 0, 679, 342)
self.bmpname=whoami()
self.answer = self.r.render_screen(0)
self.expected_answer = QtCore.QRect(0, 0, 679, 342)
self.bmpname = whoami()
def test_theme_horizontal_align_left_lyric(self):
t=Theme(u'blank_theme.xml')
t = Theme(u'blank_theme.xml')
t.BackgroundType = 0
t.BackgroundParameter1 = QtGui.QColor(0,0,64);
t.BackgroundParameter1 = QtGui.QColor(0,0,64)
t.VerticalAlign = 0
t.HorizontalAlign = 0
t.WrapStyle=1
t.Name="halign left lyric"
t.WrapStyle = 1
t.Name = "halign left lyric"
self.r.set_theme(t)
self.answer=self.r.render_screen(0)
self.expected_answer=QtCore.QRect(0, 0, 778, 342)
self.bmpname=whoami()
self.answer = self.r.render_screen(0)
self.expected_answer = QtCore.QRect(0, 0, 778, 342)
self.bmpname = whoami()
# }}}
# {{{ Shadows and outlines
def test_theme_shadow_outline(self):
t=Theme(u'blank_theme.xml')
t = Theme(u'blank_theme.xml')
t.BackgroundType = 0
t.BackgroundParameter1 = QtGui.QColor(0,0,0);
t.Name="shadow/outline"
t.Shadow=1
t.Outline=1
t.ShadowColor=QtGui.QColor(64,128,0)
t.OutlineColor=QtGui.QColor(128,0,0)
t.Shadow = 1
t.Outline = 1
t.ShadowColor = QtGui.QColor(64,128,0)
t.OutlineColor = QtGui.QColor(128,0,0)
self.r.set_debug(1)
self.r.set_theme(t)
self.answer=self.r.render_screen(0)
hoffset=self.r._shadow_offset+2*(self.r._outline_offset)
voffset=hoffset * (len(self.r.words[0])+1)
self.answer = self.r.render_screen(0)
hoffset = self.r._shadow_offset+2*(self.r._outline_offset)
voffset = hoffset * (len(self.r.words[0])+1)
self.expected_answer= QtCore.QRect(0, 0, 559+hoffset, 342+voffset)
self.bmpname=whoami()
self.expected_answer = QtCore.QRect(0, 0, 559+hoffset, 342+voffset)
self.bmpname = whoami()
# }}}
def test_theme_font(self):
t=Theme(u'blank_theme.xml')
t = Theme(u'blank_theme.xml')
t.BackgroundType = 0
t.BackgroundParameter1 = QtGui.QColor(0,0,64);
t.Name="font"
t.FontName="Times New Roman"
t.BackgroundParameter1 = QtGui.QColor(0,0,64)
t.Name = "font"
t.FontName = "Times New Roman"
self.r.set_theme(t)
self.answer=self.r.render_screen(0)
self.expected_answer= QtCore.QRect(0, 0, 499, 336)
self.answer = self.r.render_screen(0)
self.expected_answer = QtCore.QRect(0, 0, 499, 336)
self.bmpname=whoami()
if __name__=="__main__":
t=TestRenderTheme()
if __name__ == "__main__":
t = TestRenderTheme()
t.setup_class()
t.setup_method(None)
t.test_bg_stretch_y()

View File

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

View File

@ -21,8 +21,7 @@ import logging
import os, os.path
from PyQt4 import QtCore, QtGui
from openlp.core.lib import ThemeXML, Renderer, file_to_xml, str_to_bool, \
translate
from openlp.core.lib import ThemeXML, Renderer, file_to_xml, translate
from amendthemedialog import Ui_AmendThemeDialog
@ -125,10 +124,10 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
new_theme.add_background_transparent()
else:
if self.theme.background_type == u'solid':
new_theme.add_background_solid( \
new_theme.add_background_solid(
unicode(self.theme.background_color))
elif self.theme.background_type == u'gradient':
new_theme.add_background_gradient( \
new_theme.add_background_gradient(
unicode(self.theme.background_startColor),
unicode(self.theme.background_endColor),
self.theme.background_direction)
@ -172,64 +171,16 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
save_from, save_to) is not False:
return QtGui.QDialog.accept(self)
def loadTheme(self, theme):
log.debug(u'LoadTheme %s', theme)
if theme == None:
self.theme.parse(self.baseTheme())
else:
xml_file = os.path.join(self.path, theme, theme + u'.xml')
xml = file_to_xml(xml_file)
self.theme.parse(xml)
self.theme.extend_image_filename(self.path)
self.cleanTheme(self.theme)
def setTheme(self, theme):
self.theme = theme
def loadTheme(self):
log.debug(u'LoadTheme %s', self.theme)
self.allowPreview = False
self.paintUi(self.theme)
self.allowPreview = True
self.previewTheme(self.theme)
def cleanTheme(self, theme):
self.theme.background_color = theme.background_color.strip()
self.theme.background_direction = theme.background_direction.strip()
self.theme.background_endColor = theme.background_endColor.strip()
if theme.background_filename:
self.theme.background_filename = theme.background_filename.strip()
#self.theme.background_mode
self.theme.background_startColor = theme.background_startColor.strip()
#self.theme.background_type
self.theme.display_display = theme.display_display.strip()
self.theme.display_horizontalAlign = \
theme.display_horizontalAlign.strip()
self.theme.display_outline = str_to_bool(theme.display_outline)
#self.theme.display_outline_color
self.theme.display_shadow = str_to_bool(theme.display_shadow)
#self.theme.display_shadow_color
self.theme.display_verticalAlign = \
theme.display_verticalAlign.strip()
self.theme.display_wrapStyle = theme.display_wrapStyle.strip()
self.theme.font_footer_color = theme.font_footer_color.strip()
self.theme.font_footer_height = theme.font_footer_height.strip()
self.theme.font_footer_italics = str_to_bool(theme.font_footer_italics)
self.theme.font_footer_name = theme.font_footer_name.strip()
#self.theme.font_footer_override
self.theme.font_footer_proportion = \
theme.font_footer_proportion.strip()
self.theme.font_footer_weight = theme.font_footer_weight.strip()
self.theme.font_footer_width = theme.font_footer_width.strip()
self.theme.font_footer_x = theme.font_footer_x.strip()
self.theme.font_footer_y = theme.font_footer_y.strip()
self.theme.font_main_color = theme.font_main_color.strip()
self.theme.font_main_height = theme.font_main_height.strip()
self.theme.font_main_italics = str_to_bool(theme.font_main_italics)
self.theme.font_main_name = theme.font_main_name.strip()
#self.theme.font_main_override
self.theme.font_main_proportion = theme.font_main_proportion.strip()
self.theme.font_main_weight = theme.font_main_weight.strip()
self.theme.font_main_x = theme.font_main_x.strip()
self.theme.font_main_y = theme.font_main_y.strip()
#self.theme.theme_mode
self.theme.theme_name = theme.theme_name.strip()
#self.theme.theme_version
def onImageToolButtonClicked(self):
filename = QtGui.QFileDialog.getOpenFileName(self, 'Open file')
if filename != "":
@ -244,7 +195,7 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
self.previewTheme(self.theme)
def onFontMainWeightComboBoxSelected(self, value):
if value ==0:
if value == 0:
self.theme.font_main_weight = u'Normal'
self.theme.font_main_italics = False
elif value == 1:
@ -288,7 +239,7 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
self.FontMainXSpinBox.setValue(int(self.theme.font_main_x))
self.FontMainYSpinBox.setValue(int(self.theme.font_main_y))
self.FontMainWidthSpinBox.setValue(int(self.theme.font_main_width))
self.FontMainHeightSpinBox.setValue(int( \
self.FontMainHeightSpinBox.setValue(int(
self.theme.font_main_height))
self.stateChanging(self.theme)
self.previewTheme(self.theme)
@ -367,9 +318,9 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
self.FontFooterXSpinBox.setValue(int(self.theme.font_footer_x))
self.FontFooterYSpinBox.setValue(int(self.theme.font_footer_y))
self.FontFooterWidthSpinBox.setValue(int( \
self.FontFooterWidthSpinBox.setValue(int(
self.theme.font_footer_width))
self.FontFooterHeightSpinBox.setValue(int( \
self.FontFooterHeightSpinBox.setValue(int(
self.theme.font_footer_height))
self.stateChanging(self.theme)
@ -502,21 +453,6 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
#
#Local Methods
#
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 paintUi(self, theme):
self.stateChanging(theme)
self.ThemeNameEdit.setText(self.theme.theme_name)
@ -556,7 +492,7 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
self.FontMainYSpinBox.setValue(int(self.theme.font_main_y))
self.FontMainWidthSpinBox.setValue(int(self.theme.font_main_width))
self.FontMainHeightSpinBox.setValue(int(self.theme.font_main_height))
self.FontFooterSizeSpinBox.setValue(int( \
self.FontFooterSizeSpinBox.setValue(int(
self.theme.font_footer_proportion))
if not self.theme.font_footer_italics and \
self.theme.font_footer_weight == u'Normal':
@ -572,7 +508,7 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
self.FontFooterXSpinBox.setValue(int(self.theme.font_footer_x))
self.FontFooterYSpinBox.setValue(int(self.theme.font_footer_y))
self.FontFooterWidthSpinBox.setValue(int(self.theme.font_footer_width))
self.FontFooterHeightSpinBox.setValue(int( \
self.FontFooterHeightSpinBox.setValue(int(
self.theme.font_footer_height))
self.FontMainColorPushButton.setStyleSheet(
u'background-color: %s' % unicode(theme.font_main_color))
@ -608,9 +544,9 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
self.ShadowCheckBox.setChecked(False)
self.ShadowColorPushButton.setEnabled(False)
self.HorizontalComboBox.setCurrentIndex(int( \
self.HorizontalComboBox.setCurrentIndex(int(
self.theme.display_horizontalAlign))
self.VerticalComboBox.setCurrentIndex(int( \
self.VerticalComboBox.setCurrentIndex(int(
self.theme.display_verticalAlign))
def stateChanging(self, theme):

View File

@ -26,16 +26,19 @@ from openlp.core.ui import AboutForm, SettingsForm, AlertForm, \
ServiceManager, ThemeManager, MainDisplay, SlideController, \
PluginForm
from openlp.core.lib import translate, Plugin, MediaManagerItem, \
SettingsTab, RenderManager, PluginConfig, \
SettingsTab, RenderManager, PluginConfig, str_to_bool, \
SettingsManager, PluginManager, Receiver
from openlp.core.utils import ConfigHelper
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
"""
Set up the user interface
"""
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,
QtGui.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
@ -118,6 +121,7 @@ class Ui_MainWindow(object):
self.MediaManagerDock.setWidget(self.MediaManagerContents)
MainWindow.addDockWidget(
QtCore.Qt.DockWidgetArea(1), self.MediaManagerDock)
self.MediaManagerDock.setVisible(self.settingsmanager.showMediaManager)
# Create the service manager
self.ServiceManagerDock = QtGui.QDockWidget(MainWindow)
ServiceManagerIcon = QtGui.QIcon()
@ -133,6 +137,8 @@ class Ui_MainWindow(object):
self.ServiceManagerDock.setWidget(self.ServiceManagerContents)
MainWindow.addDockWidget(
QtCore.Qt.DockWidgetArea(2), self.ServiceManagerDock)
self.ServiceManagerDock.setVisible(
self.settingsmanager.showServiceManager)
# Create the theme manager
self.ThemeManagerDock = QtGui.QDockWidget(MainWindow)
ThemeManagerIcon = QtGui.QIcon()
@ -146,18 +152,22 @@ class Ui_MainWindow(object):
self.ThemeManagerDock.setWidget(self.ThemeManagerContents)
MainWindow.addDockWidget(
QtCore.Qt.DockWidgetArea(2), self.ThemeManagerDock)
self.ThemeManagerDock.setVisible(self.settingsmanager.showThemeManager)
# Create the menu items
self.FileNewItem = QtGui.QAction(MainWindow)
self.FileNewItem.setIcon(
self.ServiceManagerContents.Toolbar.getIconFromTitle(u'New Service'))
self.ServiceManagerContents.Toolbar.getIconFromTitle(
u'New Service'))
self.FileNewItem.setObjectName(u'FileNewItem')
self.FileOpenItem = QtGui.QAction(MainWindow)
self.FileOpenItem.setIcon(
self.ServiceManagerContents.Toolbar.getIconFromTitle(u'Open Service'))
self.ServiceManagerContents.Toolbar.getIconFromTitle(
u'Open Service'))
self.FileOpenItem.setObjectName(u'FileOpenItem')
self.FileSaveItem = QtGui.QAction(MainWindow)
self.FileSaveItem.setIcon(
self.ServiceManagerContents.Toolbar.getIconFromTitle(u'Save Service'))
self.ServiceManagerContents.Toolbar.getIconFromTitle(
u'Save Service'))
self.FileSaveItem.setObjectName(u'FileSaveItem')
self.FileSaveAsItem = QtGui.QAction(MainWindow)
self.FileSaveAsItem.setObjectName(u'FileSaveAsItem')
@ -185,17 +195,20 @@ class Ui_MainWindow(object):
self.OptionsSettingsItem.setObjectName(u'OptionsSettingsItem')
self.ViewMediaManagerItem = QtGui.QAction(MainWindow)
self.ViewMediaManagerItem.setCheckable(True)
self.ViewMediaManagerItem.setChecked(True)
self.ViewMediaManagerItem.setChecked(
self.settingsmanager.showMediaManager)
self.ViewMediaManagerItem.setIcon(icon)
self.ViewMediaManagerItem.setObjectName(u'ViewMediaManagerItem')
self.ViewThemeManagerItem = QtGui.QAction(MainWindow)
self.ViewThemeManagerItem.setCheckable(True)
self.ViewThemeManagerItem.setChecked(True)
self.ViewThemeManagerItem.setChecked(
self.settingsmanager.showThemeManager)
self.ViewThemeManagerItem.setIcon(ThemeManagerIcon)
self.ViewThemeManagerItem.setObjectName(u'ViewThemeManagerItem')
self.ViewServiceManagerItem = QtGui.QAction(MainWindow)
self.ViewServiceManagerItem.setCheckable(True)
self.ViewServiceManagerItem.setChecked(True)
self.ViewServiceManagerItem.setChecked(
self.settingsmanager.showServiceManager)
self.ViewServiceManagerItem.setIcon(ServiceManagerIcon)
self.ViewServiceManagerItem.setObjectName(u'ViewServiceManagerItem')
self.ToolsAlertItem = QtGui.QAction(MainWindow)
@ -212,7 +225,8 @@ class Ui_MainWindow(object):
self.PluginItem.setObjectName(u'PluginItem')
self.HelpDocumentationItem = QtGui.QAction(MainWindow)
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)
self.HelpDocumentationItem.setIcon(ContentsIcon)
self.HelpDocumentationItem.setObjectName(u'HelpDocumentationItem')
@ -238,8 +252,11 @@ class Ui_MainWindow(object):
self.ToolsAddToolItem.setObjectName(u'ToolsAddToolItem')
self.action_Preview_Panel = QtGui.QAction(MainWindow)
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.PreviewController.Panel.setVisible(
self.settingsmanager.showPreviewPanel)
self.ModeLiveItem = QtGui.QAction(MainWindow)
self.ModeLiveItem.setObjectName(u'ModeLiveItem')
self.FileImportMenu.addAction(self.ImportThemeItem)
@ -296,7 +313,8 @@ class Ui_MainWindow(object):
Set up the translation system
"""
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)
self.FileMenu.setTitle(translate(u'mainWindow', u'&File'))
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.OptionsViewMenu.setTitle(translate(u'mainWindow', u'&View'))
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.HelpMenu.setTitle(translate(u'mainWindow', u'&Help'))
self.MediaManagerDock.setWindowTitle(
@ -364,6 +383,13 @@ class Ui_MainWindow(object):
self.ViewServiceManagerItem.setStatusTip(translate(u'mainWindow',
u'Toggle the visibility of the Service Manager'))
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.setStatusTip(
translate(u'mainWindow', u'Show an alert message'))
@ -430,23 +456,35 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.setupUi(self)
# Set up signals and slots
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.SIGNAL(u'triggered()'), self.ThemeManagerContents.onExportTheme)
QtCore.SIGNAL(u'triggered()'),
self.ThemeManagerContents.onExportTheme)
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.SIGNAL(u'triggered(bool)'), self.ServiceManagerDock.setVisible)
QtCore.SIGNAL(u'triggered(bool)'),
self.toggleServiceManager)
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.SIGNAL(u'toggled(bool)'), self.PreviewController.Panel.setVisible)
QtCore.SIGNAL(u'toggled(bool)'),
self.togglePreviewPanel)
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.SIGNAL(u'visibilityChanged(bool)'), self.ViewServiceManagerItem.setChecked)
QtCore.SIGNAL(u'visibilityChanged(bool)'),
self.ViewServiceManagerItem.setChecked)
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.SIGNAL(u'triggered()'), self.onHelpAboutItemClicked)
QtCore.QObject.connect(self.ToolsAlertItem,
@ -472,7 +510,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.plugin_manager.find_plugins(pluginpath, self.plugin_helpers)
# hook methods have to happen after find_plugins. Find plugins needs the
# controllers hence the hooks have moved from setupUI() to here
# Find and insert settings tabs
log.info(u'hook settings')
self.plugin_manager.hook_settings_tabs(self.settingsForm)
@ -555,7 +592,10 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
ret = QtGui.QMessageBox.question(None,
translate(u'mainWindow', u'Save Changes to Service?'),
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)
if ret == QtGui.QMessageBox.Save:
self.ServiceManagerContents.onSaveService()
@ -598,3 +638,23 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def defaultThemeChanged(self, 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
# deleting items
if __name__=="__main__":
if __name__ == "__main__":
t=TestServiceManager_base()
t.setup_class()

View File

@ -28,9 +28,8 @@ from PyQt4 import QtCore, QtGui
from openlp.core.ui import AmendThemeForm, ServiceManager
from openlp.core.theme import Theme
from openlp.core.lib import PluginConfig, \
OpenLPToolbar, ThemeXML, Renderer, translate, \
file_to_xml, buildIcon, Receiver
from openlp.core.lib import PluginConfig, OpenLPToolbar, ThemeXML, Renderer, \
translate, str_to_bool, file_to_xml, buildIcon, Receiver
from openlp.core.utils import ConfigHelper
class ThemeManager(QtGui.QWidget):
@ -52,17 +51,21 @@ class ThemeManager(QtGui.QWidget):
translate(u'ThemeManager', u'New Theme'), u':/themes/theme_new.png',
translate(u'ThemeManager', u'Create a new theme'), self.onAddTheme)
self.Toolbar.addToolbarButton(
translate(u'ThemeManager', u'Edit Theme'), u':/themes/theme_edit.png',
translate(u'ThemeManager', u'Edit Theme'),
u':/themes/theme_edit.png',
translate(u'ThemeManager', u'Edit a theme'), self.onEditTheme)
self.Toolbar.addToolbarButton(
translate(u'ThemeManager', u'Delete Theme'), u':/themes/theme_delete.png',
translate(u'ThemeManager', u'Delete Theme'),
u':/themes/theme_delete.png',
translate(u'ThemeManager', u'Delete a theme'), self.onDeleteTheme)
self.Toolbar.addSeparator()
self.Toolbar.addToolbarButton(
translate(u'ThemeManager', u'Import Theme'), u':/themes/theme_import.png',
translate(u'ThemeManager', u'Import Theme'),
u':/themes/theme_import.png',
translate(u'ThemeManager', u'Import a theme'), self.onImportTheme)
self.Toolbar.addToolbarButton(
translate(u'ThemeManager', u'Export Theme'), u':/themes/theme_export.png',
translate(u'ThemeManager', u'Export Theme'),
u':/themes/theme_export.png',
translate(u'ThemeManager', u'Export a theme'), self.onExportTheme)
self.ThemeWidget = QtGui.QWidgetAction(self.Toolbar)
self.Layout.addWidget(self.Toolbar)
@ -72,7 +75,8 @@ class ThemeManager(QtGui.QWidget):
self.Layout.addWidget(self.ThemeListWidget)
#Signals
QtCore.QObject.connect(self.ThemeListWidget,
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), self.changeGlobalFromScreen)
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'),
self.changeGlobalFromScreen)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'update_global_theme'), self.changeGlobalFromTab)
#Variables
@ -83,7 +87,8 @@ class ThemeManager(QtGui.QWidget):
# Last little bits of setting up
self.config = PluginConfig(u'themes')
self.servicePath = self.config.get_data_path()
self.global_theme = unicode(self.config.get_config(u'theme global theme', u''))
self.global_theme = unicode(
self.config.get_config(u'theme global theme', u''))
def changeGlobalFromTab(self, themeName):
log.debug(u'changeGlobalFromTab %s', themeName)
@ -96,7 +101,8 @@ class ThemeManager(QtGui.QWidget):
self.ThemeListWidget.item(count).setText(newName)
#Set the new name
if themeName == newName:
name = u'%s (%s)' % (newName, translate(u'ThemeManager', u'default'))
name = u'%s (%s)' % (newName, translate(u'ThemeManager',
u'default'))
self.ThemeListWidget.item(count).setText(name)
def changeGlobalFromScreen(self, index):
@ -106,28 +112,36 @@ class ThemeManager(QtGui.QWidget):
oldName = item.text()
#reset the old name
if oldName != unicode(item.data(QtCore.Qt.UserRole).toString()):
self.ThemeListWidget.item(count).setText(unicode(item.data(QtCore.Qt.UserRole).toString()))
self.ThemeListWidget.item(count).setText(
unicode(item.data(QtCore.Qt.UserRole).toString()))
#Set the new name
if count == index.row():
self.global_theme = unicode(self.ThemeListWidget.item(count).text())
name = u'%s (%s)' % (self.global_theme, translate(u'ThemeManager', u'default'))
self.global_theme = unicode(
self.ThemeListWidget.item(count).text())
name = u'%s (%s)' % (self.global_theme,
translate(u'ThemeManager', u'default'))
self.ThemeListWidget.item(count).setText(name)
self.config.set_config(u'theme global theme', self.global_theme)
Receiver().send_message(u'update_global_theme', self.global_theme )
Receiver().send_message(u'update_global_theme',
self.global_theme)
self.pushThemes()
def onAddTheme(self):
self.amendThemeForm.loadTheme(None)
self.amendThemeForm.theme.parse(self.baseTheme())
self.amendThemeForm.loadTheme()
self.amendThemeForm.exec_()
def onEditTheme(self):
item = self.ThemeListWidget.currentItem()
if item is not None:
self.amendThemeForm.loadTheme(unicode(item.data(QtCore.Qt.UserRole).toString()))
self.amendThemeForm.setTheme(self.getThemeData(
item.data(QtCore.Qt.UserRole).toString()))
self.amendThemeForm.loadTheme()
self.amendThemeForm.exec_()
def onDeleteTheme(self):
self.global_theme = unicode(self.config.get_config(u'theme global theme', u''))
self.global_theme = unicode(
self.config.get_config(u'theme global theme', u''))
item = self.ThemeListWidget.currentItem()
if item is not None:
theme = unicode(item.text())
@ -135,7 +149,8 @@ class ThemeManager(QtGui.QWidget):
if theme != unicode(item.data(QtCore.Qt.UserRole).toString()):
QtGui.QMessageBox.critical(self,
translate(u'ThemeManager', u'Error'),
translate(u'ThemeManager', u'You are unable to delete the default theme!'),
translate(u'ThemeManager',
u'You are unable to delete the default theme!'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
else:
self.themelist.remove(theme)
@ -152,8 +167,9 @@ class ThemeManager(QtGui.QWidget):
except:
#if not present do not worry
pass
#As we do not reload the themes push out the change
#Reaload the list as the internal lists and events need to be triggered
# As we do not reload the themes push out the change
# Reaload the list as the internal lists and events need
# to be triggered
self.pushThemes()
def onExportTheme(self):
@ -188,12 +204,14 @@ class ThemeManager(QtGui.QWidget):
(path, filename) = os.path.split(unicode(file))
textName = os.path.splitext(name)[0]
if textName == self.global_theme:
name = u'%s (%s)' % (textName, translate(u'ThemeManager', u'default'))
name = u'%s (%s)' % (textName,
translate(u'ThemeManager', u'default'))
else:
name = textName
item_name = QtGui.QListWidgetItem(name)
item_name.setIcon(buildIcon(theme))
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(textName))
item_name.setData(QtCore.Qt.UserRole,
QtCore.QVariant(textName))
self.ThemeListWidget.addItem(item_name)
self.themelist.append(textName)
self.pushThemes()
@ -206,21 +224,16 @@ class ThemeManager(QtGui.QWidget):
def getThemeData(self, themename):
log.debug(u'getthemedata for theme %s', themename)
xml_file = os.path.join(self.path, unicode(themename), unicode(themename) + u'.xml')
xml_file = os.path.join(self.path, unicode(themename),
unicode(themename) + u'.xml')
try:
xml = file_to_xml(xml_file)
except:
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))
xml = newtheme.extract_xml()
xml = self.baseTheme()
theme = ThemeXML()
theme.parse(xml)
theme.extend_image_filename(self.path)
self.cleanTheme(theme)
return theme
def checkThemesExists(self, dir):
@ -254,7 +267,8 @@ class ThemeManager(QtGui.QWidget):
if os.path.splitext(file)[1].lower() in [u'.xml']:
if self.checkVersion1(xml_data):
# upgrade theme xml
filexml = self.migrateVersion122(filename, fullpath, xml_data)
filexml = self.migrateVersion122(filename,
fullpath, xml_data)
else:
filexml = xml_data
outfile = open(fullpath, u'w')
@ -289,7 +303,8 @@ class ThemeManager(QtGui.QWidget):
newtheme = ThemeXML()
newtheme.new_document(theme.Name)
if theme.BackgroundType == 0:
newtheme.add_background_solid(unicode(theme.BackgroundParameter1.name()))
newtheme.add_background_solid(unicode(
theme.BackgroundParameter1.name()))
elif theme.BackgroundType == 1:
direction = u'vertical'
if theme.BackgroundParameter3.name() == 1:
@ -335,8 +350,8 @@ class ThemeManager(QtGui.QWidget):
if os.path.exists(theme_file):
result = QtGui.QMessageBox.question(
self,
translate(u'ThemeManager',u'Theme Exists'),
translate(u'ThemeManager',u'A theme with this name already exists, would you like to overwrite it?'),
translate(u'ThemeManager', u'Theme Exists'),
translate(u'ThemeManager', u'A theme with this name already exists, would you like to overwrite it?'),
(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No),
QtGui.QMessageBox.No)
if result == QtGui.QMessageBox.Yes:
@ -378,3 +393,57 @@ class ThemeManager(QtGui.QWidget):
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):
global log
log=logging.getLogger(u'BibleDBImpl')
log = logging.getLogger(u'BibleDBImpl')
log.info(u'BibleDBimpl loaded')
def __init__(self, biblepath, biblename, config):
@ -122,34 +122,45 @@ class BibleDBImpl(BibleCommon):
def get_max_bible_book_verses(self, 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
def get_max_bible_book_chapter(self, 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
def get_bible_book(self, 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:
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
def get_bible_chapter(self, 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):
log.debug(u'get_bible_text %s, %s, %s, %s', bookname, chapter, sverse, 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()
log.debug(u'get_bible_text %s, %s, %s, %s', bookname, chapter, sverse,
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
def get_verses_from_text(self, versetext):
log.debug(u'get_verses_from_text %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
def dump_bible(self):

View File

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

View File

@ -32,7 +32,7 @@ class FileListData(QAbstractListModel):
def __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):
return len(self.items)
@ -56,10 +56,10 @@ class FileListData(QAbstractListModel):
self.insertRow(len(self.items), filename)
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!
return QVariant()
if role==Qt.DisplayRole:
if role == Qt.DisplayRole:
retval= self.items[row][1]
# elif role == Qt.DecorationRole:
# retval= self.items[row][1]