コード例 #1
0
def _compareToPygameRect(rect, pygameRectleft, pygameRectTop, pygameRectWidth,
                         pygameRectHeight):
    rect = pyrect.Rect(pygameRectleft, pygameRectTop, pygameRectWidth,
                       pygameRectHeight)
    pygameRect = pygame.Rect(pygameRectleft, pygameRectTop, pygameRectWidth,
                             pygameRectHeight)
    assert rect.left == pygameRect.left
    assert rect.right == pygameRect.right
    assert rect.top == pygameRect.top
    assert rect.bottom == pygameRect.bottom

    assert rect.width == pygameRect.width
    assert rect.height == pygameRect.height

    assert rect.topleft == pygameRect.topleft
    assert rect.topright == pygameRect.topright
    assert rect.bottomleft == pygameRect.bottomleft
    assert rect.bottomright == pygameRect.bottomright

    assert rect.midtop == pygameRect.midtop
    assert rect.midbottom == pygameRect.midbottom
    assert rect.midleft == pygameRect.midleft
    assert rect.midleft == pygameRect.midleft

    assert rect.center == pygameRect.center
    assert rect.centerx == pygameRect.centerx
    assert rect.centery == pygameRect.centery
コード例 #2
0
    def __init__(self, hWnd=None):
        # hWnd equivalent in MacOS is CGWindowID
        # https://developer.apple.com/documentation/coregraphics/cgwindowid?language=objc
        self._hWnd = hWnd
        self._app = None

        def _onRead(attrName):
            r = _getWindowRect(self._hWnd)
            self._rect._left = r.left  # Setting _left directly to skip the onRead.
            self._rect._top = r.top  # Setting _top directly to skip the onRead.
            self._rect._width = r.right - r.left  # Setting _width directly to skip the onRead.
            self._rect._height = r.bottom - r.top  # Setting _height directly to skip the onRead.

        def _onChange(oldBox, newBox):
            self.moveTo(newBox.left, newBox.top)
            self.resizeTo(newBox.width, newBox.height)

        r = _getWindowRect(self._hWnd)
        self._rect = pyrect.Rect(r.left,
                                 r.top,
                                 r.right - r.left,
                                 r.bottom - r.top,
                                 onChange=_onChange,
                                 onRead=_onRead)
        self.__get_kCGWindow_dict()
コード例 #3
0
def test_box():
    # Test invalid settings
    r = pyrect.Rect(0, 0, 100, 100)

    assert r.box == (0, 0, 100, 100)
    r.box = (1, 2, 3, 4)
    assert r.left == 1
    assert r.top == 2
    assert r.width == 3
    assert r.height == 4

    with pytest.raises(pyrect.PyRectException):
        r.box = ('invalid', 1, 100, 200)
    with pytest.raises(pyrect.PyRectException):
        r.box = (0, 'invalid', 100, 200)
    with pytest.raises(pyrect.PyRectException):
        r.box = (0, 1, 'invalid', 200)
    with pytest.raises(pyrect.PyRectException):
        r.box = (0, 1, 100, 'invalid')

    with pytest.raises(AttributeError):
        del r.box

    r.enableFloat = True
    assert r.box == (1.0, 2.0, 3.0, 4.0)
コード例 #4
0
def get_eve_window_rect():
    oper_os = 'linux'
    oper_os = 'windows'
    if oper_os == 'windows':
        import pygetwindow
        win_hdn = pygetwindow.getWindowsWithTitle('EVE - Jayon Luthric')
        print('Did I find the rect??')
        print(win_hdn)

    elif oper_os == 'linux':
        # pyautogui.moveTo(1920,0,1)
        # print(pyautogui.getInfo())
        # print(pyautogui.position())

        rect = pyrect.Rect(1920, 0, 3840, 2160)
        rect = pyrect.Rect(1920, 0, 2560, 1440)

        return rect

    return None
コード例 #5
0
def win_warp_absolute_to_relative_rect(self, int_rect):
    '''
    添加pyautogui.Windows功能
    屏幕矩形->窗口内相对浮点矩形
    '''
    r = pyrect.Rect(enableFloat=True)
    r.left = (int_rect.left - self.left) / self.width
    r.top = (int_rect.top - self.top) / self.height
    r.width = int_rect.width / self.width
    r.height = int_rect.height / self.height
    return r
