当前位置: 首页>>代码示例>>Python>>正文


Python Workflow.finish_capture方法代码示例

本文整理汇总了Python中spreads.workflow.Workflow.finish_capture方法的典型用法代码示例。如果您正苦于以下问题:Python Workflow.finish_capture方法的具体用法?Python Workflow.finish_capture怎么用?Python Workflow.finish_capture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在spreads.workflow.Workflow的用法示例。


在下文中一共展示了Workflow.finish_capture方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: capture

# 需要导入模块: from spreads.workflow import Workflow [as 别名]
# 或者: from spreads.workflow.Workflow import finish_capture [as 别名]
def capture(config):
    path = config['path'].get()
    workflow = Workflow(config=config, path=path)
    if len(workflow.devices) != 2:
        raise DeviceException("Please connect and turn on two"
                              " pre-configured devices! ({0} were"
                              " found)".format(len(workflow.devices)))
    print(colorize("Found {0} devices!".format(len(workflow.devices)),
                   colorama.Fore.GREEN))
    if any(not x.target_page for x in workflow.devices):
        raise DeviceException("At least one of the devices has not been"
                              " properly configured, please re-run the"
                              " program with the \'configure\' option!")
    # Set up for capturing
    print("Setting up devices for capturing.")
    workflow.prepare_capture()
    # Start capture loop
    shot_count = 0
    pages_per_hour = 0
    capture_keys = workflow.config['capture']['capture_keys'].as_str_seq()
    print("({0}) capture | (r) retake last shot | (f) finish "
          .format("/".join(capture_keys)))
    while True:
        retake = False
        char = getch().lower()
        if char == 'f':
            break
        elif char == 'r':
            retake = True
        elif char not in capture_keys:
            continue
        workflow.capture(retake=retake)
        shot_count += len(workflow.devices)
        pages_per_hour = (3600/(time.time() -
                          workflow.capture_start))*shot_count
        status = ("\rShot {0: >3} pages [{1: >4.0f}/h] "
                  .format(unicode(shot_count), pages_per_hour))
        sys.stdout.write(status)
        sys.stdout.flush()
    workflow.finish_capture()
    if workflow.capture_start is None:
        return
    sys.stdout.write("\rShot {0} pages in {1:.1f} minutes, average speed was"
                     " {2:.0f} pages per hour\n"
                     .format(colorize(str(shot_count), colorama.Fore.GREEN),
                             (time.time() - workflow.capture_start)/60,
                             pages_per_hour))
    sys.stdout.flush()
开发者ID:Gunirus,项目名称:spreads,代码行数:50,代码来源:cli.py

示例2: capture

# 需要导入模块: from spreads.workflow import Workflow [as 别名]
# 或者: from spreads.workflow.Workflow import finish_capture [as 别名]
def capture(config):
    path = config['path'].get()
    workflow = Workflow(config=config, path=path)
    workflow.on_created.send(workflow=workflow)
    capture_keys = workflow.config['capture']['capture_keys'].as_str_seq()

    # Some closures
    def refresh_stats():
        # Callback to print statistics
        if refresh_stats.start_time is not None:
            pages_per_hour = ((3600/(time.time() - refresh_stats.start_time))
                              * workflow.pages_shot)
        else:
            pages_per_hour = 0.0
            refresh_stats.start_time = time.time()
        status = ("\rShot {0: >3} pages [{1: >4.0f}/h] "
                  .format(unicode(workflow.pages_shot), pages_per_hour))
        sys.stdout.write(status)
        sys.stdout.flush()
    refresh_stats.start_time = None

    def trigger_loop():
        is_posix = sys.platform != 'win32'
        old_count = workflow.pages_shot
        if is_posix:
            import select
            old_settings = termios.tcgetattr(sys.stdin)
            data_available = lambda: (select.select([sys.stdin], [], [], 0) ==
                                     ([sys.stdin], [], []))
            read_char = lambda: sys.stdin.read(1)
        else:
            data_available = msvcrt.kbhit
            read_char = msvcrt.getch

        try:
            if is_posix:
                tty.setcbreak(sys.stdin.fileno())
            while True:
                time.sleep(0.01)
                if workflow.pages_shot != old_count:
                    old_count = workflow.pages_shot
                    refresh_stats()
                if not data_available():
                    continue
                char = read_char()
                if char in tuple(capture_keys) + ('r', ):
                    workflow.capture(retake=(char == 'r'))
                    refresh_stats()
                elif char == 'f':
                    break
        finally:
            if is_posix:
                termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)

    if len(workflow.devices) != 2:
        raise DeviceException("Please connect and turn on two"
                              " pre-configured devices! ({0} were"
                              " found)".format(len(workflow.devices)))
    print(colorize("Found {0} devices!".format(len(workflow.devices)),
                   colorama.Fore.GREEN))
    if any(not x.target_page for x in workflow.devices):
        raise DeviceException("At least one of the devices has not been"
                              " properly configured, please re-run the"
                              " program with the \'configure\' option!")
    # Set up for capturing
    print("Setting up devices for capturing.")
    workflow.prepare_capture()

    print("({0}) capture | (r) retake last shot | (f) finish "
          .format("/".join(capture_keys)))
    # Start trigger loop
    trigger_loop()

    workflow.finish_capture()
开发者ID:matti-kariluoma,项目名称:spreads,代码行数:76,代码来源:cli.py


注:本文中的spreads.workflow.Workflow.finish_capture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。