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