forked from openlp/openlp
Fix Up / Down Confusion
Give SongUsage some TLC and fix UTF8 bugs and better messaging. Service Items now more meaningful in their titles. bzr-revno: 1252
This commit is contained in:
commit
8aa519f2e9
@ -315,7 +315,7 @@ def check_directory_exists(dir):
|
|||||||
``dir``
|
``dir``
|
||||||
Theme directory to make sure exists
|
Theme directory to make sure exists
|
||||||
"""
|
"""
|
||||||
log.debug(u'check_directory_exists')
|
log.debug(u'check_directory_exists %s' % dir)
|
||||||
if not os.path.exists(dir):
|
if not os.path.exists(dir):
|
||||||
os.makedirs(dir)
|
os.makedirs(dir)
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ class ItemCapabilities(object):
|
|||||||
OnLoadUpdate = 8
|
OnLoadUpdate = 8
|
||||||
AddIfNewItem = 9
|
AddIfNewItem = 9
|
||||||
ProvidesOwnDisplay = 10
|
ProvidesOwnDisplay = 10
|
||||||
|
AllowsDetailedTitleDisplay = 11
|
||||||
|
|
||||||
|
|
||||||
class ServiceItem(object):
|
class ServiceItem(object):
|
||||||
@ -314,6 +315,20 @@ class ServiceItem(object):
|
|||||||
path, text_image[u'title'], text_image[u'image'] )
|
path, text_image[u'title'], text_image[u'image'] )
|
||||||
self._new_item()
|
self._new_item()
|
||||||
|
|
||||||
|
def get_display_title(self):
|
||||||
|
"""
|
||||||
|
Returns the title of the service item.
|
||||||
|
"""
|
||||||
|
if self.is_text():
|
||||||
|
return self.title
|
||||||
|
else:
|
||||||
|
if ItemCapabilities.AllowsDetailedTitleDisplay in self.capabilities:
|
||||||
|
return self._raw_frames[0][u'title']
|
||||||
|
elif len(self._raw_frames) > 1:
|
||||||
|
return self.title
|
||||||
|
else:
|
||||||
|
return self._raw_frames[0][u'title']
|
||||||
|
|
||||||
def merge(self, other):
|
def merge(self, other):
|
||||||
"""
|
"""
|
||||||
Updates the _uuid with the value from the original one
|
Updates the _uuid with the value from the original one
|
||||||
|
@ -178,8 +178,8 @@ class ServiceManager(QtGui.QWidget):
|
|||||||
translate('OpenLP.ServiceManager', 'Move &down'),
|
translate('OpenLP.ServiceManager', 'Move &down'),
|
||||||
None,
|
None,
|
||||||
translate('OpenLP.ServiceManager',
|
translate('OpenLP.ServiceManager',
|
||||||
'Moves the selection up the window.'),
|
'Moves the selection down the window.'),
|
||||||
self.onMoveSelectionDown, shortcut=QtCore.Qt.Key_Up)
|
self.onMoveSelectionDown, shortcut=QtCore.Qt.Key_Down)
|
||||||
self.serviceManagerList.down.setVisible(False)
|
self.serviceManagerList.down.setVisible(False)
|
||||||
self.serviceManagerList.up = self.orderToolbar.addToolbarButton(
|
self.serviceManagerList.up = self.orderToolbar.addToolbarButton(
|
||||||
translate('OpenLP.ServiceManager', 'Move up'),
|
translate('OpenLP.ServiceManager', 'Move up'),
|
||||||
@ -833,7 +833,7 @@ class ServiceManager(QtGui.QWidget):
|
|||||||
else:
|
else:
|
||||||
treewidgetitem.setIcon(0,
|
treewidgetitem.setIcon(0,
|
||||||
build_icon(u':/general/general_delete.png'))
|
build_icon(u':/general/general_delete.png'))
|
||||||
treewidgetitem.setText(0, serviceitem.title)
|
treewidgetitem.setText(0, serviceitem.get_display_title())
|
||||||
treewidgetitem.setToolTip(0, serviceitem.notes)
|
treewidgetitem.setToolTip(0, serviceitem.notes)
|
||||||
treewidgetitem.setData(0, QtCore.Qt.UserRole,
|
treewidgetitem.setData(0, QtCore.Qt.UserRole,
|
||||||
QtCore.QVariant(item[u'order']))
|
QtCore.QVariant(item[u'order']))
|
||||||
@ -1176,7 +1176,7 @@ class ServiceManager(QtGui.QWidget):
|
|||||||
for item in self.serviceItems:
|
for item in self.serviceItems:
|
||||||
service_item = item[u'service_item']
|
service_item = item[u'service_item']
|
||||||
data_item = {}
|
data_item = {}
|
||||||
data_item[u'title'] = unicode(service_item.title)
|
data_item[u'title'] = unicode(service_item.get_display_title())
|
||||||
data_item[u'plugin'] = unicode(service_item.name)
|
data_item[u'plugin'] = unicode(service_item.name)
|
||||||
data_item[u'notes'] = unicode(service_item.notes)
|
data_item[u'notes'] = unicode(service_item.notes)
|
||||||
data_item[u'selected'] = (item == curitem)
|
data_item[u'selected'] = (item == curitem)
|
||||||
|
@ -250,6 +250,7 @@ class PresentationMediaItem(MediaManagerItem):
|
|||||||
service_item.title = unicode(self.displayTypeComboBox.currentText())
|
service_item.title = unicode(self.displayTypeComboBox.currentText())
|
||||||
service_item.shortname = unicode(self.displayTypeComboBox.currentText())
|
service_item.shortname = unicode(self.displayTypeComboBox.currentText())
|
||||||
service_item.add_capability(ItemCapabilities.ProvidesOwnDisplay)
|
service_item.add_capability(ItemCapabilities.ProvidesOwnDisplay)
|
||||||
|
service_item.add_capability(ItemCapabilities.AllowsDetailedTitleDisplay)
|
||||||
shortname = service_item.shortname
|
shortname = service_item.shortname
|
||||||
if shortname:
|
if shortname:
|
||||||
for item in items:
|
for item in items:
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
from PyQt4 import QtGui
|
from PyQt4 import QtGui
|
||||||
|
|
||||||
from openlp.core.lib import translate
|
from openlp.core.lib import translate, Receiver
|
||||||
from openlp.plugins.songusage.lib.db import SongUsageItem
|
from openlp.plugins.songusage.lib.db import SongUsageItem
|
||||||
from songusagedeletedialog import Ui_SongUsageDeleteDialog
|
from songusagedeletedialog import Ui_SongUsageDeleteDialog
|
||||||
|
|
||||||
@ -55,4 +55,9 @@ class SongUsageDeleteForm(QtGui.QDialog, Ui_SongUsageDeleteDialog):
|
|||||||
deleteDate = self.deleteCalendar.selectedDate().toPyDate()
|
deleteDate = self.deleteCalendar.selectedDate().toPyDate()
|
||||||
self.manager.delete_all_objects(SongUsageItem,
|
self.manager.delete_all_objects(SongUsageItem,
|
||||||
SongUsageItem.usagedate <= deleteDate)
|
SongUsageItem.usagedate <= deleteDate)
|
||||||
self.close()
|
Receiver.send_message(u'openlp_information_message', {
|
||||||
|
u'title': translate('SongUsagePlugin.SongUsageDeleteForm',
|
||||||
|
'Deletion Successful'),
|
||||||
|
u'message': translate('SongUsagePlugin.SongUsageDeleteForm',
|
||||||
|
'All requested data has been deleted successfully. ')})
|
||||||
|
self.close()
|
||||||
|
@ -60,10 +60,12 @@ class Ui_SongUsageDetailDialog(object):
|
|||||||
self.horizontalLayout.setObjectName(u'horizontalLayout')
|
self.horizontalLayout.setObjectName(u'horizontalLayout')
|
||||||
self.fileLineEdit = QtGui.QLineEdit(self.fileGroupBox)
|
self.fileLineEdit = QtGui.QLineEdit(self.fileGroupBox)
|
||||||
self.fileLineEdit.setObjectName(u'fileLineEdit')
|
self.fileLineEdit.setObjectName(u'fileLineEdit')
|
||||||
|
self.fileLineEdit.setReadOnly(True)
|
||||||
|
self.fileLineEdit.setEnabled(False)
|
||||||
self.horizontalLayout.addWidget(self.fileLineEdit)
|
self.horizontalLayout.addWidget(self.fileLineEdit)
|
||||||
self.saveFilePushButton = QtGui.QPushButton(self.fileGroupBox)
|
self.saveFilePushButton = QtGui.QPushButton(self.fileGroupBox)
|
||||||
self.saveFilePushButton.setIcon(
|
self.saveFilePushButton.setIcon(
|
||||||
build_icon(u':/general/general_load.png'))
|
build_icon(u':/general/general_open.png'))
|
||||||
self.saveFilePushButton.setObjectName(u'saveFilePushButton')
|
self.saveFilePushButton.setObjectName(u'saveFilePushButton')
|
||||||
self.horizontalLayout.addWidget(self.saveFilePushButton)
|
self.horizontalLayout.addWidget(self.saveFilePushButton)
|
||||||
self.verticalLayout4.addLayout(self.horizontalLayout)
|
self.verticalLayout4.addLayout(self.horizontalLayout)
|
||||||
@ -96,4 +98,4 @@ class Ui_SongUsageDetailDialog(object):
|
|||||||
translate('SongUsagePlugin.SongUsageDetailForm', 'to'))
|
translate('SongUsagePlugin.SongUsageDetailForm', 'to'))
|
||||||
self.fileGroupBox.setTitle(
|
self.fileGroupBox.setTitle(
|
||||||
translate('SongUsagePlugin.SongUsageDetailForm',
|
translate('SongUsagePlugin.SongUsageDetailForm',
|
||||||
'Report Location'))
|
'Report Location'))
|
||||||
|
@ -30,7 +30,8 @@ import os
|
|||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
from sqlalchemy.sql import and_
|
from sqlalchemy.sql import and_
|
||||||
|
|
||||||
from openlp.core.lib import SettingsManager, translate
|
from openlp.core.lib import SettingsManager, translate, Receiver, \
|
||||||
|
check_directory_exists
|
||||||
from openlp.plugins.songusage.lib.db import SongUsageItem
|
from openlp.plugins.songusage.lib.db import SongUsageItem
|
||||||
from songusagedetaildialog import Ui_SongUsageDetailDialog
|
from songusagedetaildialog import Ui_SongUsageDetailDialog
|
||||||
|
|
||||||
@ -51,49 +52,74 @@ class SongUsageDetailForm(QtGui.QDialog, Ui_SongUsageDetailDialog):
|
|||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
|
||||||
def initialise(self):
|
def initialise(self):
|
||||||
|
"""
|
||||||
|
We need to set up the screen
|
||||||
|
"""
|
||||||
year = QtCore.QDate().currentDate().year()
|
year = QtCore.QDate().currentDate().year()
|
||||||
if QtCore.QDate().currentDate().month() < 9:
|
if QtCore.QDate().currentDate().month() < 9:
|
||||||
year -= 1
|
year -= 1
|
||||||
toDate = QtCore.QDate(year, 8, 31)
|
toDate = QtCore.QSettings().value(
|
||||||
fromDate = QtCore.QDate(year - 1, 9, 1)
|
u'songusage/to date',
|
||||||
|
QtCore.QVariant(QtCore.QDate(year, 8, 31))).toDate()
|
||||||
|
fromDate = QtCore.QSettings().value(
|
||||||
|
u'songusage/from date',
|
||||||
|
QtCore.QVariant(QtCore.QDate(year - 1, 9, 1))).toDate()
|
||||||
self.fromDate.setSelectedDate(fromDate)
|
self.fromDate.setSelectedDate(fromDate)
|
||||||
self.toDate.setSelectedDate(toDate)
|
self.toDate.setSelectedDate(toDate)
|
||||||
self.fileLineEdit.setText(
|
self.fileLineEdit.setText(
|
||||||
SettingsManager.get_last_dir(self.plugin.settingsSection, 1))
|
SettingsManager.get_last_dir(self.plugin.settingsSection, 1))
|
||||||
|
|
||||||
def defineOutputLocation(self):
|
def defineOutputLocation(self):
|
||||||
|
"""
|
||||||
|
Triggered when the Directory selection button is pressed
|
||||||
|
"""
|
||||||
path = QtGui.QFileDialog.getExistingDirectory(self,
|
path = QtGui.QFileDialog.getExistingDirectory(self,
|
||||||
translate('SongUsagePlugin.SongUsageDetailForm',
|
translate('SongUsagePlugin.SongUsageDetailForm',
|
||||||
'Output File Location'),
|
'Output File Location'),
|
||||||
SettingsManager.get_last_dir(self.plugin.settingsSection, 1))
|
SettingsManager.get_last_dir(self.plugin.settingsSection, 1))
|
||||||
path = unicode(path)
|
path = unicode(path)
|
||||||
if path != u'':
|
if path:
|
||||||
SettingsManager.set_last_dir(self.plugin.settingsSection, path, 1)
|
SettingsManager.set_last_dir(self.plugin.settingsSection, path, 1)
|
||||||
self.fileLineEdit.setText(path)
|
self.fileLineEdit.setText(path)
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
log.debug(u'Detailed report generated')
|
"""
|
||||||
|
Ok was pressed so lets save the data and run the report
|
||||||
|
"""
|
||||||
|
log.debug(u'accept')
|
||||||
|
path = unicode(self.fileLineEdit.text())
|
||||||
|
check_directory_exists(path)
|
||||||
filename = unicode(translate('SongUsagePlugin.SongUsageDetailForm',
|
filename = unicode(translate('SongUsagePlugin.SongUsageDetailForm',
|
||||||
'usage_detail_%s_%s.txt')) % (
|
'usage_detail_%s_%s.txt')) % (
|
||||||
self.fromDate.selectedDate().toString(u'ddMMyyyy'),
|
self.fromDate.selectedDate().toString(u'ddMMyyyy'),
|
||||||
self.toDate.selectedDate().toString(u'ddMMyyyy'))
|
self.toDate.selectedDate().toString(u'ddMMyyyy'))
|
||||||
|
QtCore.QSettings().setValue(u'songusage/from date',
|
||||||
|
QtCore.QVariant(self.fromDate.selectedDate()))
|
||||||
|
QtCore.QSettings().setValue(u'songusage/to date',
|
||||||
|
QtCore.QVariant(self.toDate.selectedDate()))
|
||||||
usage = self.plugin.manager.get_all_objects(
|
usage = self.plugin.manager.get_all_objects(
|
||||||
SongUsageItem, and_(
|
SongUsageItem, and_(
|
||||||
SongUsageItem.usagedate >= self.fromDate.selectedDate().toPyDate(),
|
SongUsageItem.usagedate >= self.fromDate.selectedDate().toPyDate(),
|
||||||
SongUsageItem.usagedate < self.toDate.selectedDate().toPyDate()),
|
SongUsageItem.usagedate < self.toDate.selectedDate().toPyDate()),
|
||||||
[SongUsageItem.usagedate, SongUsageItem.usagetime])
|
[SongUsageItem.usagedate, SongUsageItem.usagetime])
|
||||||
outname = os.path.join(unicode(self.fileLineEdit.text()), filename)
|
outname = os.path.join(path, filename)
|
||||||
file = None
|
fileHandle = None
|
||||||
try:
|
try:
|
||||||
file = open(outname, u'w')
|
fileHandle = open(outname, u'w')
|
||||||
for instance in usage:
|
for instance in usage:
|
||||||
record = u'\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"\n' % (
|
record = u'\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"\n' % (
|
||||||
instance.usagedate, instance.usagetime, instance.title,
|
instance.usagedate, instance.usagetime, instance.title,
|
||||||
instance.copyright, instance.ccl_number, instance.authors)
|
instance.copyright, instance.ccl_number, instance.authors)
|
||||||
file.write(record)
|
fileHandle.write(record.encode(u'utf-8'))
|
||||||
|
Receiver.send_message(u'openlp_information_message', {
|
||||||
|
u'title': translate('SongUsagePlugin.SongUsageDetailForm',
|
||||||
|
'Report Creation'),
|
||||||
|
u'message': unicode(translate(
|
||||||
|
'SongUsagePlugin.SongUsageDetailForm', 'Report \n%s \n'
|
||||||
|
'has been successfully created. ')) % outname})
|
||||||
except IOError:
|
except IOError:
|
||||||
log.exception(u'Failed to write out song usage records')
|
log.exception(u'Failed to write out song usage records')
|
||||||
finally:
|
finally:
|
||||||
if file:
|
if fileHandle:
|
||||||
file.close()
|
fileHandle.close()
|
||||||
self.close()
|
self.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user