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
None.
``textfile``
The name of the file.
:param text_file: The name of the file.
:return The file as a single string
"""
if not os.path.isfile(text_file):
return False
@ -114,8 +114,8 @@ def str_to_bool(string_value):
"""
Convert a string version of a boolean into a real boolean.
``string_value``
The string value to examine and convert to a boolean type.
:param string_value: The string value to examine and convert to a boolean type.
:return The correct boolean value
"""
if isinstance(string_value, bool):
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
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
location like ``/path/to/file.png``. However, the **recommended** way is to specify a resource string.
:return The build icon.
"""
button_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.
``image``
The image to converted.
:param image: The image to converted.
"""
log.debug('image_to_byte - start')
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.
``image_path``
The image file to create the icon from.
``thumb_path``
The filename to save the thumbnail to.
``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.
:param image_path: 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``.
:param size: Allows to state a own size (QtCore.QSize) to use. Defaults to ``None``, which means that a default
height of 88 is used.
:return The final icon.
"""
ext = os.path.splitext(thumb_path)[1].lower()
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,
before checking the existence of the file.
``file_path``
The path to the file. The file **must** exist!
``thumb_path``
The path to the thumb.
:param file_path: 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.
"""
if not os.path.exists(thumb_path):
return False
@ -218,19 +210,12 @@ def resize_image(image_path, width, height, background='#000000'):
"""
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!
: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')
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
``list_widget``
The list to check for selected items
``message``
The message to give the user if no item is selected
:param list_widget: The list to check for selected items
:param message: The message to give the user if no item is selected
"""
if not list_widget.selectedIndexes():
QtGui.QMessageBox.information(list_widget.parent(),
@ -281,6 +263,8 @@ def check_item_selected(list_widget, message):
def clean_tags(text):
"""
Remove Tags from text for display
:param text: Text to be cleaned
"""
text = text.replace('<br>', '\n')
text = text.replace('{br}', '\n')
@ -294,6 +278,8 @@ def clean_tags(text):
def expand_tags(text):
"""
Expand tags HTML for display
:param text: The text to be expanded.
"""
for tag in FormattingTags.get_html_tags():
text = text.replace(tag['start tag'], tag['start html'])
@ -304,11 +290,11 @@ def expand_tags(text):
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
to QLocale::createSeparatedList which was introduced in Qt 4.8 and implements the algorithm from
http://www.unicode.org/reports/tr35/#ListPatterns
``string_list``
List of unicode strings
:param string_list: List of unicode strings
"""
if LooseVersion(Qt.PYQT_VERSION_STR) >= LooseVersion('4.9') and \
LooseVersion(Qt.qVersion()) >= LooseVersion('4.8'):

View File

