Skip to content

Commit

Permalink
Merge fbac689 into 2fe7d76
Browse files Browse the repository at this point in the history
  • Loading branch information
spyoungtech committed Apr 11, 2020
2 parents 2fe7d76 + fbac689 commit 6c75ce7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
16 changes: 16 additions & 0 deletions ahk/console_spy.py
@@ -0,0 +1,16 @@
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():
_console_spy()
9 changes: 6 additions & 3 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 @@ -81,7 +81,7 @@ def __init__(self, executable_path: str = "", **kwargs):
: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 All @@ -91,7 +91,7 @@ def render_template(self, template_name, directives=None, blocking=True, **kwarg
Renders a given jinja template and returns a string of script text
:param template_name: the name of the jinja template to render
:param directives: additional AHK directives to add to the resulting script
:param directives: additional AHK directives to add to all scripts
:param blocking: whether the template should be rendered to block (use #Persistent directive)
:param kwargs: keywords passed to template rendering
:return: An AutoHotkey script as a string
Expand All @@ -111,6 +111,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 6c75ce7

Please sign in to comment.