def _getWindowRect(self): """Returns a rect of window position and size (left, top, right, bottom). It follows ctypes format for compatibility""" frame = self._hWnd.frame() res = resolution() x = int(frame.origin.x) y = int(res.height) - int(frame.origin.y) - int(frame.size.height) w = x + int(frame.size.width) h = y + int(frame.size.height) return Rect(x, y, w, h)
def personinit(fig_path): rect_bg = Rect(50, 50, 133, 142) bg_speed = 2 begger_pos = [] begger = pygame.image.load(fig_path + 'person.png').convert_alpha() begger_width = begger.get_width() begger_height = begger.get_height() a = { 'rect_bg': rect_bg, 'bg_speed': bg_speed, 'begger_pos': begger_pos, 'begger': begger, 'begger_width': begger_width, 'begger_height': begger_height } return a
def _getWindowRect(self): """A nice wrapper for GetWindowRect(). TODO Syntax: BOOL GetWindowRect( HWND hWnd, LPRECT lpRect ); Microsoft Documentation: https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getwindowrect """ rect = RECT() result = ctypes.windll.user32.GetWindowRect(self._hWnd, ctypes.byref(rect)) if result != 0: return Rect(rect.left, rect.top, rect.right, rect.bottom) else: _raiseWithLastError()
def _getWindowRect(self): wininfos = subprocess.check_output(['xwininfo', '-id', str(self.x_id)]).decode('utf8') left = 0 top = 0 width = 0 height = 0 for info in wininfos.split("\n"): if "Absolute upper-left X" in info: left = int(info.split(": ")[1]) elif "Absolute upper-left Y" in info: top = int(info.split(": ")[1]) elif "Width" in info: width = int(info.split(": ")[1]) elif "Height" in info: height = int(info.split(": ")[1]) right = left + width bottom = top + height return Rect(left, top, right, bottom)
def _getWindowRect(self): """Returns a rect of window position and size (left, top, right, bottom). It follows ctypes format for compatibility""" cmd = """osascript -e 'tell application "System Events" to tell application process "%s" set winName to "%s" set appBounds to {0, 0, 0, 0} try set appPos to get position of window winName set appSize to get size of window winName set appBounds to {appPos, appSize} end try end tell return appBounds'""" % (self.appName, self.title) w = subprocess.check_output( cmd, shell=True).decode(encoding="utf-8").strip().split(", ") return Rect(int(w[0]), int(w[1]), int(w[0]) + int(w[2]), int(w[1]) + int(w[3]))
def _getWindowRect(self): """Returns a rect of window position and size (left, top, right, bottom). It follows ctypes format for compatibility""" # https://stackoverflow.com/questions/12775136/get-window-position-and-size-in-python-with-xlib - mgalgs win = self._hWnd x = y = w = h = 0 geom = win.get_geometry() (x, y) = (geom.x, geom.y) while True: parent = win.query_tree().parent pgeom = parent.get_geometry() x += pgeom.x y += pgeom.y if parent.id == ROOT.id: break win = parent w = geom.width h = geom.height return Rect(x, y, x + w, y + h)