@ -63,6 +63,7 @@ class ServiceManagerList(QtGui.QTreeWidget):
def keyPressEvent(self, event):
"""
Capture Key press and respond accordingly.
:param event:
"""
if isinstance(event, QtGui.QKeyEvent):
# 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
move just tell it what plugin to call
:param event:
"""
if event.buttons() != QtCore.Qt.LeftButton:
event.ignore()
@ -104,6 +106,7 @@ class Ui_ServiceManager(object):
def setup_ui(self, widget):
"""
Define the UI
:param widget:
"""
# start with the layout
self.layout = QtGui.QVBoxLayout(widget)
@ -298,8 +301,7 @@ class Ui_ServiceManager(object):
"""
Accept Drag events
``event``
Handle of the event passed
:param event: Handle of the event passed
"""
event.accept()
@ -327,6 +329,9 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
self.service_has_all_original_files = True
def bootstrap_initialise(self):
"""
To be called as part of initialisation
"""
self.setup_ui(self)
# 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)
@ -342,6 +347,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def set_modified(self, modified=True):
"""
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:
self.service_id += 1
@ -358,6 +365,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def set_file_name(self, file_name):
"""
Setter for service file.
:param file_name: The service file name
"""
self._file_name = str(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.
``suffix_list``
New Suffix's to be supported
:param suffix_list: New Suffix's to be supported
"""
for suffix in suffix_list:
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):
"""
Create a new service.
:param field:
"""
if self.is_modified():
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.
``load_file``
The service file to the loaded. Will be None is from menu so selection will be required.
:param load_file: The service file to the loaded. Will be None is from menu so selection will be required.
"""
if self.is_modified():
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):
"""
Load a recent file as the service triggered by mainwindow recent service list.
:param field:
"""
sender = self.sender()
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)
base_name = os.path.splitext(file_name)[0]
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)
service = []
write_list = []
@ -564,7 +573,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
shutil.copy(audio_from, save_file)
zip_file.write(audio_from, audio_to)
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'),
translate('OpenLP.ServiceManager', 'There was an error saving your file.'))
success = False
@ -686,6 +695,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def decide_save_method(self, field=None):
"""
Determine which type of save method to use.
:param field:
"""
if not self.file_name():
return self.save_file_as()
@ -697,6 +707,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def load_file(self, file_name):
"""
Load an existing service file
:param file_name:
"""
if not file_name:
return False
@ -719,7 +730,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
os_file = ucs_file.replace('/', os.path.sep)
if not os_file.startswith('audio'):
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_file.extract(zip_info, self.service_path)
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):
"""
The Right click context menu from the Serviceitem list
:param point: The location of the cursor.
"""
item = self.service_manager_list.itemAt(point)
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):
"""
Allow the service note to be edited
:param field:
"""
item = self.find_service_item()[0]
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):
"""
Opens a dialog to type in service item notes.
:param field:
"""
item = self.find_service_item()[0]
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):
"""
Toggle Auto play slide once. Inverts auto play once option for the item
:param field:
"""
item = self.find_service_item()[0]
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):
"""
Toggle Auto play slide loop.
:param field:
"""
item = self.find_service_item()[0]
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):
"""
Shows input dialog for enter interval in seconds for delay
:param field:
"""
item = self.find_service_item()[0]
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):
"""
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]
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
if relevant.
``unique_identifier``
Reference to the service_item
``row``
individual row number
:param unique_identifier: Reference to the service_item
:param row: individual row number
"""
for sitem in self.service_items:
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.
``last_slide``
Is this the last slide in the service_item
:param last_slide: Is this the last slide in the service_item.
"""
if not self.service_manager_list.selected_items():
return
@ -1024,12 +1038,17 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_set_item(self, message, field=None):
"""
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))
def set_item(self, index):
"""
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():
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):
"""
Collapse all the service items.
:param field:
"""
for item in self.service_items:
item['expanded'] = False
@ -1067,6 +1087,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def collapsed(self, item):
"""
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)
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):
"""
Collapse all the service items.
:param field:
"""
for item in self.service_items:
item['expanded'] = True
@ -1082,6 +1105,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def expanded(self, item):
"""
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)
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):
"""
Move the current ServiceItem to the top of the list.
:param field:
"""
item, child = self.find_service_item()
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):
"""
Move the current ServiceItem one position up in the list.
:param field:
"""
item, child = self.find_service_item()
if item > 0:
@ -1113,6 +1140,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_service_down(self, field=None):
"""
Move the current ServiceItem one position down in the list.
:param field:
"""
item, child = self.find_service_item()
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):
"""
Move the current ServiceItem to the bottom of the list.
:param field:
"""
item, child = self.find_service_item()
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):
"""
Remove the current ServiceItem from the list.
:param field:
"""
item = self.find_service_item()[0]
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
place in a supporting list, and when regenerating all the items due to theme changes.
``service_item``
The item which changed. (int)
``service_item_child``
The child of the ``service_item``, which will be selected. (int)
:param service_item: The item which changed. (int)
:param service_item_child: The child of the ``service_item``, which will be selected. (int)
"""
# Correct order of items in array
count = 1
@ -1235,6 +1262,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_theme_combo_box_selected(self, current_index):
"""
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.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):
"""
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()
# 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):
"""
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):
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
``item``
Service Item to be added
``expand``
Override the default expand settings. (Tristate)
:param item: 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)
:param replace: Is the service item a replacement (Default False)
: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 expand is None:
expand = Settings().value('advanced/expand service item')
item.from_service = True
if replace:
sitem, child = self.find_service_item()
item.merge(self.service_items[sitem]['service_item'])
self.service_items[sitem]['service_item'] = item
self.repaint_service_list(sitem, child)
s_item, child = self.find_service_item()
item.merge(self.service_items[s_item]['service_item'])
self.service_items[s_item]['service_item'] = item
self.repaint_service_list(s_item, child)
self.live_controller.replace_service_manager_item(item)
else:
item.render()
# nothing selected for dnd
if self.drop_position == 0:
if isinstance(item, list):
for inditem in item:
self.service_items.append({'service_item': inditem,
for ind_item in item:
self.service_items.append({'service_item': ind_item,
'order': len(self.service_items) + 1,
'expanded': expand, 'selected': selected})
else:
@ -1371,6 +1405,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def on_make_live(self, field=None):
"""
Send the current item to the Live slide controller but triggered by a tablewidget click event.
:param field:
"""
self.make_live()
@ -1378,8 +1413,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
"""
Send the current item to the Live slide controller
``row``
Row number to be displayed if from preview. -1 is passed if the value is not set
:param row: Row number to be displayed if from preview. -1 is passed if the value is not set
"""
item, child = self.find_service_item()
# No items in service
@ -1408,6 +1442,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
def remote_edit(self, field=None):
"""
Triggers a remote edit to a plugin to allow item to be edited.
:param field:
"""
item = self.find_service_item()[0]
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):
"""
Saves the current text item as a custom slide
:param field:
"""
item = self.find_service_item()[0]
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.
The drag event payload carries the plugin name
``event``
Handle of the event pint passed
:param event: Handle of the event passed
"""
link = event.mimeData()
if link.hasUrls():
@ -1512,8 +1547,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
"""
Called from ThemeManager when the Themes have changed
``theme_list``
A list of current themes to be displayed
:param theme_list: A list of current themes to be displayed
"""
self.theme_combo_box.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):
"""
Handles theme change events
:param field:
"""
theme = self.sender().objectName()
# 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):
"""
Finds and returns the parent item for any item
:param item: The service item list item to be checked.
"""
parent_item = item.parent()
if parent_item is None:

