- changed a few loops to list comprehensions

- fixed unclosed file
- attempt to reduce possible tracebacks when running two instances of the FRW

bzr-revno: 1525
This commit is contained in:
Andreas Preikschat 2011-05-08 13:08:28 +02:00
commit a4e5d290a3
6 changed files with 19 additions and 13 deletions

View File

@ -87,8 +87,8 @@ 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])
for key, value in kwargs.iteritems():
instance.__setattr__(key, value)
return instance

View File

@ -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(

View File

@ -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(

View File

@ -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)
self.sendReportButton.setEnabled(state)

View File

@ -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,8 +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')
if not os.path.exists(temp_dir):
return
for filename in os.listdir(temp_dir):
os.remove(os.path.join(temp_dir, filename))
delete_file(os.path.join(temp_dir, filename))
os.removedirs(temp_dir)
def blankCheck(self):

View File

@ -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)