def wrapper(*args, **kwargs):
     self, pms, loc, shape = args
     flag = kwargs.get("radio", "")
     print(args, flag, "check_radio")
     loc_x, loc_y = loc
     print(loc_x, loc_y, "check_radio")
     off_x, off_y = 22, 5
     fil_x = loc_x - off_x if loc_x - off_x > 0 else 0
     fil_y = loc_y - off_y if loc_y - off_y > 0 else 0
     filter_dic = {"left": fil_x, "top": fil_y, "width": 30, "height": 30}
     save_path = get_current_dir() + "/Test_Data/td_power_manager/temp.png"
     capture_screen_by_loc(save_path, filter_dic)
     if flag.upper() == "ON":
         path_sel = self._file_path + "Common/Radio_selected/"
         pic_path_list = get_folder_items(path_sel, file_only=True)
         for i in pic_path_list:
             if compare_pic_similarity(path_sel + i, save_path):
                 print(self.Info.format("Status is already checked"))
                 return
         else:
             func(*args, **kwargs)
     elif flag.upper() == "OFF":
         path_sel = self._file_path + "Common/Radio_unselected/"
         pic_path_list = get_folder_items(path_sel, file_only=True)
         for i in pic_path_list:
             if compare_pic_similarity(path_sel + i, save_path):
                 print(self.Info.format("Status is already unchecked"))
                 return
         else:
             func(*args, **kwargs)
Пример #2
0
 def wrapper(*args, **kwargs):
     res = func(*args, **kwargs)
     if not res:
         return False
     loc, shape = res
     checked = status.get("checkedbox", "")
     text = status.get("text", "")
     selected = status.get("selected", "")
     loc_x, loc_y = loc
     save_path = get_current_dir() + "/Test_Data/td_power_manager/temp.png"
     if checked:
         checked_path = get_current_dir("Test_Data/td_power_manager/verify_screen_saver_works/checked")
         if checked.lower() == "disabled":
             checked_path = get_current_dir("Test_Data/td_power_manager/verify_screen_saver_works/unchecked")
         pic_list = get_folder_items(checked_path)
         assert pic_list != [], "{} not exist".format(checked_path)
         off_x, off_y = -30, -15
         fil_x = loc_x + off_x if loc_x + off_x > 0 else 0
         fil_y = loc_y + off_y if loc_y + off_y > 0 else 0
         filter_dic = {"left": fil_x, "top": fil_y, "width": 30, "height": 30}
         capture_screen_by_loc(save_path, filter_dic)
         for i in pic_list:
             if compare_pic_similarity(checked_path + "/" + i, save_path):
                 break
         else:
             return False
     elif text:
         text_path = get_current_dir("Test_Data/td_power_manager/verify_screen_saver_works/text/{}".format(text))
         pic_list = get_folder_items(text_path)
         assert pic_list != [], "{} not exist".format(text_path)
         off_x, off_y = shape[1] - 10, -15
         fil_x = loc_x + off_x if loc_x + off_x > 0 else 0
         fil_y = loc_y + off_y if loc_y + off_y > 0 else 0
         filter_dic = {"left": fil_x, "top": fil_y, "width": 200, "height": 35}
         capture_screen_by_loc(save_path, filter_dic)
         for i in pic_list:
             if compare_pic_similarity(text_path + "/" + i, save_path):
                 break
         else:
             return False
     elif selected:
         text_path = get_current_dir("Test_Data/td_power_manager/verify_screen_saver_works/selected/{}".format(selected.lower()))
         pic_list = get_folder_items(text_path)
         assert pic_list != [], "{} not exist".format(text_path)
         off_x, off_y = shape[1] - 10, -15
         fil_x = loc_x + off_x if loc_x + off_x > 0 else 0
         fil_y = loc_y + off_y if loc_y + off_y > 0 else 0
         filter_dic = {"left": fil_x, "top": fil_y, "width": 200, "height": 35}
         capture_screen_by_loc(save_path, filter_dic)
         for i in pic_list:
             if compare_pic_similarity(text_path + "/" + i, save_path):
                 break
         else:
             return False
     return True