View File

@ -53,8 +53,8 @@ class Ui_ThemeManager(object):
def setup_ui(self, widget):
"""
Define the UI
:param widget: The screen object the the dialog is to be attached to.
"""
# start with the layout
self.layout = QtGui.QVBoxLayout(widget)
self.layout.setSpacing(0)
@ -173,6 +173,9 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
"""
If Default theme selected remove delete button.
Note for some reason a dummy field is required. Nothing is passed!
:param field:
:param item: Service Item to process
"""
if item is None:
return
@ -186,8 +189,9 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def context_menu(self, point):
"""
Build the Right Click Context menu and set state depending on
the type of theme.
Build the Right Click Context menu and set state depending on 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)
if item is None:
@ -221,8 +225,9 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def change_global_from_screen(self, index=-1):
"""
Change the global theme when a theme is double clicked upon in the
Theme Manager list
Change the global theme when a theme is double clicked upon in the Theme Manager list.
:param index:
"""
selected_row = self.theme_list_widget.currentRow()
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):
"""
Loads a new theme with the default settings and then launches the theme
editing form for the user to make their customisations.
Loads a new theme with the default settings and then launches the theme editing form for the user to make
their customisations.
:param field:
"""
theme = ThemeXML()
theme.set_default_header_footer()
@ -254,6 +260,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def on_rename_theme(self, field=None):
"""
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.'),
translate('OpenLP.ThemeManager', 'Rename Confirmation'),
@ -278,6 +285,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def on_copy_theme(self, field=None):
"""
Copies an existing theme to a new name
:param field:
"""
item = self.theme_list_widget.currentItem()
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):
"""
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_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
theme editing form so the user can make their changes.
:param field:
"""
if check_item_selected(self.theme_list_widget,
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):
"""
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.'),
translate('OpenLP.ThemeManager', 'Delete Confirmation'),
@ -341,8 +354,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
"""
Delete a theme.
``theme``
The theme to delete.
:param theme: The theme to delete.
"""
self.theme_list.remove(theme)
thumb = '%s.png' % theme
@ -358,6 +370,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def on_export_theme(self, field=None):
"""
Export the theme in a zip file
:param field:
"""
item = self.theme_list_widget.currentItem()
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
those files. This process will load both OpenLP version 1 and version 2 themes.
:param field:
"""
files = FileDialog.getOpenFileNames(self,
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
``theme_name``
Name of the theme to load from file
:param theme_name: Name of the theme to load from file
:return The theme object.
"""
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')
@ -498,6 +512,8 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def over_write_message_box(self, theme_name):
"""
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'),
translate('OpenLP.ThemeManager',
@ -510,11 +526,12 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def unzip_theme(self, file_name, directory):
"""
Unzip the theme, remove the preview file if stored
Generate a new preview file. Check the XML theme version and upgrade if
necessary.
Unzip the theme, remove the preview file if stored. Generate a new preview file. Check the XML theme version
and upgrade if 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)
theme_zip = 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
``theme_name``
Name of the Theme to test
:param theme_name: Name of the Theme to test
:return True or False if theme exists
"""
theme_dir = os.path.join(self.path, theme_name)
if os.path.exists(theme_dir):
@ -597,6 +614,10 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager):
def save_theme(self, theme, image_from, image_to):
"""
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)
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):
"""
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
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):
"""
Generate and save a preview image
:param name: The name of the theme.
:param theme: The theme data object.
"""
frame = self.generate_image(theme)
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
``theme_data``
The theme to generated a preview for.
``force_page``
Flag to tell message lines per page need to be generated.
:param theme_data: The theme to generated a preview for.
:param force_page: Flag to tell message lines per page need to be generated.
"""
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
``theme``
The theme to return the image for
:param theme: The theme to return the image for.
"""
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
``theme_xml``
The XML data to load into the theme
:param theme_xml: The Theme data object.
:param image_path: Where the theme image is stored
:return Theme data.
"""
theme = ThemeXML()
theme.parse(theme_xml)
theme.extend_image_filename(path)
theme.extend_image_filename(image_path)
return theme
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.
: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')
if check_item_selected(self.theme_list_widget, select_text):

View File

@ -127,9 +127,15 @@ __default_settings__ = {
class AlertsPlugin(Plugin):
"""
The Alerts Plugin Class
"""
log.info('Alerts Plugin loaded')
def __init__(self):
"""
Class __init__ method
"""
super(AlertsPlugin, self).__init__('alerts', __default_settings__, settings_tab_class=AlertsTab)
self.weight = -3
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.
``tools_menu``
:param tools_menu:
The actual **Tools** menu item, so that your actions can use it as their parent.
"""
log.info('add tools menu')
self.tools_alert_item = create_action(tools_menu, 'toolsAlertItem',
text=translate('AlertsPlugin', '&Alert'), icon=':/plugins/plugin_alerts.png',
text=translate('AlertsPlugin', '&Alert'),
icon=':/plugins/plugin_alerts.png',
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)
def initialise(self):
"""
Initialise plugin
"""
log.info('Alerts Initialising')
super(AlertsPlugin, self).initialise()
self.tools_alert_item.setVisible(True)
@ -171,16 +181,27 @@ class AlertsPlugin(Plugin):
action_list.remove_action(self.tools_alert_item, 'Tools')
def toggle_alerts_state(self):
"""
Switch the alerts state
"""
self.alerts_active = not self.alerts_active
Settings().setValue(self.settings_section + '/active', self.alerts_active)
def on_alerts_trigger(self):
"""
Start of the Alerts dialog triggered from the main menu.
"""
self.alert_form.load_list()
self.alert_form.exec_()
def about(self):
"""
Plugin Alerts about method
:return: text
"""
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
def set_plugin_text_strings(self):

