Clean up settings and alerts

This commit is contained in:
Tim Bentley 2013-02-14 21:31:17 +00:00
parent b7cd1456a9
commit bd0ff619a9
9 changed files with 192 additions and 161 deletions

View File

@ -36,9 +36,8 @@ import sys
from PyQt4 import QtCore, QtGui
from openlp.core.lib import SlideLimits
from openlp.core.lib import SlideLimits, UiStrings
from openlp.core.lib.theme import ThemeLevel
from openlp.core.lib import UiStrings
log = logging.getLogger(__name__)
@ -70,7 +69,8 @@ class Settings(QtCore.QSettings):
``__obsolete_settings__``
Each entry is structured in the following way::
(u'general/enable slide loop', u'advanced/slide limits', [(SlideLimits.Wrap, True), (SlideLimits.End, False)])
(u'general/enable slide loop', u'advanced/slide limits',
[(SlideLimits.Wrap, True), (SlideLimits.End, False)])
The first entry is the *old key*; it will be removed.
@ -259,7 +259,6 @@ class Settings(QtCore.QSettings):
"""
Settings.__default_settings__ = dict(default_values.items() + Settings.__default_settings__.items())
@staticmethod
def set_filename(ini_file):
"""

View File

@ -106,7 +106,7 @@ class ExceptionForm(QtGui.QDialog, Ui_ExceptionDialog):
"""
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
self.settingsSection = u'crashreport'
self.settings_section = u'crashreport'
def exec_(self):
"""
@ -159,12 +159,11 @@ class ExceptionForm(QtGui.QDialog, Ui_ExceptionDialog):
'--- Library Versions ---\n%s\n')
filename = QtGui.QFileDialog.getSaveFileName(self,
translate('OpenLP.ExceptionForm', 'Save Crash Report'),
Settings().value(self.settingsSection + u'/last directory'),
translate('OpenLP.ExceptionForm',
'Text files (*.txt *.log *.text)'))
Settings().value(self.settings_section + u'/last directory'),
translate('OpenLP.ExceptionForm', 'Text files (*.txt *.log *.text)'))
if filename:
filename = unicode(filename).replace(u'/', os.path.sep)
Settings().setValue(self.settingsSection + u'/last directory', os.path.dirname(filename))
Settings().setValue(self.settings_section + u'/last directory', os.path.dirname(filename))
report_text = report_text % self._createReport()
try:
report_file = open(filename, u'w')
@ -230,7 +229,7 @@ class ExceptionForm(QtGui.QDialog, Ui_ExceptionDialog):
"""
files = QtGui.QFileDialog.getOpenFileName(
self, translate('ImagePlugin.ExceptionDialog', 'Select Attachment'),
Settings().value(self.settingsSection + u'/last directory'), u'%s (*.*) (*)' % UiStrings().AllFiles)
Settings().value(self.settings_section + u'/last directory'), u'%s (*.*) (*)' % UiStrings().AllFiles)
log.info(u'New files(s) %s', unicode(files))
if files:
self.fileAttachment = unicode(files)

View File

@ -300,7 +300,7 @@ class MainDisplay(Display):
self.image(path)
# Update the preview frame.
if self.isLive:
self.parent().updatePreview()
self.live_controller.updatePreview()
return True
def image(self, path):
@ -513,6 +513,16 @@ class MainDisplay(Display):
application = property(_get_application)
def _get_live_controller(self):
"""
Adds the live controller to the class dynamically
"""
if not hasattr(self, u'_live_controller'):
self._live_controller = Registry().get(u'live_controller')
return self._live_controller
live_controller = property(_get_live_controller)
class AudioPlayer(QtCore.QObject):
"""

View File

