Fix up button

This commit is contained in:
Tim Bentley 2011-06-30 19:59:51 +01:00
parent 870d0b51e9
commit 0b41274f8e

View File

@ -51,7 +51,7 @@ class SongUsagePlugin(Plugin):
self.activeIcon = QtGui.QIcon(u':/songusage/song_usage_active.png') self.activeIcon = QtGui.QIcon(u':/songusage/song_usage_active.png')
self.inactiveIcon = QtGui.QIcon(u':/songusage/song_usage_inactive.png') self.inactiveIcon = QtGui.QIcon(u':/songusage/song_usage_inactive.png')
self.manager = None self.manager = None
self.songusageActive = False self.songUsageActive = False
def addToolsMenuItem(self, tools_menu): def addToolsMenuItem(self, tools_menu):
""" """
@ -85,15 +85,17 @@ class SongUsagePlugin(Plugin):
self.toolsMenu.addAction(self.songUsageMenu.menuAction()) self.toolsMenu.addAction(self.songUsageMenu.menuAction())
self.songUsageMenu.addAction(self.songUsageDelete) self.songUsageMenu.addAction(self.songUsageDelete)
self.songUsageMenu.addAction(self.songUsageReport) self.songUsageMenu.addAction(self.songUsageReport)
self.songUsageStatus = QtGui.QToolButton(self.formparent.statusBar) self.songUsageActiveButton = QtGui.QToolButton(
self.songUsageStatus.setCheckable(True) self.formparent.statusBar)
self.songUsageStatus.setStatusTip(translate('SongUsagePlugin', self.songUsageActiveButton.setCheckable(True)
self.songUsageActiveButton.setStatusTip(translate('SongUsagePlugin',
'Toggle the tracking of song usage.')) 'Toggle the tracking of song usage.'))
self.songUsageStatus.setObjectName(u'songUsageStatus') self.songUsageActiveButton.setObjectName(u'songUsageActiveButton')
self.formparent.statusBar.insertPermanentWidget(1, self.songUsageStatus) self.formparent.statusBar.insertPermanentWidget(1,
self.songUsageStatus.hide() self.songUsageActiveButton)
self.songUsageActiveButton.hide()
# Signals and slots # Signals and slots
QtCore.QObject.connect(self.songUsageStatus, QtCore.QObject.connect(self.songUsageActiveButton,
QtCore.SIGNAL(u'toggled(bool)'), QtCore.SIGNAL(u'toggled(bool)'),
self.toggleSongUsageState) self.toggleSongUsageState)
QtCore.QObject.connect(self.songUsageDelete, QtCore.QObject.connect(self.songUsageDelete,
@ -108,10 +110,15 @@ class SongUsagePlugin(Plugin):
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'slidecontroller_live_started'), QtCore.SIGNAL(u'slidecontroller_live_started'),
self.onReceiveSongUsage) self.onReceiveSongUsage)
self.SongUsageActive = QtCore.QSettings().value( self.songUsageActive = QtCore.QSettings().value(
self.settingsSection + u'/active', self.settingsSection + u'/active',
QtCore.QVariant(False)).toBool() QtCore.QVariant(False)).toBool()
self.songUsageStatus.setChecked(self.SongUsageActive) # Set the correct state and icon turn of signals as the state
# will get messed up
self.songUsageActiveButton.blockSignals(True)
self.songUsageActiveButton.setChecked(self.songUsageActive)
self.setButtonState()
self.songUsageActiveButton.blockSignals(False)
action_list = ActionList.get_instance() action_list = ActionList.get_instance()
action_list.add_action(self.songUsageDelete, action_list.add_action(self.songUsageDelete,
translate('SongUsagePlugin', 'Song Usage')) translate('SongUsagePlugin', 'Song Usage'))
@ -123,8 +130,7 @@ class SongUsagePlugin(Plugin):
self.formparent) self.formparent)
self.songUsageDetailForm = SongUsageDetailForm(self, self.formparent) self.songUsageDetailForm = SongUsageDetailForm(self, self.formparent)
self.songUsageMenu.menuAction().setVisible(True) self.songUsageMenu.menuAction().setVisible(True)
self.songUsageStatus.show() self.songUsageActiveButton.show()
self.songUsageStatus.setIcon(self.activeIcon)
def finalise(self): def finalise(self):
""" """
@ -139,32 +145,32 @@ class SongUsagePlugin(Plugin):
translate('SongUsagePlugin', 'Song Usage')) translate('SongUsagePlugin', 'Song Usage'))
action_list.remove_action(self.songUsageReport, action_list.remove_action(self.songUsageReport,
translate('SongUsagePlugin', 'Song Usage')) translate('SongUsagePlugin', 'Song Usage'))
self.songUsageStatus.hide() self.songUsageActiveButton.hide()
# stop any events being processed # stop any events being processed
self.SongUsageActive = False self.songUsageActive = False
def toggleSongUsageState(self): def toggleSongUsageState(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,
""" """
print "toggle state" self.songUsageActive = not self.songUsageActive
self.SongUsageActive = not self.SongUsageActive
QtCore.QSettings().setValue(self.settingsSection + u'/active', QtCore.QSettings().setValue(self.settingsSection + u'/active',
QtCore.QVariant(self.SongUsageActive)) QtCore.QVariant(self.songUsageActive))
if self.SongUsageActive: self.setButtonState()
self.songUsageStatus.setIcon(self.activeIcon)
def setButtonState(self):
if self.songUsageActive:
self.songUsageActiveButton.setIcon(self.activeIcon)
else: else:
self.songUsageStatus.setIcon(self.inactiveIcon) self.songUsageActiveButton.setIcon(self.inactiveIcon)
def onReceiveSongUsage(self, item): def onReceiveSongUsage(self, item):
""" """
Song Usage for live song from SlideController Song Usage for live song from SlideController
""" """
audit = item[0].audit audit = item[0].audit
print audit if self.songUsageActive and audit:
if self.SongUsageActive and audit:
print "here"
song_usage_item = SongUsageItem() song_usage_item = SongUsageItem()
song_usage_item.usagedate = datetime.today() song_usage_item.usagedate = datetime.today()
song_usage_item.usagetime = datetime.now().time() song_usage_item.usagetime = datetime.now().time()