コード例 #6
0
def test_ctor():
    # Test basic positional and keyword arguments.
    r = pyrect.Rect(0, 1, 100, 200)
    _compareToPygameRect(r, 0, 1, 100, 200)
    assert r.left == 0
    assert r.top == 1
    assert r.width == 100
    assert r.height == 200

    r = pyrect.Rect(left=0, top=1, width=100, height=200)
    _compareToPygameRect(r, 0, 1, 100, 200)
    assert r.left == 0
    assert r.top == 1
    assert r.width == 100
    assert r.height == 200

    # Test float arguments with enableFloat
    r = pyrect.Rect(0.9, 1.9, 100.9, 200.9, enableFloat=True)
    assert r.left == 0.9
    assert r.top == 1.9
    assert r.width == 100.9
    assert r.height == 200.9

    # Test float arguments without enableFloat
    r = pyrect.Rect(0.9, 1.9, 100.9, 200.9, enableFloat=False)
    assert r.left == 0
    assert r.top == 1
    assert r.width == 100
    assert r.height == 200

    r = pyrect.Rect(0.9, 1.9, 100.9,
                    200.9)  # enableFloat should be False by default
    assert r.left == 0
    assert r.top == 1
    assert r.width == 100
    assert r.height == 200

    # Test invalid settings
    with pytest.raises(pyrect.PyRectException):
        pyrect.Rect('invalid', 1, 100, 200)
    with pytest.raises(pyrect.PyRectException):
        pyrect.Rect(0, 'invalid', 100, 200)
    with pytest.raises(pyrect.PyRectException):
        pyrect.Rect(0, 1, 'invalid', 200)
    with pytest.raises(pyrect.PyRectException):
        pyrect.Rect(0, 1, 100, 'invalid')
コード例 #7
0
def win_warp_relative_to_absolute_rect(self, float_rect):
    '''
    添加pyautogui.Windows功能
    窗口内相对浮点矩形转换到屏幕矩形
    '''
    #float_rect=pyrect.Rect(*float_list,enableFloat=True)
    r = pyrect.Rect()
    r.left = int(float_rect.left * self.width + 0.5) + self.left
    r.top = int(float_rect.top * self.height + 0.5) + self.top
    r.width = int(float_rect.width * self.width + 0.5)
    r.height = int(float_rect.height * self.height + 0.5)
    return r
コード例 #8
0
ファイル: __init__.py プロジェクト: dev-chip/EasyBoard
    def _setupRectProperties(self):
        def _onRead(attrName):
            r = self._getWindowRect()
            self._rect._left = r.left  # Setting _left directly to skip the onRead.
            self._rect._top = r.top  # Setting _top directly to skip the onRead.
            self._rect._width = r.right - r.left  # Setting _width directly to skip the onRead.
            self._rect._height = r.bottom - r.top  # Setting _height directly to skip the onRead.

        def _onChange(oldBox, newBox):
            self.moveTo(newBox.left, newBox.top)
            self.resizeTo(newBox.width, newBox.height)

        r = self._getWindowRect()
        self._rect = pyrect.Rect(r.left, r.top, r.right - r.left, r.bottom - r.top, onChange=_onChange, onRead=_onRead)
コード例 #9
0
def test_enableFloat():
    rect = pyrect.Rect(1, 2, 10, 20)
    assert rect.enableFloat == False
    assert rect.topleft == (1, 2)
    rect.enableFloat = True
    assert rect.topleft == (1.0, 2.0)
    rect.enableFloat = False
    assert rect.topleft == (1, 2)

    with pytest.raises(pyrect.PyRectException):
        rect.enableFloat = 'invalid'

    with pytest.raises(AttributeError):
        del rect.enableFloat
コード例 #10
0
ファイル: _pygetwindow_win.py プロジェクト: Serq0/T-racer
    def __init__(self, hWnd):
        self._hWnd = hWnd # TODO fix this, this is a LP_c_long insead of an int.

        def _onRead(attrName):
            r = _getWindowRect(self._hWnd)
            self._rect._left = r.left # Setting _left directly to skip the onRead.
            self._rect._top = r.top # Setting _top directly to skip the onRead.
            self._rect._width = r.right - r.left # Setting _width directly to skip the onRead.
            self._rect._height = r.bottom - r.top # Setting _height directly to skip the onRead.

        def _onChange(oldBox, newBox):
            self.moveTo(newBox.left, newBox.top)
            self.resizeTo(newBox.width, newBox.height)

        r = _getWindowRect(self._hWnd)
        self._rect = pyrect.Rect(r.left, r.top, r.right - r.left, r.bottom - r.top, onChange=_onChange, onRead=_onRead)
