diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index 8b01351cb..9af8debb8 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -62,6 +62,7 @@ class ServiceItemAction(object): PreviousLastSlide = 2 Next = 3 + def translate(context, text, comment=None, encoding=QtCore.QCoreApplication.CodecForTr, n=-1, translate=QtCore.QCoreApplication.translate): @@ -83,6 +84,7 @@ def translate(context, text, comment=None, """ return translate(context, text, comment, encoding, n) + def get_text_file_string(text_file): """ Open a file and return its content as unicode string. If the supplied file @@ -111,6 +113,7 @@ def get_text_file_string(text_file): file_handle.close() return content_string + def str_to_bool(stringvalue): """ Convert a string version of a boolean into a real boolean. @@ -122,6 +125,7 @@ def str_to_bool(stringvalue): return stringvalue return unicode(stringvalue).strip().lower() in (u'true', u'yes', u'y') + def build_icon(icon): """ Build a QIcon instance from an existing QIcon, a resource location, or a @@ -148,6 +152,7 @@ def build_icon(icon): QtGui.QIcon.Normal, QtGui.QIcon.Off) return button_icon + def image_to_byte(image): """ Resize an image to fit on the current screen for the web and returns @@ -166,6 +171,7 @@ def image_to_byte(image): # convert to base64 encoding so does not get missed! return byte_array.toBase64() + def create_thumb(image_path, thumb_path, return_icon=True, size=None): """ Create a thumbnail from the given image path and depending on @@ -201,6 +207,7 @@ def create_thumb(image_path, thumb_path, return_icon=True, size=None): # Fallback for files with animation support. return build_icon(unicode(image_path)) + def validate_thumb(file_path, thumb_path): """ Validates whether an file's thumb still exists and if is up to date. @@ -219,6 +226,7 @@ def validate_thumb(file_path, thumb_path): thumb_date = os.stat(thumb_path).st_mtime return image_date <= thumb_date + def resize_image(image_path, width, height, background=u'#000000'): """ Resize an image to fit on the current screen. @@ -266,6 +274,7 @@ def resize_image(image_path, width, height, background=u'#000000'): painter.drawImage((width - realw) / 2, (height - realh) / 2, preview) return new_image + def check_item_selected(list_widget, message): """ Check if a list item is selected so an action may be performed on it @@ -282,6 +291,7 @@ def check_item_selected(list_widget, message): return False return True + def clean_tags(text): """ Remove Tags from text for display @@ -294,6 +304,7 @@ def clean_tags(text): text = text.replace(tag[u'end tag'], u'') return text + def expand_tags(text): """ Expand tags HTML for display @@ -303,6 +314,7 @@ def expand_tags(text): text = text.replace(tag[u'end tag'], tag[u'end html']) return text + def check_directory_exists(dir): """ Check a theme directory exists and if not create it @@ -317,6 +329,7 @@ def check_directory_exists(dir): except IOError: pass + def create_separated_list(stringlist): """ Returns a string that represents a join of a list of strings with a @@ -345,6 +358,7 @@ def create_separated_list(stringlist): return unicode(translate('OpenLP.core.lib', '%1, %2', u'Locale list separator: start').arg(stringlist[0], merged)) + from eventreceiver import Receiver from listwidgetwithdnd import ListWidgetWithDnD from formattingtags import FormattingTags diff --git a/openlp/core/lib/ui.py b/openlp/core/lib/ui.py index 1117c01a0..c4b1181b1 100644 --- a/openlp/core/lib/ui.py +++ b/openlp/core/lib/ui.py @@ -143,6 +143,7 @@ class UiStrings(object): self.View = translate('OpenLP.Ui', 'View') self.ViewMode = translate('OpenLP.Ui', 'View Mode') + def add_welcome_page(parent, image): """ Generate an opening welcome page for a wizard using a provided image. @@ -170,6 +171,7 @@ def add_welcome_page(parent, image): parent.welcomeLayout.addStretch() parent.addPage(parent.welcomePage) + def create_button_box(dialog, name, standard_buttons, custom_buttons=[]): """ Creates a QDialogButtonBox with the given buttons. The ``accepted()`` and @@ -216,6 +218,7 @@ def create_button_box(dialog, name, standard_buttons, custom_buttons=[]): dialog.reject) return button_box + def critical_error_message_box(title=None, message=None, parent=None, question=False): """ @@ -242,6 +245,7 @@ def critical_error_message_box(title=None, message=None, parent=None, data[u'title'] = title if title else UiStrings().Error return Receiver.send_message(u'openlp_error_message', data) + def create_horizontal_adjusting_combo_box(parent, name): """ Creates a QComboBox with adapting width for media items. @@ -258,6 +262,7 @@ def create_horizontal_adjusting_combo_box(parent, name): combo.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed) return combo + def create_button(parent, name, **kwargs): """ Return an button with the object name set and the given parameters. @@ -324,6 +329,7 @@ def create_button(parent, name, **kwargs): log.warn(u'Parameter %s was not consumed in create_button().', key) return button + def create_action(parent, name, **kwargs): """ Return an action with the object name set and the given parameters. @@ -411,6 +417,7 @@ def create_action(parent, name, **kwargs): log.warn(u'Parameter %s was not consumed in create_action().', key) return action + def create_widget_action(parent, name=u'', **kwargs): """ Return a new QAction by calling ``create_action(parent, name, **kwargs)``. @@ -422,6 +429,7 @@ def create_widget_action(parent, name=u'', **kwargs): parent.addAction(action) return action + def set_case_insensitive_completer(cache, widget): """ Sets a case insensitive text completer for a widget. @@ -436,6 +444,7 @@ def set_case_insensitive_completer(cache, widget): completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive) widget.setCompleter(completer) + def create_valign_selection_widgets(parent): """ Creates a standard label and combo box for asking users to select a @@ -455,6 +464,7 @@ def create_valign_selection_widgets(parent): label.setBuddy(combo_box) return label, combo_box + def find_and_set_in_combo_box(combo_box, value_to_find): """ Find a string in a combo box and set it as the selected item if present