def set_user_password():
    current_path = get_current_dir("Test_Data")
    temp_path = current_path + "/temp.png"
    user = current_path + "/td_power_manager/user_icon"
    enabled = user + "/enabled"
    change_path = user + "/change"
    SwitchThinProMode("admin")
    time.sleep(1)
    log.info("Open security desktop")
    os.popen(
        "hptc-control-panel --config-panel /etc/hptc-control-panel/applications/hptc-security.desktop"
    )
    time.sleep(4)
    print(user)
    res = wait_element(user)
    if res:
        location, shape = res
        loc_x, loc_y = location
        offset_x, offset_y = 0, -20
        loc = {
            "left": loc_x + offset_x,
            "top": loc_y + offset_y,
            "width": 500,
            "height": 40
        }
        capture_screen_by_loc(temp_path, loc)
        enabled_list = get_folder_items(enabled, file_only=True)
        change_path_list = get_folder_items(change_path, file_only=True)
        flag = True
        for i in enabled_list:
            if compare_pic_similarity(enabled + "/{}".format(i), temp_path):
                break
        else:
            flag = False
        for i in change_path_list:
            change_res = compare_pic_similarity(change_path + "/{}".format(i),
                                                temp_path)
            if change_res:
                break
        else:
            change_res = False
        if flag and change_res:
            print(change_res, "change")
            change_loc, change_shape = change_res
            offset = (change_loc[0] + int(change_shape[1] / 2),
                      change_loc[1] + int(change_shape[0] / 2))
            print(offset)
            return (loc_x + offset_x, loc_y + offset_y), offset
    return False
Пример #4
0
 def __capture_part_screen(self, icon_path, position: tuple) -> tuple:
     save_path = get_current_dir("loc_demo.png")
     if not position:
         return picture_operator.wait_element(icon_path, offset=(0, 0))
     if not len(position) == 4:
         raise KeyError(
             "Position must be a tuple as: (left, top, width, height)")
     left, top, width, height = position
     current_x, current_y = self.loc
     pos = {
         "left": current_x + left,
         "top": current_y + top,
         "width": width,
         "height": height
     }
     capture_screen_by_loc(file_path=save_path, loc_dic=pos)
     items = get_folder_items(icon_path, file_only=True, filter_name=".png")
     pic_path_list = list(
         map(lambda file_name: icon_path + f"/{file_name}", items))
     for pic_item in pic_path_list:
         element_shape = compare_pic_similarity(img=pic_item, tmp=save_path)
         if element_shape:
             loc, size = element_shape
             loc_x, loc_y = loc
             current_left, current_top = current_x + left + loc_x, current_y + top + loc_y
             return (current_left, current_top), size
     return ()
 def lib_action_status(self):
     lib_action = os.path.join(self.folder, 'lib_action')
     file_list=get_folder_items(lib_action)
     for file in file_list:
         tag = file.split(".")[0].split("_")[-1]
         res = get_position(file, base_dir=lib_action,similaity=0.99)
         if res:
             return self.check_power_action_type(res[0], (200, 0))
