From 980a6dde05f132ef0618d423ba8c1acc949857ff Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 24 Sep 2021 11:27:35 -0400 Subject: [PATCH] Add ib gateway support, loop through names --- snippets/ib_data_reset.py | 49 ++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/snippets/ib_data_reset.py b/snippets/ib_data_reset.py index 2c252218..f5d4ca39 100644 --- a/snippets/ib_data_reset.py +++ b/snippets/ib_data_reset.py @@ -26,29 +26,36 @@ i3 = i3ipc.Connection() t = i3.get_tree() # for tws -win_name = 'Interactive Brokers' # what for gw tho? -con = t.find_named(win_name)[0] +win_names: list[str] = [ + 'Interactive Brokers', # tws running in i3 + 'IB Gateway.', # gw running in i3 +] -win_id = str(con.window) -w, h = con.rect.width, con.rect.height +for name in win_names: + results = t.find_named(name) + if results: + con = results[0] + print(f'Resetting data feed for {name}') + win_id = str(con.window) + w, h = con.rect.width, con.rect.height -# TODO: seems to be a few libs for python but not sure -# if they support all the sub commands we need, order of -# most recent commit history: -# https://github.com/rr-/pyxdotool -# https://github.com/ShaneHutter/pyxdotool -# https://github.com/cphyc/pyxdotool -subprocess.call([ - 'xdotool', - 'windowactivate', '--sync', win_id, + # TODO: seems to be a few libs for python but not sure + # if they support all the sub commands we need, order of + # most recent commit history: + # https://github.com/rr-/pyxdotool + # https://github.com/ShaneHutter/pyxdotool + # https://github.com/cphyc/pyxdotool + subprocess.call([ + 'xdotool', + 'windowactivate', '--sync', win_id, - # move mouse to bottom left of window (where there should - # be nothing to click). - 'mousemove_relative', '--sync', str(w-3), str(h-3), + # move mouse to bottom left of window (where there should + # be nothing to click). + 'mousemove_relative', '--sync', str(w-3), str(h-3), - # NOTE: we may need to stick a `--retry 3` in here.. - 'click', '--window', win_id, '1', + # NOTE: we may need to stick a `--retry 3` in here.. + 'click', '--window', win_id, '1', - # hackzorzes - 'key', 'ctrl+alt+f', -]) + # hackzorzes + 'key', 'ctrl+alt+f', + ])