Skip to content

Commit

Permalink
Added emwhlib
Browse files Browse the repository at this point in the history
Fixed width/height calculations in Windows
  • Loading branch information
Kalmat committed Jul 20, 2023
1 parent 23f3685 commit 07bb48c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
Binary file not shown.
4 changes: 2 additions & 2 deletions src/pywinbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

import sys
from collections.abc import Callable
from typing import Union, Tuple, overload, Optional, NamedTuple
from typing import Union, Tuple, NamedTuple

__all__ = [
"version", "PyWinBox", "defaultOnQuery", "defaultOnSet", "Box", "Rect", "Point", "Size", "pointInBox"
]

__version__ = "0.0.8"
__version__ = "0.0.9"


def version(numberOnly: bool = True):
Expand Down
2 changes: 1 addition & 1 deletion src/pywinbox/_pywinbox_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _getHandle(handle: Union[int, str]) -> Optional[int]:

def _getWindowBox(handle: int) -> Box:
x, y, r, b = win32gui.GetWindowRect(handle)
return Box(x, y, abs(r - abs(x)), abs(b - abs(y)))
return Box(x, y, abs(r - x), abs(b - y))


def _moveResizeWindow(handle: int, newBox: Box):
Expand Down
19 changes: 19 additions & 0 deletions tests/test_pywinbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,77 +55,96 @@ def test_basic():
else:
myPyBox = pywinbox.PyWinBox(onQuery=pywinbox.defaultOnQuery, onSet=pywinbox.defaultOnSet, handle=npw.getHandle())

print("INIT", npw.box, npw.rect)

myPyBox.left = 250
time.sleep(timelap)
print("LEFT", npw.box, npw.rect)
assert npw.left == 250

myPyBox.right = 950
time.sleep(timelap)
print("RIGHT", npw.box, npw.rect)
assert npw.right == 950

myPyBox.top = 150
time.sleep(timelap)
print("TOP", npw.box, npw.rect)
assert npw.top == 150

myPyBox.bottom = 775
time.sleep(timelap)
print("BOTTOM", npw.box, npw.rect)
assert npw.bottom == 775

myPyBox.topleft = (155, 350)
time.sleep(timelap)
print(npw.box, npw.rect)
assert npw.topleft == (155, 350)

myPyBox.topright = (1000, 300)
time.sleep(timelap)
print(npw.box, npw.rect)
assert npw.topright == (1000, 300)

myPyBox.bottomleft = (300, 975)
time.sleep(timelap)
print(npw.box, npw.rect)
assert npw.bottomleft == (300, 975)

myPyBox.bottomright = (1000, 900)
time.sleep(timelap)
print(npw.box, npw.rect)
assert npw.bottomright == (1000, 900)

myPyBox.midleft = (300, 400)
time.sleep(timelap)
print(npw.box, npw.rect)
assert npw.midleft == (300, 400)

myPyBox.midright = (1050, 600)
time.sleep(timelap)
print(npw.box, npw.rect)
assert npw.midright == (1050, 600)

myPyBox.midtop = (500, 350)
time.sleep(timelap)
print(npw.box, npw.rect)
assert npw.midtop == (500, 350)

myPyBox.midbottom = (500, 800)
time.sleep(timelap)
print(npw.box, npw.rect)
assert npw.midbottom == (500, 800)

myPyBox.center = (500, 350)
time.sleep(timelap)
print(npw.box, npw.rect)
assert npw.center == (500, 350)

myPyBox.centerx = 1000
time.sleep(timelap)
print(npw.box, npw.rect)
assert npw.centerx == 1000

myPyBox.centery = 600
time.sleep(timelap)
print(npw.box, npw.rect)
assert npw.centery == 600

myPyBox.width = 700
time.sleep(timelap)
print(npw.box, npw.rect)
assert npw.width == 700

myPyBox.height = 500
time.sleep(timelap)
print(npw.box, npw.rect)
assert npw.height == 500

myPyBox.size = (801, 601)
time.sleep(timelap)
print(npw.box, npw.rect)
assert npw.size == (801, 601)

# Test closing
Expand Down

0 comments on commit 07bb48c

Please sign in to comment.