def set_user_password(**kwargs):
    current_path = common_function.get_current_dir("Test_Data")
    temp_path = current_path + "/temp.png"
    user = current_path + "/td_power_manager/user_icon"
    enabled = user + "/enabled"
    change_path = user + "/change"
    SwitchThinProMode("admin")
    time.sleep(1)
    log.info("Open security desktop")
    os.popen("hptc-control-panel --config-panel /etc/hptc-control-panel/applications/hptc-security.desktop")
    time.sleep(2)
    res = picture_operator.wait_element(user)
    if res:
        location, shape = res
        loc_x, loc_y = location
        offset_x, offset_y = 0, -20
        loc = {"left": loc_x + offset_x, "top": loc_y + offset_y, "width": 500, "height": 40}
        picture_operator.capture_screen_by_loc(temp_path, loc)
        enabled_list = common_function.get_folder_items(enabled, file_only=True)
        change_path_list = common_function.get_folder_items(change_path, file_only=True)
        flag = True
        for i in enabled_list:
            if picture_operator.compare_pic_similarity(enabled + "/{}".format(i), temp_path):
                break
        else:
            flag = False
        for i in change_path_list:
            change_res = picture_operator.compare_pic_similarity(change_path + "/{}".format(i), temp_path)
            if change_res:
                break
        else:
            change_res = False
        if flag and change_res:
            change_loc, change_shape = change_res
            offset = (change_loc[0] + int(change_shape[1] / 2), change_loc[1] + int(change_shape[0] / 2))
            res = (loc_x + offset_x, loc_y + offset_y), offset
            loc, offset = res
            loc_x, loc_y = loc[0] + offset[0], loc[1] + offset[1]
            tool.click(loc_x, loc_y)
            time.sleep(1)
            tool.tap_key("1", 1)
            tool.tap_key("Tab", 1)
            tool.tap_key("1", 1)
            tool.tap_key(tool.keyboard.enter_key, 2)
            os.popen("hptc-control-panel --term")
 def switch(self, path=""):
     icon_path_list = get_folder_items(self.file_path, file_only=True)
     print(icon_path_list)
     res = self._get_loc_from_path_list(self.file_path, icon_path_list)
     loc, shape = res
     offset = int(shape[1] / 2), int(shape[0] / 2)
     self._click(loc, offset)
     PowerManager.common["switch"] = self._class_name
     return
 def apply(cls):
     print(cls._file_path, "apply")
     icon_path_list = get_folder_items(cls._file_path, file_only=True)
     assert icon_path_list, cls.Path_Error.format(icon_path_list)
     print(icon_path_list, "apply")
     res = cls._get_loc_from_path_list(cls._file_path, icon_path_list)
     loc, shape = res
     cls._click(loc, [int(shape[1] / 2), int(shape[0] / 2)])
     print(loc, shape, "apply")
 def cpu_mode_status(self):
     cpu_mode = os.path.join(self.folder, 'cpu_mode')
     file_list=get_folder_items(cpu_mode)
     for file in file_list:
         tag = file.split(".")[0].split("_")[-1]
         res = get_position(file, base_dir=cpu_mode,similaity=0.99)
         if res and tag=="ondemand":
             print("ondemand")
             return "ondemand"
         elif res and tag=="performance":
             print('performance')
             return 'performance'
 def look(self,sub_folder):
     full_folder = os.path.join(self.folder, sub_folder)
     file_list=get_folder_items(full_folder)
     for file in file_list:
         tag = file.split(".")[0].split("_")[-1]
         res = get_position(file, base_dir=full_folder,similaity=0.99)
         if res and tag=="checked":
             print("checked")
             return True
         elif res and tag=="unchecked":
             print('unchecked')
             return False
    def set_brightness_mtc_only(self, percent="0"):
        _bar_length = 405
        _bar_scope_per = 3.95
        _icon = (13, 13)
        _brightness_path = self._file_path + "Common/Brightness/"
        _icon_path = self._file_path + "Common/Brightness/Bright_Icon/"
        pic_path_list = get_folder_items(_brightness_path, file_only=True)
        print(_brightness_path, pic_path_list)
        assert pic_path_list, self.Path_Error.format(_brightness_path)
        res = self._get_loc_from_path_list(_brightness_path, pic_path_list)
        loc, shape = res
        print(res)
        loc_x_r = loc[0] + int(shape[1])

        icon_path_list = get_folder_items(_icon_path, file_only=True)
        assert pic_path_list, self.Path_Error.format(_icon_path)
        res = self._get_loc_from_path_list(_icon_path, icon_path_list)
        loc_i, shape_i = res
        offset_loc = (loc_i[0] + int(shape_i[1] / 2), loc_i[1] + int(shape_i[0] / 2))
        offset_x = _bar_scope_per * (percent-1) if isinstance(percent, float) else _bar_scope_per * (int(percent) -1)
        offset_x = int(round(offset_x + 7))
        drag(offset_loc, (loc_x_r + int(offset_x), offset_loc[1]))
