forked from openlp/openlp
Cleaning up SongUsage
This commit is contained in:
parent
c6ad115b10
commit
ab31ffb775
@ -32,29 +32,30 @@ from PyQt4 import QtCore, QtGui
|
|||||||
from openlp.core.lib import translate
|
from openlp.core.lib import translate
|
||||||
from openlp.core.lib.ui import create_button_box
|
from openlp.core.lib.ui import create_button_box
|
||||||
|
|
||||||
class Ui_SongUsageDeleteDialog(object):
|
|
||||||
def setupUi(self, songUsageDeleteDialog):
|
|
||||||
songUsageDeleteDialog.setObjectName(u'songUsageDeleteDialog')
|
|
||||||
songUsageDeleteDialog.resize(291, 243)
|
|
||||||
self.verticalLayout = QtGui.QVBoxLayout(songUsageDeleteDialog)
|
|
||||||
self.verticalLayout.setSpacing(8)
|
|
||||||
self.verticalLayout.setContentsMargins(8, 8, 8, 8)
|
|
||||||
self.verticalLayout.setObjectName(u'verticalLayout')
|
|
||||||
self.deleteLabel = QtGui.QLabel(songUsageDeleteDialog)
|
|
||||||
self.deleteLabel.setObjectName(u'deleteLabel')
|
|
||||||
self.verticalLayout.addWidget(self.deleteLabel)
|
|
||||||
self.deleteCalendar = QtGui.QCalendarWidget(songUsageDeleteDialog)
|
|
||||||
self.deleteCalendar.setFirstDayOfWeek(QtCore.Qt.Sunday)
|
|
||||||
self.deleteCalendar.setGridVisible(True)
|
|
||||||
self.deleteCalendar.setVerticalHeaderFormat(QtGui.QCalendarWidget.NoVerticalHeader)
|
|
||||||
self.deleteCalendar.setObjectName(u'deleteCalendar')
|
|
||||||
self.verticalLayout.addWidget(self.deleteCalendar)
|
|
||||||
self.button_box = create_button_box(songUsageDeleteDialog, u'button_box', [u'cancel', u'ok'])
|
|
||||||
self.verticalLayout.addWidget(self.button_box)
|
|
||||||
self.retranslateUi(songUsageDeleteDialog)
|
|
||||||
|
|
||||||
def retranslateUi(self, songUsageDeleteDialog):
|
class Ui_SongUsageDeleteDialog(object):
|
||||||
songUsageDeleteDialog.setWindowTitle(translate('SongUsagePlugin.SongUsageDeleteForm', 'Delete Song Usage Data'))
|
def setupUi(self, song_usage_delete_dialog):
|
||||||
self.deleteLabel.setText(
|
song_usage_delete_dialog.setObjectName(u'song_usage_delete_dialog')
|
||||||
|
song_usage_delete_dialog.resize(291, 243)
|
||||||
|
self.vertical_layout = QtGui.QVBoxLayout(song_usage_delete_dialog)
|
||||||
|
self.vertical_layout.setSpacing(8)
|
||||||
|
self.vertical_layout.setContentsMargins(8, 8, 8, 8)
|
||||||
|
self.vertical_layout.setObjectName(u'vertical_layout')
|
||||||
|
self.delete_label = QtGui.QLabel(song_usage_delete_dialog)
|
||||||
|
self.delete_label.setObjectName(u'delete_label')
|
||||||
|
self.vertical_layout.addWidget(self.delete_label)
|
||||||
|
self.delete_calendar = QtGui.QCalendarWidget(song_usage_delete_dialog)
|
||||||
|
self.delete_calendar.setFirstDayOfWeek(QtCore.Qt.Sunday)
|
||||||
|
self.delete_calendar.setGridVisible(True)
|
||||||
|
self.delete_calendar.setVerticalHeaderFormat(QtGui.QCalendarWidget.NoVerticalHeader)
|
||||||
|
self.delete_calendar.setObjectName(u'delete_calendar')
|
||||||
|
self.vertical_layout.addWidget(self.delete_calendar)
|
||||||
|
self.button_box = create_button_box(song_usage_delete_dialog, u'button_box', [u'cancel', u'ok'])
|
||||||
|
self.vertical_layout.addWidget(self.button_box)
|
||||||
|
self.retranslateUi(song_usage_delete_dialog)
|
||||||
|
|
||||||
|
def retranslateUi(self, song_usage_delete_dialog):
|
||||||
|
song_usage_delete_dialog.setWindowTitle(translate('SongUsagePlugin.SongUsageDeleteForm', 'Delete Song Usage Data'))
|
||||||
|
self.delete_label.setText(
|
||||||
translate('SongUsagePlugin.SongUsageDeleteForm', 'Select the date up to which the song usage data '
|
translate('SongUsagePlugin.SongUsageDeleteForm', 'Select the date up to which the song usage data '
|
||||||
'should be deleted. All data recorded before this date will be permanently deleted.'))
|
'should be deleted. All data recorded before this date will be permanently deleted.'))
|
||||||
|
@ -45,10 +45,9 @@ class SongUsageDeleteForm(QtGui.QDialog, Ui_SongUsageDeleteDialog):
|
|||||||
self.manager = manager
|
self.manager = manager
|
||||||
QtGui.QDialog.__init__(self, parent)
|
QtGui.QDialog.__init__(self, parent)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
QtCore.QObject.connect(self.button_box, QtCore.SIGNAL(u'clicked(QAbstractButton*)'),
|
self.button_box.clicked.connect(self.on_button_box_clicked)
|
||||||
self.onButtonBoxClicked)
|
|
||||||
|
|
||||||
def onButtonBoxClicked(self, button):
|
def on_button_box_clicked(self, button):
|
||||||
if self.button_box.standardButton(button) == QtGui.QDialogButtonBox.Ok:
|
if self.button_box.standardButton(button) == QtGui.QDialogButtonBox.Ok:
|
||||||
ret = QtGui.QMessageBox.question(self,
|
ret = QtGui.QMessageBox.question(self,
|
||||||
translate('SongUsagePlugin.SongUsageDeleteForm', 'Delete Selected Song Usage Events?'),
|
translate('SongUsagePlugin.SongUsageDeleteForm', 'Delete Selected Song Usage Events?'),
|
||||||
@ -56,12 +55,12 @@ class SongUsageDeleteForm(QtGui.QDialog, Ui_SongUsageDeleteDialog):
|
|||||||
'Are you sure you want to delete selected Song Usage data?'),
|
'Are you sure you want to delete selected Song Usage data?'),
|
||||||
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), QtGui.QMessageBox.No)
|
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), QtGui.QMessageBox.No)
|
||||||
if ret == QtGui.QMessageBox.Yes:
|
if ret == QtGui.QMessageBox.Yes:
|
||||||
deleteDate = self.deleteCalendar.selectedDate().toPyDate()
|
delete_date = self.delete_calendar.selectedDate().toPyDate()
|
||||||
self.manager.delete_all_objects(SongUsageItem, SongUsageItem.usagedate <= deleteDate)
|
self.manager.delete_all_objects(SongUsageItem, SongUsageItem.usagedate <= delete_date)
|
||||||
self.main_window.information_message(
|
self.main_window.information_message(
|
||||||
translate('SongUsagePlugin.SongUsageDeleteForm', 'Deletion Successful'),
|
translate('SongUsagePlugin.SongUsageDeleteForm', 'Deletion Successful'),
|
||||||
translate(
|
translate(
|
||||||
'SongUsagePlugin.SongUsageDeleteForm', 'All requested data has been deleted successfully. ')
|
'SongUsagePlugin.SongUsageDeleteForm', 'All requested data has been deleted successfully.')
|
||||||
)
|
)
|
||||||
self.accept()
|
self.accept()
|
||||||
else:
|
else:
|
||||||
@ -75,4 +74,4 @@ class SongUsageDeleteForm(QtGui.QDialog, Ui_SongUsageDeleteDialog):
|
|||||||
self._main_window = Registry().get(u'main_window')
|
self._main_window = Registry().get(u'main_window')
|
||||||
return self._main_window
|
return self._main_window
|
||||||
|
|
||||||
main_window = property(_get_main_window)
|
main_window = property(_get_main_window)
|
||||||
|
@ -32,56 +32,56 @@ from PyQt4 import QtCore, QtGui
|
|||||||
from openlp.core.lib import build_icon, translate
|
from openlp.core.lib import build_icon, translate
|
||||||
from openlp.core.lib.ui import create_button_box
|
from openlp.core.lib.ui import create_button_box
|
||||||
|
|
||||||
|
|
||||||
class Ui_SongUsageDetailDialog(object):
|
class Ui_SongUsageDetailDialog(object):
|
||||||
def setupUi(self, songUsageDetailDialog):
|
def setupUi(self, songUsageDetailDialog):
|
||||||
songUsageDetailDialog.setObjectName(u'songUsageDetailDialog')
|
songUsageDetailDialog.setObjectName(u'songUsageDetailDialog')
|
||||||
songUsageDetailDialog.resize(609, 413)
|
songUsageDetailDialog.resize(609, 413)
|
||||||
self.verticalLayout = QtGui.QVBoxLayout(songUsageDetailDialog)
|
self.vertical_layout = QtGui.QVBoxLayout(songUsageDetailDialog)
|
||||||
self.verticalLayout.setSpacing(8)
|
self.vertical_layout.setSpacing(8)
|
||||||
self.verticalLayout.setContentsMargins(8, 8, 8, 8)
|
self.vertical_layout.setContentsMargins(8, 8, 8, 8)
|
||||||
self.verticalLayout.setObjectName(u'verticalLayout')
|
self.vertical_layout.setObjectName(u'vertical_layout')
|
||||||
self.dateRangeGroupBox = QtGui.QGroupBox(songUsageDetailDialog)
|
self.date_range_group_box = QtGui.QGroupBox(songUsageDetailDialog)
|
||||||
self.dateRangeGroupBox.setObjectName(u'dateRangeGroupBox')
|
self.date_range_group_box.setObjectName(u'date_range_group_box')
|
||||||
self.dateHorizontalLayout = QtGui.QHBoxLayout(self.dateRangeGroupBox)
|
self.date_horizontal_layout = QtGui.QHBoxLayout(self.date_range_group_box)
|
||||||
self.dateHorizontalLayout.setSpacing(8)
|
self.date_horizontal_layout.setSpacing(8)
|
||||||
self.dateHorizontalLayout.setContentsMargins(8, 8, 8, 8)
|
self.date_horizontal_layout.setContentsMargins(8, 8, 8, 8)
|
||||||
self.dateHorizontalLayout.setObjectName(u'dateHorizontalLayout')
|
self.date_horizontal_layout.setObjectName(u'date_horizontal_layout')
|
||||||
self.fromDate = QtGui.QCalendarWidget(self.dateRangeGroupBox)
|
self.from_date = QtGui.QCalendarWidget(self.date_range_group_box)
|
||||||
self.fromDate.setObjectName(u'fromDate')
|
self.from_date.setObjectName(u'from_date')
|
||||||
self.dateHorizontalLayout.addWidget(self.fromDate)
|
self.date_horizontal_layout.addWidget(self.from_date)
|
||||||
self.toLabel = QtGui.QLabel(self.dateRangeGroupBox)
|
self.to_label = QtGui.QLabel(self.date_range_group_box)
|
||||||
self.toLabel.setScaledContents(False)
|
self.to_label.setScaledContents(False)
|
||||||
self.toLabel.setAlignment(QtCore.Qt.AlignCenter)
|
self.to_label.setAlignment(QtCore.Qt.AlignCenter)
|
||||||
self.toLabel.setObjectName(u'toLabel')
|
self.to_label.setObjectName(u'to_label')
|
||||||
self.dateHorizontalLayout.addWidget(self.toLabel)
|
self.date_horizontal_layout.addWidget(self.to_label)
|
||||||
self.toDate = QtGui.QCalendarWidget(self.dateRangeGroupBox)
|
self.to_date = QtGui.QCalendarWidget(self.date_range_group_box)
|
||||||
self.toDate.setObjectName(u'toDate')
|
self.to_date.setObjectName(u'to_date')
|
||||||
self.dateHorizontalLayout.addWidget(self.toDate)
|
self.date_horizontal_layout.addWidget(self.to_date)
|
||||||
self.verticalLayout.addWidget(self.dateRangeGroupBox)
|
self.vertical_layout.addWidget(self.date_range_group_box)
|
||||||
self.fileGroupBox = QtGui.QGroupBox(self.dateRangeGroupBox)
|
self.file_group_box = QtGui.QGroupBox(self.date_range_group_box)
|
||||||
self.fileGroupBox.setObjectName(u'fileGroupBox')
|
self.file_group_box.setObjectName(u'file_group_box')
|
||||||
self.fileHorizontalLayout = QtGui.QHBoxLayout(self.fileGroupBox)
|
self.file_horizontal_layout = QtGui.QHBoxLayout(self.file_group_box)
|
||||||
self.fileHorizontalLayout.setSpacing(8)
|
self.file_horizontal_layout.setSpacing(8)
|
||||||
self.fileHorizontalLayout.setContentsMargins(8, 8, 8, 8)
|
self.file_horizontal_layout.setContentsMargins(8, 8, 8, 8)
|
||||||
self.fileHorizontalLayout.setObjectName(u'fileHorizontalLayout')
|
self.file_horizontal_layout.setObjectName(u'file_horizontal_layout')
|
||||||
self.fileLineEdit = QtGui.QLineEdit(self.fileGroupBox)
|
self.file_line_edit = QtGui.QLineEdit(self.file_group_box)
|
||||||
self.fileLineEdit.setObjectName(u'fileLineEdit')
|
self.file_line_edit.setObjectName(u'file_line_edit')
|
||||||
self.fileLineEdit.setReadOnly(True)
|
self.file_line_edit.setReadOnly(True)
|
||||||
self.fileHorizontalLayout.addWidget(self.fileLineEdit)
|
self.file_horizontal_layout.addWidget(self.file_line_edit)
|
||||||
self.saveFilePushButton = QtGui.QPushButton(self.fileGroupBox)
|
self.save_file_push_button = QtGui.QPushButton(self.file_group_box)
|
||||||
self.saveFilePushButton.setMaximumWidth(self.saveFilePushButton.size().height())
|
self.save_file_push_button.setMaximumWidth(self.save_file_push_button.size().height())
|
||||||
self.saveFilePushButton.setIcon(build_icon(u':/general/general_open.png'))
|
self.save_file_push_button.setIcon(build_icon(u':/general/general_open.png'))
|
||||||
self.saveFilePushButton.setObjectName(u'saveFilePushButton')
|
self.save_file_push_button.setObjectName(u'save_file_push_button')
|
||||||
self.fileHorizontalLayout.addWidget(self.saveFilePushButton)
|
self.file_horizontal_layout.addWidget(self.save_file_push_button)
|
||||||
self.verticalLayout.addWidget(self.fileGroupBox)
|
self.vertical_layout.addWidget(self.file_group_box)
|
||||||
self.button_box = create_button_box(songUsageDetailDialog, u'button_box', [u'cancel', u'ok'])
|
self.button_box = create_button_box(songUsageDetailDialog, u'button_box', [u'cancel', u'ok'])
|
||||||
self.verticalLayout.addWidget(self.button_box)
|
self.vertical_layout.addWidget(self.button_box)
|
||||||
self.retranslateUi(songUsageDetailDialog)
|
self.retranslateUi(songUsageDetailDialog)
|
||||||
QtCore.QObject.connect(self.saveFilePushButton, QtCore.SIGNAL(u'clicked()'),
|
self.save_file_push_button.clicked.connect(songUsageDetailDialog.define_output_location)
|
||||||
songUsageDetailDialog.defineOutputLocation)
|
|
||||||
|
|
||||||
def retranslateUi(self, songUsageDetailDialog):
|
def retranslateUi(self, songUsageDetailDialog):
|
||||||
songUsageDetailDialog.setWindowTitle(translate('SongUsagePlugin.SongUsageDetailForm', 'Song Usage Extraction'))
|
songUsageDetailDialog.setWindowTitle(translate('SongUsagePlugin.SongUsageDetailForm', 'Song Usage Extraction'))
|
||||||
self.dateRangeGroupBox.setTitle(translate('SongUsagePlugin.SongUsageDetailForm', 'Select Date Range'))
|
self.date_range_group_box.setTitle(translate('SongUsagePlugin.SongUsageDetailForm', 'Select Date Range'))
|
||||||
self.toLabel.setText(translate('SongUsagePlugin.SongUsageDetailForm', 'to'))
|
self.to_label.setText(translate('SongUsagePlugin.SongUsageDetailForm', 'to'))
|
||||||
self.fileGroupBox.setTitle(translate('SongUsagePlugin.SongUsageDetailForm', 'Report Location'))
|
self.file_group_box.setTitle(translate('SongUsagePlugin.SongUsageDetailForm', 'Report Location'))
|
||||||
|
@ -39,6 +39,7 @@ from songusagedetaildialog import Ui_SongUsageDetailDialog
|
|||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class SongUsageDetailForm(QtGui.QDialog, Ui_SongUsageDetailDialog):
|
class SongUsageDetailForm(QtGui.QDialog, Ui_SongUsageDetailDialog):
|
||||||
"""
|
"""
|
||||||
Class documentation goes here.
|
Class documentation goes here.
|
||||||
@ -57,13 +58,13 @@ class SongUsageDetailForm(QtGui.QDialog, Ui_SongUsageDetailDialog):
|
|||||||
"""
|
"""
|
||||||
We need to set up the screen
|
We need to set up the screen
|
||||||
"""
|
"""
|
||||||
toDate = Settings().value(self.plugin.settingsSection + u'/to date')
|
to_date = Settings().value(self.plugin.settingsSection + u'/to date')
|
||||||
fromDate = Settings().value(self.plugin.settingsSection + u'/from date')
|
from_date = Settings().value(self.plugin.settingsSection + u'/from date')
|
||||||
self.fromDate.setSelectedDate(fromDate)
|
self.from_date.setSelectedDate(from_date)
|
||||||
self.toDate.setSelectedDate(toDate)
|
self.to_date.setSelectedDate(to_date)
|
||||||
self.fileLineEdit.setText(Settings().value(self.plugin.settingsSection + u'/last directory export'))
|
self.file_line_edit.setText(Settings().value(self.plugin.settingsSection + u'/last directory export'))
|
||||||
|
|
||||||
def defineOutputLocation(self):
|
def define_output_location(self):
|
||||||
"""
|
"""
|
||||||
Triggered when the Directory selection button is clicked
|
Triggered when the Directory selection button is clicked
|
||||||
"""
|
"""
|
||||||
@ -72,14 +73,14 @@ class SongUsageDetailForm(QtGui.QDialog, Ui_SongUsageDetailDialog):
|
|||||||
Settings().value(self.plugin.settingsSection + u'/last directory export'))
|
Settings().value(self.plugin.settingsSection + u'/last directory export'))
|
||||||
if path:
|
if path:
|
||||||
Settings().setValue(self.plugin.settingsSection + u'/last directory export', path)
|
Settings().setValue(self.plugin.settingsSection + u'/last directory export', path)
|
||||||
self.fileLineEdit.setText(path)
|
self.file_line_edit.setText(path)
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
"""
|
"""
|
||||||
Ok was triggered so lets save the data and run the report
|
Ok was triggered so lets save the data and run the report
|
||||||
"""
|
"""
|
||||||
log.debug(u'accept')
|
log.debug(u'accept')
|
||||||
path = self.fileLineEdit.text()
|
path = self.file_line_edit.text()
|
||||||
if not path:
|
if not path:
|
||||||
self.main_window.error_message(
|
self.main_window.error_message(
|
||||||
translate('SongUsagePlugin.SongUsageDetailForm', 'Output Path Not Selected'),
|
translate('SongUsagePlugin.SongUsageDetailForm', 'Output Path Not Selected'),
|
||||||
@ -88,36 +89,36 @@ class SongUsageDetailForm(QtGui.QDialog, Ui_SongUsageDetailDialog):
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
check_directory_exists(path)
|
check_directory_exists(path)
|
||||||
filename = translate('SongUsagePlugin.SongUsageDetailForm', 'usage_detail_%s_%s.txt') % (
|
file_name = translate('SongUsagePlugin.SongUsageDetailForm', 'usage_detail_%s_%s.txt') % (
|
||||||
self.fromDate.selectedDate().toString(u'ddMMyyyy'),
|
self.from_date.selectedDate().toString(u'ddMMyyyy'),
|
||||||
self.toDate.selectedDate().toString(u'ddMMyyyy'))
|
self.to_date.selectedDate().toString(u'ddMMyyyy'))
|
||||||
Settings().setValue(u'songusage/from date', self.fromDate.selectedDate())
|
Settings().setValue(u'songusage/from date', self.from_date.selectedDate())
|
||||||
Settings().setValue(u'songusage/to date', self.toDate.selectedDate())
|
Settings().setValue(u'songusage/to date', self.to_date.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.from_date.selectedDate().toPyDate(),
|
||||||
SongUsageItem.usagedate < self.toDate.selectedDate().toPyDate()),
|
SongUsageItem.usagedate < self.to_date.selectedDate().toPyDate()),
|
||||||
[SongUsageItem.usagedate, SongUsageItem.usagetime])
|
[SongUsageItem.usagedate, SongUsageItem.usagetime])
|
||||||
outname = os.path.join(path, filename)
|
report_file_name = os.path.join(path, file_name)
|
||||||
fileHandle = None
|
file_handle = None
|
||||||
try:
|
try:
|
||||||
fileHandle = open(outname, u'w')
|
file_handle = open(report_file_name, u'w')
|
||||||
for instance in usage:
|
for instance in usage:
|
||||||
record = u'\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",' \
|
record = u'\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",' \
|
||||||
u'\"%s\",\"%s\"\n' % (instance.usagedate,
|
u'\"%s\",\"%s\"\n' % (instance.usagedate,
|
||||||
instance.usagetime, instance.title, instance.copyright,
|
instance.usagetime, instance.title, instance.copyright,
|
||||||
instance.ccl_number, instance.authors, instance.plugin_name, instance.source)
|
instance.ccl_number, instance.authors, instance.plugin_name, instance.source)
|
||||||
fileHandle.write(record.encode(u'utf-8'))
|
file_handle.write(record.encode(u'utf-8'))
|
||||||
self.main_window.information_message(
|
self.main_window.information_message(
|
||||||
translate('SongUsagePlugin.SongUsageDetailForm', 'Report Creation'),
|
translate('SongUsagePlugin.SongUsageDetailForm', 'Report Creation'),
|
||||||
translate('SongUsagePlugin.SongUsageDetailForm', 'Report \n%s \n'
|
translate('SongUsagePlugin.SongUsageDetailForm', 'Report \n%s \n'
|
||||||
'has been successfully created. ') % outname
|
'has been successfully created. ') % report_file_name
|
||||||
)
|
)
|
||||||
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 fileHandle:
|
if file_handle:
|
||||||
fileHandle.close()
|
file_handle.close()
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def _get_main_window(self):
|
def _get_main_window(self):
|
||||||
@ -128,4 +129,4 @@ class SongUsageDetailForm(QtGui.QDialog, Ui_SongUsageDetailDialog):
|
|||||||
self._main_window = Registry().get(u'main_window')
|
self._main_window = Registry().get(u'main_window')
|
||||||
return self._main_window
|
return self._main_window
|
||||||
|
|
||||||
main_window = property(_get_main_window)
|
main_window = property(_get_main_window)
|
||||||
|
@ -42,7 +42,6 @@ from openlp.plugins.songusage.lib.db import init_schema, SongUsageItem
|
|||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
@ -54,7 +53,7 @@ __default_settings__ = {
|
|||||||
u'songusage/to date': QtCore.QDate(YEAR, 8, 31),
|
u'songusage/to date': QtCore.QDate(YEAR, 8, 31),
|
||||||
u'songusage/from date': QtCore.QDate(YEAR - 1, 9, 1),
|
u'songusage/from date': QtCore.QDate(YEAR - 1, 9, 1),
|
||||||
u'songusage/last directory export': u''
|
u'songusage/last directory export': u''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class SongUsagePlugin(Plugin):
|
class SongUsagePlugin(Plugin):
|
||||||
@ -83,59 +82,59 @@ class SongUsagePlugin(Plugin):
|
|||||||
"""
|
"""
|
||||||
log.info(u'add tools menu')
|
log.info(u'add tools menu')
|
||||||
self.toolsMenu = tools_menu
|
self.toolsMenu = tools_menu
|
||||||
self.songUsageMenu = QtGui.QMenu(tools_menu)
|
self.song_usage_menu = QtGui.QMenu(tools_menu)
|
||||||
self.songUsageMenu.setObjectName(u'songUsageMenu')
|
self.song_usage_menu.setObjectName(u'song_usage_menu')
|
||||||
self.songUsageMenu.setTitle(translate('SongUsagePlugin', '&Song Usage Tracking'))
|
self.song_usage_menu.setTitle(translate('SongUsagePlugin', '&Song Usage Tracking'))
|
||||||
# SongUsage Delete
|
# SongUsage Delete
|
||||||
self.songUsageDelete = create_action(tools_menu, u'songUsageDelete',
|
self.song_usage_delete = create_action(tools_menu, u'songUsageDelete',
|
||||||
text=translate('SongUsagePlugin', '&Delete Tracking Data'),
|
text=translate('SongUsagePlugin', '&Delete Tracking Data'),
|
||||||
statustip=translate('SongUsagePlugin', 'Delete song usage data up to a specified date.'),
|
statustip=translate('SongUsagePlugin', 'Delete song usage data up to a specified date.'),
|
||||||
triggers=self.onSongUsageDelete)
|
triggers=self.on_song_usage_delete)
|
||||||
# SongUsage Report
|
# SongUsage Report
|
||||||
self.songUsageReport = create_action(tools_menu, u'songUsageReport',
|
self.song_usage_report = create_action(tools_menu, u'songUsageReport',
|
||||||
text=translate('SongUsagePlugin', '&Extract Tracking Data'),
|
text=translate('SongUsagePlugin', '&Extract Tracking Data'),
|
||||||
statustip=translate('SongUsagePlugin', 'Generate a report on song usage.'),
|
statustip=translate('SongUsagePlugin', 'Generate a report on song usage.'),
|
||||||
triggers=self.onSongUsageReport)
|
triggers=self.on_song_usage_report)
|
||||||
# SongUsage activation
|
# SongUsage activation
|
||||||
self.songUsageStatus = create_action(tools_menu, u'songUsageStatus',
|
self.song_usage_status = create_action(tools_menu, u'songUsageStatus',
|
||||||
text=translate('SongUsagePlugin', 'Toggle Tracking'),
|
text=translate('SongUsagePlugin', 'Toggle Tracking'),
|
||||||
statustip=translate('SongUsagePlugin', 'Toggle the tracking of song usage.'), checked=False,
|
statustip=translate('SongUsagePlugin', 'Toggle the tracking of song usage.'), checked=False,
|
||||||
shortcuts=[QtCore.Qt.Key_F4], triggers=self.toggleSongUsageState)
|
shortcuts=[QtCore.Qt.Key_F4], triggers=self.toggle_song_usage_state)
|
||||||
# Add Menus together
|
# Add Menus together
|
||||||
self.toolsMenu.addAction(self.songUsageMenu.menuAction())
|
self.toolsMenu.addAction(self.song_usage_menu.menuAction())
|
||||||
self.songUsageMenu.addAction(self.songUsageStatus)
|
self.song_usage_menu.addAction(self.song_usage_status)
|
||||||
self.songUsageMenu.addSeparator()
|
self.song_usage_menu.addSeparator()
|
||||||
self.songUsageMenu.addAction(self.songUsageReport)
|
self.song_usage_menu.addAction(self.song_usage_report)
|
||||||
self.songUsageMenu.addAction(self.songUsageDelete)
|
self.song_usage_menu.addAction(self.song_usage_delete)
|
||||||
self.songUsageActiveButton = QtGui.QToolButton(self.main_window.statusBar)
|
self.song_usage_active_button = QtGui.QToolButton(self.main_window.statusBar)
|
||||||
self.songUsageActiveButton.setCheckable(True)
|
self.song_usage_active_button.setCheckable(True)
|
||||||
self.songUsageActiveButton.setAutoRaise(True)
|
self.song_usage_active_button.setAutoRaise(True)
|
||||||
self.songUsageActiveButton.setStatusTip(translate('SongUsagePlugin', 'Toggle the tracking of song usage.'))
|
self.song_usage_active_button.setStatusTip(translate('SongUsagePlugin', 'Toggle the tracking of song usage.'))
|
||||||
self.songUsageActiveButton.setObjectName(u'songUsageActiveButton')
|
self.song_usage_active_button.setObjectName(u'song_usage_active_button')
|
||||||
self.main_window.statusBar.insertPermanentWidget(1, self.songUsageActiveButton)
|
self.main_window.statusBar.insertPermanentWidget(1, self.song_usage_active_button)
|
||||||
self.songUsageActiveButton.hide()
|
self.song_usage_active_button.hide()
|
||||||
# Signals and slots
|
# Signals and slots
|
||||||
QtCore.QObject.connect(self.songUsageStatus, QtCore.SIGNAL(u'visibilityChanged(bool)'),
|
QtCore.QObject.connect(self.song_usage_status, QtCore.SIGNAL(u'visibilityChanged(bool)'),
|
||||||
self.songUsageStatus.setChecked)
|
self.song_usage_status.setChecked)
|
||||||
QtCore.QObject.connect(self.songUsageActiveButton, QtCore.SIGNAL(u'toggled(bool)'), self.toggleSongUsageState)
|
self.song_usage_active_button.toggled.connect(self.toggle_song_usage_state)
|
||||||
self.songUsageMenu.menuAction().setVisible(False)
|
self.song_usage_menu.menuAction().setVisible(False)
|
||||||
|
|
||||||
def initialise(self):
|
def initialise(self):
|
||||||
log.info(u'SongUsage Initialising')
|
log.info(u'SongUsage Initialising')
|
||||||
Plugin.initialise(self)
|
Plugin.initialise(self)
|
||||||
Registry().register_function(u'slidecontroller_live_started', self.display_song_usage)
|
Registry().register_function(u'slidecontroller_live_started', self.display_song_usage)
|
||||||
Registry().register_function(u'print_service_started', self.print_song_usage)
|
Registry().register_function(u'print_service_started', self.print_song_usage)
|
||||||
self.songUsageActive = Settings().value(self.settingsSection + u'/active')
|
self.song_usage_active = Settings().value(self.settingsSection + u'/active')
|
||||||
# Set the button and checkbox state
|
# Set the button and checkbox state
|
||||||
self.setButtonState()
|
self.set_button_state()
|
||||||
action_list = ActionList.get_instance()
|
action_list = ActionList.get_instance()
|
||||||
action_list.add_action(self.songUsageStatus, translate('SongUsagePlugin', 'Song Usage'))
|
action_list.add_action(self.song_usage_status, translate('SongUsagePlugin', 'Song Usage'))
|
||||||
action_list.add_action(self.songUsageDelete, translate('SongUsagePlugin', 'Song Usage'))
|
action_list.add_action(self.song_usage_delete, translate('SongUsagePlugin', 'Song Usage'))
|
||||||
action_list.add_action(self.songUsageReport, translate('SongUsagePlugin', 'Song Usage'))
|
action_list.add_action(self.song_usage_report, translate('SongUsagePlugin', 'Song Usage'))
|
||||||
self.songUsageDeleteForm = SongUsageDeleteForm(self.manager, self.main_window)
|
self.song_usage_delete_form = SongUsageDeleteForm(self.manager, self.main_window)
|
||||||
self.songUsageDetailForm = SongUsageDetailForm(self, self.main_window)
|
self.song_usage_detail_form = SongUsageDetailForm(self, self.main_window)
|
||||||
self.songUsageMenu.menuAction().setVisible(True)
|
self.song_usage_menu.menuAction().setVisible(True)
|
||||||
self.songUsageActiveButton.show()
|
self.song_usage_active_button.show()
|
||||||
|
|
||||||
def finalise(self):
|
def finalise(self):
|
||||||
"""
|
"""
|
||||||
@ -144,44 +143,43 @@ class SongUsagePlugin(Plugin):
|
|||||||
log.info(u'Plugin Finalise')
|
log.info(u'Plugin Finalise')
|
||||||
self.manager.finalise()
|
self.manager.finalise()
|
||||||
Plugin.finalise(self)
|
Plugin.finalise(self)
|
||||||
self.songUsageMenu.menuAction().setVisible(False)
|
self.song_usage_menu.menuAction().setVisible(False)
|
||||||
action_list = ActionList.get_instance()
|
action_list = ActionList.get_instance()
|
||||||
action_list.remove_action(self.songUsageStatus, translate('SongUsagePlugin', 'Song Usage'))
|
action_list.remove_action(self.song_usage_status, translate('SongUsagePlugin', 'Song Usage'))
|
||||||
action_list.remove_action(self.songUsageDelete, translate('SongUsagePlugin', 'Song Usage'))
|
action_list.remove_action(self.song_usage_delete, translate('SongUsagePlugin', 'Song Usage'))
|
||||||
action_list.remove_action(self.songUsageReport, translate('SongUsagePlugin', 'Song Usage'))
|
action_list.remove_action(self.song_usage_report, translate('SongUsagePlugin', 'Song Usage'))
|
||||||
self.songUsageActiveButton.hide()
|
self.song_usage_active_button.hide()
|
||||||
# stop any events being processed
|
# stop any events being processed
|
||||||
self.songUsageActive = False
|
self.song_usage_active = False
|
||||||
|
|
||||||
def toggleSongUsageState(self):
|
def toggle_song_usage_state(self):
|
||||||
"""
|
"""
|
||||||
Manage the state of the audit collection and amend
|
Manage the state of the audit collection and amend
|
||||||
the UI when necessary,
|
the UI when necessary,
|
||||||
"""
|
"""
|
||||||
self.songUsageActive = not self.songUsageActive
|
self.song_usage_active = not self.song_usage_active
|
||||||
Settings().setValue(self.settingsSection + u'/active', self.songUsageActive)
|
Settings().setValue(self.settingsSection + u'/active', self.song_usage_active)
|
||||||
self.setButtonState()
|
self.set_button_state()
|
||||||
|
|
||||||
def setButtonState(self):
|
def set_button_state(self):
|
||||||
"""
|
"""
|
||||||
Keep buttons inline. Turn of signals to stop dead loop but we need the
|
Keep buttons inline. Turn of signals to stop dead loop but we need the
|
||||||
button and check box set correctly.
|
button and check box set correctly.
|
||||||
"""
|
"""
|
||||||
self.songUsageActiveButton.blockSignals(True)
|
self.song_usage_active_button.blockSignals(True)
|
||||||
self.songUsageStatus.blockSignals(True)
|
self.song_usage_status.blockSignals(True)
|
||||||
if self.songUsageActive:
|
if self.songUsageActive:
|
||||||
self.songUsageActiveButton.setIcon(self.activeIcon)
|
self.song_usage_active_button.setIcon(self.activeIcon)
|
||||||
self.songUsageStatus.setChecked(True)
|
self.song_usage_status.setChecked(True)
|
||||||
self.songUsageActiveButton.setChecked(True)
|
self.song_usage_active_button.setChecked(True)
|
||||||
self.songUsageActiveButton.setToolTip(translate('SongUsagePlugin', 'Song usage tracking is active.'))
|
self.song_usage_active_button.setToolTip(translate('SongUsagePlugin', 'Song usage tracking is active.'))
|
||||||
else:
|
else:
|
||||||
self.songUsageActiveButton.setIcon(self.inactiveIcon)
|
self.song_usage_active_button.setIcon(self.inactiveIcon)
|
||||||
self.songUsageStatus.setChecked(False)
|
self.song_usage_status.setChecked(False)
|
||||||
self.songUsageActiveButton.setChecked(False)
|
self.song_usage_active_button.setChecked(False)
|
||||||
self.songUsageActiveButton.setToolTip(translate('SongUsagePlugin', 'Song usage tracking is inactive.'))
|
self.song_usage_active_button.setToolTip(translate('SongUsagePlugin', 'Song usage tracking is inactive.'))
|
||||||
self.songUsageActiveButton.blockSignals(False)
|
self.song_usage_active_button.blockSignals(False)
|
||||||
self.songUsageStatus.blockSignals(False)
|
self.song_usage_status.blockSignals(False)
|
||||||
|
|
||||||
|
|
||||||
def display_song_usage(self, item):
|
def display_song_usage(self, item):
|
||||||
"""
|
"""
|
||||||
@ -209,12 +207,12 @@ class SongUsagePlugin(Plugin):
|
|||||||
song_usage_item.source = source
|
song_usage_item.source = source
|
||||||
self.manager.save_object(song_usage_item)
|
self.manager.save_object(song_usage_item)
|
||||||
|
|
||||||
def onSongUsageDelete(self):
|
def on_song_usage_delete(self):
|
||||||
self.songUsageDeleteForm.exec_()
|
self.song_usage_delete_form.exec_()
|
||||||
|
|
||||||
def onSongUsageReport(self):
|
def on_song_usage_report(self):
|
||||||
self.songUsageDetailForm.initialise()
|
self.song_usage_detail_form.initialise()
|
||||||
self.songUsageDetailForm.exec_()
|
self.song_usage_detail_form.exec_()
|
||||||
|
|
||||||
def about(self):
|
def about(self):
|
||||||
about_text = translate('SongUsagePlugin', '<strong>SongUsage Plugin'
|
about_text = translate('SongUsagePlugin', '<strong>SongUsage Plugin'
|
||||||
|
Loading…
Reference in New Issue
Block a user