Установка с помощью PyWinAuto

Contents
Введение
Похожие статьи

Введение

# utils/install_controls.py import os import time import shutil def click_button(button: str, app, window_name: str, timeout=2): window = wait_for_window(app, window_name, timeout) match button: case "Install": window.Install.click() case "Next": window.Next.click() case "OK": window.OK.click() case "Start": window.Start.click() case "Yes": try: window.Yes.click() except Exception as e: print(f"Exception - did not manage to click Yes in {window_name}: {e}") # print(f"Control Identifier for {window_name}") # window.print_control_identifiers() return app def click_radiobutton(app, window_name: str, title:str, timeout=2) -> object: window = wait_for_window(app, window_name, timeout) # window.print_control_identifiers() rb = window.child_window(title=title, class_name="Button") try: rb.click() except Exception as e: print(f"\n\nException - did not manage to click {title} radio button: {e}") return app def input_text_to_child(app, window_name: str, child_title: str, text, timeout=2) -> object: window = wait_for_window(app, window_name, timeout) # window.print_control_identifiers() child = window.child_window(title=child_title, class_name="Edit") time.sleep(2) child.set_edit_text(text) return app def remove_directory(path): if os.path.exists(path): shutil.rmtree(path) else: print(f'{path} doesn\'t exist') def wait_for_window(app, window_name: str, timeout) -> object: timer = 0 time.sleep(1) while not app.window(best_match=window_name).exists(): time.sleep(.5) timer += 0.5 if timer > timeout: print(f"\n\nException - waited {timer} seconds for {window_name}") raise TimeoutError window = app.window(best_match=window_name) return window

# install.py import time from pywinauto.application import Application from aredel_module.aredel_paths import aredel_PATHS from utils.install_controls import click_button, click_radiobutton, input_text_to_child, remove_directory remove_directory(aredel_PATHS.aredel_DESTINATION_CATALOG) app_name = "Aredel Setup" print("\naredel_PATHS.aredel_INSTALL_EXE\n", aredel_PATHS.aredel_INSTALL_EXE) app = Application(backend='win32').start(aredel_PATHS.aredel_INSTALL_EXE) app = app.connect(best_match=app_name, timeout=3) while not app.windows(): time.sleep(.5) app = click_button("Next", app, "Welcome", 4) app = click_button("Next", app, "Select Target Directory") app = click_button("Yes", app, "Aredel Setup") app = click_button("Next", app, "Select Program Folder") app = click_radiobutton(app, 'Install License', title="&Yes") # No is "N&o" app = input_text_to_child(app, 'Install License', "A:\", aredel_PATHS.aredel_LICENSE) app = click_button("Install", app, 'Install License') app = click_button("OK", app, "Aredel Setup") app = click_button("Next", app, "Install License") app = click_button("Start", app, "Start Installation of Aredel 1.01")

Article author: Andrei Olegovich

Related articles
Automation
pywinauto
Python

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: