예제 #1
0
 def calDemo(self):
     app = Application(backend="uia").start('calc.exe')
     dlg = Desktop(backend="uia").Calculator
     dlg.type_keys('2*3=')
     dlg.print_control_identifiers()
     dlg.minimize()
     Desktop(backend="uia").window(title='Calculator',
                                   visible_only=False).restore()
예제 #2
0
def pywinauto_demo():
    from pywinauto import Application, Desktop

    # 获取应用对象
    # 三种方式任选一种
    # 方式一:应用进程pid(连接)
    # pid= 12492
    # app = Application(backend='uia').connect(process=pid)
    # # 方式二:应用完整路径(连接)
    # app = Application(backend='uia').connect(path="D:\Program Files (x86)\Tencent\WeChat\WeChat.exe")
    # # 方式三:打开应用(打开)
    # app = Application(backend='uia').start('D:\Program Files (x86)\Tencent\WeChat\WeChat.exe')

    app = Application(backend="uia").start('calc.exe')

    dlg = Desktop(backend="uia").计算器  # window specification
    dlg.type_keys('2*3=')
    dlg.print_control_identifiers()  # this is also window spec method

    dlg.minimize()
    # minimized window needs some tricks to find it and restore
    Desktop(backend="uia").window(title='计算器', visible_only=False).restore()
예제 #3
0
"""
Example script for Calculator on Windows 10

Requirements:
  - Windows 10
  - pywinauto 0.6.1+

Win10 version of Calculator is very specific. Few different processes (!)
own different windows and controls, so the full hierarchy can be accessed
through Desktop object only.

Minimized Calculator is a process in a "Suspended" state.
But it can be restored with some trick for invisible main window.
"""

from pywinauto import Desktop, Application

app = Application(backend="uia").start('calc.exe')

dlg = Desktop(backend="uia").Calculator
dlg.type_keys('2*3=')
dlg.print_control_identifiers()

dlg.minimize()
Desktop(backend="uia").window(title='Calculator', visible_only=False).restore()
예제 #4
0
# 设置检测记录信息的txt文件路径
record_txt_file = txt_path + "record.txt"

# 设置中文编码格式
# if sys.getdefaultencoding() != 'gbk':
#     importlib.reload(sys)
    # sys.setdefaultencoding('gbk')

# 打开计算器应用
app = Application(backend="uia").start("calc.exe")
dlg_spec = Desktop(backend="uia").window(title=u"计算器", visible_only=False)
dlg_spec.restore()

# 打印控件信息到指定路径
dlg_spec.print_control_identifiers(filename=control_txt_name)