View File

@ -36,6 +36,11 @@ from openlp.core.lib.ui import create_button, create_button_box
class Ui_AlertDialog(object):
def setupUi(self, alert_dialog):
"""
Setup the Alert UI dialog
:param alert_dialog:
"""
alert_dialog.setObjectName('alert_dialog')
alert_dialog.resize(400, 300)
alert_dialog.setWindowIcon(build_icon(':/icon/openlp-logo-16x16.png'))
@ -86,6 +91,10 @@ class Ui_AlertDialog(object):
self.retranslateUi(alert_dialog)
def retranslateUi(self, alert_dialog):
"""
Retranslate the UI strings
:param 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:'))

View File

@ -114,7 +114,8 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
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'
translate('AlertsPlugin.AlertForm',
'You haven\'t specified any text for your alert. \n'
'Please type in some text before clicking New.'))
else:
alert = AlertItem()
@ -153,10 +154,10 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
List item has been double clicked to display it.
"""
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)
list_item = self.alert_list_widget.item(item.row())
self.trigger_alert(list_item.text())
self.alert_text_edit.setText(list_item.text())
self.item_id = list_item.data(QtCore.Qt.UserRole)
self.save_button.setEnabled(False)
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.
"""
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)
list_item = self.alert_list_widget.item(item.row())
self.alert_text_edit.setText(list_item.text())
self.item_id = list_item.data(QtCore.Qt.UserRole)
# If the alert does not contain '<>' we clear the ParameterEdit field.
if self.alert_text_edit.text().find('<>') == -1:
self.parameter_edit.setText('')
@ -182,20 +183,25 @@ 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('<>') != -1 and not self.parameter_edit.text() and QtGui.QMessageBox.question(self,
if text.find('<>') != -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'
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:
QtGui.QMessageBox.StandardButtons(
QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No:
self.parameter_edit.setFocus()
return False
# The ParameterEdit field is not empty, but we have not found '<>'
# 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 \
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:
QtGui.QMessageBox.StandardButtons(
QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No:
self.parameter_edit.setFocus()
return False
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.
``text``
display text
:param text:
The text to display
"""
log.debug('display alert called %s' % 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.
``event``
:param event:
the QT event that has been triggered.
"""
log.debug('timer event')

View File

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

View File

@ -47,7 +47,7 @@ def init_schema(url):
"""
Setup the alerts database connection and initialise the database schema
``url``
:param url:
The database to setup
"""
session, metadata = init_db(url)