2020年6月9日火曜日

開発環境

退屈なことはPythonにやらせよう ―ノンプログラマーにもできる自動化処理プログラミング (Al Sweigart(著)、相川 愛三(翻訳)、オライリージャパン)の第Ⅱ部(処理の自動化)、18章(GUIオートメーションによるキーボードとマウスの制御)、18.13(演習プロジェクト)、18.13.1(忙しそうに見せる)の解答を求めてみる。

コード

#!/usr/bin/env python3
import time
import pyautogui

x = 1
# secs = 10
secs = 1
while True:
    time.sleep(secs)
    pyautogui.moveRel(x, 0)
    x *= -1
    print(pyautogui.position())

入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))

% ./sample1.py 
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/rubicon/objc/ctypes_patch.py:21: UserWarning: rubicon.objc.ctypes_patch has only been tested with Python 3.4 through 3.7. You are using Python 3.8.3. Most likely things will work properly, but you may experience crashes if Python's internals have changed significantly.
  warnings.warn(
Point(x=39, y=41)
Point(x=38, y=51)
Point(x=39, y=51)
Point(x=38, y=51)
Point(x=16, y=52)
Point(x=15, y=52)
Point(x=16, y=52)
Point(x=215, y=62)
Point(x=227, y=63)
Point(x=226, y=63)
Point(x=227, y=63)
Traceback (most recent call last):
  File "./sample1.py", line 10, in <module>
    pyautogui.moveRel(x, 0)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyautogui/__init__.py", line 587, in wrapper
    failSafeCheck()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyautogui/__init__.py", line 1671, in failSafeCheck
    raise FailSafeException(
pyautogui.FailSafeException: PyAutoGUI fail-safe triggered from mouse moving to a corner of the screen. To disable this fail-safe, set pyautogui.FAILSAFE to False. DISABLING FAIL-SAFE IS NOT RECOMMENDED.
%

0 コメント:

コメントを投稿