diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index 5b8efed95..4f1e5abf4 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -18,6 +18,7 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ import logging +import os import time from openlp.core.lib import buildIcon from PyQt4 import QtCore, QtGui @@ -79,12 +80,12 @@ class ServiceItem(): self.frames = self.service_frames self.service_frames = [] elif self.service_item_type == u'image': - print "image" - print self.service_frames + #print "image" + #print self.service_frames for slide in self.service_frames: slide[u'image'] = self.RenderManager.resize_image(slide[u'image']) self.frames = self.service_frames - self.service_frames = [] + #self.service_frames = [] else: log.error(u'Invalid value renderer :%s' % self.service_item_type) @@ -112,14 +113,21 @@ class ServiceItem(): oos_data = [] if self.service_item_type == u'text': for slide in self.service_frames: - oos_data.append(slide[u'raw_slide']) - return {u'header': oos_header, u'data': self.service_frames} + oos_data.append(slide) + elif self.service_item_type == u'image': + #print "sf", self.service_frames + for slide in self.service_frames: + #print "s", slide + oos_data.append(slide[u'title']) + #print "od", oos_data + return {u'header': oos_header, u'data': oos_data} - def set_from_oos(self, serviceitem): + def set_from_oos(self, serviceitem, path=None): """ This method takes some oos list (passed from the ServiceManager) and extracts the data actually required """ + #print "sfs", serviceitem header = serviceitem[u'serviceitem'][u'header'] self.title = header[u'title'] self.service_item_type = header[u'type'] @@ -127,4 +135,12 @@ class ServiceItem(): self.theme = header[u'theme'] self.addIcon(header[u'icon']) self.raw_footer = header[u'footer'] - self.service_frames = serviceitem[u'serviceitem'][u'data'] + if self.service_item_type == u'text': + for slide in serviceitem[u'serviceitem'][u'data']: + self.service_frames.append(slide) + elif self.service_item_type == u'image': + for text_image in serviceitem[u'serviceitem'][u'data']: + filename = os.path.join(path, text_image) + #print "fn", filename + real_image = QtGui.QImage(unicode(filename)) + self.add_from_image(path, text_image, real_image) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index f111481df..90323e25f 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -21,11 +21,13 @@ import os import logging import cPickle import zipfile +import shutil from PyQt4 import QtCore, QtGui from openlp.core.lib import PluginConfig, OpenLPToolbar, ServiceItem, Event, \ RenderManager, EventType, EventManager, translate, buildIcon, \ contextMenuAction, contextMenuSeparator +from openlp.core.utils import ConfigHelper class ServiceManager(QtGui.QWidget): """ @@ -111,7 +113,8 @@ class ServiceManager(QtGui.QWidget): QtCore.QObject.connect(self.ServiceManagerList, QtCore.SIGNAL(u'itemExpanded(QTreeWidgetItem*)'), self.expanded) # Last little bits of setting up - self.config = PluginConfig(u'Main') + self.config = PluginConfig(u'ServiceManager') + self.servicePath = self.config.get_data_path() self.service_theme = self.config.get_config(u'theme service theme', u'') def collapsed(self, item): @@ -217,16 +220,16 @@ class ServiceManager(QtGui.QWidget): self.config.set_last_dir(filename) service = [] servicefile= filename + u'.ood' + zip = zipfile.ZipFile(unicode(filename) + u'.oos', 'w') for item in self.serviceItems: service.append({u'serviceitem':item[u'data'].get_oos_repr()}) if item[u'data'].service_item_type == u'image': - print item[u'data'].service_item_path for frame in item[u'data'].frames: - print frame[u'title'] + path_from = unicode(item[u'data'].service_item_path + u'/' + frame[u'title']) + zip.write(path_from) file = open(servicefile, u'wb') cPickle.dump(service, file) file.close() - zip = zipfile.ZipFile(unicode(filename)+u'.oos', 'w') zip.write(servicefile) zip.close() try: @@ -234,7 +237,6 @@ class ServiceManager(QtGui.QWidget): except: pass #if not present do not worry - def onLoadService(self): """ Load an existing service from disk @@ -248,25 +250,28 @@ class ServiceManager(QtGui.QWidget): filexml = None themename = None for file in zip.namelist(): - pickle_data = zip.read(file) - path = file.split(u'.') - p_file = unicode(u'/'+path[0]+u'.ood') - file_handle = open(p_file, u'wb') - file_handle.write(pickle_data) - file_handle.close() - file = open(p_file, u'r') - items = cPickle.load(file) - file.close() - self.onNewService() - for item in items: - serviceitem = ServiceItem() - serviceitem.RenderManager = self.parent.RenderManager - serviceitem.set_from_oos(item) - self.addServiceItem(serviceitem) - try: - os.remove(p_file) - except: - pass #if not present do not worry + names = file.split(os.path.sep) + file_to = os.path.join(self.servicePath, names[len(names) - 1]) + file_data = zip.read(file) + f = open(file_to, u'w') + f.write(file_data) + f.close() + if file_to.endswith(u'ood'): + p_file = file_to + f = open(p_file, u'r') + items = cPickle.load(f) + f.close() + self.onNewService() + for item in items: + #print item + serviceitem = ServiceItem() + serviceitem.RenderManager = self.parent.RenderManager + serviceitem.set_from_oos(item, self.servicePath ) + self.addServiceItem(serviceitem) + try: + os.remove(p_file) + except: + pass #if not present do not worry def onThemeComboBoxSelected(self, currentIndex): """ diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 91ceabad7..d292f6fe5 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -40,7 +40,7 @@ class ThemeData(QtCore.QAbstractListModel): Root contains a list of ThemeItems """ global log - log=logging.getLogger(u'ThemeData') + log = logging.getLogger(u'ThemeData') def __init__(self): QtCore.QAbstractListModel.__init__(self) @@ -335,7 +335,7 @@ class ThemeManager(QtGui.QWidget): outfile = open(theme_file, u'w') outfile.write(theme_xml) outfile.close() - if image_from is not None and image_from != image_to: + if image_from is not None and image_from is not image_to: shutil.copyfile(image_from, image_to) self.generateAndSaveImage(self.path, name, theme_xml) self.themeData.clearItems() diff --git a/openlp/plugins/bibles/lib/bibleHTTPimpl.py b/openlp/plugins/bibles/lib/bibleHTTPimpl.py index 7338e8dce..db055ccef 100644 --- a/openlp/plugins/bibles/lib/bibleHTTPimpl.py +++ b/openlp/plugins/bibles/lib/bibleHTTPimpl.py @@ -44,7 +44,7 @@ class BGExtract(BibleCommon): log.debug( u'get_bible_chapter %s,%s,%s,%s', version, bookid, bookname, chapter) urlstring = u'http://www.biblegateway.com/passage/?book_id='+unicode(bookid)+u'&chapter'+unicode(chapter)+u'&version='+unicode(version) xml_string = self._get_web_text(urlstring, self.proxyurl) - print xml_string + #print xml_string VerseSearch = u'class='+u'"'+u'sup'+u'"'+u'>' verse = 1 i= xml_string.find(u'result-text-style-normal') @@ -97,7 +97,7 @@ class CWExtract(BibleCommon): """ log.debug(u'get_bible_chapter %s,%s,%s,%s', version, bookid, bookname, chapter) bookname = bookname.replace(u' ', '') - urlstring = "http://bible.crosswalk.com/OnlineStudyBible/bible.cgi?word="+bookname+"+"+unicode(chapter)+"&version="+version + urlstring = u'http://bible.crosswalk.com/OnlineStudyBible/bible.cgi?word='+bookname+u'+'+unicode(chapter)+u'&version='+version xml_string = self._get_web_text(urlstring, self.proxyurl) #log.debug(u'Return data %s', xml_string) ## Strip Book Title from Heading to return it to system @@ -115,27 +115,33 @@ class CWExtract(BibleCommon): ## Strip Verse Data from Page and build an array ## + #log.debug(u'bible data %s', xml_string) i= xml_string.find(u'NavCurrentChapter') xml_string = xml_string[i:len(xml_string)] i= xml_string.find(u'') - xml_string = xml_string[i + 3 :len(xml_string)] #remove the at the front - i= xml_string.find(u'') # Remove the heading for the book - xml_string = xml_string[i + 3 :len(xml_string)] #remove the at the front + #remove the at the front + xml_string = xml_string[i + 3 :len(xml_string)] + # Remove the heading for the book + i= xml_string.find(u'') + #remove the at the front + xml_string = xml_string[i + 3 :len(xml_string)] versePos = xml_string.find(u'
') - #log.debug( versePos) + #log.debug(u'verse pos %d', versePos) bible = {} while versePos > 0: - verseText = '' # clear out string + verseText = u'' versePos = xml_string.find(u'', versePos) + 6 i = xml_string.find(u'', versePos) #log.debug( versePos, i) verse= xml_string[versePos:i] # Got the Chapter #verse = int(temp) - #log.debug( 'Chapter = ' + unicode(temp)) - versePos = i + 8 # move the starting position to negining of the text - i = xml_string.find(u'', versePos) # fine the start of the next verse + #log.debug( 'Chapter = %s', verse) + # move the starting position to begining of the text + versePos = i + 8 + # fined the start of the next verse + i = xml_string.find(u'', versePos) if i == -1: i = xml_string.find(u'
',versePos) verseText = xml_string[versePos: i] diff --git a/openlp/plugins/bibles/lib/common.py b/openlp/plugins/bibles/lib/common.py index a34f4283d..c63fc5e71 100644 --- a/openlp/plugins/bibles/lib/common.py +++ b/openlp/plugins/bibles/lib/common.py @@ -53,12 +53,12 @@ class BibleCommon: http_support = urllib2.HTTPHandler() opener= urllib2.build_opener(proxy_support, http_support) urllib2.install_opener(opener) - xml_string = "" + xml_string = u'' req = urllib2.Request(urlstring) req.add_header(u'User-Agent', 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)') try: handle = urllib2.urlopen(req) - xml_string = handle.read() + xml_string = unicode(handle.read()) except IOError, e: if hasattr(e, u'reason'): log.error(u'Reason : ') @@ -97,9 +97,9 @@ class BibleCommon: text= text.replace(u'

', u'') text= text.replace(u'
', u'') text= text.replace(u'
', u'') - text= text.replace(chr(189), u'1/2') - text= text.replace(u'"", u''') - text= text.replace(u''", u''') + #text= text.replace(chr(189), u'1/2');print "l" + text= text.replace(u'"', "'") + text= text.replace(u''', "'") i = text.find(u'<') while i > -1 : diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 45aaf3f57..23f58c013 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -239,17 +239,19 @@ class BibleManager(): text = [] log.debug(u'get_verse_text %s,%s,%s,%s,%s,%s', bible, bookname, schapter, echapter, sverse, everse) if not self.bible_http_cache [bible] == None: - book= self.bible_db_cache[bible].get_bible_book(bookname) # check to see if book/chapter exists + # check to see if book/chapter exists + book= self.bible_db_cache[bible].get_bible_book(bookname) if book == None: log.debug(u'get_verse_text : new book') for chapter in range(schapter, echapter+1): search_results = self.bible_http_cache [bible].get_bible_chapter(bible, 0, bookname, chapter) - if search_results.has_verselist() : + if search_results.has_verse_list() : ## We have found a book of the bible lets check to see if it was there. ## By reusing the returned book name we get a correct book. ## For example it is possible to request ac and get Acts back. bookname = search_results.get_book() - book= self.bible_db_cache[bible].get_bible_book(bookname) # check to see if book/chapter exists + # check to see if book/chapter exists + book= self.bible_db_cache[bible].get_bible_book(bookname) if book == None: ## Then create book, chapter and text book = self.bible_db_cache[bible].create_book(bookname, \