"""

# 读取控件信息txt文件
fr = open(control_txt_name, "r")
# 设置正则表达式,用于提取button控件的title
par = r'.+title=\"([^,]+)\".+\"Button\"'
content = []
for line in fr.readlines():
    res = re.compile(par).findall(line)
    if res:
        result = str(res[0]).split(',')
        par_str = str(result[0])
        content.append(par_str)
    else:
예제 #5
0
from pywinauto import Desktop, Application
app = Application(backend="uia").start(
    "zoom --url=https://auhsdschools.zoom.us/j/7753695672?pwd=NTB1V1FRYTRnalBlYlBidnhXdDd2dz09#success"
)
#geet = app.start("zoom --url=https://auhsdschools.zoom.us/j/7753695672?pwd=NTB1V1FRYTRnalBlYlBidnhXdDd2dz09#success")

#dialog
#dialog = geet.child_window(title="Zoom Cloud Meetings", control_type="window")
dialog = Desktop(backend="uia").window(title="Zoom Cloud Meetings")
dialog.print_control_identifiers()

#dlg = app.window(title_re="Zoom Meetings")
#dlg.print_ctrl_ids()
#dlg = app.child_window(title="zoom", classname="zoomclass")
예제 #6
0
from pywinauto import Desktop, Application

Application().start('explorer.exe "C:\\Program Files"')

# connect to another process spawned by explorer.exe
app = Application(backend="uia").connect(path="explorer.exe", title="Program Files")

app.ProgramFiles.set_focus()
common_files = app.ProgramFiles.ItemsView.get_item('Common Files')
common_files.right_click_input()
app.ContextMenu.Properties.invoke()

# this dialog is open in another process (Desktop object doesn't rely on any process id)
Properties = Desktop(backend='uia').Common_Files_Properties
Properties.print_control_identifiers()
Properties.Cancel.click()
Properties.wait_not('visible') # make sure the dialog is closed
예제 #7
0
from pywinauto import Desktop, mouse

notifyWindow = Desktop(backend="uia").window(title_re='New notification')
notifyWindow.wait('visible', timeout=20)
print(notifyWindow.print_control_identifiers())
mailNotification = notifyWindow.child_window(
    title_re='New notification from Mail')
rect = mailNotification.rectangle()
mouse.click(coords=(rect.left // 2 + rect.right // 2,
                    rect.top // 2 + rect.bottom // 2 - 50))
예제 #8
0
class Calc:

    # LOCATORS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    def jeden(self):
        return self.window_name.child_window(title="1")

    def dwa(self):
        return self.window_name.child_window(title="2")

    def trzy(self):
        return self.window_name.child_window(title="3")

    def cztery(self):
        return self.window_name.child_window(title="4")

    def piec(self):
        return self.window_name.child_window(title="5")

    def szesc(self):
        return self.window_name.child_window(title="6")

    def siedem(self):
        return self.window_name.child_window(title="7")

    def osiem(self):
        return self.window_name.child_window(title="8")

    def dziewiec(self):
        return self.window_name.child_window(title="9")

    def zero(self):
        return self.window_name.child_window(title="0")

    def plus(self):
        return self.window_name.child_window(title="+")

    def rownasie(self):
        return self.window_name.child_window(title="Wykonaj")

    def wyczysc(self):
        return self.window_name.child_window(title="wyczyść")

    def wyczysc_his(self):
        return self.window_name.child_window(title="Wyczyść")

    def med(self):
        return self.window_name.child_window(title="Med")

    def p_nawias(self):
        return self.window_name.child_window(title=")")

    # END OF LOCATORS !!!!!!!!!!!!!!!!!!!!!!!!!

    # parameterized constructor
    def __init__(self, window_name):
        self.window_name = Desktop(backend="win32").window(best_match=window_name)

    def get_result(self):
        result = self.window_name.child_window(auto_id="tbWynik").texts()
        assert result[0] == result[1], ">>>>>>>>>>>>>>> somethig wrong with result - check get_result mehod in Calc.py"
        # if result[0] != result[1]:
        #     print(">>>>>>>>>>>>>>> somethig wrong with result - check get_result mehod in Calc.py")
        #     print(result[0], " 1= ", result[1])
        result = result[0]
        return result

    def get_ids(self, level):
        self.window_name.print_control_identifiers(depth=level)

    # click number (0-9)
    def click_1(self):
        self.jeden().click()

    def click_2(self):
        self.dwa().click()

    def click_3(self):
        self.trzy().click()

    def click_4(self):
        self.cztery().click()

    def click_5(self):
        self.piec().click()

    def click_6(self):
        self.szesc().click()

    def click_7(self):
        self.siedem().click()

    def click_8(self):
        self.osiem().click()

    def click_9(self):
        self.dziewiec().click()

    def click_0(self):
        self.zero().click()

    def click_plus(self):
        self.plus().click()

    def click_equal(self):
        self.rownasie().click()

    def click_wyczysc(self):
        self.wyczysc().click()

    def click_wyczysc_his(self):
        self.wyczysc_his().click()

    def click_med(self):
        self.med().click()

    def click_p_nawias(self):
        self.p_nawias().click()

    def click_rownasie(self):
        self.rownasie().click()

    def add_2(self, num1, num2):
        self.click_wyczysc()
        send_keys(num1)
        self.click_plus()
        send_keys(num2)
        self.click_rownasie()
        return self.get_result()

    def med_2(self, num1, num2):
        self.click_wyczysc()
        self.click_med()
        send_keys(num1)
        send_keys(";")
        send_keys(num2)
        self.click_p_nawias()
        self.click_rownasie()
        return self.get_result()

    def med_5(self, num1, num2, num3, num4, num5):
        self.click_wyczysc()
        self.click_med()
        send_keys(num1)
        send_keys(";")
        send_keys(num2)
        send_keys(";")
        send_keys(num3)
        send_keys(";")
        send_keys(num4)
        send_keys(";")
        send_keys(num5)
        self.click_p_nawias()
        self.click_rownasie()
        return self.get_result()
예제 #9
0
파일: check.py 프로젝트: nkpc14/ARYA
class AryaAI:
    """ Pywin @params  """
    MyApplicationList = {
        'sublime':
        'C:\\Program Files\\Sublime Text 3\\sublime_text.exe',
        'notepad':
        'notepad.exe',
        'paint':
        'mspaint.exe',
        'chrome':
        'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'
    }
    dlg = None
    app = None
    pxwindowclass = None
    menu_item = None

    def __init__(self):
        self.voiceModel = ""
        """ Starting Speech Recognisation  """

    def show():

        # Open "Control Panel"
        Application().start('control.exe')
        app = Application(backend='uia').connect(path='explorer.exe',
                                                 title='Control Panel')

        # Go to "Programs"
        app.window(title='Control Panel').ProgramsHyperlink.invoke()
        app.wait_cpu_usage_lower(threshold=0.5, timeout=30, usage_interval=1.0)

        # Go to "Installed Updates"
        app.window(title='Programs').child_window(
            title='View installed updates', control_type='Hyperlink').invoke()
        app.wait_cpu_usage_lower(threshold=0.5, timeout=30, usage_interval=1.0)

        list_box = app.InstalledUpdates.FolderViewListBox

        # list all updates
        items = list_box.descendants(control_type='ListItem')
        all_updates = [item.window_text() for item in items]
        print('\nAll updates ({}):\n'.format(len(all_updates)))
        print(all_updates)

        # list updates from "Microsoft Windows" group only
        windows_group_box = list_box.child_window(
            title_re='^Microsoft Windows.*', control_type='Group')
        windows_items = windows_group_box.descendants(control_type='ListItem')
        windows_updates = [item.window_text() for item in windows_items]
        print('\nWindows updates only ({}):\n'.format(len(windows_updates)))
        print(windows_updates)

    def aryaSTT(self):
        """
        # obtain audio from the microphone
        main()
        self.voiceModel = AryaSpeechModule.voiceModelData
        print("Arya : " + self.voiceModel)
        """
        r = sr.Recognizer()
        with sr.Microphone() as source:
            print("Say something!")
            audio = r.listen(source)
        # recognize speech using ARYA Speech Recognition
        GOOGLE_CLOUD_SPEECH_CREDENTIALS = os.environ.get(
            'GOOGLE_APPLICATION_CREDENTIALS')
        try:
            print(
                "Google Cloud Speech recognition for \"numero\" with different sets of preferred phrases:"
            )
            print(
                r.recognize_google_cloud(
                    audio,
                    credentials_json=GOOGLE_CLOUD_SPEECH_CREDENTIALS,
                    preferred_phrases=["noomarow"]))
            print(
                r.recognize_google_cloud(
                    audio,
                    credentials_json=GOOGLE_CLOUD_SPEECH_CREDENTIALS,
                    preferred_phrases=["newmarrow"]))
        except sr.UnknownValueError:
            print("Google Cloud Speech could not understand audio")
        except sr.RequestError as e:
            print(
                "Could not request results from Google Cloud Speech service; {0}"
                .format(e))

        try:
            self.voiceModel = r.recognize_google(audio)
            print("ARYA thinks you said " + self.voiceModel)
        except sr.UnknownValueError:
            print("ARYA  could not understand audio")
        except sr.RequestError as e:
            print("Could not request results from ARYA service; {0}".format(e))
        self.voiceModel = self.voiceModel.lower()

    def startSublime(self):
        self.app = Application().Start(
            cmd_line=u'"C:\\Program Files\\Sublime Text 3\\sublime_text.exe"')
        self.app = Application().Connect(
            title=u'untitled (demo) - Sublime Text (UNREGISTERED)',
            class_name='PX_WINDOW_CLASS')
        self.pxwindowclass = app.PX_WINDOW_CLASS
        self.pxwindowclass.Wait('ready')
        menu_item2 = self.pxwindowclass.MenuItem(u'&File->&New File\tCtrl+N')
        menu_item2.ClickInput()

    def startChrome(self):
        app = Application().Start(
            cmd_line=
            u'"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" -- "http:\\www.msftconnecttest.com\\redirect"'
        )
        chromewidgetwin = app.Chrome_WidgetWin_1
        chromewidgetwin.Wait('ready')

    def startPaint(self):
        self.app = Application(backend='uia').start(r'mspaint.exe')
        self.dlg = self.app.window(title_re='.* - Paint')

    def startNotepad(self):
        app = Application().Start(
            cmd_line=u'"C:\\WINDOWS\\system32\\notepad.exe" ')
        self.notepad = app.Notepad
        self.notepad.Wait('ready')

    def openFile(self, param):
        if (param == "sublime"):
            self.menu_item = self.pxwindowclass.MenuItem(u'&File')
            self.menu_item.ClickInput()
        elif (param == "notepad"):
            self.menu_item = self.notepad.MenuItem(u'&File')
            self.menu_item.ClickInput()
        elif (param == "paint"):
            self.dlg.File_tab.click()
            self.dlg.child_window(title='Open',
                                  control_type='MenuItem',
                                  found_index=0).invoke()
        else:
            pass

    def openNewFile(self, param):
        if (param == "sublime"):
            self.menu_item2 = self.pxwindowclass.MenuItem(
                u'&File->&New\tCtrl+N')
            self.menu_item2.ClickInput()
        elif (param == "notepad"):
            self.menu_item = self.notepad.MenuItem(u'&File->&New File\tCtrl+N')
            self.menu_item.ClickInput()

        elif (param == "paint"):
            self.dlg.File_tab.click()
            self.dlg.child_window(title='New',
                                  control_type='MenuItem',
                                  found_index=0).invoke()

        elif (param == "chrome"):
            pass
        else:
            pass

    def exitProgramm(self):
        self.app = Application().Connect(
            title=u'untitled (demo) - Sublime Text (UNREGISTERED)',
            class_name='PX_WINDOW_CLASS')
        self.menu_item2 = self.pxwindowclass.MenuItem(u'&File->&Exit')
        self.menu_item2.ClickInput()

    def typeSomething(self, param, message):

        if (param == "sublime"):
            self.pxwindowclass.type_keys(message, with_spaces=True)
        elif (param == "notepad"):
            self.notepad.type_keys("Hello welcome to ARYA!", with_spaces=True)
        else:
            pass

    def saveAs(self, param):
        if (param == "sublime"):
            self.menu_item = self.pxwindowclass.MenuItem(
                u'&File->Save &As\u2026\tCtrl+Shift+S')
            self.menu_item.ClickInput()
            SendKeys('{ENTER 2}')
        elif (param == "notepad"):
            self.app = Application().connect(title_re=".*Notepad",
                                             class_name="Notepad")
            self.app.notepad.menu_select("File->SaveAs")
            self.app.SaveAs.EncodingComboBox.select("UTF-8")
            self.app.SaveAs.edit1.set_edit_text("Example-utf8.txt")
            self.app.SaveAs.Save.close_click()
        elif (param == "paint"):
            self.dlg = self.app.window(title_re='.* - Paint')
            self.dlg.File_tab.click()
            self.dlg.SaveAsGroup.child_window(title="Save as",
                                              found_index=1).invoke()
        elif (param == "chrome"):
            pass
        else:
            pass

    def selectAll(self, param):
        if (param == "sublime"):
            self.app = Application().connect(title_re=".*Notepad",
                                             class_name="Notepad")
            self.app.notepad.menu_select("File->SaveAs")
        elif param == "notepad":
            self.app = Application().connect(title_re=".*Notepad",
                                             class_name="Notepad")
            menu_item2 = self.app.notepad.menu_select(
                "Edit->Select All\tCtrl+A")
            menu_item2.ClickInput()

    def copy(self, param):
        if (param == "sublime"):
            self.app = Application().connect(title_re=".*Notepad",
                                             class_name="Notepad")
            self.app.notepad.menu_select("File->SaveAs")
        elif param == "notepad":
            self.app = Application().connect(title_re=".*Notepad",
                                             class_name="Notepad")
            menu_item2 = self.app.notepad.menu_select("Edit->Copy\tCtrl+C")
            menu_item2.ClickInput()

    def paste(self, param):
        if (param == "sublime"):
            self.app = Application().connect(title_re=".*Notepad",
                                             class_name="Notepad")
            self.app.notepad.menu_select("File->SaveAs")
        elif param == "notepad":
            self.app = Application().connect(title_re=".*Notepad",
                                             class_name="Notepad")
            menu_item2 = self.app.notepad.menu_select("Edit->Paste\tCtrl+V")
            menu_item2.ClickInput()

    def exitApp(self, param):
        if param == "sublime":
            self.app = Application().connect(title_re=".*Notepad",
                                             class_name="Notepad")
            self.app.notepad.menu_select("File->Exit")
        elif param == "notepad":
            self.app = Application().connect(title_re=".*Notepad",
                                             class_name="Notepad")
            self.app.notepad.menu_select("File->Exit")

    def aryaVoiceModule(self, speech):
        engine = pyttsx3.init()
        engine.say(speech)
        engine.runAndWait()

    def openPaintMenuItem(self, param):
        if param == "new":
            self.dlg.child_window(title='New',
                                  control_type='MenuItem',
                                  found_index=0).invoke()
        elif param == "open":
            self.dlg.child_window(title='Open',
                                  control_type='MenuItem',
                                  found_index=0).invoke()
        elif param == "exit":
            self.dlg.child_window(title='Exit',
                                  control_type='MenuItem',
                                  found_index=0).invoke()

    def fileName(self, FileName):
        file_name_edit = self.dlg.Open.child_window(title="File name:",
                                                    control_type="Edit")
        file_name_edit.set_text(FileName + '.jpg')
        self.dlg.Open.child_window(title="Open",
                                   auto_id="1",
                                   control_type="Button").click()

    def resizePaint(self):
        self.dlg = self.app.window(title_re='.* - Paint')
        self.dlg.ResizeButton.click()
        self.dlg.ResizeAndSkew.Pixels.select()
        if self.dlg.ResizeAndSkew.Maintain_aspect_ratio.get_toggle_state(
        ) != 1:
            self.dlg.ResizeAndSkew.Maintain_aspect_ratio.toggle()
        self.dlg.ResizeAndSkew.HorizontalEdit1.set_text('100')
        self.dlg.ResizeAndSkew.OK.click()

    def saveImageType(self, param):
        self.dlg = self.app.window(title_re='.* - Paint')
        if param == "png":
            self.dlg.child_window(title='PNG picture', found_index=0).invoke()
            self.dlg.SaveAs.File_name_ComboBox.Edit.set_text('image.png')
            self.dlg.SaveAs.Save.click()
            if self.dlg.ConfirmSaveAs.exists():
                self.dlg.ConfirmSaveAs.Yes.click()
            #self.dlg.close()
        elif param == "jpg":
            self.dlg.child_window(title='JPEG picture', found_index=0).invoke()
            self.dlg.SaveAs.File_name_ComboBox.Edit.set_text('image.png')
            self.dlg.SaveAs.Save.click()
            if self.dlg.ConfirmSaveAs.exists():
                self.dlg.ConfirmSaveAs.Yes.click()
            #self.dlg.close()
        elif param == "bmp":
            self.dlg.child_window(title='BMP picture', found_index=0).invoke()
            self.dlg.SaveAs.File_name_ComboBox.Edit.set_text('image.png')
            self.dlg.SaveAs.Save.click()
            if self.dlg.ConfirmSaveAs.exists():
                self.dlg.ConfirmSaveAs.Yes.click()
            #self.dlg.close()
        elif param == "gif":
            self.dlg.child_window(title='GIF picture', found_index=0).invoke()
            self.dlg.SaveAs.File_name_ComboBox.Edit.set_text('image.png')
            self.dlg.SaveAs.Save.click()
            if self.dlg.ConfirmSaveAs.exists():
                self.dlg.ConfirmSaveAs.Yes.click()
            #self.dlg.close()

    def printPaint(self):
        self.dlg.SaveAsGroup.child_window(title="Print",
                                          found_index=1).invoke()
        self.dlg.child_window(title='Print', found_index=0).invoke()

    def close(self):
        self.dlg = self.app.window(title_re='.* - Paint')
        self.dlg.close()

    def calDemo(self):
        pass

    def startCal(self):
        self.app = self.Application(backend="uia").start('calc.exe')
        self.dlg = Desktop(backend="uia").Calculator
        self.dlg.type_keys('2*3=')
        self.dlg.print_control_identifiers()

    def exitNotepad(self):
        self.app = Application().connect(title_re=".*Notepad",
                                         class_name="Notepad")
        self.menu_item = self.notepad.MenuItem(u'&File')
        self.menu_item.ClickInput()
예제 #10
0
class AryaAI:
    """ Pywin @params  """
    MyApplicationList = {
        'sublime':
        'C:\\Program Files\\Sublime Text 3\\sublime_text.exe',
        'notepad':
        'notepad.exe',
        'paint':
        'mspaint.exe',
        'chrome':
        'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'
    }
    dlg = None
    app = None
    pxwindowclass = None
    menu_item = None

    def __init__(self):
        self.voiceModel = ""
        """ Starting Speech Recognisation  """

    def show():

        # Open "Control Panel"
        Application().start('control.exe')
        app = Application(backend='uia').connect(path='explorer.exe',
                                                 title='Control Panel')

        # Go to "Programs"
        app.window(title='Control Panel').ProgramsHyperlink.invoke()
        app.wait_cpu_usage_lower(threshold=0.5, timeout=30, usage_interval=1.0)

        # Go to "Installed Updates"
        app.window(title='Programs').child_window(
            title='View installed updates', control_type='Hyperlink').invoke()
        app.wait_cpu_usage_lower(threshold=0.5, timeout=30, usage_interval=1.0)

        list_box = app.InstalledUpdates.FolderViewListBox

        # list all updates
        items = list_box.descendants(control_type='ListItem')
        all_updates = [item.window_text() for item in items]
        print('\nAll updates ({}):\n'.format(len(all_updates)))
        print(all_updates)

        # list updates from "Microsoft Windows" group only
        windows_group_box = list_box.child_window(
            title_re='^Microsoft Windows.*', control_type='Group')
        windows_items = windows_group_box.descendants(control_type='ListItem')
        windows_updates = [item.window_text() for item in windows_items]
        print('\nWindows updates only ({}):\n'.format(len(windows_updates)))
        print(windows_updates)

    def aryaSTT(self):
        AryaMicToAudio.main()
        self.voiceModel = AryaAudToRecognise.convertToText()
        self.voiceModel = self.voiceModel.lower()

    def startSublime(self):
        self.app = Application().Start(
            cmd_line=u'"C:\\Program Files\\Sublime Text 3\\sublime_text.exe"')
        self.app = Application().Connect(
            title=u'untitled (demo) - Sublime Text (UNREGISTERED)',
            class_name='PX_WINDOW_CLASS')
        self.pxwindowclass = app.PX_WINDOW_CLASS
        self.pxwindowclass.Wait('ready')
        menu_item2 = self.pxwindowclass.MenuItem(u'&File->&New File\tCtrl+N')
        menu_item2.ClickInput()

    def startChrome(self):
        app = Application().Start(
            cmd_line=
            u'"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" -- "http:\\www.msftconnecttest.com\\redirect"'
        )
        chromewidgetwin = app.Chrome_WidgetWin_1
        chromewidgetwin.Wait('ready')

    def startPaint(self):
        self.app = Application(backend='uia').start(r'mspaint.exe')
        self.dlg = self.app.window(title_re='.* - Paint')

    def startNotepad(self):
        app = Application().Start(
            cmd_line=u'"C:\\WINDOWS\\system32\\notepad.exe" ')
        self.notepad = app.Notepad
        self.notepad.Wait('ready')

    def openFile(self, param):
        if (param == "sublime"):
            self.menu_item = self.pxwindowclass.MenuItem(u'&File')
            self.menu_item.ClickInput()
        elif (param == "notepad"):
            self.menu_item = self.notepad.MenuItem(u'&File')
            self.menu_item.ClickInput()
        elif (param == "paint"):
            self.dlg.File_tab.click()
            self.dlg.child_window(title='Open',
                                  control_type='MenuItem',
                                  found_index=0).invoke()
        else:
            pass

    def openNewFile(self, param):
        if (param == "sublime"):
            self.menu_item2 = self.pxwindowclass.MenuItem(
                u'&File->&New\tCtrl+N')
            self.menu_item2.ClickInput()
        elif (param == "notepad"):
            self.menu_item = self.notepad.MenuItem(u'&File->&New File\tCtrl+N')
            self.menu_item.ClickInput()

        elif (param == "paint"):
            self.dlg.File_tab.click()
            self.dlg.child_window(title='New',
                                  control_type='MenuItem',
                                  found_index=0).invoke()

        elif (param == "chrome"):
            pass
        else:
            pass

    def exitProgramm(self):
        self.app = Application().Connect(
            title=u'untitled (demo) - Sublime Text (UNREGISTERED)',
            class_name='PX_WINDOW_CLASS')
        self.menu_item2 = self.pxwindowclass.MenuItem(u'&File->&Exit')
        self.menu_item2.ClickInput()

    def typeSomething(self, param, message):

        if (param == "sublime"):
            self.pxwindowclass.type_keys(message, with_spaces=True)
        elif (param == "notepad"):
            self.notepad.type_keys(message, with_spaces=True)
        else:
            pass

    def saveAs(self, param):
        if (param == "sublime"):
            self.menu_item = self.pxwindowclass.MenuItem(
                u'&File->Save &As\u2026\tCtrl+Shift+S')
            self.menu_item.ClickInput()
            SendKeys('{ENTER 2}')
        elif (param == "notepad"):
            self.app = Application().connect(title_re=".*Notepad",
                                             class_name="Notepad")
            self.app.notepad.menu_select("File->SaveAs")
            self.app.SaveAs.EncodingComboBox.select("UTF-8")
            self.app.SaveAs.edit1.set_edit_text("Example-utf8.txt")
            self.app.SaveAs.Save.close_click()
        elif (param == "paint"):
            self.dlg = self.app.window(title_re='.* - Paint')
            self.dlg.File_tab.click()
            self.dlg.SaveAsGroup.child_window(title="Save as",
                                              found_index=1).invoke()
        elif (param == "chrome"):
            pass
        else:
            pass

    def selectAll(self, param):
        if (param == "sublime"):
            self.app = Application().connect(title_re=".*Notepad",
                                             class_name="Notepad")
            self.app.notepad.menu_select("File->SaveAs")
        elif param == "notepad":
            self.app = Application().connect(title_re=".*Notepad",
                                             class_name="Notepad")
            menu_item2 = self.app.notepad.menu_select(
                "Edit->Select All\tCtrl+A")
            menu_item2.ClickInput()

    def copy(self, param):
        if (param == "sublime"):
            self.app = Application().connect(title_re=".*Notepad",
                                             class_name="Notepad")
            self.app.notepad.menu_select("File->SaveAs")
        elif param == "notepad":
            self.app = Application().connect(title_re=".*Notepad",
                                             class_name="Notepad")
            menu_item2 = self.app.notepad.menu_select("Edit->Copy\tCtrl+C")
            menu_item2.ClickInput()

    def paste(self, param):
        if (param == "sublime"):
            self.app = Application().connect(title_re=".*Notepad",
                                             class_name="Notepad")
            self.app.notepad.menu_select("File->SaveAs")
        elif param == "notepad":
            self.app = Application().connect(title_re=".*Notepad",
                                             class_name="Notepad")
            menu_item2 = self.app.notepad.menu_select("Edit->Paste\tCtrl+V")
            menu_item2.ClickInput()

    def exitApp(self, param):
        if param == "sublime":
            self.app = Application().connect(title_re=".*Notepad",
                                             class_name="Notepad")
            self.app.notepad.menu_select("File->Exit")
        elif param == "notepad":
            self.app = Application().connect(title_re=".*Notepad",
                                             class_name="Notepad")
            self.app.notepad.menu_select("File->Exit")

    def aryaVoiceModule(self, speech):
        engine = pyttsx3.init()
        engine.say(speech)
        engine.runAndWait()

    def openPaintMenuItem(self, param):
        if param == "new":
            self.dlg.child_window(title='New',
                                  control_type='MenuItem',
                                  found_index=0).invoke()
        elif param == "open":
            self.dlg.child_window(title='Open',
                                  control_type='MenuItem',
                                  found_index=0).invoke()
        elif param == "exit":
            self.dlg.child_window(title='Exit',
                                  control_type='MenuItem',
                                  found_index=0).invoke()

    def fileName(self, FileName):
        file_name_edit = self.dlg.Open.child_window(title="File name:",
                                                    control_type="Edit")
        file_name_edit.set_text(FileName + '.jpg')
        self.dlg.Open.child_window(title="Open",
                                   auto_id="1",
                                   control_type="Button").click()

    def resizePaint(self):
        self.dlg = self.app.window(title_re='.* - Paint')
        self.dlg.ResizeButton.click()
        self.dlg.ResizeAndSkew.Pixels.select()
        if self.dlg.ResizeAndSkew.Maintain_aspect_ratio.get_toggle_state(
        ) != 1:
            self.dlg.ResizeAndSkew.Maintain_aspect_ratio.toggle()
        self.dlg.ResizeAndSkew.HorizontalEdit1.set_text('100')
        self.dlg.ResizeAndSkew.OK.click()

    def saveImageType(self, param):
        self.dlg = self.app.window(title_re='.* - Paint')
        if param == "png":
            self.dlg.child_window(title='PNG picture', found_index=0).invoke()
            self.dlg.SaveAs.File_name_ComboBox.Edit.set_text('image.png')
            self.dlg.SaveAs.Save.click()
            if self.dlg.ConfirmSaveAs.exists():
                self.dlg.ConfirmSaveAs.Yes.click()
            #self.dlg.close()
        elif param == "jpg":
            self.dlg.child_window(title='JPEG picture', found_index=0).invoke()
            self.dlg.SaveAs.File_name_ComboBox.Edit.set_text('image.png')
            self.dlg.SaveAs.Save.click()
            if self.dlg.ConfirmSaveAs.exists():
                self.dlg.ConfirmSaveAs.Yes.click()
            #self.dlg.close()
        elif param == "bmp":
            self.dlg.child_window(title='BMP picture', found_index=0).invoke()
            self.dlg.SaveAs.File_name_ComboBox.Edit.set_text('image.png')
            self.dlg.SaveAs.Save.click()
            if self.dlg.ConfirmSaveAs.exists():
                self.dlg.ConfirmSaveAs.Yes.click()
            #self.dlg.close()
        elif param == "gif":
            self.dlg.child_window(title='GIF picture', found_index=0).invoke()
            self.dlg.SaveAs.File_name_ComboBox.Edit.set_text('image.png')
            self.dlg.SaveAs.Save.click()
            if self.dlg.ConfirmSaveAs.exists():
                self.dlg.ConfirmSaveAs.Yes.click()
            #self.dlg.close()

    def printPaint(self):
        self.dlg.SaveAsGroup.child_window(title="Print",
                                          found_index=1).invoke()
        self.dlg.child_window(title='Print', found_index=0).invoke()

    def close(self):
        self.dlg = self.app.window(title_re='.* - Paint')
        self.dlg.close()

    def calDemo(self):
        app = Application(backend="uia").start('calc.exe')
        dlg = Desktop(backend="uia").Calculator
        dlg.type_keys('2*3=')
        dlg.print_control_identifiers()
        dlg.minimize()
        Desktop(backend="uia").window(title='Calculator',
                                      visible_only=False).restore()

    def startCal(self):
        self.app = self.Application(backend="uia").start('calc.exe')
        self.dlg = Desktop(backend="uia").Calculator
        self.dlg.type_keys('2*3=')
        self.dlg.print_control_identifiers()

    def exitNotepad(self):
        self.app = Application().connect(title_re=".*Notepad",
                                         class_name="Notepad")
        self.menu_item = self.notepad.MenuItem(u'&File')
        self.menu_item.ClickInput()

    def msPaintDemo(self):
        parser = argparse.ArgumentParser()
        parser.add_argument("--log",
                            help="enable logging",
                            type=str,
                            required=False)
        args = parser.parse_args()
        actionlogger.enable()
        logger = logging.getLogger('pywinauto')
        if args.log:
            logger.handlers[0] = logging.FileHandler(args.log)

        app = Application(backend='uia').start(r'mspaint.exe')
        dlg = app.window(title_re='.* - Paint')
        # File->Open menu selection
        dlg.File_tab.click()
        dlg.child_window(title='Open', control_type='MenuItem',
                         found_index=0).invoke()

        # handle Open dialog
        file_name_edit = dlg.Open.child_window(title="File name:",
                                               control_type="Edit")
        file_name_edit.set_text('image.jpg')
        dlg.Open.child_window(title="Open", auto_id="1",
                              control_type="Button").click()
        dlg.ResizeButton.click()
        dlg.ResizeAndSkew.Pixels.select()
        if dlg.ResizeAndSkew.Maintain_aspect_ratio.get_toggle_state() != 1:
            dlg.ResizeAndSkew.Maintain_aspect_ratio.toggle()
        dlg.ResizeAndSkew.HorizontalEdit1.set_text('100')
        dlg.ResizeAndSkew.OK.click()
        # Select menu "File->Save as->PNG picture"
        dlg.File_tab.click()
        dlg.SaveAsGroup.child_window(title="Save as", found_index=1).invoke()
        dlg.child_window(title='PNG picture', found_index=0).invoke()
        # Type output file name and save
        dlg.SaveAs.File_name_ComboBox.Edit.set_text('image.png')
        dlg.SaveAs.Save.click()
        if dlg.ConfirmSaveAs.exists():
            dlg.ConfirmSaveAs.Yes.click()
        # Close application
        dlg.close()
예제 #11
0
from pywinauto import Desktop, Application

Application().start('explorer.exe "C:\\Program Files"')

# connect to another process spawned by explorer.exe
# Note: make sure the script is running as Administrator!
app = Application(backend="uia").connect(path="explorer.exe",
                                         title="Program Files")

app.ProgramFiles.set_focus()
common_files = app.ProgramFiles.ItemsView.get_item('Common Files')
common_files.right_click_input()
app.ContextMenu.Properties.invoke()

# this dialog is open in another process (Desktop object doesn't rely on any process id)
Properties = Desktop(backend='uia').Common_Files_Properties
Properties.print_control_identifiers()
Properties.Cancel.click()
Properties.wait_not('visible')  # make sure the dialog is closed
예제 #12
0
class Calc:

    # LOCATORS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    def jeden(self):
        return self.window_name.Jeden

    def dwa(self):
        return self.window_name.Dwa

    def trzy(self):
        return self.window_name.Trzy

    def cztery(self):
        return self.window_name.Cztery

    def piec(self):
        return self.window_name.Pięć

    def szesc(self):
        return self.window_name.Sześć

    def siedem(self):
        return self.window_name.Siedem

    def osiem(self):
        return self.window_name.Osiem

    def dziewiec(self):
        return self.window_name.Dziewięć

    def zero(self):
        return self.window_name.Zero

    def plus(self):
        return self.window_name.Plus

    def rownasie(self):
        return self.window_name.child_window(title="Równa się", control_type="Button")

    # END OF LOCATORS !!!!!!!!!!!!!!!!!!!!!!!!!

    # parameterized constructor
    def __init__(self, window_name):
        self.window_name = Desktop(backend="uia").window(best_match=window_name)

    def set_button_by_title(self, button_title):
        self.window_name.child_window(title=button_title, control_type="Button").click()

    def set_button(self, button_name):
        try:
            self.window_name.child_window(title=button_name, control_type="Button").click()
        except Exception as e1:
            logging.exception(e1)
            try:
                self.window_name.child_window(auto_id=button_name, class_name="Button").click()
            except Exception as e:
                print("!!!!!!!No such button!!!!!!!!!")
                logging.exception(e)

    def get_result(self):
        result = self.window_name.child_window(auto_id="CalculatorResults", control_type="Text").texts()
        result = ''.join(result)
        result = result.strip("Wyświetlana wartość to ")
        result = result.replace(u'\xa0', u'')
        return result

    def get_ids(self, level):
        self.window_name.print_control_identifiers(depth=level)

    # click number (0-9)
    def click_1(self):
        self.jeden().click()

    def click_2(self):
        self.dwa().click()

    def click_3(self):
        self.trzy().click()

    def click_4(self):
        self.cztery().click()

    def click_5(self):
        self.piec().click()

    def click_6(self):
        self.szesc().click()

    def click_7(self):
        self.siedem().click()

    def click_8(self):
        self.osiem().click()

    def click_9(self):
        self.dziewiec().click()

    def click_0(self):
        self.zero().click()

    def click_plus(self):
        self.plus().click()

    def click_equal(self):
        self.rownasie().click()

    def add_2(self, num1, num2):
        send_keys(num1)
        self.click_plus()
        send_keys(num2)
        self.rownasie().click()
        return self.get_result()