コード例 #11
0
def test_height():
    r = pyrect.Rect(0, 0, 100, 201)
    r.height = 200
    assert r.left == 0
    assert r.top == 0
    assert r.right == 100
    assert r.bottom == 200
    assert r.width == 100
    assert r.height == 200

    with pytest.raises(pyrect.PyRectException):
        r.height = 'invalid'

    with pytest.raises(AttributeError):
        del r.height

    r.enableFloat = True
    r.height = 99.1
    assert r.height == 99.1
コード例 #12
0
def test_centerx():
    r = pyrect.Rect(0, 150, 100, 200)
    r.centerx = 100
    assert r.centerx == 100
    assert r.left == 50
    assert r.top == 150
    assert r.right == 150
    assert r.bottom == 350
    assert r.width == 100
    assert r.height == 200

    with pytest.raises(pyrect.PyRectException):
        r.centerx = 'invalid'

    with pytest.raises(AttributeError):
        del r.centerx

    r.enableFloat = True
    r.centerx = 99.1
    assert r.centerx == 99.1
コード例 #13
0
def test_size():
    r = pyrect.Rect(0, 0, 100, 200)
    r.size = (22, 33)
    assert r.size == (22, 33)
    assert r.left == 0
    assert r.top == 0
    assert r.right == 22
    assert r.bottom == 33
    assert r.width == 22
    assert r.height == 33

    with pytest.raises(pyrect.PyRectException):
        r.size = 'invalid'

    with pytest.raises(AttributeError):
        del r.size

    r.enableFloat = True
    r.size = (99.1, 99.2)
    assert r.size == (99.1, 99.2)
コード例 #14
0
def test_center():
    r = pyrect.Rect(0, 99, 100, 200)
    r.center = (100, 150)
    assert r.center == (100, 150)
    assert r.left == 50
    assert r.top == 50
    assert r.right == 150
    assert r.bottom == 250
    assert r.width == 100
    assert r.height == 200

    with pytest.raises(pyrect.PyRectException):
        r.center = 'invalid'
    with pytest.raises(pyrect.PyRectException):
        r.center = 42

    with pytest.raises(AttributeError):
        del r.center

    r.enableFloat = True
    r.center = (99.1, 99.2)
    assert r.center == (99.1, 99.2)
コード例 #15
0
def test_readonly():
    r = pyrect.Rect(0, 10, 100, 200, readOnly=True)
    with pytest.raises(pyrect.PyRectException):
        r.left = 1000
    with pytest.raises(pyrect.PyRectException):
        r.right = 1000
    with pytest.raises(pyrect.PyRectException):
        r.top = 1000
    with pytest.raises(pyrect.PyRectException):
        r.bottom = 1000
    with pytest.raises(pyrect.PyRectException):
        r.centerx = 1000
    with pytest.raises(pyrect.PyRectException):
        r.centery = 1000
    with pytest.raises(pyrect.PyRectException):
        r.width = 1000
    with pytest.raises(pyrect.PyRectException):
        r.height = 1000
    with pytest.raises(pyrect.PyRectException):
        r.topleft = (1000, 2000)
    with pytest.raises(pyrect.PyRectException):
        r.topright = (1000, 2000)
    with pytest.raises(pyrect.PyRectException):
        r.bottomleft = (1000, 2000)
    with pytest.raises(pyrect.PyRectException):
        r.bottomright = (1000, 2000)
    with pytest.raises(pyrect.PyRectException):
        r.size = (1000, 2000)
    with pytest.raises(pyrect.PyRectException):
        r.midleft = (1000, 2000)
    with pytest.raises(pyrect.PyRectException):
        r.midright = (1000, 2000)
    with pytest.raises(pyrect.PyRectException):
        r.midtop = (1000, 2000)
    with pytest.raises(pyrect.PyRectException):
        r.midbottom = (1000, 2000)
    with pytest.raises(pyrect.PyRectException):
        r.box = (1000, 2000, 3000, 4000)
コード例 #16
0
def test_copy():
    r = pyrect.Rect(0, 0, 100, 100)
    c = r.copy()

    assert r == c
コード例 #17
0
def win_cfg_to_rect(self, list_rect):
    p = pyrect.Rect(*list_rect, enableFloat=True)
    ap = self.rect2absolute(p)
    #print(f"ap{ap},p{p}")
    return ap
