Skip to content

Commit

Permalink
ALL: Added getMonitor() as alias for getDisplay()
Browse files Browse the repository at this point in the history
LINUX: Added ewmhlib as separate module. Fixed getAllMonitors() returns empty list if XDG_CURRENT_DESKTOP is not set. Improved getClientFrame() and getExtraFrameSize() by properly using _NET_EXTENTS and GTK_EXTENTS, Added a new Window.LEGACY_NAME="WM_NAME" property (for apps not setting _NET_WM_NAME)
MACOS: Removed MacOSNSWindow. Fixed lowerWindow(), raiseWindow() and isAlive. Fixed test_pywinctl.py to avoid crashing in small screens
  • Loading branch information
Kalmat committed Apr 22, 2024
1 parent 7a985a7 commit 9483058
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
Binary file removed dist/PyWinCtl-dev0.1-py3-none-any.whl
Binary file not shown.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
install_requires=[
"pywin32>=302; sys_platform == 'win32'",
"python-xlib>=0.21; sys_platform == 'linux'",
"ewmhlib>=0.1; sys_platform == 'linux'",
"ewmhlib>=0.2; sys_platform == 'linux'",
"pyobjc>=8.1; sys_platform == 'darwin'",
"typing_extensions>=4.4.0",
"pywinbox>=0.7",
"pymonctl>=0.8"
"pymonctl>=0.92"
],
extras_require={
'dev': [
Expand Down
9 changes: 4 additions & 5 deletions src/pywinctl/_pywinctl_macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,11 +909,15 @@ def lowerWindow(self):
try
tell application "System Events"
set procList to name of every application process whose background only is false
set frontAppName to name of first application process whose frontmost is true
end tell
repeat with procName in procList
if procName is not equal to appName then
try
activate application procName
if frontAppName is not equal to appName then
activate application frontAppName
end if
end try
end if
end repeat
Expand Down Expand Up @@ -1856,11 +1860,6 @@ def run(self):
while not self._kill.is_set():
if self._hWnd.isActive:
self._hWnd.lowerWindow()
for app in self._apps:
try:
app.activateWithOptions_(Quartz.NSApplicationActivateIgnoringOtherApps)
except:
continue
self._kill.wait(self._interval)

def kill(self):
Expand Down
37 changes: 20 additions & 17 deletions tests/test_pywinctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import subprocess
import sys
import time
from typing import Any, cast

import pywinctl

Expand Down Expand Up @@ -204,12 +203,12 @@ def activeCB(isActive):
test_moveresize('centerx', 900)
print("MOVE CENTERY", 600)
test_moveresize('centery', 600)
print("RESIZE WIDTH", 500)
test_moveresize('width', 500)
print("RESIZE HEIGHT", 400)
test_moveresize('height', 400)
print("RESIZE", 540, 410)
test_moveresize('size', (540, 410))
print("RESIZE WIDTH", 620)
test_moveresize('width', 620)
print("RESIZE HEIGHT", 410)
test_moveresize('height', 410)
print("RESIZE", 640, 420)
test_moveresize('size', (640, 420))

# Test window stacking
print("LOWER WINDOW")
Expand Down Expand Up @@ -254,26 +253,30 @@ def activeCB(isActive):
assert npw.isChild(parent)
children = npw.getChildren()
for child in children:
if child:
if isinstance(child, int):
print("WINDOW CHILD:", child, npw.isParent(child))
else:
print("WINDOW CHILD:", child.id, npw.isParent(child))
if child and isinstance(child, int):
print("WINDOW CHILD:", child, npw.isParent(child))

# Test menu options
print("MENU INFO (WORKING IN WINDOWS 10 AND MACOS, BUT NOT IN WINDOWS 11 NOR LINUX)")
if sys.platform in ("win32", "darwin"):
# Show "About" dialog. Using numbers instead of menu/option names since they are language-dependent
if sys.platform == "darwin":
targetSubmenu = 1
targetOption = 0
else:
targetSubmenu = 4
targetOption = 2
menu = npw.menu.getMenu()
submenu = {}
for i, key in enumerate(menu):
if i == 1:
if i == targetSubmenu:
submenu = menu[key].get("entries", {})
break
option: dict[str, Any] | None = None
option = {}
for i, key in enumerate(submenu):
if i == 0:
option = cast("dict[str, Any]", submenu[key])

if i == targetOption:
option = submenu[key]
break
if option:
print("CLICK OPTION")
npw.menu.clickMenuItem(wID=option.get("wID", ""))
Expand Down

0 comments on commit 9483058

Please sign in to comment.