@ -230,7 +230,7 @@ class SlideController(DisplayController):
self.playSlidesOnce = create_action(self, u'playSlidesOnce', text=UiStrings().PlaySlidesToEnd,
icon=u':/media/media_time.png', checked=False, shortcuts=[],
category=self.category, triggers=self.onPlaySlidesOnce)
if Settings().value(self.parent().advancedSettingsSection + u'/slide limits') == SlideLimits.Wrap:
if Settings().value(self.main_window.advancedSettingsSection + u'/slide limits') == SlideLimits.Wrap:
self.playSlidesMenu.setDefaultAction(self.playSlidesLoop)
else:
self.playSlidesMenu.setDefaultAction(self.playSlidesOnce)
@ -582,7 +582,7 @@ class SlideController(DisplayController):
self.previewListWidget.resizeRowsToContents()
else:
# Sort out image heights.
width = self.parent().controlSplitter.sizes()[self.split]
width = self.main_window.controlSplitter.sizes()[self.split]
for framenumber in range(len(self.serviceItem.get_frames())):
self.previewListWidget.setRowHeight(framenumber, width / self.ratio)
self.onControllerSizeChanged(self.controller.width(), self.controller.height())
@ -618,7 +618,7 @@ class SlideController(DisplayController):
"""
Updates the Slide Limits variable from the settings.
"""
self.slide_limits = Settings().value(self.parent().advancedSettingsSection + u'/slide limits')
self.slide_limits = Settings().value(self.main_window.advancedSettingsSection + u'/slide limits')
def enableToolBar(self, item):
"""
@ -646,7 +646,7 @@ class SlideController(DisplayController):
self.playSlidesLoop.setChecked(False)
self.playSlidesLoop.setIcon(build_icon(u':/media/media_time.png'))
if item.is_text():
if Settings().value(self.parent().songsSettingsSection + u'/display songbar') and self.slideList:
if Settings().value(self.main_window.songsSettingsSection + u'/display songbar') and self.slideList:
self.songMenu.show()
if item.is_capable(ItemCapabilities.CanLoop) and len(item.get_frames()) > 1:
self.toolbar.setWidgetVisible(self.loopList)
@ -748,7 +748,7 @@ class SlideController(DisplayController):
self._resetBlank()
Registry().execute(u'%s_start' % serviceItem.name.lower(), [serviceItem, self.isLive, self.hideMode(), slideno])
self.slideList = {}
width = self.parent().controlSplitter.sizes()[self.split]
width = self.main_window.controlSplitter.sizes()[self.split]
self.previewListWidget.clear()
self.previewListWidget.setRowCount(0)
self.previewListWidget.setColumnWidth(0, width)
@ -767,8 +767,8 @@ class SlideController(DisplayController):
action.setData(counter)
QtCore.QObject.connect(action, QtCore.SIGNAL(u'triggered(bool)'), self.onTrackTriggered)
self.display.audioPlayer.repeat = Settings().value(
self.parent().generalSettingsSection + u'/audio repeat list')
if Settings().value(self.parent().generalSettingsSection + u'/audio start paused'):
self.main_window.generalSettingsSection + u'/audio repeat list')
if Settings().value(self.main_window.generalSettingsSection + u'/audio start paused'):
self.audioPauseItem.setChecked(True)
self.display.audioPlayer.pause()
else:
@ -877,7 +877,7 @@ class SlideController(DisplayController):
Allow the main display to blank the main display at startup time
"""
log.debug(u'mainDisplaySetBackground live = %s' % self.isLive)
display_type = Settings().value(self.parent().generalSettingsSection + u'/screen blank')
display_type = Settings().value(self.main_window.generalSettingsSection + u'/screen blank')
if self.screens.which_screen(self.window()) != self.screens.which_screen(self.display):
# Order done to handle initial conversion
if display_type == u'themed':
@ -915,9 +915,9 @@ class SlideController(DisplayController):
self.themeScreen.setChecked(False)
self.desktopScreen.setChecked(False)
if checked:
Settings().setValue(self.parent().generalSettingsSection + u'/screen blank', u'blanked')
Settings().setValue(self.main_window.generalSettingsSection + u'/screen blank', u'blanked')
else:
Settings().remove(self.parent().generalSettingsSection + u'/screen blank')
Settings().remove(self.main_window.generalSettingsSection + u'/screen blank')
self.blankPlugin()
self.updatePreview()
self.onToggleLoop()
@ -934,9 +934,9 @@ class SlideController(DisplayController):
self.themeScreen.setChecked(checked)
self.desktopScreen.setChecked(False)
if checked:
Settings().setValue(self.parent().generalSettingsSection + u'/screen blank', u'themed')
Settings().setValue(self.main_window.generalSettingsSection + u'/screen blank', u'themed')
else:
Settings().remove(self.parent().generalSettingsSection + u'/screen blank')
Settings().remove(self.main_window.generalSettingsSection + u'/screen blank')
self.blankPlugin()
self.updatePreview()
self.onToggleLoop()
@ -953,9 +953,9 @@ class SlideController(DisplayController):
self.themeScreen.setChecked(False)
self.desktopScreen.setChecked(checked)
if checked:
Settings().setValue(self.parent().generalSettingsSection + u'/screen blank', u'hidden')
Settings().setValue(self.main_window.generalSettingsSection + u'/screen blank', u'hidden')
else:
Settings().remove(self.parent().generalSettingsSection + u'/screen blank')
Settings().remove(self.main_window.generalSettingsSection + u'/screen blank')
self.hidePlugin(checked)
self.updatePreview()
self.onToggleLoop()
@ -1255,7 +1255,7 @@ class SlideController(DisplayController):
def onGoLive(self):
"""
If preview copy slide item to live
If preview copy slide item to live controller from Preview Controller
"""
row = self.previewListWidget.currentRow()
if -1 < row < self.previewListWidget.rowCount():
@ -1384,3 +1384,14 @@ class SlideController(DisplayController):
return self._live_controller
live_controller = property(_get_live_controller)
def _get_main_window(self):
"""
Adds the main window to the class dynamically
"""
if not hasattr(self, u'_main_window'):
self._main_window = Registry().get(u'main_window')
return self._main_window
main_window = property(_get_main_window)

