From 307ef744dd53b50be52fe23c74b00180ee95c7fb Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 4 May 2011 09:29:16 +0200 Subject: [PATCH] - fixed not closed file - attempt to make FRW avoiding tracebacks when running more than once - clean ups --- openlp/core/lib/db.py | 3 +-- openlp/core/lib/searchedit.py | 4 ++-- openlp/core/lib/serviceitem.py | 6 ++---- openlp/core/lib/toolbar.py | 6 ++---- openlp/core/ui/exceptionform.py | 8 ++++++-- openlp/core/ui/mainwindow.py | 9 +++++---- openlp/plugins/songs/songsplugin.py | 4 +++- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/openlp/core/lib/db.py b/openlp/core/lib/db.py index 42dab1e42..0ebb554a2 100644 --- a/openlp/core/lib/db.py +++ b/openlp/core/lib/db.py @@ -87,8 +87,7 @@ class BaseModel(object): Creates an instance of a class and populates it, returning the instance """ instance = cls() - for key in kwargs: - instance.__setattr__(key, kwargs[key]) + [instance.__setattr__(key, kwargs[key]) for key in kwargs] return instance diff --git a/openlp/core/lib/searchedit.py b/openlp/core/lib/searchedit.py index 94152ef2f..b524855ba 100644 --- a/openlp/core/lib/searchedit.py +++ b/openlp/core/lib/searchedit.py @@ -74,10 +74,10 @@ class SearchEdit(QtGui.QLineEdit): if hasattr(self, u'menuButton'): leftPadding = self.menuButton.width() self.setStyleSheet( - u'QLineEdit { padding-left: %spx; padding-right: %spx; } ' % \ + u'QLineEdit { padding-left: %spx; padding-right: %spx; } ' % (leftPadding, rightPadding)) else: - self.setStyleSheet(u'QLineEdit { padding-right: %spx; } ' % \ + self.setStyleSheet(u'QLineEdit { padding-right: %spx; } ' % rightPadding) msz = self.minimumSizeHint() self.setMinimumSize( diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index a2cb014a4..c1ae95b8b 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -269,11 +269,9 @@ class ServiceItem(object): } service_data = [] if self.service_item_type == ServiceItemType.Text: - for slide in self._raw_frames: - service_data.append(slide) + service_data = [slide for slide in self._raw_frames] elif self.service_item_type == ServiceItemType.Image: - for slide in self._raw_frames: - service_data.append(slide[u'title']) + service_data = [slide[u'title'] for slide in self._raw_frames] elif self.service_item_type == ServiceItemType.Command: for slide in self._raw_frames: service_data.append( diff --git a/openlp/core/lib/toolbar.py b/openlp/core/lib/toolbar.py index d2b37df51..c3dc8236c 100644 --- a/openlp/core/lib/toolbar.py +++ b/openlp/core/lib/toolbar.py @@ -140,8 +140,7 @@ class OpenLPToolbar(QtGui.QToolBar): ``widgets`` The list of names of widgets to be hidden. """ - for widget in widgets: - self.actions[widget].setVisible(False) + [self.actions[widget].setVisible(False) for widget in widgets] def makeWidgetsVisible(self, widgets): """ @@ -150,8 +149,7 @@ class OpenLPToolbar(QtGui.QToolBar): ``widgets`` The list of names of widgets to be shown. """ - for widget in widgets: - self.actions[widget].setVisible(True) + [self.actions[widget].setVisible(True) for widget in widgets] def addPushButton(self, image_file=None, text=u''): """ diff --git a/openlp/core/ui/exceptionform.py b/openlp/core/ui/exceptionform.py index 622d60f79..279122937 100644 --- a/openlp/core/ui/exceptionform.py +++ b/openlp/core/ui/exceptionform.py @@ -130,9 +130,12 @@ class ExceptionForm(QtGui.QDialog, Ui_ExceptionDialog): file.close() file = open(filename, u'wb') file.write(report.encode(u'utf-8')) - file.close() + finally: + file.close() except IOError: log.exception(u'Failed to write crash report') + finally: + file.close() def onSendReportButtonPressed(self): """ @@ -185,4 +188,5 @@ class ExceptionForm(QtGui.QDialog, Ui_ExceptionDialog): def __buttonState(self, state): self.saveReportButton.setEnabled(state) - self.sendReportButton.setEnabled(state) \ No newline at end of file + self.sendReportButton.setEnabled(state) + diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index aadc1c175..181cab1aa 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -38,7 +38,7 @@ from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, \ ThemeManager, SlideController, PluginForm, MediaDockManager, \ ShortcutListForm, DisplayTagForm from openlp.core.utils import AppLocation, add_actions, LanguageManager, \ - get_application_version + get_application_version, delete_file from openlp.core.utils.actions import ActionList, CategoryOrder log = logging.getLogger(__name__) @@ -657,9 +657,10 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): plugin.firstTime() Receiver.send_message(u'openlp_process_events') temp_dir = os.path.join(unicode(gettempdir()), u'openlp') - for filename in os.listdir(temp_dir): - os.remove(os.path.join(temp_dir, filename)) - os.removedirs(temp_dir) + if os.path.exists(temp_dir): + for filename in os.listdir(temp_dir): + delete_file(os.path.join(temp_dir, filename)) + os.removedirs(temp_dir) def blankCheck(self): """ diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index 85294dee2..198bcb7bb 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -229,12 +229,14 @@ class SongsPlugin(Plugin): If the first time wizard has run, this function is run to import all the new songs into the database. """ + self.onToolsReindexItemTriggered() db_dir = unicode(os.path.join(gettempdir(), u'openlp')) + if not os.path.exists(db_dir): + return song_dbs = [] for sfile in os.listdir(db_dir): if sfile.startswith(u'songs_') and sfile.endswith(u'.sqlite'): song_dbs.append(os.path.join(db_dir, sfile)) - self.onToolsReindexItemTriggered() if len(song_dbs) == 0: return progress = QtGui.QProgressDialog(self.formparent)