From 45034c1b8b60d804b50c01493fba35a0ea481e36 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 19 Mar 2011 19:45:22 +0000 Subject: [PATCH] Force default theme if no theme present --- openlp/core/lib/ui.py | 1 + openlp/core/ui/mainwindow.py | 6 +++--- openlp/core/ui/thememanager.py | 22 ++++++++++++++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/openlp/core/lib/ui.py b/openlp/core/lib/ui.py index eae4f60ca..987e99bf8 100644 --- a/openlp/core/lib/ui.py +++ b/openlp/core/lib/ui.py @@ -49,6 +49,7 @@ class UiStrings(object): Cancel = translate('OpenLP.Ui', 'Cancel') CCLINumberLabel = translate('OpenLP.Ui', 'CCLI number:') CreateService = translate('OpenLP.Ui', 'Create a new service.') + Default = unicode(translate('OpenLP.Ui', 'Default')) Delete = translate('OpenLP.Ui', '&Delete') Edit = translate('OpenLP.Ui', '&Edit') EmptyField = translate('OpenLP.Ui', 'Empty Field') diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 294cca49b..37ff71170 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -619,9 +619,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): # Call the initialise method to setup plugins. log.info(u'initialise plugins') self.pluginManager.initialise_plugins() - # Once all components are initialised load the Themes - log.info(u'Load Themes') - self.themeManagerContents.loadThemes() log.info(u'Load data from Settings') if QtCore.QSettings().value(u'advanced/save current plugin', QtCore.QVariant(False)).toBool(): @@ -630,6 +627,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): if savedPlugin != -1: self.MediaToolBox.setCurrentIndex(savedPlugin) self.settingsForm.postSetUp() + # Once all components are initialised load the Themes + log.info(u'Load Themes') + self.themeManagerContents.loadThemes(True) Receiver.send_message(u'cursor_normal') def setAutoLanguage(self, value): diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 407d0cfa8..a96147f81 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -159,7 +159,7 @@ class ThemeManager(QtGui.QWidget): self.loadThemes() Receiver.send_message(u'cursor_normal') - def configUpdated(self, firstTime=False): + def configUpdated(self): """ Triggered when Config dialog is updated. """ @@ -433,7 +433,7 @@ class ThemeManager(QtGui.QWidget): self.loadThemes() Receiver.send_message(u'cursor_normal') - def loadThemes(self): + def loadThemes(self, firstTime=False): """ Loads the theme lists and triggers updates accross the whole system using direct calls or core functions and events for the plugins. @@ -443,6 +443,24 @@ class ThemeManager(QtGui.QWidget): self.themelist = [] self.themeListWidget.clear() dirList = os.listdir(self.path) + if firstTime: + found = False + for name in dirList: + if name.endswith(u'.png'): + theme = os.path.join(self.path, name) + if os.path.exists(theme): + found = True + break + # No themes have been found so create one + if not found: + theme = ThemeXML() + theme.theme_name = UiStrings.Default + self._writeTheme(theme, None, None) + QtCore.QSettings().setValue( + self.settingsSection + u'/global theme', + QtCore.QVariant(theme.theme_name)) + self.configUpdated() + dirList = os.listdir(self.path) dirList.sort() for name in dirList: if name.endswith(u'.png'):