More PEP 8 changes

This commit is contained in:
Tim Bentley 2014-01-01 09:33:07 +00:00
parent 259b2b074f
commit 2755aad4c6
9 changed files with 266 additions and 149 deletions

View File

@ -89,8 +89,8 @@ def get_text_file_string(text_file):
returns False. If there is an error loading the file or the content can't be decoded then the function will return returns False. If there is an error loading the file or the content can't be decoded then the function will return
None. None.
``textfile`` :param text_file: The name of the file.
The name of the file. :return The file as a single string
""" """
if not os.path.isfile(text_file): if not os.path.isfile(text_file):
return False return False
@ -114,8 +114,8 @@ def str_to_bool(string_value):
""" """
Convert a string version of a boolean into a real boolean. Convert a string version of a boolean into a real boolean.
``string_value`` :param string_value: The string value to examine and convert to a boolean type.
The string value to examine and convert to a boolean type. :return The correct boolean value
""" """
if isinstance(string_value, bool): if isinstance(string_value, bool):
return string_value return string_value
@ -127,9 +127,10 @@ def build_icon(icon):
Build a QIcon instance from an existing QIcon, a resource location, or a physical file location. If the icon is a Build a QIcon instance from an existing QIcon, a resource location, or a physical file location. If the icon is a
QIcon instance, that icon is simply returned. If not, it builds a QIcon instance from the resource or file name. QIcon instance, that icon is simply returned. If not, it builds a QIcon instance from the resource or file name.
``icon`` :param icon:
The icon to build. This can be a QIcon, a resource string in the form ``:/resource/file.png``, or a file The icon to build. This can be a QIcon, a resource string in the form ``:/resource/file.png``, or a file
location like ``/path/to/file.png``. However, the **recommended** way is to specify a resource string. location like ``/path/to/file.png``. However, the **recommended** way is to specify a resource string.
:return The build icon.
""" """
button_icon = QtGui.QIcon() button_icon = QtGui.QIcon()
if isinstance(icon, QtGui.QIcon): if isinstance(icon, QtGui.QIcon):
@ -148,8 +149,7 @@ def image_to_byte(image):
""" """
Resize an image to fit on the current screen for the web and returns it as a byte stream. Resize an image to fit on the current screen for the web and returns it as a byte stream.
``image`` :param image: The image to converted.
The image to converted.
""" """
log.debug('image_to_byte - start') log.debug('image_to_byte - start')
byte_array = QtCore.QByteArray() byte_array = QtCore.QByteArray()
@ -166,18 +166,12 @@ def create_thumb(image_path, thumb_path, return_icon=True, size=None):
""" """
Create a thumbnail from the given image path and depending on ``return_icon`` it returns an icon from this thumb. Create a thumbnail from the given image path and depending on ``return_icon`` it returns an icon from this thumb.
``image_path`` :param image_path: The image file to create the icon from.
The image file to create the icon from. :param thumb_path: The filename to save the thumbnail to.
:param return_icon: States if an icon should be build and returned from the thumb. Defaults to ``True``.
``thumb_path`` :param size: Allows to state a own size (QtCore.QSize) to use. Defaults to ``None``, which means that a default
The filename to save the thumbnail to. height of 88 is used.
:return The final icon.
``return_icon``
States if an icon should be build and returned from the thumb. Defaults to ``True``.
``size``
Allows to state a own size (QtCore.QSize) to use. Defaults to ``None``, which means that a default height of 88
is used.
""" """
ext = os.path.splitext(thumb_path)[1].lower() ext = os.path.splitext(thumb_path)[1].lower()
reader = QtGui.QImageReader(image_path) reader = QtGui.QImageReader(image_path)
@ -201,11 +195,9 @@ def validate_thumb(file_path, thumb_path):
Validates whether an file's thumb still exists and if is up to date. **Note**, you must **not** call this function, Validates whether an file's thumb still exists and if is up to date. **Note**, you must **not** call this function,
before checking the existence of the file. before checking the existence of the file.
``file_path`` :param file_path: The path to the file. The file **must** exist!
The path to the file. The file **must** exist! :param thumb_path: The path to the thumb.
:return True, False if the image has changed since the thumb was created.
``thumb_path``
The path to the thumb.
""" """
if not os.path.exists(thumb_path): if not os.path.exists(thumb_path):
return False return False
@ -218,19 +210,12 @@ def resize_image(image_path, width, height, background='#000000'):
""" """
Resize an image to fit on the current screen. Resize an image to fit on the current screen.
``image_path``
The path to the image to resize.
``width``
The new image width.
``height``
The new image height.
``background``
The background colour. Defaults to black.
DO NOT REMOVE THE DEFAULT BACKGROUND VALUE! DO NOT REMOVE THE DEFAULT BACKGROUND VALUE!
:param image_path: The path to the image to resize.
:param width: The new image width.
:param height: The new image height.
:param background: The background colour. Defaults to black.
""" """
log.debug('resize_image - start') log.debug('resize_image - start')
reader = QtGui.QImageReader(image_path) reader = QtGui.QImageReader(image_path)
@ -265,11 +250,8 @@ def check_item_selected(list_widget, message):
""" """
Check if a list item is selected so an action may be performed on it Check if a list item is selected so an action may be performed on it
``list_widget`` :param list_widget: The list to check for selected items
The list to check for selected items :param message: The message to give the user if no item is selected
``message``
The message to give the user if no item is selected
""" """
if not list_widget.selectedIndexes(): if not list_widget.selectedIndexes():
QtGui.QMessageBox.information(list_widget.parent(), QtGui.QMessageBox.information(list_widget.parent(),
@ -281,6 +263,8 @@ def check_item_selected(list_widget, message):
def clean_tags(text): def clean_tags(text):
""" """
Remove Tags from text for display Remove Tags from text for display
:param text: Text to be cleaned
""" """
text = text.replace('<br>', '\n') text = text.replace('<br>', '\n')
text = text.replace('{br}', '\n') text = text.replace('{br}', '\n')
@ -294,6 +278,8 @@ def clean_tags(text):
def expand_tags(text): def expand_tags(text):
""" """
Expand tags HTML for display Expand tags HTML for display
:param text: The text to be expanded.
""" """
for tag in FormattingTags.get_html_tags(): for tag in FormattingTags.get_html_tags():
text = text.replace(tag['start tag'], tag['start html']) text = text.replace(tag['start tag'], tag['start html'])
@ -304,11 +290,11 @@ def expand_tags(text):
def create_separated_list(string_list): def create_separated_list(string_list):
""" """
Returns a string that represents a join of a list of strings with a localized separator. This function corresponds Returns a string that represents a join of a list of strings with a localized separator. This function corresponds
to QLocale::createSeparatedList which was introduced in Qt 4.8 and implements the algorithm from to QLocale::createSeparatedList which was introduced in Qt 4.8 and implements the algorithm from
http://www.unicode.org/reports/tr35/#ListPatterns http://www.unicode.org/reports/tr35/#ListPatterns
``string_list`` :param string_list: List of unicode strings
List of unicode strings
""" """
if LooseVersion(Qt.PYQT_VERSION_STR) >= LooseVersion('4.9') and \ if LooseVersion(Qt.PYQT_VERSION_STR) >= LooseVersion('4.9') and \
LooseVersion(Qt.qVersion()) >= LooseVersion('4.8'): LooseVersion(Qt.qVersion()) >= LooseVersion('4.8'):

View File

@ -63,6 +63,7 @@ class ServiceManagerList(QtGui.QTreeWidget):
def keyPressEvent(self, event): def keyPressEvent(self, event):
""" """
Capture Key press and respond accordingly. Capture Key press and respond accordingly.
:param event:
""" """
if isinstance(event, QtGui.QKeyEvent): if isinstance(event, QtGui.QKeyEvent):
# here accept the event and do something # here accept the event and do something
@ -83,6 +84,7 @@ class ServiceManagerList(QtGui.QTreeWidget):
""" """
Drag and drop event does not care what data is selected as the recipient will use events to request the data Drag and drop event does not care what data is selected as the recipient will use events to request the data
move just tell it what plugin to call move just tell it what plugin to call
:param event:
""" """
if event.buttons() != QtCore.Qt.LeftButton: if event.buttons() != QtCore.Qt.LeftButton:
event.ignore() event.ignore()
@ -104,6 +106,7 @@ class Ui_ServiceManager(object):
def setup_ui(self, widget): def setup_ui(self, widget):
""" """
Define the UI Define the UI
:param widget:
""" """
# start with the layout # start with the layout
self.layout = QtGui.QVBoxLayout(widget) self.layout = QtGui.QVBoxLayout(widget)
@ -298,8 +301,7 @@ class Ui_ServiceManager(object):
""" """
Accept Drag events Accept Drag events
``event`` :param event: Handle of the event passed
Handle of the event passed
""" """
event.accept() event.accept()
@ -327,6 +329,9 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
self.service_has_all_original_files = True self.service_has_all_original_files = True
def bootstrap_initialise(self): def bootstrap_initialise(self):
"""
To be called as part of initialisation
"""
self.setup_ui(self) self.setup_ui(self)
# Need to use event as called across threads and UI is updated # Need to use event as called across threads and UI is updated
QtCore.QObject.connect(self, QtCore.SIGNAL('servicemanager_set_item'), self.on_set_item) QtCore.QObject.connect(self, QtCore.SIGNAL('servicemanager_set_item'), self.on_set_item)
@ -342,6 +347,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def set_modified(self, modified=True): def set_modified(self, modified=True):
""" """
Setter for property "modified". Sets whether or not the current service has been modified. Setter for property "modified". Sets whether or not the current service has been modified.
:param modified: Indicates if the service has new or removed items. Used to trigger a remote update.
""" """
if modified: if modified:
self.service_id += 1 self.service_id += 1
@ -358,6 +365,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def set_file_name(self, file_name): def set_file_name(self, file_name):
""" """
Setter for service file. Setter for service file.
:param file_name: The service file name
""" """
self._file_name = str(file_name) self._file_name = str(file_name)
self.main_window.set_service_modified(self.is_modified(), self.short_file_name()) self.main_window.set_service_modified(self.is_modified(), self.short_file_name())
@ -387,8 +396,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
""" """
Adds Suffixes supported to the master list. Called from Plugins. Adds Suffixes supported to the master list. Called from Plugins.
``suffix_list`` :param suffix_list: New Suffix's to be supported
New Suffix's to be supported
""" """
for suffix in suffix_list: for suffix in suffix_list:
if not suffix in self.suffixes: if not suffix in self.suffixes:
@ -397,6 +405,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_new_service_clicked(self, field=None): def on_new_service_clicked(self, field=None):
""" """
Create a new service. Create a new service.
:param field:
""" """
if self.is_modified(): if self.is_modified():
result = self.save_modified_service() result = self.save_modified_service()
@ -411,8 +420,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
""" """
Loads the service file and saves the existing one it there is one unchanged. Loads the service file and saves the existing one it there is one unchanged.
``load_file`` :param load_file: The service file to the loaded. Will be None is from menu so selection will be required.
The service file to the loaded. Will be None is from menu so selection will be required.
""" """
if self.is_modified(): if self.is_modified():
result = self.save_modified_service() result = self.save_modified_service()
@ -450,6 +458,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_recent_service_clicked(self, field=None): def on_recent_service_clicked(self, field=None):
""" """
Load a recent file as the service triggered by mainwindow recent service list. Load a recent file as the service triggered by mainwindow recent service list.
:param field:
""" """
sender = self.sender() sender = self.sender()
self.load_file(sender.data()) self.load_file(sender.data())
@ -484,7 +493,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
path, file_name = os.path.split(path_file_name) path, file_name = os.path.split(path_file_name)
base_name = os.path.splitext(file_name)[0] base_name = os.path.splitext(file_name)[0]
service_file_name = '%s.osj' % base_name service_file_name = '%s.osj' % base_name
self.log_debug('ServiceManager.save_file - %s', path_file_name) self.log_debug('ServiceManager.save_file - %s' % path_file_name)
Settings().setValue(self.main_window.service_manager_settings_section + '/last directory', path) Settings().setValue(self.main_window.service_manager_settings_section + '/last directory', path)
service = [] service = []
write_list = [] write_list = []
@ -564,7 +573,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
shutil.copy(audio_from, save_file) shutil.copy(audio_from, save_file)
zip_file.write(audio_from, audio_to) zip_file.write(audio_from, audio_to)
except IOError: except IOError:
self.log_exception('Failed to save service to disk: %s', temp_file_name) self.log_exception('Failed to save service to disk: %s' % temp_file_name)
self.main_window.error_message(translate('OpenLP.ServiceManager', 'Error Saving File'), self.main_window.error_message(translate('OpenLP.ServiceManager', 'Error Saving File'),
translate('OpenLP.ServiceManager', 'There was an error saving your file.')) translate('OpenLP.ServiceManager', 'There was an error saving your file.'))
success = False success = False
@ -686,6 +695,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def decide_save_method(self, field=None): def decide_save_method(self, field=None):
""" """
Determine which type of save method to use. Determine which type of save method to use.
:param field:
""" """
if not self.file_name(): if not self.file_name():
return self.save_file_as() return self.save_file_as()
@ -697,6 +707,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def load_file(self, file_name): def load_file(self, file_name):
""" """
Load an existing service file Load an existing service file
:param file_name:
""" """
if not file_name: if not file_name:
return False return False
@ -719,7 +730,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
os_file = ucs_file.replace('/', os.path.sep) os_file = ucs_file.replace('/', os.path.sep)
if not os_file.startswith('audio'): if not os_file.startswith('audio'):
os_file = os.path.split(os_file)[1] os_file = os.path.split(os_file)[1]
self.log_debug('Extract file: %s', os_file) self.log_debug('Extract file: %s' % os_file)
zip_info.filename = os_file zip_info.filename = os_file
zip_file.extract(zip_info, self.service_path) zip_file.extract(zip_info, self.service_path)
if os_file.endswith('osj') or os_file.endswith('osd'): if os_file.endswith('osj') or os_file.endswith('osd'):
@ -795,6 +806,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def context_menu(self, point): def context_menu(self, point):
""" """
The Right click context menu from the Serviceitem list The Right click context menu from the Serviceitem list
:param point: The location of the cursor.
""" """
item = self.service_manager_list.itemAt(point) item = self.service_manager_list.itemAt(point)
if item is None: if item is None:
@ -861,6 +874,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_service_item_note_form(self, field=None): def on_service_item_note_form(self, field=None):
""" """
Allow the service note to be edited Allow the service note to be edited
:param field:
""" """
item = self.find_service_item()[0] item = self.find_service_item()[0]
self.service_note_form.text_edit.setPlainText(self.service_items[item]['service_item'].notes) self.service_note_form.text_edit.setPlainText(self.service_items[item]['service_item'].notes)
@ -872,6 +886,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_start_time_form(self, field=None): def on_start_time_form(self, field=None):
""" """
Opens a dialog to type in service item notes. Opens a dialog to type in service item notes.
:param field:
""" """
item = self.find_service_item()[0] item = self.find_service_item()[0]
self.start_time_form.item = self.service_items[item] self.start_time_form.item = self.service_items[item]
@ -881,6 +896,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def toggle_auto_play_slides_once(self, field=None): def toggle_auto_play_slides_once(self, field=None):
""" """
Toggle Auto play slide once. Inverts auto play once option for the item Toggle Auto play slide once. Inverts auto play once option for the item
:param field:
""" """
item = self.find_service_item()[0] item = self.find_service_item()[0]
service_item = self.service_items[item]['service_item'] service_item = self.service_items[item]['service_item']
@ -896,6 +912,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def toggle_auto_play_slides_loop(self, field=None): def toggle_auto_play_slides_loop(self, field=None):
""" """
Toggle Auto play slide loop. Toggle Auto play slide loop.
:param field:
""" """
item = self.find_service_item()[0] item = self.find_service_item()[0]
service_item = self.service_items[item]['service_item'] service_item = self.service_items[item]['service_item']
@ -911,6 +928,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_timed_slide_interval(self, field=None): def on_timed_slide_interval(self, field=None):
""" """
Shows input dialog for enter interval in seconds for delay Shows input dialog for enter interval in seconds for delay
:param field:
""" """
item = self.find_service_item()[0] item = self.find_service_item()[0]
service_item = self.service_items[item]['service_item'] service_item = self.service_items[item]['service_item']
@ -944,6 +962,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_service_item_edit_form(self, field=None): def on_service_item_edit_form(self, field=None):
""" """
Opens a dialog to edit the service item and update the service display if changes are saved. Opens a dialog to edit the service item and update the service display if changes are saved.
:param field:
""" """
item = self.find_service_item()[0] item = self.find_service_item()[0]
self.service_item_edit_form.set_service_item(self.service_items[item]['service_item']) self.service_item_edit_form.set_service_item(self.service_items[item]['service_item'])
@ -956,11 +975,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
Called by the SlideController to request a preview item be made live and allows the next preview to be updated Called by the SlideController to request a preview item be made live and allows the next preview to be updated
if relevant. if relevant.
``unique_identifier`` :param unique_identifier: Reference to the service_item
Reference to the service_item :param row: individual row number
``row``
individual row number
""" """
for sitem in self.service_items: for sitem in self.service_items:
if sitem['service_item'].unique_identifier == unique_identifier: if sitem['service_item'].unique_identifier == unique_identifier:
@ -991,9 +1007,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
""" """
Called by the SlideController to select the previous service item. Called by the SlideController to select the previous service item.
``last_slide`` :param last_slide: Is this the last slide in the service_item.
Is this the last slide in the service_item
""" """
if not self.service_manager_list.selected_items(): if not self.service_manager_list.selected_items():
return return
@ -1024,12 +1038,17 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_set_item(self, message, field=None): def on_set_item(self, message, field=None):
""" """
Called by a signal to select a specific item and make it live usually from remote. Called by a signal to select a specific item and make it live usually from remote.
:param field:
:param message: The data passed in from a remove message
""" """
self.set_item(int(message)) self.set_item(int(message))
def set_item(self, index): def set_item(self, index):
""" """
Makes a specific item in the service live. Makes a specific item in the service live.
:param index: The index of the service item list to be actioned.
""" """
if 0 >= index < self.service_manager_list.topLevelItemCount(): if 0 >= index < self.service_manager_list.topLevelItemCount():
item = self.service_manager_list.topLevelItem(index) item = self.service_manager_list.topLevelItem(index)
@ -1059,6 +1078,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_collapse_all(self, field=None): def on_collapse_all(self, field=None):
""" """
Collapse all the service items. Collapse all the service items.
:param field:
""" """
for item in self.service_items: for item in self.service_items:
item['expanded'] = False item['expanded'] = False
@ -1067,6 +1087,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def collapsed(self, item): def collapsed(self, item):
""" """
Record if an item is collapsed. Used when repainting the list to get the correct state. Record if an item is collapsed. Used when repainting the list to get the correct state.
:param item: The service item to be checked
""" """
pos = item.data(0, QtCore.Qt.UserRole) pos = item.data(0, QtCore.Qt.UserRole)
self.service_items[pos - 1]['expanded'] = False self.service_items[pos - 1]['expanded'] = False
@ -1074,6 +1096,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_expand_all(self, field=None): def on_expand_all(self, field=None):
""" """
Collapse all the service items. Collapse all the service items.
:param field:
""" """
for item in self.service_items: for item in self.service_items:
item['expanded'] = True item['expanded'] = True
@ -1082,6 +1105,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def expanded(self, item): def expanded(self, item):
""" """
Record if an item is collapsed. Used when repainting the list to get the correct state. Record if an item is collapsed. Used when repainting the list to get the correct state.
:param item: The service item to be checked
""" """
pos = item.data(0, QtCore.Qt.UserRole) pos = item.data(0, QtCore.Qt.UserRole)
self.service_items[pos - 1]['expanded'] = True self.service_items[pos - 1]['expanded'] = True
@ -1089,6 +1114,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_service_top(self, field=None): def on_service_top(self, field=None):
""" """
Move the current ServiceItem to the top of the list. Move the current ServiceItem to the top of the list.
:param field:
""" """
item, child = self.find_service_item() item, child = self.find_service_item()
if item < len(self.service_items) and item != -1: if item < len(self.service_items) and item != -1:
@ -1101,6 +1127,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_service_up(self, field=None): def on_service_up(self, field=None):
""" """
Move the current ServiceItem one position up in the list. Move the current ServiceItem one position up in the list.
:param field:
""" """
item, child = self.find_service_item() item, child = self.find_service_item()
if item > 0: if item > 0:
@ -1113,6 +1140,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_service_down(self, field=None): def on_service_down(self, field=None):
""" """
Move the current ServiceItem one position down in the list. Move the current ServiceItem one position down in the list.
:param field:
""" """
item, child = self.find_service_item() item, child = self.find_service_item()
if item < len(self.service_items) and item != -1: if item < len(self.service_items) and item != -1:
@ -1125,6 +1153,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_service_end(self, field=None): def on_service_end(self, field=None):
""" """
Move the current ServiceItem to the bottom of the list. Move the current ServiceItem to the bottom of the list.
:param field:
""" """
item, child = self.find_service_item() item, child = self.find_service_item()
if item < len(self.service_items) and item != -1: if item < len(self.service_items) and item != -1:
@ -1137,6 +1166,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_delete_from_service(self, field=None): def on_delete_from_service(self, field=None):
""" """
Remove the current ServiceItem from the list. Remove the current ServiceItem from the list.
:param field:
""" """
item = self.find_service_item()[0] item = self.find_service_item()[0]
if item != -1: if item != -1:
@ -1149,11 +1179,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
Clear the existing service list and prepaint all the items. This is used when moving items as the move takes Clear the existing service list and prepaint all the items. This is used when moving items as the move takes
place in a supporting list, and when regenerating all the items due to theme changes. place in a supporting list, and when regenerating all the items due to theme changes.
``service_item`` :param service_item: The item which changed. (int)
The item which changed. (int) :param service_item_child: The child of the ``service_item``, which will be selected. (int)
``service_item_child``
The child of the ``service_item``, which will be selected. (int)
""" """
# Correct order of items in array # Correct order of items in array
count = 1 count = 1
@ -1235,6 +1262,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_theme_combo_box_selected(self, current_index): def on_theme_combo_box_selected(self, current_index):
""" """
Set the theme for the current service. Set the theme for the current service.
:param current_index: The combo box index for the selected item
""" """
self.service_theme = self.theme_combo_box.currentText() self.service_theme = self.theme_combo_box.currentText()
self.renderer.set_service_theme(self.service_theme) self.renderer.set_service_theme(self.service_theme)
@ -1252,6 +1281,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def regenerate_service_items(self, changed=False): def regenerate_service_items(self, changed=False):
""" """
Rebuild the service list as things have changed and a repaint is the easiest way to do this. Rebuild the service list as things have changed and a repaint is the easiest way to do this.
:param changed: True if the list has changed for new / removed items. False for a theme change.
""" """
self.application.set_busy_cursor() self.application.set_busy_cursor()
# force reset of renderer as theme data has changed # force reset of renderer as theme data has changed
@ -1288,6 +1319,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def replace_service_item(self, new_item): def replace_service_item(self, new_item):
""" """
Using the service item passed replace the one with the same edit id if found. Using the service item passed replace the one with the same edit id if found.
:param new_item: a new service item to up date an existing one.
""" """
for item_count, item in enumerate(self.service_items): for item_count, item in enumerate(self.service_items):
if item['service_item'].edit_id == new_item.edit_id and item['service_item'].name == new_item.name: if item['service_item'].edit_id == new_item.edit_id and item['service_item'].name == new_item.name:
@ -1302,29 +1335,30 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
""" """
Add a Service item to the list Add a Service item to the list
``item`` :param item: Service Item to be added
Service Item to be added :param rebuild: Do we need to rebuild the live display (Default False)
:param expand: Override the default expand settings. (Tristate)
``expand`` :param replace: Is the service item a replacement (Default False)
Override the default expand settings. (Tristate) :param repaint: Do we need to repaint the service item list (Default True)
:param selected: Has the item been selected (Default False)
""" """
# if not passed set to config value # if not passed set to config value
if expand is None: if expand is None:
expand = Settings().value('advanced/expand service item') expand = Settings().value('advanced/expand service item')
item.from_service = True item.from_service = True
if replace: if replace:
sitem, child = self.find_service_item() s_item, child = self.find_service_item()
item.merge(self.service_items[sitem]['service_item']) item.merge(self.service_items[s_item]['service_item'])
self.service_items[sitem]['service_item'] = item self.service_items[s_item]['service_item'] = item
self.repaint_service_list(sitem, child) self.repaint_service_list(s_item, child)
self.live_controller.replace_service_manager_item(item) self.live_controller.replace_service_manager_item(item)
else: else:
item.render() item.render()
# nothing selected for dnd # nothing selected for dnd
if self.drop_position == 0: if self.drop_position == 0:
if isinstance(item, list): if isinstance(item, list):
for inditem in item: for ind_item in item:
self.service_items.append({'service_item': inditem, self.service_items.append({'service_item': ind_item,
'order': len(self.service_items) + 1, 'order': len(self.service_items) + 1,
'expanded': expand, 'selected': selected}) 'expanded': expand, 'selected': selected})
else: else:
@ -1371,6 +1405,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_make_live(self, field=None): def on_make_live(self, field=None):
""" """
Send the current item to the Live slide controller but triggered by a tablewidget click event. Send the current item to the Live slide controller but triggered by a tablewidget click event.
:param field:
""" """
self.make_live() self.make_live()
@ -1378,8 +1413,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
""" """
Send the current item to the Live slide controller Send the current item to the Live slide controller
``row`` :param row: Row number to be displayed if from preview. -1 is passed if the value is not set
Row number to be displayed if from preview. -1 is passed if the value is not set
""" """
item, child = self.find_service_item() item, child = self.find_service_item()
# No items in service # No items in service
@ -1408,6 +1442,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def remote_edit(self, field=None): def remote_edit(self, field=None):
""" """
Triggers a remote edit to a plugin to allow item to be edited. Triggers a remote edit to a plugin to allow item to be edited.
:param field:
""" """
item = self.find_service_item()[0] item = self.find_service_item()[0]
if self.service_items[item]['service_item'].is_capable(ItemCapabilities.CanEdit): if self.service_items[item]['service_item'].is_capable(ItemCapabilities.CanEdit):
@ -1419,6 +1454,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def create_custom(self, field=None): def create_custom(self, field=None):
""" """
Saves the current text item as a custom slide Saves the current text item as a custom slide
:param field:
""" """
item = self.find_service_item()[0] item = self.find_service_item()[0]
Registry().execute('custom_create_from_service', self.service_items[item]['service_item']) Registry().execute('custom_create_from_service', self.service_items[item]['service_item'])
@ -1452,8 +1488,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
Receive drop event and trigger an internal event to get the plugins to build and push the correct service item. Receive drop event and trigger an internal event to get the plugins to build and push the correct service item.
The drag event payload carries the plugin name The drag event payload carries the plugin name
``event`` :param event: Handle of the event passed
Handle of the event pint passed
""" """
link = event.mimeData() link = event.mimeData()
if link.hasUrls(): if link.hasUrls():
@ -1512,8 +1547,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
""" """
Called from ThemeManager when the Themes have changed Called from ThemeManager when the Themes have changed
``theme_list`` :param theme_list: A list of current themes to be displayed
A list of current themes to be displayed
""" """
self.theme_combo_box.clear() self.theme_combo_box.clear()
self.theme_menu.clear() self.theme_menu.clear()
@ -1539,6 +1573,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_theme_change_action(self, field=None): def on_theme_change_action(self, field=None):
""" """
Handles theme change events Handles theme change events
:param field:
""" """
theme = self.sender().objectName() theme = self.sender().objectName()
# No object name means that the "Default" theme is supposed to be used. # No object name means that the "Default" theme is supposed to be used.
@ -1551,6 +1587,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def _get_parent_item_data(self, item): def _get_parent_item_data(self, item):
""" """
Finds and returns the parent item for any item Finds and returns the parent item for any item
:param item: The service item list item to be checked.
""" """
parent_item = item.parent() parent_item = item.parent()
if parent_item is None: if parent_item is None:

View File

@ -53,8 +53,8 @@ class Ui_ThemeManager(object):
def setup_ui(self, widget): def setup_ui(self, widget):
""" """
Define the UI Define the UI
:param widget: The screen object the the dialog is to be attached to.
""" """
# start with the layout # start with the layout
self.layout = QtGui.QVBoxLayout(widget) self.layout = QtGui.QVBoxLayout(widget)
self.layout.setSpacing(0) self.layout.setSpacing(0)
@ -173,6 +173,9 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
""" """
If Default theme selected remove delete button. If Default theme selected remove delete button.
Note for some reason a dummy field is required. Nothing is passed! Note for some reason a dummy field is required. Nothing is passed!
:param field:
:param item: Service Item to process
""" """
if item is None: if item is None:
return return
@ -186,8 +189,9 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def context_menu(self, point): def context_menu(self, point):
""" """
Build the Right Click Context menu and set state depending on Build the Right Click Context menu and set state depending on the type of theme.
the type of theme.
:param point: The position of the mouse so the correct item can be found.
""" """
item = self.theme_list_widget.itemAt(point) item = self.theme_list_widget.itemAt(point)
if item is None: if item is None:
@ -221,8 +225,9 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def change_global_from_screen(self, index=-1): def change_global_from_screen(self, index=-1):
""" """
Change the global theme when a theme is double clicked upon in the Change the global theme when a theme is double clicked upon in the Theme Manager list.
Theme Manager list
:param index:
""" """
selected_row = self.theme_list_widget.currentRow() selected_row = self.theme_list_widget.currentRow()
for count in range(0, self.theme_list_widget.count()): for count in range(0, self.theme_list_widget.count()):
@ -242,8 +247,9 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def on_add_theme(self, field=None): def on_add_theme(self, field=None):
""" """
Loads a new theme with the default settings and then launches the theme Loads a new theme with the default settings and then launches the theme editing form for the user to make
editing form for the user to make their customisations. their customisations.
:param field:
""" """
theme = ThemeXML() theme = ThemeXML()
theme.set_default_header_footer() theme.set_default_header_footer()
@ -254,6 +260,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def on_rename_theme(self, field=None): def on_rename_theme(self, field=None):
""" """
Renames an existing theme to a new name Renames an existing theme to a new name
:param field:
""" """
if self._validate_theme_action(translate('OpenLP.ThemeManager', 'You must select a theme to rename.'), if self._validate_theme_action(translate('OpenLP.ThemeManager', 'You must select a theme to rename.'),
translate('OpenLP.ThemeManager', 'Rename Confirmation'), translate('OpenLP.ThemeManager', 'Rename Confirmation'),
@ -278,6 +285,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def on_copy_theme(self, field=None): def on_copy_theme(self, field=None):
""" """
Copies an existing theme to a new name Copies an existing theme to a new name
:param field:
""" """
item = self.theme_list_widget.currentItem() item = self.theme_list_widget.currentItem()
old_theme_name = item.data(QtCore.Qt.UserRole) old_theme_name = item.data(QtCore.Qt.UserRole)
@ -292,6 +300,9 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def clone_theme_data(self, theme_data, new_theme_name): def clone_theme_data(self, theme_data, new_theme_name):
""" """
Takes a theme and makes a new copy of it as well as saving it. Takes a theme and makes a new copy of it as well as saving it.
:param theme_data: The theme to be used
:param new_theme_name: The new theme name to save the data to
""" """
save_to = None save_to = None
save_from = None save_from = None
@ -307,6 +318,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
""" """
Loads the settings for the theme that is to be edited and launches the Loads the settings for the theme that is to be edited and launches the
theme editing form so the user can make their changes. theme editing form so the user can make their changes.
:param field:
""" """
if check_item_selected(self.theme_list_widget, if check_item_selected(self.theme_list_widget,
translate('OpenLP.ThemeManager', 'You must select a theme to edit.')): translate('OpenLP.ThemeManager', 'You must select a theme to edit.')):
@ -322,7 +334,8 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def on_delete_theme(self, field=None): def on_delete_theme(self, field=None):
""" """
Delete a theme Delete a theme triggered by the UI.
:param field:
""" """
if self._validate_theme_action(translate('OpenLP.ThemeManager', 'You must select a theme to delete.'), if self._validate_theme_action(translate('OpenLP.ThemeManager', 'You must select a theme to delete.'),
translate('OpenLP.ThemeManager', 'Delete Confirmation'), translate('OpenLP.ThemeManager', 'Delete Confirmation'),
@ -341,8 +354,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
""" """
Delete a theme. Delete a theme.
``theme`` :param theme: The theme to delete.
The theme to delete.
""" """
self.theme_list.remove(theme) self.theme_list.remove(theme)
thumb = '%s.png' % theme thumb = '%s.png' % theme
@ -358,6 +370,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def on_export_theme(self, field=None): def on_export_theme(self, field=None):
""" """
Export the theme in a zip file Export the theme in a zip file
:param field:
""" """
item = self.theme_list_widget.currentItem() item = self.theme_list_widget.currentItem()
if item is None: if item is None:
@ -399,6 +412,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
""" """
Opens a file dialog to select the theme file(s) to import before attempting to extract OpenLP themes from Opens a file dialog to select the theme file(s) to import before attempting to extract OpenLP themes from
those files. This process will load both OpenLP version 1 and version 2 themes. those files. This process will load both OpenLP version 1 and version 2 themes.
:param field:
""" """
files = FileDialog.getOpenFileNames(self, files = FileDialog.getOpenFileNames(self,
translate('OpenLP.ThemeManager', 'Select Theme Import File'), translate('OpenLP.ThemeManager', 'Select Theme Import File'),
@ -483,8 +497,8 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
""" """
Returns a theme object from an XML file Returns a theme object from an XML file
``theme_name`` :param theme_name: Name of the theme to load from file
Name of the theme to load from file :return The theme object.
""" """
self.log_debug('get theme data for theme %s' % theme_name) self.log_debug('get theme data for theme %s' % theme_name)
xml_file = os.path.join(self.path, str(theme_name), str(theme_name) + '.xml') xml_file = os.path.join(self.path, str(theme_name), str(theme_name) + '.xml')
@ -498,6 +512,8 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def over_write_message_box(self, theme_name): def over_write_message_box(self, theme_name):
""" """
Display a warning box to the user that a theme already exists Display a warning box to the user that a theme already exists
:param theme_name: Name of the theme.
:return Confirm if the theme is to be overeritten.
""" """
ret = QtGui.QMessageBox.question(self, translate('OpenLP.ThemeManager', 'Theme Already Exists'), ret = QtGui.QMessageBox.question(self, translate('OpenLP.ThemeManager', 'Theme Already Exists'),
translate('OpenLP.ThemeManager', translate('OpenLP.ThemeManager',
@ -510,11 +526,12 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def unzip_theme(self, file_name, directory): def unzip_theme(self, file_name, directory):
""" """
Unzip the theme, remove the preview file if stored Unzip the theme, remove the preview file if stored. Generate a new preview file. Check the XML theme version
Generate a new preview file. Check the XML theme version and upgrade if and upgrade if necessary.
necessary. :param file_name:
:param directory:
""" """
self.log_debug('Unzipping theme %s', file_name) self.log_debug('Unzipping theme %s' % file_name)
file_name = str(file_name) file_name = str(file_name)
theme_zip = None theme_zip = None
out_file = None out_file = None
@ -583,8 +600,8 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
""" """
Check if theme already exists and displays error message Check if theme already exists and displays error message
``theme_name`` :param theme_name: Name of the Theme to test
Name of the Theme to test :return True or False if theme exists
""" """
theme_dir = os.path.join(self.path, theme_name) theme_dir = os.path.join(self.path, theme_name)
if os.path.exists(theme_dir): if os.path.exists(theme_dir):
@ -596,7 +613,11 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def save_theme(self, theme, image_from, image_to): def save_theme(self, theme, image_from, image_to):
""" """
Called by thememaintenance Dialog to save the theme and to trigger the reload of the theme list Called by theme maintenance Dialog to save the theme and to trigger the reload of the theme list
:param theme: The theme data object.
:param image_from: Where the theme image is currently located.
:param image_to: Where the Theme Image is to be saved to
""" """
self._write_theme(theme, image_from, image_to) self._write_theme(theme, image_from, image_to)
if theme.background_type == BackgroundType.to_string(BackgroundType.Image): if theme.background_type == BackgroundType.to_string(BackgroundType.Image):
@ -608,6 +629,10 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def _write_theme(self, theme, image_from, image_to): def _write_theme(self, theme, image_from, image_to):
""" """
Writes the theme to the disk and handles the background image if necessary Writes the theme to the disk and handles the background image if necessary
:param theme: The theme data object.
:param image_from: Where the theme image is currently located.
:param image_to: Where the Theme Image is to be saved to
""" """
name = theme.theme_name name = theme.theme_name
theme_pretty_xml = theme.extract_formatted_xml() theme_pretty_xml = theme.extract_formatted_xml()
@ -637,6 +662,9 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def generate_and_save_image(self, name, theme): def generate_and_save_image(self, name, theme):
""" """
Generate and save a preview image Generate and save a preview image
:param name: The name of the theme.
:param theme: The theme data object.
""" """
frame = self.generate_image(theme) frame = self.generate_image(theme)
sample_path_name = os.path.join(self.path, name + '.png') sample_path_name = os.path.join(self.path, name + '.png')
@ -661,11 +689,8 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
""" """
Call the renderer to build a Sample Image Call the renderer to build a Sample Image
``theme_data`` :param theme_data: The theme to generated a preview for.
The theme to generated a preview for. :param force_page: Flag to tell message lines per page need to be generated.
``force_page``
Flag to tell message lines per page need to be generated.
""" """
return self.renderer.generate_preview(theme_data, force_page) return self.renderer.generate_preview(theme_data, force_page)
@ -673,26 +698,33 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
""" """
Return an image representing the look of the theme Return an image representing the look of the theme
``theme`` :param theme: The theme to return the image for.
The theme to return the image for
""" """
return os.path.join(self.path, theme + '.png') return os.path.join(self.path, theme + '.png')
def _create_theme_from_xml(self, theme_xml, path): def _create_theme_from_xml(self, theme_xml, image_path):
""" """
Return a theme object using information parsed from XML Return a theme object using information parsed from XML
``theme_xml`` :param theme_xml: The Theme data object.
The XML data to load into the theme :param image_path: Where the theme image is stored
:return Theme data.
""" """
theme = ThemeXML() theme = ThemeXML()
theme.parse(theme_xml) theme.parse(theme_xml)
theme.extend_image_filename(path) theme.extend_image_filename(image_path)
return theme return theme
def _validate_theme_action(self, select_text, confirm_title, confirm_text, test_plugin=True, confirm=True): def _validate_theme_action(self, select_text, confirm_title, confirm_text, test_plugin=True, confirm=True):
""" """
Check to see if theme has been selected and the destructive action is allowed. Check to see if theme has been selected and the destructive action is allowed.
:param select_text: Text for message box if no item selected.
:param confirm_title: Confirm message title to be displayed.
:param confirm_text: Confirm message text to be displayed.
:param test_plugin: Do we check the plugins for theme usage.
:param confirm: Do we display a confirm box before run checks.
:return True or False depending on the validity.
""" """
self.global_theme = Settings().value(self.settings_section + '/global theme') self.global_theme = Settings().value(self.settings_section + '/global theme')
if check_item_selected(self.theme_list_widget, select_text): if check_item_selected(self.theme_list_widget, select_text):

View File

@ -127,9 +127,15 @@ __default_settings__ = {
class AlertsPlugin(Plugin): class AlertsPlugin(Plugin):
"""
The Alerts Plugin Class
"""
log.info('Alerts Plugin loaded') log.info('Alerts Plugin loaded')
def __init__(self): def __init__(self):
"""
Class __init__ method
"""
super(AlertsPlugin, self).__init__('alerts', __default_settings__, settings_tab_class=AlertsTab) super(AlertsPlugin, self).__init__('alerts', __default_settings__, settings_tab_class=AlertsTab)
self.weight = -3 self.weight = -3
self.icon_path = ':/plugins/plugin_alerts.png' self.icon_path = ':/plugins/plugin_alerts.png'
@ -142,17 +148,21 @@ class AlertsPlugin(Plugin):
""" """
Give the alerts plugin the opportunity to add items to the **Tools** menu. Give the alerts plugin the opportunity to add items to the **Tools** menu.
``tools_menu`` :param tools_menu:
The actual **Tools** menu item, so that your actions can use it as their parent. The actual **Tools** menu item, so that your actions can use it as their parent.
""" """
log.info('add tools menu') log.info('add tools menu')
self.tools_alert_item = create_action(tools_menu, 'toolsAlertItem', self.tools_alert_item = create_action(tools_menu, 'toolsAlertItem',
text=translate('AlertsPlugin', '&Alert'), icon=':/plugins/plugin_alerts.png', text=translate('AlertsPlugin', '&Alert'),
statustip=translate('AlertsPlugin', 'Show an alert message.'), icon=':/plugins/plugin_alerts.png',
visible=False, can_shortcuts=True, triggers=self.on_alerts_trigger) statustip=translate('AlertsPlugin', 'Show an alert message.'),
visible=False, can_shortcuts=True, triggers=self.on_alerts_trigger)
self.main_window.tools_menu.addAction(self.tools_alert_item) self.main_window.tools_menu.addAction(self.tools_alert_item)
def initialise(self): def initialise(self):
"""
Initialise plugin
"""
log.info('Alerts Initialising') log.info('Alerts Initialising')
super(AlertsPlugin, self).initialise() super(AlertsPlugin, self).initialise()
self.tools_alert_item.setVisible(True) self.tools_alert_item.setVisible(True)
@ -171,16 +181,27 @@ class AlertsPlugin(Plugin):
action_list.remove_action(self.tools_alert_item, 'Tools') action_list.remove_action(self.tools_alert_item, 'Tools')
def toggle_alerts_state(self): def toggle_alerts_state(self):
"""
Switch the alerts state
"""
self.alerts_active = not self.alerts_active self.alerts_active = not self.alerts_active
Settings().setValue(self.settings_section + '/active', self.alerts_active) Settings().setValue(self.settings_section + '/active', self.alerts_active)
def on_alerts_trigger(self): def on_alerts_trigger(self):
"""
Start of the Alerts dialog triggered from the main menu.
"""
self.alert_form.load_list() self.alert_form.load_list()
self.alert_form.exec_() self.alert_form.exec_()
def about(self): def about(self):
"""
Plugin Alerts about method
:return: text
"""
about_text = translate('AlertsPlugin', '<strong>Alerts Plugin</strong>' about_text = translate('AlertsPlugin', '<strong>Alerts Plugin</strong>'
'<br />The alert plugin controls the displaying of nursery alerts on the display screen.') '<br />The alert plugin controls the displaying of alerts on the display screen.')
return about_text return about_text
def set_plugin_text_strings(self): def set_plugin_text_strings(self):
@ -209,7 +230,7 @@ class AlertsPlugin(Plugin):
""" """
align = VerticalType.Names[self.settings_tab.location] align = VerticalType.Names[self.settings_tab.location]
return CSS % (align, self.settings_tab.font_face, self.settings_tab.font_size, self.settings_tab.font_color, return CSS % (align, self.settings_tab.font_face, self.settings_tab.font_size, self.settings_tab.font_color,
self.settings_tab.background_color) self.settings_tab.background_color)
def get_display_html(self): def get_display_html(self):
""" """
@ -226,5 +247,5 @@ class AlertsPlugin(Plugin):
""" """
align = VerticalType.Names[self.settings_tab.location] align = VerticalType.Names[self.settings_tab.location]
frame.evaluateJavaScript('update_css("%s", "%s", "%s", "%s", "%s")' % frame.evaluateJavaScript('update_css("%s", "%s", "%s", "%s", "%s")' %
(align, self.settings_tab.font_face, self.settings_tab.font_size, (align, self.settings_tab.font_face, self.settings_tab.font_size,
self.settings_tab.font_color, self.settings_tab.background_color)) self.settings_tab.font_color, self.settings_tab.background_color))

View File

@ -36,6 +36,11 @@ from openlp.core.lib.ui import create_button, create_button_box
class Ui_AlertDialog(object): class Ui_AlertDialog(object):
def setupUi(self, alert_dialog): def setupUi(self, alert_dialog):
"""
Setup the Alert UI dialog
:param alert_dialog:
"""
alert_dialog.setObjectName('alert_dialog') alert_dialog.setObjectName('alert_dialog')
alert_dialog.resize(400, 300) alert_dialog.resize(400, 300)
alert_dialog.setWindowIcon(build_icon(':/icon/openlp-logo-16x16.png')) alert_dialog.setWindowIcon(build_icon(':/icon/openlp-logo-16x16.png'))
@ -72,20 +77,24 @@ class Ui_AlertDialog(object):
self.save_button.setObjectName('save_button') self.save_button.setObjectName('save_button')
self.manage_button_layout.addWidget(self.save_button) self.manage_button_layout.addWidget(self.save_button)
self.delete_button = create_button(alert_dialog, 'delete_button', role='delete', enabled=False, self.delete_button = create_button(alert_dialog, 'delete_button', role='delete', enabled=False,
click=alert_dialog.on_delete_button_clicked) click=alert_dialog.on_delete_button_clicked)
self.manage_button_layout.addWidget(self.delete_button) self.manage_button_layout.addWidget(self.delete_button)
self.manage_button_layout.addStretch() self.manage_button_layout.addStretch()
self.alert_dialog_layout.addLayout(self.manage_button_layout, 1, 1) self.alert_dialog_layout.addLayout(self.manage_button_layout, 1, 1)
display_icon = build_icon(':/general/general_live.png') display_icon = build_icon(':/general/general_live.png')
self.display_button = create_button(alert_dialog, 'display_button', icon=display_icon, enabled=False) self.display_button = create_button(alert_dialog, 'display_button', icon=display_icon, enabled=False)
self.display_close_button = create_button(alert_dialog, 'display_close_button', icon=display_icon, self.display_close_button = create_button(alert_dialog, 'display_close_button', icon=display_icon,
enabled=False) enabled=False)
self.button_box = create_button_box(alert_dialog, 'button_box', ['close'], self.button_box = create_button_box(alert_dialog, 'button_box', ['close'],
[self.display_button, self.display_close_button]) [self.display_button, self.display_close_button])
self.alert_dialog_layout.addWidget(self.button_box, 2, 0, 1, 2) self.alert_dialog_layout.addWidget(self.button_box, 2, 0, 1, 2)
self.retranslateUi(alert_dialog) self.retranslateUi(alert_dialog)
def retranslateUi(self, alert_dialog): def retranslateUi(self, alert_dialog):
"""
Retranslate the UI strings
:param alert_dialog:
"""
alert_dialog.setWindowTitle(translate('AlertsPlugin.AlertForm', 'Alert Message')) alert_dialog.setWindowTitle(translate('AlertsPlugin.AlertForm', 'Alert Message'))
self.alert_entry_label.setText(translate('AlertsPlugin.AlertForm', 'Alert &text:')) self.alert_entry_label.setText(translate('AlertsPlugin.AlertForm', 'Alert &text:'))
self.alert_parameter.setText(translate('AlertsPlugin.AlertForm', '&Parameter:')) self.alert_parameter.setText(translate('AlertsPlugin.AlertForm', '&Parameter:'))

View File

@ -113,9 +113,10 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
""" """
if not self.alert_text_edit.text(): if not self.alert_text_edit.text():
QtGui.QMessageBox.information(self, QtGui.QMessageBox.information(self,
translate('AlertsPlugin.AlertForm', 'New Alert'), translate('AlertsPlugin.AlertForm', 'New Alert'),
translate('AlertsPlugin.AlertForm', 'You haven\'t specified any text for your alert. \n' translate('AlertsPlugin.AlertForm',
'Please type in some text before clicking New.')) 'You haven\'t specified any text for your alert. \n'
'Please type in some text before clicking New.'))
else: else:
alert = AlertItem() alert = AlertItem()
alert.text = self.alert_text_edit.text() alert.text = self.alert_text_edit.text()
@ -153,10 +154,10 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
List item has been double clicked to display it. List item has been double clicked to display it.
""" """
item = self.alert_list_widget.selectedIndexes()[0] item = self.alert_list_widget.selectedIndexes()[0]
bitem = self.alert_list_widget.item(item.row()) list_item = self.alert_list_widget.item(item.row())
self.trigger_alert(bitem.text()) self.trigger_alert(list_item.text())
self.alert_text_edit.setText(bitem.text()) self.alert_text_edit.setText(list_item.text())
self.item_id = bitem.data(QtCore.Qt.UserRole) self.item_id = list_item.data(QtCore.Qt.UserRole)
self.save_button.setEnabled(False) self.save_button.setEnabled(False)
def on_single_click(self): def on_single_click(self):
@ -164,9 +165,9 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
List item has been single clicked to add it to the edit field so it can be changed. List item has been single clicked to add it to the edit field so it can be changed.
""" """
item = self.alert_list_widget.selectedIndexes()[0] item = self.alert_list_widget.selectedIndexes()[0]
bitem = self.alert_list_widget.item(item.row()) list_item = self.alert_list_widget.item(item.row())
self.alert_text_edit.setText(bitem.text()) self.alert_text_edit.setText(list_item.text())
self.item_id = bitem.data(QtCore.Qt.UserRole) self.item_id = list_item.data(QtCore.Qt.UserRole)
# If the alert does not contain '<>' we clear the ParameterEdit field. # If the alert does not contain '<>' we clear the ParameterEdit field.
if self.alert_text_edit.text().find('<>') == -1: if self.alert_text_edit.text().find('<>') == -1:
self.parameter_edit.setText('') self.parameter_edit.setText('')
@ -182,20 +183,25 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
if not text: if not text:
return False return False
# We found '<>' in the alert text, but the ParameterEdit field is empty. # We found '<>' in the alert text, but the ParameterEdit field is empty.
if text.find('<>') != -1 and not self.parameter_edit.text() and QtGui.QMessageBox.question(self, if text.find('<>') != -1 and not self.parameter_edit.text() and \
translate('AlertsPlugin.AlertForm', 'No Parameter Found'), QtGui.QMessageBox.question(self,
translate('AlertsPlugin.AlertForm', 'You have not entered a parameter to be replaced.\n' translate('AlertsPlugin.AlertForm', 'No Parameter Found'),
'Do you want to continue anyway?'), translate('AlertsPlugin.AlertForm',
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No: '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.parameter_edit.setFocus() self.parameter_edit.setFocus()
return False return False
# The ParameterEdit field is not empty, but we have not found '<>' # The ParameterEdit field is not empty, but we have not found '<>'
# in the alert text. # in the alert text.
elif text.find('<>') == -1 and self.parameter_edit.text() and QtGui.QMessageBox.question(self, elif text.find('<>') == -1 and self.parameter_edit.text() and \
translate('AlertsPlugin.AlertForm', 'No Placeholder Found'), QtGui.QMessageBox.question(self,
translate('AlertsPlugin.AlertForm', 'The alert text does not contain \'<>\'.\n' translate('AlertsPlugin.AlertForm', 'No Placeholder Found'),
'Do you want to continue anyway?'), translate('AlertsPlugin.AlertForm', 'The alert text does not contain \'<>\'.\n'
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No: 'Do you want to continue anyway?'),
QtGui.QMessageBox.StandardButtons(
QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No:
self.parameter_edit.setFocus() self.parameter_edit.setFocus()
return False return False
text = text.replace('<>', self.parameter_edit.text()) text = text.replace('<>', self.parameter_edit.text())

View File

@ -67,8 +67,8 @@ class AlertsManager(QtCore.QObject):
""" """
Called from the Alert Tab to display an alert. Called from the Alert Tab to display an alert.
``text`` :param text:
display text The text to display
""" """
log.debug('display alert called %s' % text) log.debug('display alert called %s' % text)
if text: if text:
@ -98,7 +98,7 @@ class AlertsManager(QtCore.QObject):
""" """
Time has finished so if our time then request the next Alert if there is one and reset the timer. Time has finished so if our time then request the next Alert if there is one and reset the timer.
``event`` :param event:
the QT event that has been triggered. the QT event that has been triggered.
""" """
log.debug('timer event') log.debug('timer event')

View File

@ -114,6 +114,9 @@ class AlertsTab(SettingsTab):
self.font_preview.setText(UiStrings().OLPV2x) self.font_preview.setText(UiStrings().OLPV2x)
def on_background_color_button_clicked(self): def on_background_color_button_clicked(self):
"""
The background color has been changed.
"""
new_color = QtGui.QColorDialog.getColor(QtGui.QColor(self.background_color), self) new_color = QtGui.QColorDialog.getColor(QtGui.QColor(self.background_color), self)
if new_color.isValid(): if new_color.isValid():
self.background_color = new_color.name() self.background_color = new_color.name()
@ -121,9 +124,15 @@ class AlertsTab(SettingsTab):
self.update_display() self.update_display()
def on_font_combo_box_clicked(self): def on_font_combo_box_clicked(self):
"""
The Font Combo was changed.
"""
self.update_display() self.update_display()
def on_font_color_button_clicked(self): def on_font_color_button_clicked(self):
"""
The Font Color button has clicked.
"""
new_color = QtGui.QColorDialog.getColor(QtGui.QColor(self.font_color), self) new_color = QtGui.QColorDialog.getColor(QtGui.QColor(self.font_color), self)
if new_color.isValid(): if new_color.isValid():
self.font_color = new_color.name() self.font_color = new_color.name()
@ -131,14 +140,24 @@ class AlertsTab(SettingsTab):
self.update_display() self.update_display()
def on_timeout_spin_box_changed(self): def on_timeout_spin_box_changed(self):
"""
The Time out spin box has changed.
"""
self.timeout = self.timeout_spin_box.value() self.timeout = self.timeout_spin_box.value()
self.changed = True self.changed = True
def on_font_size_spin_box_changed(self): def on_font_size_spin_box_changed(self):
"""
The font size spin box has changed.
"""
self.font_size = self.font_size_spin_box.value() self.font_size = self.font_size_spin_box.value()
self.update_display() self.update_display()
def load(self): def load(self):
"""
Load the settings into the UI.
"""
settings = Settings() settings = Settings()
settings.beginGroup(self.settings_section) settings.beginGroup(self.settings_section)
self.timeout = settings.value('timeout') self.timeout = settings.value('timeout')
@ -160,6 +179,9 @@ class AlertsTab(SettingsTab):
self.changed = False self.changed = False
def save(self): def save(self):
"""
Save the changes on exit of the Settings dialog.
"""
settings = Settings() settings = Settings()
settings.beginGroup(self.settings_section) settings.beginGroup(self.settings_section)
# Check value has changed as no event handles this field # Check value has changed as no event handles this field
@ -179,6 +201,9 @@ class AlertsTab(SettingsTab):
self.changed = False self.changed = False
def update_display(self): def update_display(self):
"""
Update the preview display after changes have been made,
"""
font = QtGui.QFont() font = QtGui.QFont()
font.setFamily(self.font_combo_box.currentFont().family()) font.setFamily(self.font_combo_box.currentFont().family())
font.setBold(True) font.setBold(True)

View File

@ -47,14 +47,14 @@ def init_schema(url):
""" """
Setup the alerts database connection and initialise the database schema Setup the alerts database connection and initialise the database schema
``url`` :param url:
The database to setup The database to setup
""" """
session, metadata = init_db(url) session, metadata = init_db(url)
alerts_table = Table('alerts', metadata, alerts_table = Table('alerts', metadata,
Column('id', types.Integer(), primary_key=True), Column('id', types.Integer(), primary_key=True),
Column('text', types.UnicodeText, nullable=False)) Column('text', types.UnicodeText, nullable=False))
mapper(AlertItem, alerts_table) mapper(AlertItem, alerts_table)