from time import sleep # from subprocess import check_output import re # import subprocess as sp import keyboard as kb import pyautogui as gui import pywinctl as gw sleep_time = 0.05 CONF = 0.8 interval_ = 0.05 mentor_user = 'Utilizator: Contab' def abbr(short_cut, abbr_message, modifier=''): shc = short_cut if shc == ' ': shc1 = re.findall(' +', shc) gui.typewrite(abbr_message) gui.press('left', presses=1, interval=0.001) gui.press('backspace', presses=1, interval=0.001) gui.press('right', presses=1, interval=0.001) else: shc1 = re.findall('[a-z0-9-]*', shc) gui.press('backspace', presses=len(''.join(shc1) + modifier), interval=interval_) # gui.typewrite(abbr_message, interval=sleep_time) kb.write(abbr_message) def _printer(func): def wrapper(): print(func.__doc__, 'h_key performed') return func() return wrapper def mv_mouse_right(): size = gui.size() gui.moveTo(size[0] / 1.01, size[1] / 1.01) # gui.click() def mv_mouse_cent(): size = gui.size() gui.moveTo(size[0] / 2, size[1] / 2) @_printer def remake_journal(): '''refacere jurnal''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # # # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/contabile.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('enter') mv_mouse_cent() # gui.move(1, 1) except IndexError: print('activate mentor') @_printer def cash_registry(): '''registru de casa''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # # # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/trezorerie.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('right', 1, interval_) gui.press('down', 1, interval_) gui.press('return', 1, interval_) mv_mouse_cent() # print('please activate Window LISTE') except IndexError: print('activate mentor') @_printer def clients_ron(): '''clienti datornici''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # # # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/parteneri.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('right', 1, interval_) # gui.press('down', 2, interval_) gui.press('return', 2, interval_) mv_mouse_cent() except IndexError: print('activate mentor') @_printer def verif_balance(): '''balanta de verificare''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # # # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/contabile.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 1, interval_) gui.press('right', 1, interval_) gui.press('down', 1, interval_) gui.press('return', 2, interval_) mv_mouse_cent() except IndexError: print('activate mentor') @_printer def suppliers_ron(): '''furnizori neachitati''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # # # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/parteneri.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 1, interval_) gui.press('right', 1, interval_) gui.press('down', 3, interval_) gui.press('return', 2, interval_) mv_mouse_cent() except IndexError: print('activate mentor') @_printer def suppliers_ron_verif(): '''furnizori neachitati''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # # # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/parteneri.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 1, interval_) gui.press('right', 1, interval_) gui.press('down', 2, interval_) gui.press('return', 2, interval_) mv_mouse_cent() except IndexError: print('activate mentor') @_printer def suppliers_val(): '''furnizori neachitati eur''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # # # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/parteneri.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 1, interval_) gui.press('right', 1, interval_) gui.press('down', 4, interval_) gui.press('return', 2, interval_) mv_mouse_cent() except IndexError: print('activate mentor') @_printer def bank_registry_ron(): '''registru de banca lei''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # # # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/trezorerie.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 4, interval_) gui.press('return', 1, interval_) mv_mouse_cent() except IndexError: print('activate mentor') @_printer def h_key12(): '''registru de banca''' try: sleep(sleep_time) dummy = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] active_win = gw.getActiveWindowTitle() if dummy.title in active_win: try: dummy.activate() except Exception as e: print(str(e)) mv_mouse_right() kb.press_and_release('ctrl+f10') # gui.press('f10') gui.press('right', 3, interval_) gui.press('down', 1, 0.0) gui.press('down', 6, 0.0) gui.press('return', 1, interval_) except IndexError: print('please activate Window LISTE') @_printer def bank_registry_val(): '''registru de banca val''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # # # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/trezorerie.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 6, 0.0) gui.press('return', 1, interval_) mv_mouse_cent() except IndexError: print('activate mentor') def close_all_lists(): '''inchide toate ferestrele''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # # # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/inchidere.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) mv_mouse_cent() except IndexError: print('activate mentor') def close_list(): '''inchide fereastra''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # # # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/close.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) mv_mouse_cent() except IndexError: print('activate mentor') @_printer def account_details(): '''fisa de cont''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # # # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/contabile.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() mv_mouse_right() gui.press('down', 6, 0.0) gui.press('return', 1, interval_) gui.moveTo(pos_x_y[0], pos_x_y[1]) # mv_mouse_cent() except IndexError: print('activate mentor') @_printer def partner_balance(): '''fisa partener''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # # # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/parteneri.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 1, 0.0) gui.press('down', 7, 0.0) gui.press('return', 2, interval_) mv_mouse_cent() except IndexError: print('activate mentor') @_printer def partner_balance2(): '''balanta partener''' # mentor_win = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/parteneri.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 9, interval_) gui.press('return', 1, interval_) gui.press('down', 1, interval_) gui.press('return', 1, interval_) mv_mouse_cent() @_printer def assets(): '''registru imobilizari''' # mentor_win = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/miscari.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 14, interval_) gui.press('return', 1, interval_) gui.press('down', 1, interval_) # gui.press('return', 1, sleep_time) mv_mouse_cent() @_printer def product_details(): '''fisa de magazie''' # _date_ = gui.getWindow('LISTE - ') try: # mentor_win = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # # # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/stocuri.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('right', 1, interval_) gui.press('return', 1, interval_) mv_mouse_cent() except IndexError: print('activate mentor') @_printer def stocks(): '''stocuri pe gestiuni''' try: # mentor_win = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # # # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/stocuri.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 8, 0.0) gui.press('return', 1, interval_) mv_mouse_cent() except IndexError: print('activate mentor') @_printer def buy_journal(): '''jurnal de cumparari''' # mentor_win = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/trezorerie.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 12, 0.0) gui.press('right', 1, sleep_time) gui.press('down', 3, sleep_time) gui.press('return', 1, sleep_time) mv_mouse_cent() # print('please activate Window LISTE') @_printer def sell_journal(): '''jurnal de vanzari''' # mentor_win = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] active_win = gw.getActiveWindowTitle() if mentor_user.title() in active_win.title(): # # # mentor_win.activate() butt_x_y = gui.locateCenterOnScreen(f'mentor_imgs/trezorerie.png', confidence=CONF) sleep(0.1) if butt_x_y: gui.click(butt_x_y[0], butt_x_y[1]) pos_x_y = gui.position() gui.moveTo(pos_x_y[0], pos_x_y[1]) gui.press('down', 13, 0.0) gui.press('right', 1, sleep_time) gui.press('down', 3, sleep_time) gui.press('return', 1, sleep_time) mv_mouse_cent() # print('please activate Window LISTE') @_printer def h_key19(): '''pe cont 602.02''' try: sleep(sleep_time) # dummy = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] # active_win = gw.getActiveWindowTitle() # if dummy.title in active_win: # try: # dummy.activate() # except Exception as e: # print(str(e)) mv_mouse_right() gui.press('return', 1, sleep_time) gui.press('down', 4, sleep_time) gui.press('return', 1, sleep_time) gui.press('backspace', 1, sleep_time) gui.typewrite('602.02', interval=sleep_time) gui.press('return', 1, sleep_time) except IndexError: print('please activate Window LISTE') @_printer def h_key20(): '''pe cont 602.08''' try: sleep(sleep_time) # dummy = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] # active_win = gw.getActiveWindowTitle() # if dummy.title in active_win: # try: # dummy.activate() # except Exception as e: # print(str(e)) mv_mouse_right() gui.press('return', 1, sleep_time) gui.press('down', 4, sleep_time) gui.press('return', 1, sleep_time) gui.press('backspace', 1, sleep_time) gui.typewrite('602.08', interval=sleep_time) gui.press('return', 1, sleep_time) except IndexError: print('please activate Window LISTE') @_printer def h_key21(): '''pe cont 542''' try: sleep(sleep_time) # dummy = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] # active_win = gw.getActiveWindowTitle() # if dummy.title in active_win: # try: # dummy.activate() # except Exception as e: # print(str(e)) mv_mouse_right() gui.press('return', 1, sleep_time) gui.press('down', 4, sleep_time) gui.press('return', 1, sleep_time) gui.press('backspace', 1, sleep_time) gui.typewrite('542', interval=sleep_time) gui.press('return', 1, sleep_time) except IndexError: print('please activate Window LISTE') @_printer def h_key22(): '''pe cont 627''' try: sleep(sleep_time) # dummy = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] # active_win = gw.getActiveWindowTitle() # if dummy.title in active_win: # try: # dummy.activate() # except Exception as e: # print(str(e)) mv_mouse_right() gui.press('return', 1, sleep_time) # gui.press('tab', 2, sleep_time) gui.press('down', 4, sleep_time) gui.press('return', 1, sleep_time) gui.press('backspace', 1, sleep_time) gui.typewrite('627', interval=sleep_time) gui.press('return', 1, sleep_time) except IndexError: print('please activate Window LISTE') @_printer def h_key23(): '''pe cont 604''' try: sleep(sleep_time) # dummy = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] # active_win = gw.getActiveWindowTitle() # if dummy.title in active_win: # try: # dummy.activate() # except Exception as e: # print(str(e)) mv_mouse_right() gui.press('return', 1, sleep_time) gui.press('down', 4, sleep_time) gui.press('return', 1, sleep_time) gui.press('backspace', 1, sleep_time) gui.typewrite('604', interval=sleep_time) gui.press('return', 1, sleep_time) except IndexError: print('please activate Window LISTE') @_printer def h_key24(): '''pe cont 628''' try: sleep(sleep_time) # dummy = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] # active_win = gw.getActiveWindowTitle() # if dummy.title in active_win: # try: # dummy.activate() # except Exception as e: # print(str(e)) mv_mouse_right() gui.press('return', 1, sleep_time) gui.press('down', 4, sleep_time) gui.press('return', 1, sleep_time) gui.press('backspace', 1, sleep_time) gui.typewrite('628', interval=sleep_time) gui.press('return', 1, sleep_time) except IndexError: print('please activate Window LISTE') @_printer def h_key28(): '''pe cont 623''' try: sleep(sleep_time) # dummy = gw.getWindowsWithTitle(mentor_user, condition=gw.Re.CONTAINS)[0] # active_win = gw.getActiveWindowTitle() # if dummy.title in active_win: # try: # dummy.activate() # except Exception as e: # print(str(e)) mv_mouse_right() gui.press('return', 1, sleep_time) gui.press('down', 4, sleep_time) gui.press('return', 1, sleep_time) gui.press('backspace', 1, sleep_time) gui.typewrite('623', interval=sleep_time) gui.press('return', 1, sleep_time) except IndexError: print('please activate Window LISTE') # for i in gui.getWindows(): # print(i) def main(): '''quick_hotkey_fr''' kb.register_hotkey('`+r+j', remake_journal, args=()) # refacere jurnal kb.register_hotkey('`+r+c', cash_registry, args=()) # casa kb.register_hotkey('`+c+z', clients_ron, args=()) # clienti kb.register_hotkey('`+b+v', verif_balance, args=()) # balanta kb.register_hotkey('`+r+f', suppliers_ron, args=()) # ron furnizori kb.register_hotkey('`+r+x', suppliers_ron_verif, args=()) # ron furnizori kb.register_hotkey('`+d+x', suppliers_val, args=()) # deviza furnizori kb.register_hotkey('`+f+t', partner_balance, args=()) # fisa terti kb.register_hotkey('`+r+b', bank_registry_ron, args=()) # banca lei kb.register_hotkey('`+j+v', bank_registry_val, args=()) # banca valuta kb.register_hotkey('`+f+x', account_details, args=()) # fisa cont kb.register_hotkey('`+s+m', product_details, args=()) # fisa magazie kb.register_hotkey('`+s+g', stocks, args=()) # stoc gestiuni kb.register_hotkey('control+q', close_all_lists, args=()) # close all lists kb.register_hotkey('control+e', close_list, args=()) # close all lists kb.register_hotkey('`+t+x', buy_journal, args=()) # jurnal de cumparari kb.register_hotkey('`+t+v', sell_journal, args=()) # jurnal de vanzari kb.register_hotkey('`+b+p', partner_balance2, args=()) # balanta parteneri kb.register_hotkey('`+m+u', assets, args=()) # imobilizari # kb.register_hotkey('alt+3', h_key28, args=()) # 602.08 # kb.register_hotkey('alt+4', h_key22, args=()) # 627 # kb.register_hotkey('alt+5', h_key21, args=()) # 542 # kb.register_hotkey('alt+6', h_key23, args=()) # 604 # kb.register_hotkey('alt+7', h_key24, args=()) # 628 # kb.register_hotkey('alt+8', h_key19, args=()) # 602.02 # kb.register_hotkey('alt+9', h_key20, args=()) # 602.08 # kb.register_hotkey('control+shift+0', enclose_pharenteses, args=()) # kb.register_hotkey('control+shift+]', enclose_list, args=()) # kb.register_hotkey('control+shift+`', enclose_dict, args=()) # kb.register_hotkey('shift+`', indent_comment, args=()) # kb.wait() if __name__ == '__main__': main()