~alisonken1/openlp/pjlink2-i

« back to all changes in this revision

Viewing changes to openlp/core/lib/__init__.py

  • Committer: Tim Bentley
  • Author(s): Phill
  • Date: 2017-08-11 20:31:09 UTC
  • mfrom: (2754.1.11 pathlib2)
  • Revision ID: tim.bentley@gmail.com-20170811203109-0idjanfltutf8n38
Definitely ready for merging, unless, of course you guys find some more issues!

Part 2

Changed the pathedit widget over to using pathlib
Added a 'patched' file dialog
Added a few utility methods

lp:~phill-ridout/openlp/pathlib2 (revision 2763)
[SUCCESS] https://ci.openlp.io/job/Branch-01-Pull/2125/
[SUCCESS] https://ci.openlp.io/job/Branch-02-Functional-Tests/2033/
[SUCCESS] https://ci.openlp.io/job/Branch-03-Interface-Tests/1938/
[SUCCESS] https://ci.openlp.io/job/Branch-04a-Code_Analysis...

Show diffs side-by-side

added added

removed removed

Lines of Context:
608
608
    return list_to_string
609
609
 
610
610
 
 
611
def replace_params(args, kwargs, params):
 
612
    """
 
613
    Apply a transformation function to the specified args or kwargs
 
614
 
 
615
    :param args: Positional arguments
 
616
    :type args: (,)
 
617
 
 
618
    :param kwargs: Key Word arguments
 
619
    :type kwargs: dict
 
620
 
 
621
    :param params: A tuple of tuples with the position and the key word to replace.
 
622
    :type params: ((int, str, path_to_str),)
 
623
 
 
624
    :return: The modified positional and keyword arguments
 
625
    :rtype: (tuple, dict)
 
626
 
 
627
 
 
628
    Usage:
 
629
        Take a method with the following signature, and assume we which to apply the str function to arg2:
 
630
            def method(arg1=None, arg2=None, arg3=None)
 
631
 
 
632
        As arg2 can be specified postitionally as the second argument (1 with a zero index) or as a keyword, the we
 
633
        would call this function as follows:
 
634
 
 
635
        replace_params(args, kwargs, ((1, 'arg2', str),))
 
636
    """
 
637
    args = list(args)
 
638
    for position, key_word, transform in params:
 
639
        if len(args) > position:
 
640
            args[position] = transform(args[position])
 
641
        elif key_word in kwargs:
 
642
            kwargs[key_word] = transform(kwargs[key_word])
 
643
    return tuple(args), kwargs
 
644
 
 
645
 
611
646
from .exceptions import ValidationError
612
 
from .filedialog import FileDialog
613
647
from .screen import ScreenList
614
648
from .formattingtags import FormattingTags
615
649
from .plugin import PluginStatus, StringContent, Plugin