Пример #1
0
    def __call__(self, *args, **kwargs):
        if not self.parameters:
            self.parameters.update(**kwargs)

        if self.__name in EXT_FUNCTION_NAMES:
            func = common.__getattribute__(self.__name)
            return func(*args, **kwargs)
        else:
            return super(Function, self).__call__(*args, **kwargs)
Пример #2
0
def images_slideshow(images,
                     library='default',
                     background='bg',
                     delay=2.0,
                     fade_time=0.5,
                     repeat=1):
    """ returns sequence of image slides animation """

    # get a clean slate
    ns = clean_slate()

    exec "old_image = None" in ns
    exec "fade_time = %f" % (fade_time, ) in ns
    exec "delay = %f" % (delay, ) in ns

    try:
        if background is not None:
            background = common.__getattribute__(background)
    except AttributeError:
        print "Warning slidereader.py - image_slideshow: Background common.%s not defined." % background
        background = None

    if background is not None:
        ns['bg'] = background
        exec "start(bg)" in ns
    else:
        exec "start()" in ns

    cmd = """
      
new_image = Image(get_camera(), '%s', library='%s',_alpha=0.0)
enter(new_image)

fade_in(fade_time,new_image)

if old_image:
  wait(-fade_time)
  fade_out(fade_time,old_image)

wait(delay)

if old_image:
  exit(old_image)
  

old_image = new_image


"""

    for image in images * repeat:
        exec cmd % (image, library) in ns

    exec "anim = end_animation()" in ns

    return ns['anim']
Пример #3
0
def images_slideshow(images,library='default',background='bg',delay=2.0,fade_time=0.5,repeat=1):
    """ returns sequence of image slides animation """
    
    # get a clean slate
    ns = clean_slate()

    exec "old_image = None" in ns
    exec "fade_time = %f" % (fade_time,) in ns
    exec "delay = %f" % (delay,) in ns

    try:
        if background is not None:
            background = common.__getattribute__(background)
    except AttributeError:
        print "Warning slidereader.py - image_slideshow: Background common.%s not defined." % background
        background=None

    if background is not None:
        ns['bg'] = background
        exec "start(bg)" in ns
    else:
        exec "start()" in ns


    cmd = """
      
new_image = Image(get_camera(), '%s', library='%s',_alpha=0.0)
enter(new_image)

fade_in(fade_time,new_image)

if old_image:
  wait(-fade_time)
  fade_out(fade_time,old_image)

wait(delay)

if old_image:
  exit(old_image)
  

old_image = new_image


"""

    for image in images*repeat:
       exec cmd % (image, library) in ns 
        
    exec "anim = end_animation()" in ns

    return ns['anim']
Пример #4
0
def load_image_slides(images,
                      library='default',
                      background='bg',
                      content=None):
    """ returns sequence of image slides animation """

    # get a clean slate
    ns = clean_slate()

    exec "image = None" in ns

    try:
        if background is not None:
            background = common.__getattribute__(background)
    except AttributeError:
        print "Warning slidereader.py - load_image_slides: Background common.%s not defined." % background
        background = None

    if background is not None:
        ns['bg'] = background
        exec "start(bg)" in ns
    else:
        exec "start()" in ns

    cmd = """
if image:
  pause()
  #fade_out(0.5,image)
  #exit(image)
      
new_image = Image(get_camera(), '%s', library='%s',_alpha=1.0)
enter(new_image)
#fade_in(0.5,image)

if image:
  exit(image)

image = new_image


"""

    for image in images:
        exec cmd % (image, library) in ns

    # do external slithy content if any
    if content:
        exec content in ns

    exec "anim = end_animation()" in ns

    return ns['anim']
Пример #5
0
def load_image_slides(images,library='default',background='bg',content=None):
    """ returns sequence of image slides animation """
    
    # get a clean slate
    ns = clean_slate()

    exec "image = None" in ns

    try:
        if background is not None:
            background = common.__getattribute__(background)
    except AttributeError:
        print "Warning slidereader.py - load_image_slides: Background common.%s not defined." % background
        background=None

    if background is not None:
        ns['bg'] = background
        exec "start(bg)" in ns
    else:
        exec "start()" in ns


    cmd = """
if image:
  pause()
  #fade_out(0.5,image)
  #exit(image)
      
new_image = Image(get_camera(), '%s', library='%s',_alpha=1.0)
enter(new_image)
#fade_in(0.5,image)

if image:
  exit(image)

image = new_image


"""

    for image in images:
       exec cmd % (image, library) in ns 

    # do external slithy content if any
    if content:
        exec content in ns
       
    exec "anim = end_animation()" in ns

    return ns['anim']
Пример #6
0
    def __init__(self, func_name, *args, **kwargs):
        """
        :type kwargs: object
        """
        self.__name = func_name.upper()
        self.__parameters = {}

        if self.__name in EXT_FUNCTION_NAMES:
            self.__doc__ = common.__getattribute__(self.__name).__doc__

            # self.parameters = {}
        else:
            super(Function, self).__init__(func_name, *args, **kwargs)

        if kwargs:
            self.parameters = kwargs
Пример #7
0
 def __get_default_args(self, func_name):
     """
     returns a dictionary of arg_name:default_values for the input function
     """
     func = common.__getattribute__(func_name)
     args, varargs, keywords, defaults = inspect.getargspec(func)
     if defaults:
         ret = dict(list(zip(reversed(args), reversed(defaults))))
         # 本来函数的default应该是周期,是整型.
         # 比如ret={'timeperiod1': 14, timeperiod2: 20}
         # 但是有一些函数的缺省值是字符串。这些函数
         # 是为了方便,可以使用不同的price来计算.
         # 比如TMA(prices, param_dict.timeperiod=14, price='high')
         # 我们要去掉这些字符型的字典项
         numeric_value_dict = {
             key: val
             for key, val in ret.items() if isinstance(val, int)
         }
         return numeric_value_dict
     else:
         # print func_name
         return {}