4

我已经成为许多自动化任务的 Autokey 的粉丝,并且了解如何从程序内部导入和执行 python

我无法弄清楚的是如何/是否可以导入要从程序外部执行的自动键库(python脚本)

这甚至可能吗?根据多次尝试,我得到了各种依赖错误,如果没有人能快速回答我一直失踪的难以捉摸的明显问题,我会发布失败尝试的 pastebin

更新

再次经历了这个过程,主要是我试图访问键盘类

from autokey.scripting import Keyboard

产生错误

In [1]: from autokey.scripting import Keyboard
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-9721ccad71fb> in <module>()
----> 1 from autokey.scripting import Keyboard

/usr/local/lib/python2.7/dist-packages/autokey/scripting.py in <module>()
     17 
     18 import subprocess, threading, time, re
---> 19 import common, model, iomediator
     20 if common.USING_QT:
     21     from PyQt4.QtGui import QClipboard, QApplication

/usr/local/lib/python2.7/dist-packages/autokey/model.py in <module>()
     17 
     18 import re, os, os.path, glob, logging
---> 19 from configmanager import *
     20 from iomediator import Key, NAVIGATION_KEYS, KEY_SPLIT_RE
     21 from scripting import Store

/usr/local/lib/python2.7/dist-packages/autokey/configmanager.py in <module>()
    712 from model import *
    713 
--> 714 class GlobalHotkey(AbstractHotkey):
    715     """
    716     A global application hotkey, configured from the advanced settings dialog.

NameError: name 'AbstractHotkey' is not defined

尝试直接导入 AbstractHotkey

from autokey.model import AbstractHotkey

给出错误

In [4]: from autokey.model import AbstractHotkey
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-4-fddf923ec053> in <module>()
----> 1 from autokey.model import AbstractHotkey

/usr/local/lib/python2.7/dist-packages/autokey/model.py in <module>()
     17 
     18 import re, os, os.path, glob, logging
---> 19 from configmanager import *
     20 from iomediator import Key, NAVIGATION_KEYS, KEY_SPLIT_RE
     21 from scripting import Store

/usr/local/lib/python2.7/dist-packages/autokey/configmanager.py in <module>()
    712 from model import *
    713 
--> 714 class GlobalHotkey(AbstractHotkey):
    715     """
    716     A global application hotkey, configured from the advanced settings dialog.

NameError: name 'AbstractHotkey' is not defined

诀窍是 model.py 有

from configmanager import *

在第 19 行,创建循环依赖

假设我可以创建一个补丁,但仍然好奇是否有人有不需要编辑核心文件的方法?

4

1 回答 1

2

Autokey 不提供可在从 Autokey 应用程序内部触发的脚本上下文之外使用的库。

所以不行。欢迎使用补丁,但您想要的功能尚不存在。

于 2013-04-29T19:56:55.987 回答