Skip to content

Commit

Permalink
Fixes #13
Browse files Browse the repository at this point in the history
the list of windows was not update every time the command is selected
also: item label includes window title if the process is foreground
  • Loading branch information
ueffel committed Nov 28, 2017
1 parent ea054a2 commit b8f4c48
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions kill.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self):
"""
super().__init__()
self._processes = []
self._processes_with_window = []
self._processes_with_window = {}
self._actions = []
self._icons = {}
self._default_action = "kill_by_id"
Expand Down Expand Up @@ -185,12 +185,12 @@ def _get_windows(self):
except OSError:
self.err("Failed to list windows.", str(exc))

self._processes_with_window = []
self._processes_with_window = {}

for hwnd in handles:
try:
(_, proc_id) = AltTab.get_window_thread_process_id(hwnd)
self._processes_with_window.append(proc_id)
self._processes_with_window[proc_id] = hwnd
except OSError:
continue

Expand Down Expand Up @@ -231,19 +231,26 @@ def _get_processes_from_com_object(self, wmi):
if proc.Properties_["ExecutablePath"].Value:
databag["ExecutablePath"] = proc.Properties_["ExecutablePath"].Value

label = proc.Properties_["Caption"].Value
if not self._hide_background:
if is_foreground:
label = label + " (foreground)"
label = '{}: "{}" ({})'.format(
proc.Properties_["Caption"].Value,
AltTab.get_window_text(self._processes_with_window[proc.Properties_["ProcessId"].Value]),
'foreground'
)
else:
label = label + " (background)"
label = '{} ({})'.format(proc.Properties_["Caption"].Value, 'background')
else:
label = '{}: "{}"'.format(
proc.Properties_["Caption"].Value,
AltTab.get_window_text(self._processes_with_window[proc.Properties_["ProcessId"].Value])
)

item = self.create_item(
category=category,
label=label,
short_desc=short_desc,
target=proc.Properties_["Name"].Value + "|"
+ str(proc.Properties_["ProcessId"].Value),
target=proc.Properties_["Name"].Value + "|" + str(proc.Properties_["ProcessId"].Value),
icon_handle=self._get_icon(proc.Properties_["ExecutablePath"].Value),
args_hint=kp.ItemArgsHint.REQUIRED,
hit_hint=kp.ItemHitHint.IGNORE,
Expand Down Expand Up @@ -349,6 +356,7 @@ def on_deactivated(self):
"""
Emptys the process list, when Keypirinha Box is closed
"""
self._processes_with_window = {}
self._processes = []

# for ico in self._icons.values():
Expand Down Expand Up @@ -380,7 +388,6 @@ def on_execute(self, item, action):
if act.name() == self._default_action:
action = act


if "_admin" in action.name():
self._kill_process_admin(item, action.name())
else:
Expand Down

0 comments on commit b8f4c48

Please sign in to comment.