Skip to content

Commit

Permalink
add window listing
Browse files Browse the repository at this point in the history
  • Loading branch information
spyoungtech committed Nov 27, 2018
1 parent 6417aef commit 02b3244
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion ahk/window.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ahk.script import ScriptEngine
from ahk.utils import make_script
import ast
from .utils import logger


class WindowNotFoundError(ValueError):
Expand All @@ -18,6 +19,12 @@ def __init__(self, engine, title='', text='', exclude_title='', exclude_text='',
self._exclude_text = exclude_text
self.match_mode = match_mode



@classmethod
def from_ahk_id(cls, engine, ahk_id):
raise NotImplemented

def _win_set(self, subcommand, value):
script = make_script(f'''\
WinSet, {subcommand}, {value}, {self.title}, {self.text, self._exclude_title, self._exclude_text}
Expand Down Expand Up @@ -139,9 +146,36 @@ def win_set(self, subcommand, value, **windowkwargs):
win.win_set(subcommand, value)
return win

def _win_title_from_ahk_id(self, ahk_id):
pass

def _all_window_titles(self):
script = make_script('''\
WinGet windows, List
Loop %windows%
{
id := windows%A_Index%
WinGetTitle wt, ahk_id %id%
r .= wt . "`n"
}
FileAppend, %r%, *
''')

resp = self.run_script(script, decode=False)
titles = []
for title_bytes in resp.split(bytes('\n', 'ascii')):
if not title_bytes.strip():
continue
try:
titles.append(title_bytes.decode())
except UnicodeDecodeError as e:
logger.exception('Could not decode title; %s', str(e))

return titles

def windows(self):
"""
Return a list of all windows
:return:
"""
raise NotImplemented
return [self.win_get(title=title) for title in self._all_window_titles()]

0 comments on commit 02b3244

Please sign in to comment.