View File

@ -122,7 +122,7 @@ __default_settings__ = {
u'alerts/background color': u'#660000',
u'alerts/font color': u'#ffffff',
u'alerts/timeout': 5
}
}
class AlertsPlugin(Plugin):
@ -133,7 +133,7 @@ class AlertsPlugin(Plugin):
self.weight = -3
self.iconPath = u':/plugins/plugin_alerts.png'
self.icon = build_icon(self.iconPath)
self.alertsmanager = AlertsManager(self)
self.alerts_manager = AlertsManager(self)
self.manager = Manager(u'alerts', init_schema)
self.alertForm = AlertForm(self)
@ -176,7 +176,7 @@ class AlertsPlugin(Plugin):
Settings().setValue(self.settingsSection + u'/active', self.alertsActive)
def onAlertsTrigger(self):
self.alertForm.loadList()
self.alertForm.load_list()
self.alertForm.exec_()
def about(self):
@ -194,7 +194,8 @@ class AlertsPlugin(Plugin):
u'plural': translate('AlertsPlugin', 'Alerts', 'name plural')
}
## Name for MediaDockManager, SettingsManager ##
self.textStrings[StringContent.VisibleName] = {u'title': translate('AlertsPlugin', 'Alerts', 'container title')
self.textStrings[StringContent.VisibleName] = {
u'title': translate('AlertsPlugin', 'Alerts', 'container title')
}
def getDisplayJavaScript(self):

View File

@ -32,61 +32,63 @@ from PyQt4 import QtGui
from openlp.core.lib import build_icon, translate
from openlp.core.lib.ui import create_button, create_button_box
class Ui_AlertDialog(object):
def setupUi(self, alertDialog):
alertDialog.setObjectName(u'alertDialog')
alertDialog.resize(400, 300)
alertDialog.setWindowIcon(build_icon(u':/icon/openlp-logo-16x16.png'))
self.alertDialogLayout = QtGui.QGridLayout(alertDialog)
self.alertDialogLayout.setObjectName(u'alertDialogLayout')
self.alertTextLayout = QtGui.QFormLayout()
self.alertTextLayout.setObjectName(u'alertTextLayout')
self.alertEntryLabel = QtGui.QLabel(alertDialog)
self.alertEntryLabel.setObjectName(u'alertEntryLabel')
self.alertTextEdit = QtGui.QLineEdit(alertDialog)
self.alertTextEdit.setObjectName(u'alertTextEdit')
self.alertEntryLabel.setBuddy(self.alertTextEdit)
self.alertTextLayout.addRow(self.alertEntryLabel, self.alertTextEdit)
self.alertParameter = QtGui.QLabel(alertDialog)
self.alertParameter.setObjectName(u'alertParameter')
self.parameterEdit = QtGui.QLineEdit(alertDialog)
self.parameterEdit.setObjectName(u'parameterEdit')
self.alertParameter.setBuddy(self.parameterEdit)
self.alertTextLayout.addRow(self.alertParameter, self.parameterEdit)
self.alertDialogLayout.addLayout(self.alertTextLayout, 0, 0, 1, 2)
self.alertListWidget = QtGui.QListWidget(alertDialog)
self.alertListWidget.setAlternatingRowColors(True)
self.alertListWidget.setObjectName(u'alertListWidget')
self.alertDialogLayout.addWidget(self.alertListWidget, 1, 0)
self.manageButtonLayout = QtGui.QVBoxLayout()
self.manageButtonLayout.setObjectName(u'manageButtonLayout')
self.newButton = QtGui.QPushButton(alertDialog)
self.newButton.setIcon(build_icon(u':/general/general_new.png'))
self.newButton.setObjectName(u'newButton')
self.manageButtonLayout.addWidget(self.newButton)
self.saveButton = QtGui.QPushButton(alertDialog)
self.saveButton.setEnabled(False)
self.saveButton.setIcon(build_icon(u':/general/general_save.png'))
self.saveButton.setObjectName(u'saveButton')
self.manageButtonLayout.addWidget(self.saveButton)
self.deleteButton = create_button(alertDialog, u'deleteButton', role=u'delete', enabled=False,
click=alertDialog.onDeleteButtonClicked)
self.manageButtonLayout.addWidget(self.deleteButton)
self.manageButtonLayout.addStretch()
self.alertDialogLayout.addLayout(self.manageButtonLayout, 1, 1)
displayIcon = build_icon(u':/general/general_live.png')
self.displayButton = create_button(alertDialog, u'displayButton', icon=displayIcon, enabled=False)
self.displayCloseButton = create_button(alertDialog, u'displayCloseButton', icon=displayIcon, enabled=False)
self.button_box = create_button_box(alertDialog, u'button_box', [u'close'],
[self.displayButton, self.displayCloseButton])
self.alertDialogLayout.addWidget(self.button_box, 2, 0, 1, 2)
self.retranslateUi(alertDialog)
def retranslateUi(self, alertDialog):
alertDialog.setWindowTitle(translate('AlertsPlugin.AlertForm', 'Alert Message'))
self.alertEntryLabel.setText(translate('AlertsPlugin.AlertForm', 'Alert &text:'))
self.alertParameter.setText(translate('AlertsPlugin.AlertForm', '&Parameter:'))
self.newButton.setText(translate('AlertsPlugin.AlertForm', '&New'))
self.saveButton.setText(translate('AlertsPlugin.AlertForm', '&Save'))
self.displayButton.setText(translate('AlertsPlugin.AlertForm', 'Displ&ay'))
self.displayCloseButton.setText(translate('AlertsPlugin.AlertForm', 'Display && Cl&ose'))
class Ui_AlertDialog(object):
def setupUi(self, alert_dialog):
alert_dialog.setObjectName(u'alert_dialog')
alert_dialog.resize(400, 300)
alert_dialog.setWindowIcon(build_icon(u':/icon/openlp-logo-16x16.png'))
self.alert_dialog_layout = QtGui.QGridLayout(alert_dialog)
self.alert_dialog_layout.setObjectName(u'alert_dialog_layout')
self.alert_text_layout = QtGui.QFormLayout()
self.alert_text_layout.setObjectName(u'alert_text_layout')
self.alert_entry_label = QtGui.QLabel(alert_dialog)
self.alert_entry_label.setObjectName(u'alert_entry_label')
self.alert_text_edit = QtGui.QLineEdit(alert_dialog)
self.alert_text_edit.setObjectName(u'alert_text_edit')
self.alert_entry_label.setBuddy(self.alert_text_edit)
self.alert_text_layout.addRow(self.alert_entry_label, self.alert_text_edit)
self.alert_parameter = QtGui.QLabel(alert_dialog)
self.alert_parameter.setObjectName(u'alert_parameter')
self.parameter_edit = QtGui.QLineEdit(alert_dialog)
self.parameter_edit.setObjectName(u'parameter_edit')
self.alert_parameter.setBuddy(self.parameter_edit)
self.alert_text_layout.addRow(self.alert_parameter, self.parameter_edit)
self.alert_dialog_layout.addLayout(self.alert_text_layout, 0, 0, 1, 2)
self.alert_list_widget = QtGui.QListWidget(alert_dialog)
self.alert_list_widget.setAlternatingRowColors(True)
self.alert_list_widget.setObjectName(u'alert_list_widget')
self.alert_dialog_layout.addWidget(self.alert_list_widget, 1, 0)
self.manage_button_layout = QtGui.QVBoxLayout()
self.manage_button_layout.setObjectName(u'manage_button_layout')
self.new_button = QtGui.QPushButton(alert_dialog)
self.new_button.setIcon(build_icon(u':/general/general_new.png'))
self.new_button.setObjectName(u'new_button')
self.manage_button_layout.addWidget(self.new_button)
self.save_button = QtGui.QPushButton(alert_dialog)
self.save_button.setEnabled(False)
self.save_button.setIcon(build_icon(u':/general/general_save.png'))
self.save_button.setObjectName(u'save_button')
self.manage_button_layout.addWidget(self.save_button)
self.delete_button = create_button(alert_dialog, u'delete_button', role=u'delete', enabled=False,
click=alert_dialog.onDeleteButtonClicked)
self.manage_button_layout.addWidget(self.delete_button)
self.manage_button_layout.addStretch()
self.alert_dialog_layout.addLayout(self.manage_button_layout, 1, 1)
displayIcon = build_icon(u':/general/general_live.png')
self.display_button = create_button(alert_dialog, u'display_button', icon=displayIcon, enabled=False)
self.display_close_button = create_button(alert_dialog, u'display_close_button', icon=displayIcon,
enabled=False)
self.button_box = create_button_box(alert_dialog, u'button_box', [u'close'],
[self.display_button, self.display_close_button])
self.alert_dialog_layout.addWidget(self.button_box, 2, 0, 1, 2)
self.retranslateUi(alert_dialog)
def retranslateUi(self, alert_dialog):
alert_dialog.setWindowTitle(translate('AlertsPlugin.AlertForm', 'Alert Message'))
self.alert_entry_label.setText(translate('AlertsPlugin.AlertForm', 'Alert &text:'))
self.alert_parameter.setText(translate('AlertsPlugin.AlertForm', '&Parameter:'))
self.new_button.setText(translate('AlertsPlugin.AlertForm', '&New'))
self.save_button.setText(translate('AlertsPlugin.AlertForm', '&Save'))
self.display_button.setText(translate('AlertsPlugin.AlertForm', 'Displ&ay'))
self.display_close_button.setText(translate('AlertsPlugin.AlertForm', 'Display && Cl&ose'))

View File

@ -48,131 +48,131 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
self.item_id = None
super(AlertForm, self).__init__(self.plugin.main_window)
self.setupUi(self)
QtCore.QObject.connect(self.displayButton, QtCore.SIGNAL(u'clicked()'), self.onDisplayClicked)
QtCore.QObject.connect(self.displayCloseButton, QtCore.SIGNAL(u'clicked()'), self.onDisplayCloseClicked)
QtCore.QObject.connect(self.alertTextEdit, QtCore.SIGNAL(u'textChanged(const QString&)'), self.onTextChanged)
QtCore.QObject.connect(self.newButton, QtCore.SIGNAL(u'clicked()'), self.onNewClick)
QtCore.QObject.connect(self.saveButton, QtCore.SIGNAL(u'clicked()'), self.onSaveClick)
QtCore.QObject.connect(self.alertListWidget, QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), self.onDoubleClick)
QtCore.QObject.connect(self.alertListWidget, QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onSingleClick)
QtCore.QObject.connect(self.alertListWidget, QtCore.SIGNAL(u'currentRowChanged(int)'), self.onCurrentRowChanged)
self.display_button.clicked.connect(self.on_display_clicked)
self.display_close_button.clicked.connect(self.on_display_close_clicked)
self.alert_text_edit.textChanged.connect(self.on_text_changed)
self.new_button.clicked.connect(self.on_new_click)
self.save_button.clicked.connect(self.on_save_all)
self.alert_list_widget.doubleClicked.connect(self.on_double_click)
self.alert_list_widget.clicked.connect(self.on_single_click)
self.alert_list_widget.currentRowChanged.connect(self.on_current_row_changed)
def exec_(self):
"""
Execute the dialog and return the exit code.
"""
self.displayButton.setEnabled(False)
self.displayCloseButton.setEnabled(False)
self.alertTextEdit.setText(u'')
self.display_button.setEnabled(False)
self.display_close_button.setEnabled(False)
self.alert_text_edit.setText(u'')
return QtGui.QDialog.exec_(self)
def loadList(self):
def load_list(self):
"""
Loads the list with alerts.
"""
self.alertListWidget.clear()
self.alert_list_widget.clear()
alerts = self.manager.get_all_objects(AlertItem, order_by_ref=AlertItem.text)
for alert in alerts:
item_name = QtGui.QListWidgetItem(alert.text)
item_name.setData(QtCore.Qt.UserRole, alert.id)
self.alertListWidget.addItem(item_name)
if alert.text == unicode(self.alertTextEdit.text()):
self.alert_list_widget.addItem(item_name)
if alert.text == unicode(self.alert_text_edit.text()):
self.item_id = alert.id
self.alertListWidget.setCurrentRow(self.alertListWidget.row(item_name))
self.alert_list_widget.setCurrentRow(self.alert_list_widget.row(item_name))
def onDisplayClicked(self):
def on_display_clicked(self):
"""
Display the current alert text.
"""
self.triggerAlert(self.alertTextEdit.text())
self.trigger_alert(self.alert_text_edit.text())
def onDisplayCloseClicked(self):
def on_display_close_clicked(self):
"""
Close the alert preview.
"""
if self.triggerAlert(self.alertTextEdit.text()):
if self.trigger_alert(self.alert_text_edit.text()):
self.close()
def onDeleteButtonClicked(self):
"""
Deletes the selected item.
"""
item = self.alertListWidget.currentItem()
item = self.alert_list_widget.currentItem()
if item:
item_id = item.data(QtCore.Qt.UserRole)
self.manager.delete_object(AlertItem, item_id)
row = self.alertListWidget.row(item)
self.alertListWidget.takeItem(row)
row = self.alert_list_widget.row(item)
self.alert_list_widget.takeItem(row)
self.item_id = None
self.alertTextEdit.setText(u'')
self.alert_text_edit.setText(u'')
def onNewClick(self):
def on_new_click(self):
"""
Create a new alert.
"""
if not self.alertTextEdit.text():
if not self.alert_text_edit.text():
QtGui.QMessageBox.information(self,
translate('AlertsPlugin.AlertForm', 'New Alert'),
translate('AlertsPlugin.AlertForm', 'You haven\'t specified any text for your alert. \n'
'Please type in some text before clicking New.'))
else:
alert = AlertItem()
alert.text = self.alertTextEdit.text()
alert.text = self.alert_text_edit.text()
self.manager.save_object(alert)
self.loadList()
self.load_list()
def onSaveClick(self):
def on_save_all(self):
"""
Save the alert, we are editing.
"""
if self.item_id:
alert = self.manager.get_object(AlertItem, self.item_id)
alert.text = self.alertTextEdit.text()
alert.text = self.alert_text_edit.text()
self.manager.save_object(alert)
self.item_id = None
self.loadList()
self.saveButton.setEnabled(False)
self.load_list()
self.save_button.setEnabled(False)
def onTextChanged(self):
def on_text_changed(self):
"""
Enable save button when data has been changed by editing the form.
"""
# Only enable the button, if we are editing an item.
if self.item_id:
self.saveButton.setEnabled(True)
if self.alertTextEdit.text():
self.displayButton.setEnabled(True)
self.displayCloseButton.setEnabled(True)
self.save_button.setEnabled(True)
if self.alert_text_edit.text():
self.display_button.setEnabled(True)
self.display_close_button.setEnabled(True)
else:
self.displayButton.setEnabled(False)
self.displayCloseButton.setEnabled(False)
self.display_button.setEnabled(False)
self.display_close_button.setEnabled(False)
def onDoubleClick(self):
def on_double_click(self):
"""
List item has been double clicked to display it.
"""
item = self.alertListWidget.selectedIndexes()[0]
bitem = self.alertListWidget.item(item.row())
self.triggerAlert(bitem.text())
self.alertTextEdit.setText(bitem.text())
item = self.alert_list_widget.selectedIndexes()[0]
bitem = self.alert_list_widget.item(item.row())
self.trigger_alert(bitem.text())
self.alert_text_edit.setText(bitem.text())
self.item_id = bitem.data(QtCore.Qt.UserRole)
self.saveButton.setEnabled(False)
self.save_button.setEnabled(False)
def onSingleClick(self):
def on_single_click(self):
"""
List item has been single clicked to add it to the edit field so it can
be changed.
"""
item = self.alertListWidget.selectedIndexes()[0]
bitem = self.alertListWidget.item(item.row())
self.alertTextEdit.setText(bitem.text())
item = self.alert_list_widget.selectedIndexes()[0]
bitem = self.alert_list_widget.item(item.row())
self.alert_text_edit.setText(bitem.text())
self.item_id = bitem.data(QtCore.Qt.UserRole)
# If the alert does not contain '<>' we clear the ParameterEdit field.
if self.alertTextEdit.text().find(u'<>') == -1:
self.parameterEdit.setText(u'')
self.saveButton.setEnabled(False)
if self.alert_text_edit.text().find(u'<>') == -1:
self.parameter_edit.setText(u'')
self.save_button.setEnabled(False)
def triggerAlert(self, text):
def trigger_alert(self, text):
"""
Prepares the alert text for displaying.
@ -182,42 +182,42 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
if not text:
return False
# We found '<>' in the alert text, but the ParameterEdit field is empty.
if text.find(u'<>') != -1 and not self.parameterEdit.text() and QtGui.QMessageBox.question(self,
if text.find(u'<>') != -1 and not self.parameter_edit.text() and QtGui.QMessageBox.question(self,
translate('AlertsPlugin.AlertForm', 'No Parameter Found'),
translate('AlertsPlugin.AlertForm', 'You have not entered a parameter to be replaced.\n'
'Do you want to continue anyway?'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No:
self.parameterEdit.setFocus()
self.parameter_edit.setFocus()
return False
# The ParameterEdit field is not empty, but we have not found '<>'
# in the alert text.
elif text.find(u'<>') == -1 and self.parameterEdit.text() and QtGui.QMessageBox.question(self,
elif text.find(u'<>') == -1 and self.parameter_edit.text() and QtGui.QMessageBox.question(self,
translate('AlertsPlugin.AlertForm', 'No Placeholder Found'),
translate('AlertsPlugin.AlertForm', 'The alert text does not contain \'<>\'.\n'
'Do you want to continue anyway?'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No:
self.parameterEdit.setFocus()
self.parameter_edit.setFocus()
return False
text = text.replace(u'<>', self.parameterEdit.text())
self.plugin.alertsmanager.displayAlert(text)
text = text.replace(u'<>', self.parameter_edit.text())
self.plugin.alerts_manager.display_alert(text)
return True
def onCurrentRowChanged(self, row):
def on_current_row_changed(self, row):
"""
Called when the *alertListWidget*'s current row has been changed. This
Called when the *alert_list_widget*'s current row has been changed. This
enables or disables buttons which require an item to act on.
``row``
The row (int). If there is no current row, the value is -1.
"""
if row == -1:
self.displayButton.setEnabled(False)
self.displayCloseButton.setEnabled(False)
self.saveButton.setEnabled(False)
self.deleteButton.setEnabled(False)
self.display_button.setEnabled(False)
self.display_close_button.setEnabled(False)
self.save_button.setEnabled(False)
self.delete_button.setEnabled(False)
else:
self.displayButton.setEnabled(True)
self.displayCloseButton.setEnabled(True)
self.deleteButton.setEnabled(True)
self.display_button.setEnabled(True)
self.display_close_button.setEnabled(True)
self.delete_button.setEnabled(True)
# We do not need to enable the save button, as it is only enabled
# when typing text in the "alertTextEdit".
# when typing text in the "alert_text_edit".

View File

@ -47,7 +47,6 @@ class AlertsManager(QtCore.QObject):
def __init__(self, parent):
QtCore.QObject.__init__(self, parent)
self.screen = None
self.timer_id = 0
self.alert_list = []
Registry().register_function(u'live_display_active', self.generate_alert)
@ -87,7 +86,7 @@ class AlertsManager(QtCore.QObject):
return
text = self.alert_list.pop(0)
alertTab = self.parent().settingsTab
self.parent().liveController.display.alert(text, alertTab.location)
self.live_controller.display.alert(text, alertTab.location)
# Check to see if we have a timer running.
if self.timer_id == 0:
self.timer_id = self.startTimer(int(alertTab.timeout) * 1000)
@ -103,7 +102,7 @@ class AlertsManager(QtCore.QObject):
log.debug(u'timer event')
if event.timerId() == self.timer_id:
alertTab = self.parent().settingsTab
self.parent().liveController.display.alert(u'', alertTab.location)
self.live_controller.display.alert(u'', alertTab.location)
self.killTimer(self.timer_id)
self.timer_id = 0
self.generate_alert()
@ -116,4 +115,14 @@ class AlertsManager(QtCore.QObject):
self._main_window = Registry().get(u'main_window')
return self._main_window
main_window = property(_get_main_window)
main_window = property(_get_main_window)
def _get_live_controller(self):
"""
Adds the live controller to the class dynamically
"""
if not hasattr(self, u'_live_controller'):
self._live_controller = Registry().get(u'live_controller')
return self._live_controller
live_controller = property(_get_live_controller)

View File

@ -42,7 +42,7 @@ class TestSettings(TestCase):
default_value = Settings().value(u'general/has run wizard')
# THEN the default value is returned
assert default_value is False, u'The default value defined has not been returned'
assert default_value is False, u'The default value should be False'
# WHEN a new value is saved into config
Settings().setValue(u'general/has run wizard', True)