Skip to content

Commit

Permalink
Merge 2c0eb9a into 2fe7d76
Browse files Browse the repository at this point in the history
  • Loading branch information
spyoungtech committed Apr 11, 2020
2 parents 2fe7d76 + 2c0eb9a commit 19e2b16
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
20 changes: 20 additions & 0 deletions ahk/_console_spy.py
@@ -0,0 +1,20 @@
from ahk import AHK
from ahk.window import Window
from ahk.directives import NoTrayIcon


def _console_spy(*args, **kwargs):
ahk = AHK(directives={NoTrayIcon})

while True:
position = ahk.mouse_position
window = Window.from_mouse_position(engine=ahk)
color = ahk.pixel_get_color(*position)
print(f'Mouse Position: {position} Pixel Color: {color} Window Title: {window.title} ', end='\r')


def _main():
try:
_console_spy()
except KeyboardInterrupt:
print('Exiting.')
9 changes: 7 additions & 2 deletions ahk/script.py
Expand Up @@ -65,7 +65,7 @@ def _resolve_executable_path(executable_path: str = ''):

class ScriptEngine(object):

def __init__(self, executable_path: str = "", **kwargs):
def __init__(self, executable_path: str = "", directives=None, **kwargs):
"""
This class is typically not used directly. AHK components inherit from this class
and the arguments for this class should usually be passed in to :py:class:`~ahk.AHK`.
Expand All @@ -78,10 +78,12 @@ def __init__(self, executable_path: str = "", **kwargs):
If environment variable not present, tries to look for 'AutoHotkey.exe' or 'AutoHotkeyA32.exe' with shutil.which
:param directives: additional AHK directives to add to all rendered scripts
:raises ExecutableNotFound: if AHK executable cannot be found or the specified file does not exist
"""
self.executable_path = _resolve_executable_path(executable_path)

self._directives = directives
templates_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'templates')
self.env = Environment(loader=FileSystemLoader(templates_path),
autoescape=False, trim_blocks=True)
Expand Down Expand Up @@ -111,6 +113,9 @@ def render_template(self, template_name, directives=None, blocking=True, **kwarg
directives.add(Persistent)
elif Persistent in directives:
directives.remove(Persistent)
if self._directives:
for directive in self._directives:
directives.add(directive)

kwargs['directives'] = directives
template = self.env.get_template(template_name)
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Expand Up @@ -30,5 +30,8 @@
],
tests_require=test_requirements,
include_package_data=True,
zip_safe=False
zip_safe=False,
entry_points={
'console_scripts': ['console_spy = ahk._console_spy:_main']
}
)

0 comments on commit 19e2b16

Please sign in to comment.