def Select(self): """Select the menu item This will send a message to the parent window that the item was picked """ if not self.IsEnabled(): raise MenuItemNotEnabled("MenuItem '%s' is disabled" % self.Text()) #from HwndWrapper import delay_after_menuselect #if self.State() & win32defines.MF_BYPOSITION: # print self.Text(), "BYPOSITION" # self.ctrl.NotifyMenuSelect(self.Index(), True) #else: # seems like SetFoucs might be messing with getting the # id for Popup menu items - so I calling it before SetFocus command_id = self.ID() # notify the control that a menu item was selected self.ctrl.SetFocus() self.ctrl.SendMessageTimeout(win32defines.WM_COMMAND, win32functions.MakeLong(0, command_id)) #self.ctrl.NotifyMenuSelect(self.ID()) win32functions.WaitGuiThreadIdle(self.ctrl) time.sleep(Timings.after_menu_wait)
def Select(self, start=0, end=None): "Set the edit selection of the edit control" self.VerifyActionable() # if we have been asked to select a string if isinstance(start, str): string_to_select = start # start = self.TextBlock().index(string_to_select) if end is None: end = start + len(string_to_select) if end is None: end = -1 self.SendMessageTimeout(win32defines.EM_SETSEL, start, end) # give the control a chance to catch up before continuing win32functions.WaitGuiThreadIdle(self) time.sleep(Timings.after_editselect_wait) # return this control so that actions can be chained. return self
def Click(self): """Click on the menu item If the menu is open this it will click with the mouse on the item. If the menu is not open each of it's parent's will be opened until the item is visible. """ self.ctrl.VerifyEnabled() rect = self.Rectangle() if not self.IsEnabled(): raise MenuItemNotEnabled("MenuItem '%s' is disabled" % self.Text()) # if the item is not visible - work up along it's parents # until we find an item we CAN click on if rect == (0, 0, 0, 0): if self.menu.owner_item: self.menu.owner_item.Click() rect = self.Rectangle() x_pt = (rect.left + rect.right) / 2 y_pt = (rect.top + rect.bottom) / 2 from HwndWrapper import _perform_click_input #, delay_after_menuselect _perform_click_input(None, coords=(x_pt, y_pt), absolute=True) win32functions.WaitGuiThreadIdle(self.ctrl)
def Select(self, item): """Select the ComboBox item item can be either a 0 based index of the item to select or it can be the string that you want to select """ self.VerifyActionable() index = self._get_item_index(item) # change the selected item self.SendMessageTimeout(win32defines.CB_SETCURSEL, index) # Notify the parent that we are finished selecting self.NotifyParent(win32defines.CBN_SELENDOK) # Notify the parent that we have changed self.NotifyParent(win32defines.CBN_SELCHANGE) # simple combo boxes don't have drop downs so they do not recieve # this notification if self.HasStyle(win32defines.CBS_DROPDOWN): # Notify the parent that the drop down has closed self.NotifyParent(win32defines.CBN_CLOSEUP) win32functions.WaitGuiThreadIdle(self) time.sleep(Timings.after_comboboxselect_wait) # return this control so that actions can be chained. return self
def SetEditText(self, text, pos_start=None, pos_end=None): "Set the text of the edit control" self.VerifyActionable() # allow one or both of pos_start and pos_end to be None if pos_start is not None or pos_end is not None: # if only one has been specified - then set the other # to the current selection start or end start, end = self.SelectionIndices() if pos_start is None: pos_start = start if pos_end is None: pos_end = end # set the selection if either start or end has # been specified self.Select(pos_start, pos_end) else: self.Select() # replace the selection with text = ctypes.c_wchar_p(str(text)) self.SendMessageTimeout(win32defines.EM_REPLACESEL, True, text) win32functions.WaitGuiThreadIdle(self) time.sleep(Timings.after_editsetedittext_wait) # return this control so that actions can be chained. return self
def SetCheckIndeterminate(self): "Set the checkbox to indeterminate" self.SendMessageTimeout(win32defines.BM_SETCHECK, win32defines.BST_INDETERMINATE) win32functions.WaitGuiThreadIdle(self) time.sleep(Timings.after_buttoncheck_wait) # return this control so that actions can be chained. return self
def UnCheck(self): "Uncheck a checkbox" self.SendMessageTimeout(win32defines.BM_SETCHECK, win32defines.BST_UNCHECKED) win32functions.WaitGuiThreadIdle(self) time.sleep(Timings.after_buttoncheck_wait) # return this control so that actions can be chained. return self
def SetItemFocus(self, item): "Set the ListBox focus to the item at index" index = self._get_item_index(item) # if it is a multiple selection dialog if self.HasStyle(win32defines.LBS_EXTENDEDSEL) or \ self.HasStyle(win32defines.LBS_MULTIPLESEL): self.SendMessageTimeout(win32defines.LB_SETCARETINDEX, index) else: self.SendMessageTimeout(win32defines.LB_SETCURSEL, index) win32functions.WaitGuiThreadIdle(self) time.sleep(Timings.after_listboxfocuschange_wait) # return this control so that actions can be chained. return self
def Select(self, item): """Select the ListBox item item can be either a 0 based index of the item to select or it can be the string that you want to select """ self.VerifyActionable() # Make sure we have an index so if passed in a # string then find which item it is index = self._get_item_index(item) # change the selected item self.SendMessageTimeout(win32defines.LB_SETCURSEL, index) # Notify the parent that we have changed self.NotifyParent(win32defines.LBN_SELCHANGE) win32functions.WaitGuiThreadIdle(self) time.sleep(Timings.after_listboxselect_wait) return self
def Last_Second_Save(): # start = time.time() hndls = None hndls = findwindows.find_windows() imgs = None imgs = [] for hndl in hndls: if ((handleprops.exstyle(hndl) == 256 or handleprops.exstyle(hndl) == 786688 or handleprops.exstyle(hndl) == 262400 or handleprops.exstyle(hndl) == 65792 or handleprops.exstyle(hndl) == 2097408 or handleprops.exstyle(hndl) == 262416 or handleprops.exstyle(hndl) == 327937 or handleprops.exstyle(hndl) == 0) and not (handleprops.text(hndl) == None or handleprops.text(hndl) == "")): print( str(handleprops.text(hndl)) + " - " + str(handleprops.exstyle(hndl))) if (str(handleprops.text(hndl)).strip() == ""): continue else: try: app = None app = hwndwrapper.HwndWrapper(hndl) # app.set_focus() win32functions.WaitGuiThreadIdle(hndl) if app.is_minimized(): app.restore() time.sleep(0.25) win32functions.WaitGuiThreadIdle(hndl) app.set_focus() win32functions.WaitGuiThreadIdle(hndl) rect = None rect = handleprops.rectangle(hndl) win32functions.WaitGuiThreadIdle(hndl) box = None box = (rect.left, rect.top, rect.right, rect.bottom) img = None img = getRectAsImage(box) imgs.append(img) # time.sleep(0.1) except: # print("ERROR --- "+(str(handleprops.text(hndl)) + " - " + str(handleprops.processid(hndl)))) # print("Unexpected error:", sys.exc_info()[0]) continue #START IF# if len(imgs) > 0: sqrt = math.sqrt(len(imgs)) # print(sqrt) if sqrt > int(sqrt): if len(imgs) == 1: matrix_col, matrix_row = (1, 1) else: matrix_col, matrix_row = (int(sqrt), int(sqrt)) addition = [0] while (matrix_col * matrix_row) < len(imgs): if (addition[0] == 0): matrix_col += 1 addition[0] = 1 else: matrix_row += 1 addition[0] = 0 else: matrix_col, matrix_row = (int(sqrt), int(sqrt)) # print("MATRIX: " + str(matrix_row) + "x" + str(matrix_col)) finalRes_width = 960 * matrix_col finalRes_height = 540 * matrix_row result = Image.new("RGB", (finalRes_width, finalRes_height)) # print("RESULT IMAGE SIZE: " + str(result.size)) perImg_width = 960 perImg_height = 540 lst_counter = 0 # print("NUMBER OF IMGS: " + str(len(imgs))) for col in range(matrix_col): for row in range(matrix_row): if len(imgs) > lst_counter: imgs[lst_counter].thumbnail((perImg_width, perImg_height), Image.LANCZOS) x = col * perImg_width y = row * perImg_height w, h = imgs[lst_counter].size result.paste(imgs[lst_counter], (x, y, x + w, y + h)) lst_counter += 1 now = datetime.now() name = ("LastSecondSave-" + str(now.year) + "-" + str(now.month) + "-" + str(now.day) + "-" + str(now.hour) + "-" + str(now.minute)) homeDir = os.path.expanduser("~") if os.path.isdir(homeDir + "\\LastSecondSave"): result.save(homeDir + "\\LastSecondSave\\" + name + ".jpg") else: os.mkdir(homeDir + "\\LastSecondSave") result.save(homeDir + "\\LastSecondSave\\" + name + ".jpg")