← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~meths/openlp/trivialfixes into lp:openlp

 

Jon Tibble has proposed merging lp:~meths/openlp/trivialfixes into lp:openlp.

    Requested reviews:
    OpenLP Core (openlp-core)


Clean up theme loading, parsing and cleaning

Slightly improve number of strings grabbed for translation
-- 
https://code.launchpad.net/~meths/openlp/trivialfixes/+merge/14521
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp-get-strings.py'
--- openlp-get-strings.py	2009-10-24 16:40:36 +0000
+++ openlp-get-strings.py	2009-11-06 02:45:22 +0000
@@ -42,7 +42,7 @@
       <translation type="unfinished"></translation>
     </message>
 """
-find_trUtf8 = re.compile(r"trUtf8\(u'([\w]+)'\)", re.UNICODE)
+find_trUtf8 = re.compile(r"trUtf8\(u'([\.:;\\&\w]+)'\)", re.UNICODE)
 strings = {}
 
 def parse_file(filename):
@@ -83,7 +83,7 @@
     file.close()
 
 def main():
-    start_dir = u'/home/raoul/Projects/openlp/i18n'
+    start_dir = u'.'
     for root, dirs, files in os.walk(start_dir):
         for file in files:
             if file.endswith(u'.py'):

=== modified file 'openlp/core/ui/amendthemeform.py'
--- openlp/core/ui/amendthemeform.py	2009-11-04 01:16:15 +0000
+++ openlp/core/ui/amendthemeform.py	2009-11-06 02:45:22 +0000
@@ -28,7 +28,7 @@
 
 from PyQt4 import QtCore, QtGui
 
-from openlp.core.lib import ThemeXML, file_to_xml
+from openlp.core.lib import ThemeXML
 from amendthemedialog import Ui_AmendThemeDialog
 
 log = logging.getLogger(u'AmendThemeForm')
@@ -184,14 +184,7 @@
 
     def loadTheme(self, theme):
         log.debug(u'LoadTheme %s', theme)
-        if theme is None:
-            self.theme.parse(self.thememanager.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.thememanager.cleanTheme(self.theme)
+        self.theme = self.thememanager.getThemeData(theme)
         # Stop the initial screen setup generating 1 preview per field!
         self.allowPreview = False
         self.paintUi(self.theme)

=== modified file 'openlp/core/ui/thememanager.py'
--- openlp/core/ui/thememanager.py	2009-11-05 00:09:19 +0000
+++ openlp/core/ui/thememanager.py	2009-11-06 02:45:22 +0000
@@ -269,18 +269,14 @@
         return self.themelist
 
     def getThemeData(self, themename):
+        assert(themename)
         log.debug(u'getthemedata for theme %s', themename)
         xml_file = os.path.join(self.path, unicode(themename),
             unicode(themename) + u'.xml')
-        try:
-            xml = file_to_xml(xml_file)
-        except:
+        xml = file_to_xml(xml_file)
+        if not xml:
             xml = self.baseTheme()
-        theme = ThemeXML()
-        theme.parse(xml)
-        self.cleanTheme(theme)
-        theme.extend_image_filename(self.path)
-        return theme
+        return createThemeFromXml(xml, self.path)
 
     def checkThemesExists(self, dir):
         log.debug(u'check themes')
@@ -428,10 +424,7 @@
 
     def generateAndSaveImage(self, dir, name, theme_xml):
         log.debug(u'generateAndSaveImage %s %s %s', dir, name, theme_xml)
-        theme = ThemeXML()
-        theme.parse(theme_xml)
-        self.cleanTheme(theme)
-        theme.extend_image_filename(dir)
+        theme = self.createThemeFromXml(theme_xml, dir)
         frame = self.generateImage(theme)
         samplepathname = os.path.join(self.path, name + u'.png')
         if os.path.exists(samplepathname):
@@ -465,6 +458,13 @@
             unicode(u'#FFFFFF'), unicode(0), unicode(0), unicode(0))
         return newtheme.extract_xml()
 
+    def createThemeFromXml(self, theme_xml, path):
+        theme = ThemeXML()
+        theme.parse(theme_xml)
+        self.cleanTheme(theme)
+        theme.extend_image_filename(path)
+        return theme
+
     def cleanTheme(self, theme):
         theme.background_color = theme.background_color.strip()
         theme.background_direction = theme.background_direction.strip()


Follow ups