def select_system_image():
    log.info(
        'select custom screensaver image image file diretory to the system image mode'
    )
    path = os.path.join(common_function.get_current_dir(), 'Test_Data',
                        'td_power_manager',
                        'verify_screensaver_works_in_system_image_mode',
                        'open')
    pic_list = common_function.get_folder_items(path, file_only=True)
    for i in pic_list:
        time.sleep(1)
        icon_location = wait_element(os.path.join(path, i))
        if icon_location:
            tool.click(icon_location[0][0], icon_location[0][1], 1)
 def critical_action_status(self):
     critical_action = os.path.join(self.folder, 'critical_action')
     file_list=get_folder_items(critical_action)
     for file in file_list:
         tag = file.split(".")[0].split("_")[-1]
         res = get_position(file, base_dir=critical_action,similaity=0.99)
         if res and tag=="nothing":
             print("nothing")
             return "nothing"
         elif res and tag=="shutdown":
             print('shutdown')
             return 'shutdown'
         elif res and tag=="sleep":
             print('sleep')
             return 'sleep'
 def mode_status(self):
     mode = os.path.join(self.folder, 'mode')
     file_list=get_folder_items(mode)
     for file in file_list:
         tag = file.split(".")[0].split("_")[-1]
         res = get_position(file, base_dir=mode,similaity=0.99)
         if res and tag=="normal":
             print("normal")
             return "normal"
         elif res and tag=="low":
             print('low')
             return 'low'
         elif res and tag=="critical":
             print('critical')
             return 'critical'
 def check_power_action_type(self,parent_region,offset_w_h,):
     power_actions=os.path.join(self.folder, 'power_actions')
     file_list = get_folder_items(power_actions)
     new_region=(parent_region[0],parent_region[1],parent_region[2]+offset_w_h[0],parent_region[3]+offset_w_h[1])
     for file in file_list:
         tag = file.split(".")[0].split("_")[-1]
         res = get_position(file, base_dir=power_actions, similaity=0.99,region=new_region)
         if res and tag=="nothing":
             print("nothing")
             return "nothing"
         elif res and tag=="shutdown":
             print('shutdown')
             return 'shutdown'
         elif res and tag=="sleep":
             print('sleep')
             return 'sleep'
Пример #16
0
def get_position_by_pic(name, offset=(10, 10), **kwargs):
    """
    It's a normal function to get a location
    :param name: picture path+name
    :param offset: diy a point
    :return: tuple,such as (12,12)
    """
    if isinstance(name, str) and os.path.isdir(name):
        pic_list = get_folder_items(name, file_only=True)
        assert pic_list, "pic is not exist in {}".format(name)
        pic_path_list = list(map(lambda x: name + "/{}".format(x), pic_list))
        name = pic_path_list
    if isinstance(name, list):
        time.sleep(0.5)
        return get_icon_by_pictures(name, offset, **kwargs)
    else:
        time.sleep(0.5)
        return get_icon_by_pic(name, offset, **kwargs)
 def _set_selected(self, pms, *args, **kwargs):
     loc, shape, selected, *arg = args
     print(selected, "set_sel")
     offset = pms.get("selected", ())
     assert offset != (), AttributeError("no Attribute {}".format("selected"))
     re_loc = list(map(lambda x, y: x + y, loc, (shape[1], int(shape[0] / 2))))
     self._click(re_loc, offset)
     time.sleep(0.5)
     if isinstance(selected, int):
         path = self.file_path + "{}/{}/".format(pms.get("index"), selected)
         pic_path_list = get_folder_items(path, file_only=True)
         assert pic_path_list, self.Path_Error.format(path)
         res = self._get_loc_from_path_list(path, pic_path_list)
         loc, shape = res
         offset = int(shape[1] / 2), int(shape[0] / 2)
         self._click(loc, offset)
         PowerManager.select["{}".format(self._class_name)] = selected
     elif callable(selected):
         path = self.file_path + "{}/".format(pms.get("index"))
         selected(path=path, **kwargs)
     return
 def set(self, pms, *args, **kwargs):
     radio = kwargs.get("radio", False)
     text = kwargs.get("text", "")
     selected = kwargs.get("selected", "")
     index = pms.get("index")
     if text or selected:
         print(pms.get("radio"), radio,)
         if isinstance(pms.get("radio"), tuple) and not radio:
             print(radio, "1234")
             print(self.Warning.format("Please set radio first!, try to work around"))
             radio = True
             kwargs["radio"] = "on"
     pic_parent_path = self.file_path + "{}/".format(index)
     print(pic_parent_path, "pic_path", 'set')
     pic_path_list = get_folder_items(pic_parent_path, file_only=True)
     assert pic_path_list, self.Path_Error.format(pic_parent_path)
     res = self._get_loc_from_path_list(pic_parent_path, pic_path_list)
     loc, shape = res
     if radio:
         self._set_radio(pms, loc, shape, **kwargs)
     if text:
         self._set_text(pms, loc, shape, text)
     if selected:
         self._set_selected(pms, loc, shape, selected, **kwargs)