Esempio n. 1
0
def do_click(win_class=None,
             win_name=None,
             selector=None,
             button='left',
             curson='center',
             offsetX=0,
             offsetY=0,
             times=1,
             waitfor=WAIT_FOR,
             run_mode='unctrl'):
    '''
    点击控件
    win_class:窗口的ClassName
    win_name:窗口的Name
    selector:控件的信息
    button:left,right,middle
    curson:center,lefttop,rightbottom
    offsetX:Click(10, 10): click left+10, top+10
    offsetY:Click(-10, -10): click right-10, bottom-10
    times:1单击,2双击 
    '''
    # #     __logger.debug('automation 点击控件:[' + str(win_name) + '][' + str(control) + ']')
    try:
        automation.SetGlobalSearchTimeOut(waitfor)
        if run_mode == 'ctrl':
            return do_click_element(win_class=win_class,
                                    win_name=win_name,
                                    selector=selector)

        if win_name != None:
            iwin.do_win_activate(win_title=win_name, waitfor=waitfor)

        ctrl = get_control(win_class, win_name, selector)

        if run_mode == 'unctrl':
            ratioX, ratioY = get_pos_ratio(curson, offsetX, offsetY)
            ctrl.SetFocus()
            if button == 'left':
                if times == 1:
                    ctrl.Click(ratioX, ratioY)
                    pass
                else:
                    ctrl.DoubleClick(ratioX, ratioY)
            elif button == 'right':
                ctrl.RightClick(ratioX, ratioY)
            elif button == 'middle':
                ctrl.MiddleClick(ratioX, ratioY)

    except Exception as e:
        raise e
Esempio n. 2
0
def get_selected_item(win_class=None,
                      win_name=None,
                      selector=None,
                      waitfor=WAIT_FOR):
    try:
        automation.SetGlobalSearchTimeOut(waitfor)
        if win_name != None:
            iwin.do_win_activate(win_title=win_name, waitfor=waitfor)

        ctrl = get_control(win_class, win_name, selector)

        ctrl = automation.Control.CreateControlFromControl(ctrl)
        return ctrl.CurrentValue()
    except Exception as e:
        raise e
Esempio n. 3
0
def get_text(win_class=None,
             win_name=None,
             selector=None,
             return_field='value',
             waitfor=WAIT_FOR):
    try:
        automation.SetGlobalSearchTimeOut(waitfor)
        ctrl = get_control(win_class, win_name, selector)

        ctrl = automation.Control.CreateControlFromControl(ctrl)
        if return_field == 'value':
            return ctrl.AccessibleCurrentValue()
        else:
            return ctrl.AccessibleCurrentName()
    except Exception as e:
        raise e
Esempio n. 4
0
def get_element_rectangle(win_class=None,
                          win_name=None,
                          selector=None,
                          waitfor=WAIT_FOR):
    '''
    返回 :(left, top, right, bottom)
    '''
    try:
        automation.SetGlobalSearchTimeOut(waitfor)
        if win_name != None:
            iwin.do_win_activate(win_title=win_name, waitfor=waitfor)

        ctrl = get_control(win_class, win_name, selector)

        return ctrl.BoundingRectangle()
    except Exception as e:
        raise e
Esempio n. 5
0
def set_text(win_class=None,
             win_name=None,
             selector=None,
             text=None,
             waitfor=WAIT_FOR):
    try:
        text = encrypt.decrypt(text)
        automation.SetGlobalSearchTimeOut(waitfor)
        if win_name != None:
            iwin.do_win_activate(win_title=win_name, waitfor=waitfor)

        ctrl = get_control(win_class, win_name, selector)

        ctrl = automation.Control.CreateControlFromControl(ctrl)
        ctrl.SetValue(text)
    except Exception as e:
        raise e
Esempio n. 6
0
def get_check_status(win_class=None,
                     win_name=None,
                     selector=None,
                     waitfor=WAIT_FOR):
    '''
    获取CheckBox的状态    0:未选中,1:选中
    '''
    try:
        automation.SetGlobalSearchTimeOut(waitfor)
        if win_name != None:
            iwin.do_win_activate(win_title=win_name, waitfor=waitfor)

        ctrl = get_control(win_class, win_name, selector)

        ctrl = automation.Control.CreateControlFromControl(ctrl)
        return ctrl.CurrentToggleState()
    except Exception as e:
        raise e
Esempio n. 7
0
def do_click_element(win_class=None,
                     win_name=None,
                     selector=None,
                     waitfor=WAIT_FOR):
    '''
    do mouse click backgroud
    '''
    ctrl = None
    try:
        automation.SetGlobalSearchTimeOut(waitfor)
        if win_name != None:
            iwin.do_win_activate(win_title=win_name, waitfor=waitfor)

        ctrl = get_control(win_class, win_name, selector)
        ctrl = automation.Control.CreateControlFromControl(ctrl)
        ctrl.SetFocus()
        do_click_element_msg(ctrl)
        if ctrl.IsInvokePatternAvailable():
            ctrl.Invoke()

    except Exception as e:
        print(e)
        do_click_element_msg(ctrl)
Esempio n. 8
0
def do_moveto(win_class=None,
              win_name=None,
              selector=None,
              curson='center',
              offsetX=0,
              offsetY=0,
              waitfor=WAIT_FOR):
    try:
        automation.SetGlobalSearchTimeOut(waitfor)
        if win_name != None:
            iwin.do_win_activate(win_title=win_name, waitfor=waitfor)


#         win = get_win_control(win_class, win_name)
#         win.SwitchToThisWindow()
#         win.SetFocus()

        ctrl = get_control(win_class, win_name, selector)

        ratioX, ratioY = get_pos_ratio(curson, offsetX, offsetY)

        ctrl.MoveCursor(ratioX, ratioY)
    except Exception as e:
        raise e
Esempio n. 9
0
def do_check(win_class=None,
             win_name=None,
             selector=None,
             action="check",
             waitfor=WAIT_FOR):
    try:
        automation.SetGlobalSearchTimeOut(waitfor)
        if win_name != None:
            iwin.do_win_activate(win_title=win_name, waitfor=waitfor)

        ctrl = get_control(win_class, win_name, selector)

        ctrl = automation.Control.CreateControlFromControl(ctrl)

        state = ctrl.CurrentToggleState()

        if action == "check":
            if state == 0:
                return ctrl.Toggle()
        else:
            if state == 1:
                return ctrl.Toggle()
    except Exception as e:
        raise e