Skip to content

Commit

Permalink
gh-11: Reformat changes in utils.py and final fixups to pipeline file
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyman192 committed Oct 10, 2024
1 parent 82c3b79 commit 88d54f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ jobs:
release:
name: Release pyMHF wheels and source build to PyPI
# Only run this job if the commit was tagged.
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
if: startsWith(github.ref, 'refs/tags')
needs:
- build_test
runs-on: ubuntu-latest
environment:
name: testpypi
name: pypi
url: https://pypi.org/p/pyMHF
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
Expand All @@ -58,11 +58,10 @@ jobs:
with:
name: python-package-distributions
path: dist/
- name: See what files we have
run: ls ./dist/
shell: bash
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
attestations: true

test-release:
name: Release pyMHF wheels and source build to test-PyPI
Expand All @@ -80,12 +79,8 @@ jobs:
with:
name: python-package-distributions
path: dist/
- name: See what files we have
run: ls ./dist/
shell: bash
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
attestations: true
verbose: true
18 changes: 11 additions & 7 deletions pymhf/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


def get_main_window_handle() -> Optional[int]:
""" Return the handle of the main running application window if possible.
"""Return the handle of the main running application window if possible.
This will correspond to the HWND for the window belonging to the PID of the main running process.
"""
windows = {x.getHandle(): x for x in pwc.getAllWindows()}
Expand All @@ -24,21 +24,25 @@ def get_main_window_handle() -> Optional[int]:
logger.error(f"Cannot find window handle for PID {_internal.PID}")
return None
elif len(wins) > 1:
logger.error(f"Found multiple windows for PID {_internal.PID}: {main_pid_hwnds}.\n"
"Picking the first arbitrarily but this may not be correct.")
logger.error(
f"Found multiple windows for PID {_internal.PID}: {main_pid_hwnds}.\n"
"Picking the first arbitrarily but this may not be correct."
)
return wins[0]
else:
return wins[0]


def get_hwnds_for_pid(pid: int) -> list[int]:
""" Return all HWND's for the provided PID. """
"""Return all HWND's for the provided PID."""

def callback(hwnd: int, hwnds: list[int]):
_, found_pid = win32process.GetWindowThreadProcessId(hwnd)

if found_pid == pid:
hwnds.append(hwnd)
return True

hwnds = []
win32gui.EnumWindows(callback, hwnds)
return hwnds
Expand All @@ -50,17 +54,17 @@ def get_window_by_handle(handle: int) -> Optional[pwc.Window]:


def set_main_window_active(callback: Optional[Callable[[], None]] = None):
""" Set the main window as active.
"""Set the main window as active.
If a callback is provided, it will be called after activating the window.
This callback must not take any arguments and any return value will be ignored.
"""
# Make sure that we have the MAIN_HWND in case it wasn't found earlier.
if not _internal.MAIN_HWND:
_internal.MAIN_HWND = get_main_window_handle()
if not _internal.MAIN_HWND:
logger.error(f"Cannot set main window active as we can't find it...")
logger.error("Cannot set main window active as we can't find it...")
if not is_main_window_foreground():
if (main_window := get_window_by_handle(_internal.MAIN_HWND)):
if main_window := get_window_by_handle(_internal.MAIN_HWND):
main_window.activate()
if callback is not None:
callback()
Expand Down

0 comments on commit 88d54f8

Please sign in to comment.