コード例 #18
0
def test_str():
    r = pyrect.Rect(20, 30, 100, 150)
    assert str(r) == '(x=20, y=30, w=100, h=150)'
コード例 #19
0
def test_onChange_intRects():
    # TODO - using a global variable means this test can't be executed in parallel
    global spam

    def callbackFn(oldBox, newBox):
        global spam
        spam = 'changed'

    # testing side changes
    spam = 'unchanged'
    r = pyrect.Rect(0, 10, 100, 200, onChange=callbackFn)
    r.left = 0
    assert spam == 'unchanged'
    r.left = 1000  # changing left
    assert spam == 'changed'

    spam = 'unchanged'
    r = pyrect.Rect(0, 10, 100, 200, onChange=callbackFn)
    r.top = 10
    assert spam == 'unchanged'
    r.top = 1000  # changing top
    assert spam == 'changed'

    spam = 'unchanged'
    r = pyrect.Rect(0, 10, 100, 200, onChange=callbackFn)
    r.right = 100
    assert spam == 'unchanged'
    r.right = 1000  # changing right
    assert spam == 'changed'

    spam = 'unchanged'
    r = pyrect.Rect(0, 10, 100, 200, onChange=callbackFn)
    r.bottom = 210
    assert spam == 'unchanged'
    r.bottom = 1000  # changing bottom
    assert spam == 'changed'

    # testing size changes
    spam = 'unchanged'
    r = pyrect.Rect(0, 10, 100, 200, onChange=callbackFn)
    r.width = 100
    assert spam == 'unchanged'
    r.width = 1000  # changing width
    assert spam == 'changed'

    spam = 'unchanged'
    r = pyrect.Rect(0, 10, 100, 200, onChange=callbackFn)
    r.height = 200
    assert spam == 'unchanged'
    r.height = 1000  # changing height
    assert spam == 'changed'

    spam = 'unchanged'
    r = pyrect.Rect(0, 10, 100, 200, onChange=callbackFn)
    r.size = (100, 200)
    assert spam == 'unchanged'
    r.size = (1000, 200)  # changing width
    assert spam == 'changed'

    spam = 'unchanged'
    r.size = (1000, 1000)  # changing height
    assert spam == 'changed'

    spam = 'unchanged'
    r.size = (2000, 2000)  # changing width and height
    assert spam == 'changed'

    # testing corner changes
    spam = 'unchanged'
    r = pyrect.Rect(0, 10, 100, 200, onChange=callbackFn)
    r.topleft = (0, 10)
    assert spam == 'unchanged'
    r.topleft = (1000, 10)  # changing left
    assert spam == 'changed'

    spam = 'unchanged'
    r.topleft = (1000, 1000)  # changing top
    assert spam == 'changed'

    spam = 'unchanged'
    r.topleft = (2000, 2000)  # changing top and left
    assert spam == 'changed'

    spam = 'unchanged'
    r = pyrect.Rect(0, 10, 100, 200, onChange=callbackFn)
    r.topright = (100, 10)
    assert spam == 'unchanged'
    r.topright = (1000, 10)  # changing right
    assert spam == 'changed'

    spam = 'unchanged'
    r.topright = (1000, 1000)  # changing top
    assert spam == 'changed'

    spam = 'unchanged'
    r.topright = (2000, 2000)  # changing top and left
    assert spam == 'changed'

    spam = 'unchanged'
    r = pyrect.Rect(0, 10, 100, 200, onChange=callbackFn)
    r.bottomleft = (0, 210)
    assert spam == 'unchanged'
    r.bottomleft = (1000, 10)  # changing left
    assert spam == 'changed'

    spam = 'unchanged'
    r.bottomleft = (1000, 1000)  # changing bottom
    assert spam == 'changed'

    spam = 'unchanged'
    r.bottomleft = (2000, 2000)  # changing bottom and left
    assert spam == 'changed'

    spam = 'unchanged'
    r = pyrect.Rect(0, 10, 100, 200, onChange=callbackFn)
    r.bottomright = (100, 210)
    assert spam == 'unchanged'
    r.bottomright = (1000, 210)  # changing right
    assert spam == 'changed'

    spam = 'unchanged'
    r.bottomright = (1000, 1000)  # changing bottom
    assert spam == 'changed'

    spam = 'unchanged'
    r.bottomright = (2000, 2000)  # changing bottom and right
    assert spam == 'changed'

    # test midpoints
    spam = 'unchanged'
    r = pyrect.Rect(0, 10, 100, 200, onChange=callbackFn)
    r.midleft = (0, 110)
    assert spam == 'unchanged'
    r.midleft = (1000, 110)  # changing right
    assert spam == 'changed'

    spam = 'unchanged'
    r.midleft = (1000, 1000)  # changing mid left
    assert spam == 'changed'

    spam = 'unchanged'
    r.midleft = (2000, 2000)  # changing mid left and right
    assert spam == 'changed'

    spam = 'unchanged'
    r = pyrect.Rect(0, 10, 100, 200, onChange=callbackFn)
    r.midright = (100, 110)
    assert spam == 'unchanged'
    r.midright = (1000, 110)  # changing right
    assert spam == 'changed'

    spam = 'unchanged'
    r.midright = (1000, 1000)  # changing mid right
    assert spam == 'changed'

    spam = 'unchanged'
    r.midright = (2000, 2000)  # changing mid right and right
    assert spam == 'changed'

    spam = 'unchanged'
    r = pyrect.Rect(0, 10, 100, 200, onChange=callbackFn)
    r.midtop = (50, 10)
    assert spam == 'unchanged'
    r.midtop = (1000, 10)  # changing mid top
    assert spam == 'changed'

    spam = 'unchanged'
    r.midtop = (1000, 1000)  # changing top
    assert spam == 'changed'

    spam = 'unchanged'
    r.midtop = (2000, 2000)  # changing mid top and top
    assert spam == 'changed'

    spam = 'unchanged'
    r = pyrect.Rect(0, 10, 100, 200, onChange=callbackFn)
    r.midbottom = (50, 210)
    assert spam == 'unchanged'
    r.midbottom = (1000, 210)  # changing mid bottom
    assert spam == 'changed'

    spam = 'unchanged'
    r.midbottom = (1000, 1000)  # changing bottom
    assert spam == 'changed'

    spam = 'unchanged'
    r.midbottom = (2000, 2000)  # changing bottom and mid bottom
    assert spam == 'changed'

    # testing center
    spam = 'unchanged'
    r = pyrect.Rect(0, 10, 100, 200, onChange=callbackFn)
    r.center = (50, 110)
    assert spam == 'unchanged'
    r.center = (1000, 110)  # changing centerx
    assert spam == 'changed'

    spam = 'unchanged'
    r.center = (1000, 1000)  # changing centery
    assert spam == 'changed'

    spam = 'unchanged'
    r.center = (2000, 2000)  # changing centerx and centery
    assert spam == 'changed'

    spam = 'unchanged'
    r = pyrect.Rect(0, 10, 100, 200, onChange=callbackFn)
    r.centerx = 50
    assert spam == 'unchanged'
    r.centerx = 1000  # changing centerx
    assert spam == 'changed'

    spam = 'unchanged'
    r = pyrect.Rect(0, 10, 100, 200, onChange=callbackFn)
    r.centery = 110
    assert spam == 'unchanged'
    r.centery = 1000  # changing mid bottom
    assert spam == 'changed'

    # testing box
    spam = 'unchanged'
    r = pyrect.Rect(0, 10, 100, 200, onChange=callbackFn)
    r.box = (0, 10, 100, 200)
    assert spam == 'unchanged'
    r.box = (1000, 10, 100, 200)  # changing left
    assert spam == 'changed'

    spam = 'unchanged'
    r.box = (1000, 2000, 100, 200)  # changing top
    assert spam == 'changed'

    spam = 'unchanged'
    r.box = (1000, 2000, 3000, 200)  # changing width
    assert spam == 'changed'

    spam = 'unchanged'
    r.box = (1000, 2000, 3000, 4000)  # changing height
    assert spam == 'changed'
コード例 #20
0
def test_eq_ne():
    r1 = pyrect.Rect(0, 0, 100, 100)
    r2 = pyrect.Rect(0, 0, 100, 100)

    assert r1 == r2
    assert not r1 != r2
コード例 #21
0
def test_operators():
    r1 = pyrect.Rect(0, 0, 100, 100)
    r2 = pyrect.Rect(0, 0, 100, 100)

    assert r1 == r2
コード例 #22
0
def test_repr():
    r = pyrect.Rect(20, 30, 100, 150)
    assert repr(r) == 'Rect(left=20, top=30, width=100, height=150)'