def OnInitDialog(self, hwnd, msg, wparam, lparam): self.hwnd = hwnd # centre the dialog desktop = win32gui.GetDesktopWindow() l, t, r, b = win32gui.GetWindowRect(self.hwnd) dt_l, dt_t, dt_r, dt_b = win32gui.GetWindowRect(desktop) centre_x, centre_y = win32gui.ClientToScreen(desktop, ((dt_r - dt_l) // 2, (dt_b - dt_t) // 2)) win32gui.MoveWindow(hwnd, centre_x - (r // 2), centre_y - (b // 2), r - l, b - t, 0) # self._SetupList() l, t, r, b = win32gui.GetClientRect(self.hwnd) self._DoSize(r - l, b - t, 1)
def _DoSize(self, cx, cy, repaint=1): # right-justify the textbox. ctrl = win32gui.GetDlgItem(self.hwnd, IDC_SEARCHTEXT) l, t, r, b = win32gui.GetWindowRect(ctrl) l, t = win32gui.ScreenToClient(self.hwnd, (l, t)) r, b = win32gui.ScreenToClient(self.hwnd, (r, b)) win32gui.MoveWindow(ctrl, l, t, cx - l - 5, b - t, repaint) # The button. ctrl = win32gui.GetDlgItem(self.hwnd, IDC_BUTTON_OK) l, t, r, b = win32gui.GetWindowRect(ctrl) l, t = win32gui.ScreenToClient(self.hwnd, (l, t)) r, b = win32gui.ScreenToClient(self.hwnd, (r, b)) w = r - l win32gui.MoveWindow(ctrl, cx - 5 - w, t, w, b - t, repaint)
def chkimg(imgname, check=5, hwnd=None): global g_img_x, g_img_y #比較に使う画像のロード comimg = cv2.imread(imgname, 0) #キャプチャ if hwnd != None: rect = winxpgui.GetWindowRect(hwnd) size = winxpgui.GetClientRect(hwnd) cap = [rect[0], rect[1], size[2] + rect[0], size[3] + rect[1]] baseimg = ImageGrab.grab(cap) else: baseimg = ImageGrab.grab() #画像をグレースケールに変換 npimg = np.asarray(baseimg) capimg = cv2.cvtColor(npimg, cv2.COLOR_BGR2GRAY) #座標検索 retXY = compareImg(comimg, capimg, check) #見つかった場合座標を返す #なかった場合-1,-1を返す if (retXY != None): g_img_x = retXY[0] g_img_y = retXY[1] return (True) else: return (False)
def _calculate_center(self, size): w, h = size desktop = win32gui.GetDesktopWindow() al, at, ar, ab = win32gui.GetWindowRect(desktop) cx = (ar-al)/2; cy = (ab-at)/2 cx, cy = win32gui.ClientToScreen(desktop, (cx, cy)) l = cx - w/2; t = cy - h/2 return l, t
def _get_edge_sizes(self): wl, wt, wr, wb = win32gui.GetWindowRect(self._hwnd) cl, ct, cr, cb = win32gui.GetClientRect(self._hwnd) il, it = win32gui.ClientToScreen(self._hwnd, (cl, ct)) ir, ib = win32gui.ClientToScreen(self._hwnd, (cr, cb)) el = il - wl et = it - wt er = wr - ir eb = wb - ib return el, et, er, eb
def get_ss_by_pyws(device_name, filename): # get window handle hwnd = m.getid(device_name) # get window position rect = winxpgui.GetWindowRect(hwnd) # get window size size = winxpgui.GetClientRect(hwnd) # make list [x, y, w, h] cap = [rect[0], rect[1], size[2] + rect[0], size[3] + rect[1]] # capture img = ImageGrab.grab(cap) # save img.save(filename)
def on_init_dialog(self, hwnd, msg, wparam, lparam): self._hwnd = hwnd l, t = self._dialog_initial_position el, et, er, eb = self._get_edge_sizes() w = self._dialog_initial_size[0] + el + er h = self._dialog_initial_size[1] + et + eb win32gui.MoveWindow(self._hwnd, l, t, w, h, 0) l, t, r, b = win32gui.GetWindowRect(self._hwnd) w = r - l - el - er h = b - t - et - eb self._do_size(w, h, 1) self._post_init()
def getCapture(self): directory = 'capture' if not os.path.isdir(directory): os.makedirs(directory) try: handle = m.getid(self.windowTitle) rect = winxpgui.GetWindowRect(handle) except IndexError as e: self.setMessage(str(e)) return cpimg = ImageGrab.grab(rect) cpimg = np.asarray(cpimg) cpimg = cv2.cvtColor(cpimg, cv2.COLOR_RGB2BGR) cv2.imwrite( directory + '/' + datetime.now().strftime("%Y%m%d%H%M%S") + '.jpg', cpimg)
def _DoSize(self, cx, cy, repaint=1): # right-justify the textbox. # ctrl = win32gui.GetDlgItem(self.hwnd, IDC_JOB_NAME) # win32gui.SetWindowText(ctrl, self.job_name) # l, t, r, b = win32gui.GetWindowRect(ctrl) # l, t = win32gui.ScreenToClient(self.hwnd, (l, t)) # r, b = win32gui.ScreenToClient(self.hwnd, (r, b)) # win32gui.MoveWindow(ctrl, l, t, cx-l-5, b-t, repaint) ctrl = win32gui.GetDlgItem(self.hwnd, IDC_SCRIPT) win32gui.SetFocus(ctrl) # The button. ctrl = win32gui.GetDlgItem(self.hwnd, IDC_BUTTON_SUBMIT) l, t, r, b = win32gui.GetWindowRect(ctrl) l, t = win32gui.ScreenToClient(self.hwnd, (l, t)) r, b = win32gui.ScreenToClient(self.hwnd, (r, b)) w = r - l win32gui.MoveWindow(ctrl, cx - 5 - w, t, w, b - t, repaint)
def get_screenshot(device_path, device_name, filename): # {{{ if device_path != "": screencap_cmd = ["adb", "shell", "screencap", device_path] subprocess.check_call(screencap_cmd, shell=True) pull_cmd = ["adb", "pull", device_path] subprocess.check_call(pull_cmd, shell=True) else: # get window handle hwnd = m.getid(device_name) # get window position rect = winxpgui.GetWindowRect(hwnd) # get window size size = winxpgui.GetClientRect(hwnd) # make list [x, y, w, h] cap = [rect[0], rect[1], size[2] + rect[0], size[3] + rect[1]] # capture img = ImageGrab.grab(cap) # save img.save(filename) return # }}}