def __init__(self, binary_path=r'C:\bb\bbw.exe', try_connect=True): self.biab_version = _get_exe_version(binary_path) if self.biab_version != self._TARGET_VERSION: print('This code was written for Band-in-a-Box {}, your version is {}. ' 'Proceed with caution.' .format(self._TARGET_VERSION, self.biab_version), file=sys.stderr) self._app = Application(backend='win32') if try_connect: try: self._app.connect(path=binary_path) except ProcessNotFoundError: try_connect = False if not try_connect: self._app.start(binary_path) self._app.wait_cpu_usage_lower(threshold=5) def get_ready(): rb_window = self._app.window(class_name='TBandWindow') if rb_window.exists() and rb_window.is_visible() and rb_window.is_enabled(): return raise TimeoutError() wait_until_passes(func=get_ready, exceptions=(ElementNotFoundError, TimeoutError), timeout=15, retry_interval=1)
def _menu_select(self, path, timeout=10, retry_interval=0.5): self.wait_ready() def select_option(): self._app.RealBand.menu_select(path) wait_until_passes(func=select_option, exceptions=(ElementNotEnabled, RuntimeError), timeout=timeout, retry_interval=retry_interval)
def load_style(self, path): """Load a style from the given file.""" self.wait_ready() def open_dialog(): # Bring up the style popup menu and choose to open a style file self._song_pane.click_input(coords=(44, 73), absolute=False) menu = self._app.window(class_name='#32768') menu.menu_item('File Open Style').click_input() wait_until_passes(func=open_dialog, exceptions=ElementNotFoundError, timeout=120, retry_interval=0.4) self._open_file(path)
def _get_menu_item_text(self, path, timeout=10, retry_interval=0.5): def get_text(): return self._app.RealBand.menu_item(path).text() return wait_until_passes(func=get_text, exceptions=(ElementNotEnabled, RuntimeError), timeout=timeout, retry_interval=retry_interval)
def __init__(self, binary_path=r'C:\RealBand\RealBand.exe', try_connect=True): self.realband_version = _get_exe_version(binary_path) if self.realband_version != self._TARGET_VERSION: print('This code was written for RealBand {}, your version is {}. ' 'Proceed with caution.' .format(self._TARGET_VERSION, self.realband_version), file=sys.stderr) self._app = Application(backend='win32') if try_connect: try: self._app.connect(path=binary_path) except ProcessNotFoundError: try_connect = False if not try_connect: self._app.start(binary_path) self._app.wait_cpu_usage_lower(threshold=5) def get_ready(): rb_window = self._app.window(class_name='RealBand') if rb_window.exists() and rb_window.is_visible() and rb_window.is_enabled(): return # Reject attempts to recover from a crash dialog = self._app.window(class_name='#32770') dialog_text = dialog.StaticWrapper2.element_info.name if ('Okay to restore all the default settings' in dialog_text or 'Recover data from last session' in dialog_text): dialog.Button2.click() raise TimeoutError() wait_until_passes(func=get_ready, exceptions=(ElementNotFoundError, TimeoutError), timeout=15, retry_interval=1) self._song_pane = self._app.RealBand.children( class_name='TPanelWithCanvas')[10]
from pywinauto import application from pywinauto import timings import time import os app = application.Application() app.start("D:/Utility/KiwoomFlash3/bin/nkministarter.exe") title = "번개3 Login" dlg = timings.wait_until_passes(20, 0.5, lambda: app.window(title=title)) pass_ctrl = dlg.Edit2 pass_ctrl.SetFocus() pass_ctrl.TypeKeys('jhw1098') cert_ctrl = dlg.Edit3 cert_ctrl.SetFocus() cert_ctrl.Typekeys('j@ong9589866') btn_ctrl = dlg.Button0 btn_ctrl.Click() time.sleep(50) os.system("taskkill /im khmini.exe")
def join(calender_return, current_time): # ----List if all todays meeting----- meet = list(calender_return['Start']) # ----index of current meeting---- to_join = meet.index(current_time) # -extracting body content of current meeting- link1 = list(calender_return['Body'])[to_join] # -------------------------Parsing url from body----------------------- link_to_go = re.search("(?P<url>https?://[^\\s]+)", link1).group("url") link_to_go = link_to_go[:-1] # wait for one minute before joing meeting time.sleep(60) # -Handelling the handshake errors- options = webdriver.ChromeOptions() options.add_argument('--ignore-certificate-errors') options.add_argument('--ignore-ssl-errors') options.add_experimental_option('excludeSwitches', ['enable-logging']) # ---------creating webdriver instance---------- driver = webdriver.Chrome(PATH, options=options) # opening link in webbrowser driver.get(link_to_go) app_chrome = Application().connect(title_re='.*Start Your Meeting.*') app_chrome_window = app_chrome.window(title_re='.*Start Your Meeting.*') if app_chrome_window.exists(): app_chrome_window.set_focus() # wait till the link get loaded WebDriverWait(driver, 60) # Open Meeting in Window app send_keys("{LEFT}") send_keys("{ENTER}") # ----------------------------------------------------------------------------------------------------------- # Workaround is needed to open meeting in browser if app is not installed or dont want to open in window app # ----------------------------------------------------------------------------------------------------------- # -----------handelling warnings if any ------------- warnings.simplefilter('ignore', category=UserWarning) # --------Connect to cisco webex meetng app---------- try: app = wait_until_passes( 10, 1, lambda: Application().connect(title_re=".*Meetings", class_name="wcl_manager1")) app_window = app.window(title_re=".*Meetings", class_name="wcl_manager1") # Close chrome tab and connect to meeting once app is connected if app_window.exists(): app_window.set_focus() time.sleep(7) send_keys("{ENTER}") send_keys("{ENTER}") driver.close() except Exception as e: print( f"{type(e).__name__} at line {e.__traceback__.tb_lineno} of {__file__}: {e}" )
# -*- coding:utf-8 -*- import os import time from pywinauto import application, timings app = application.Application() # 네이버 어플을 찾고 해당 다이얼로그를 찾고 거기에 타이핑하는 방법 # (이건 아님)handle = app.findwindows.find_windows(title_re="*")[0] # 앱을 handle주소를 통해 연결 - SWAPY 어플 app.connect(handle=1049572) # 원하는 부분에 접근 dlg = timings.wait_until_passes(10, 0.5, lambda: app.window(handle=1049572)) print(dlg) # 원하는 액션 dlg.type_keys("Hello Naver") dlg.click()
from pywinauto import application, timings import os, time from private_folder import privatekey # 실전투자 여부 REAL_TRADING = True app = application.Application() app.start('C:/KiwoomFlash3/bin/nkministarter.exe') title = "번개3 Login" dlg = timings.wait_until_passes(20, 0.5, lambda: app.connect(title=title).Dialog) id_ctrl = dlg.Edit0 id_ctrl.set_focus() id_ctrl.type_keys(privatekey.id) pass_ctrl = dlg.Edit2 pass_ctrl.set_focus() pass_ctrl.type_keys(privatekey.pw) if REAL_TRADING: # 공인인증서 암호 저장창 cert_ctrl = dlg.Edit3 cert_ctrl.set_focus() cert_ctrl.type_keys(privatekey.pw2) btn_ctrl = dlg.Button0 btn_ctrl.click() else: