def __call__(self, x, y, displayNumber=0):
     monitorDimensions = GetMonitorDimensions()
     try:
         displayRect = monitorDimensions[displayNumber]
     except IndexError:
         displayRect = monitorDimensions[0]
     rect = RECT()
     mons = EnumDisplayMonitors(None, None)
     mons = [item[2] for item in mons]
     for hwnd in GetTopLevelOfTargetWindows():
         GetWindowRect(hwnd, byref(rect))
         X = rect.left
         Y = rect.top
         for mon in range(len(mons)):
             if mons[mon][0] <= X and X <= mons[mon][2] and mons[mon][
                     1] <= Y and Y <= mons[mon][3]:
                 break
         if mon == len(mons):
             mon = 0
         if x is None:
             x = rect.left - mons[mon][0]
         if y is None:
             y = rect.top - mons[mon][1]
         x += displayRect[0]
         y += displayRect[1]
         MoveWindow(hwnd, x, y, rect.right - rect.left,
                    rect.bottom - rect.top, 1)
示例#2
0
def EnsureVisible(window):
    """
    Ensures the given wx.TopLevelWindow is visible on the screen.
    Moves and resizes it if necessary.
    """
    from eg.WinApi.Dynamic import (
        sizeof, byref, GetMonitorInfo, MonitorFromWindow, GetWindowRect,
        MONITORINFO, RECT, MONITOR_DEFAULTTONEAREST,
        # MonitorFromRect, MONITOR_DEFAULTTONULL,
    )

    hwnd = window.GetHandle()
    windowRect = RECT()
    GetWindowRect(hwnd, byref(windowRect))

    #hMonitor = MonitorFromRect(byref(windowRect), MONITOR_DEFAULTTONULL)
    #if hMonitor:
    #    return

    parent = window.GetParent()
    if parent:
        hwnd = parent.GetHandle()
    hMonitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST)

    monInfo = MONITORINFO()
    monInfo.cbSize = sizeof(MONITORINFO)
    GetMonitorInfo(hMonitor, byref(monInfo))
    displayRect = monInfo.rcWork

    left = windowRect.left
    right = windowRect.right
    top = windowRect.top
    bottom = windowRect.bottom

    # shift the window horizontally into the display area
    if left < displayRect.left:
        right += (displayRect.left - left)
        left = displayRect.left
        if right > displayRect.right:
            right = displayRect.right
    elif right > displayRect.right:
        left += (displayRect.right - right)
        right = displayRect.right
        if left < displayRect.left:
            left = displayRect.left

    # shift the window vertically into the display area
    if top < displayRect.top:
        bottom += (displayRect.top - top)
        top = displayRect.top
        if bottom > displayRect.bottom:
            bottom = displayRect.bottom
    elif bottom > displayRect.bottom:
        top += (displayRect.bottom - bottom)
        bottom = displayRect.bottom
        if top < displayRect.top:
            top = displayRect.top

    # set the new position and size
    window.SetRect((left, top, right - left, bottom - top))
 def __call__(self, width=None, height=None):
     rect = RECT()
     for hwnd in GetTopLevelOfTargetWindows():
         GetWindowRect(hwnd, byref(rect))
         if width is None:
             width = rect.right - rect.left - 1
         if height is None:
             height = rect.bottom - rect.top - 1
         MoveWindow(hwnd, rect.left, rect.top, width + 1, height + 1, 1)