From 307ef744dd53b50be52fe23c74b00180ee95c7fb Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 4 May 2011 09:29:16 +0200 Subject: [PATCH 1/6] - 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) From 738729e779439cfb15d05d8836fd8668c9726ce6 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 7 May 2011 13:22:34 +0200 Subject: [PATCH 2/6] re ordering --- openlp/core/ui/mainwindow.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 181cab1aa..a115d8905 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -657,10 +657,11 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): plugin.firstTime() Receiver.send_message(u'openlp_process_events') temp_dir = os.path.join(unicode(gettempdir()), u'openlp') - 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) + if not os.path.exists(temp_dir): + return + for filename in os.listdir(temp_dir): + delete_file(os.path.join(temp_dir, filename)) + os.removedirs(temp_dir) def blankCheck(self): """ From 3824c33607fdd4d4231f693e6bae8080b45b462e Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 7 May 2011 16:14:34 +0200 Subject: [PATCH 3/6] use iteritems --- openlp/core/lib/db.py | 3 ++- openlp/core/lib/toolbar.py | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/openlp/core/lib/db.py b/openlp/core/lib/db.py index 0ebb554a2..a160fec43 100644 --- a/openlp/core/lib/db.py +++ b/openlp/core/lib/db.py @@ -87,7 +87,8 @@ class BaseModel(object): Creates an instance of a class and populates it, returning the instance """ instance = cls() - [instance.__setattr__(key, kwargs[key]) for key in kwargs] + for key, value in kwargs.iteritems(): + instance.__setattr__(key, value) return instance diff --git a/openlp/core/lib/toolbar.py b/openlp/core/lib/toolbar.py index c3dc8236c..d2b37df51 100644 --- a/openlp/core/lib/toolbar.py +++ b/openlp/core/lib/toolbar.py @@ -140,7 +140,8 @@ class OpenLPToolbar(QtGui.QToolBar): ``widgets`` The list of names of widgets to be hidden. """ - [self.actions[widget].setVisible(False) for widget in widgets] + for widget in widgets: + self.actions[widget].setVisible(False) def makeWidgetsVisible(self, widgets): """ @@ -149,7 +150,8 @@ class OpenLPToolbar(QtGui.QToolBar): ``widgets`` The list of names of widgets to be shown. """ - [self.actions[widget].setVisible(True) for widget in widgets] + for widget in widgets: + self.actions[widget].setVisible(True) def addPushButton(self, image_file=None, text=u''): """ From 36ba62d86fd13e6afc20afb1505a7fe24bc17aa3 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 7 May 2011 18:43:24 +0100 Subject: [PATCH 4/6] Clean up DisplayTags UI --- openlp/core/ui/displaytagdialog.py | 19 ++++++++++++------- openlp/core/ui/displaytagform.py | 23 +++++++++++++++++------ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/openlp/core/ui/displaytagdialog.py b/openlp/core/ui/displaytagdialog.py index 8e71a60ff..c26da25d0 100644 --- a/openlp/core/ui/displaytagdialog.py +++ b/openlp/core/ui/displaytagdialog.py @@ -112,11 +112,16 @@ class Ui_DisplayTagDialog(object): self.endTagLineEdit = QtGui.QLineEdit(self.editGroupBox) self.endTagLineEdit.setObjectName(u'endTagLineEdit') self.dataGridLayout.addWidget(self.endTagLineEdit, 4, 1, 1, 1) - self.updatePushButton = QtGui.QPushButton(self.editGroupBox) - self.updatePushButton.setObjectName(u'updatePushButton') - self.dataGridLayout.addWidget(self.updatePushButton, 4, 2, 1, 1) + self.savePushButton = QtGui.QPushButton(self.editGroupBox) + self.savePushButton.setObjectName(u'savePushButton') + self.dataGridLayout.addWidget(self.savePushButton, 4, 2, 1, 1) self.listdataGridLayout.addWidget(self.editGroupBox, 2, 0, 1, 1) - self.buttonBox = create_accept_reject_button_box(displayTagDialog) + self.buttonBox = QtGui.QDialogButtonBox(displayTagDialog) + closeButton = QtGui.QDialogButtonBox.Close + self.buttonBox.setObjectName('displayTagDialogButtonBox') + self.buttonBox.setStandardButtons(closeButton) + QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(u'rejected()'), + self.reject) self.listdataGridLayout.addWidget(self.buttonBox, 3, 0, 1, 1) self.retranslateUi(displayTagDialog) @@ -127,8 +132,8 @@ class Ui_DisplayTagDialog(object): 'Configure Display Tags')) self.editGroupBox.setTitle( translate('OpenLP.DisplayTagDialog', 'Edit Selection')) - self.updatePushButton.setText( - translate('OpenLP.DisplayTagDialog', 'Update')) + self.savePushButton.setText( + translate('OpenLP.DisplayTagDialog', 'Save')) self.descriptionLabel.setText( translate('OpenLP.DisplayTagDialog', 'Description')) self.tagLabel.setText(translate('OpenLP.DisplayTagDialog', 'Tag')) @@ -151,4 +156,4 @@ class Ui_DisplayTagDialog(object): self.tagTableWidget.setColumnWidth(0, 120) self.tagTableWidget.setColumnWidth(1, 40) self.tagTableWidget.setColumnWidth(2, 240) - self.tagTableWidget.setColumnWidth(3, 240) \ No newline at end of file + self.tagTableWidget.setColumnWidth(3, 240) diff --git a/openlp/core/ui/displaytagform.py b/openlp/core/ui/displaytagform.py index 24cd14bd0..769b7cd17 100644 --- a/openlp/core/ui/displaytagform.py +++ b/openlp/core/ui/displaytagform.py @@ -54,8 +54,8 @@ class DisplayTagForm(QtGui.QDialog, Ui_DisplayTagDialog): QtCore.SIGNAL(u'pressed()'), self.onDefaultPushed) QtCore.QObject.connect(self.newPushButton, QtCore.SIGNAL(u'pressed()'), self.onNewPushed) - QtCore.QObject.connect(self.updatePushButton, - QtCore.SIGNAL(u'pressed()'), self.onUpdatePushed) + QtCore.QObject.connect(self.savePushButton, + QtCore.SIGNAL(u'pressed()'), self.onSavedPushed) QtCore.QObject.connect(self.deletePushButton, QtCore.SIGNAL(u'pressed()'), self.onDeletePushed) @@ -127,14 +127,14 @@ class DisplayTagForm(QtGui.QDialog, Ui_DisplayTagDialog): self.tagLineEdit.setEnabled(False) self.startTagLineEdit.setEnabled(False) self.endTagLineEdit.setEnabled(False) - self.updatePushButton.setEnabled(False) + self.savePushButton.setEnabled(False) self.deletePushButton.setEnabled(False) else: self.descriptionLineEdit.setEnabled(True) self.tagLineEdit.setEnabled(True) self.startTagLineEdit.setEnabled(True) self.endTagLineEdit.setEnabled(True) - self.updatePushButton.setEnabled(True) + self.savePushButton.setEnabled(True) self.deletePushButton.setEnabled(True) def onNewPushed(self): @@ -174,7 +174,7 @@ class DisplayTagForm(QtGui.QDialog, Ui_DisplayTagDialog): self.selected = -1 self._resetTable() - def onUpdatePushed(self): + def onSavedPushed(self): """ Update Custom Tag details if not duplicate. """ @@ -197,6 +197,17 @@ class DisplayTagForm(QtGui.QDialog, Ui_DisplayTagDialog): html[u'end tag'] = u'{/%s}' % tag self.selected = -1 self._resetTable() + temp = [] + for tag in DisplayTags.get_html_tags(): + if not tag[u'protected']: + temp.append(tag) + if temp: + ctemp = cPickle.dumps(temp) + QtCore.QSettings().setValue(u'displayTags/html_tags', + QtCore.QVariant(ctemp)) + else: + QtCore.QSettings().setValue(u'displayTags/html_tags', + QtCore.QVariant(u'')) def _resetTable(self): """ @@ -205,7 +216,7 @@ class DisplayTagForm(QtGui.QDialog, Ui_DisplayTagDialog): self.tagTableWidget.clearContents() self.tagTableWidget.setRowCount(0) self.newPushButton.setEnabled(True) - self.updatePushButton.setEnabled(False) + self.savePushButton.setEnabled(False) self.deletePushButton.setEnabled(False) for linenumber, html in enumerate(DisplayTags.get_html_tags()): self.tagTableWidget.setRowCount( From 0211a55c5db0ce4e753215346c9eda10869aa3b7 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 7 May 2011 20:40:48 +0200 Subject: [PATCH 5/6] fixed spelling --- openlp/core/lib/ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/lib/ui.py b/openlp/core/lib/ui.py index 47776a64b..e8be32a92 100644 --- a/openlp/core/lib/ui.py +++ b/openlp/core/lib/ui.py @@ -130,7 +130,7 @@ class UiStrings(object): self.VersePerLine = translate('OpenLP.Ui', 'Verse Per Line') self.Version = translate('OpenLP.Ui', 'Version') self.View = translate('OpenLP.Ui', 'View') - self.ViewMode = translate('OpenLP.Ui', 'View Model') + self.ViewMode = translate('OpenLP.Ui', 'View Mode') def add_welcome_page(parent, image): """ From 22553f6ef8ac954b5fbd3bc99230d2e49eb4bae7 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 8 May 2011 06:42:48 +0100 Subject: [PATCH 6/6] UI Tidy ups --- openlp/core/ui/displaytagdialog.py | 2 -- openlp/core/ui/displaytagform.py | 28 +++------------------------- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/openlp/core/ui/displaytagdialog.py b/openlp/core/ui/displaytagdialog.py index c26da25d0..9bf6cb4d1 100644 --- a/openlp/core/ui/displaytagdialog.py +++ b/openlp/core/ui/displaytagdialog.py @@ -120,8 +120,6 @@ class Ui_DisplayTagDialog(object): closeButton = QtGui.QDialogButtonBox.Close self.buttonBox.setObjectName('displayTagDialogButtonBox') self.buttonBox.setStandardButtons(closeButton) - QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(u'rejected()'), - self.reject) self.listdataGridLayout.addWidget(self.buttonBox, 3, 0, 1, 1) self.retranslateUi(displayTagDialog) diff --git a/openlp/core/ui/displaytagform.py b/openlp/core/ui/displaytagform.py index 769b7cd17..b8169b9be 100644 --- a/openlp/core/ui/displaytagform.py +++ b/openlp/core/ui/displaytagform.py @@ -58,6 +58,8 @@ class DisplayTagForm(QtGui.QDialog, Ui_DisplayTagDialog): QtCore.SIGNAL(u'pressed()'), self.onSavedPushed) QtCore.QObject.connect(self.deletePushButton, QtCore.SIGNAL(u'pressed()'), self.onDeletePushed) + QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(u'rejected()'), + self.close) def exec_(self): """ @@ -87,30 +89,6 @@ class DisplayTagForm(QtGui.QDialog, Ui_DisplayTagDialog): for t in user_tags: DisplayTags.add_html_tag(t) - def accept(self): - """ - Save Custom tags in a pickle . - """ - temp = [] - for tag in DisplayTags.get_html_tags(): - if not tag[u'protected']: - temp.append(tag) - if temp: - ctemp = cPickle.dumps(temp) - QtCore.QSettings().setValue(u'displayTags/html_tags', - QtCore.QVariant(ctemp)) - else: - QtCore.QSettings().setValue(u'displayTags/html_tags', - QtCore.QVariant(u'')) - return QtGui.QDialog.accept(self) - - def reject(self): - """ - Reset Custom tags from Settings. - """ - self._resetTable() - return QtGui.QDialog.reject(self) - def onRowSelected(self): """ Table Row selected so display items and set field state. @@ -176,7 +154,7 @@ class DisplayTagForm(QtGui.QDialog, Ui_DisplayTagDialog): def onSavedPushed(self): """ - Update Custom Tag details if not duplicate. + Update Custom Tag details if not duplicate and save the data. """ html_expands = DisplayTags.get_html_tags() if self.selected != -1: