From 305814989a5020ea47160ee1e33177da5eaa24f3 Mon Sep 17 00:00:00 2001 From: pi3c Date: Tue, 31 Oct 2023 11:53:13 +0300 Subject: [PATCH] Final test --- .gitignore | 1 + part1_basic/final_test/app.py | 113 +++++++++++++++++++++++++++++ part1_basic/final_test/clicker.ahk | 10 +++ part1_basic/final_test/img.png | Bin 0 -> 6449 bytes 4 files changed, 124 insertions(+) create mode 100644 part1_basic/final_test/app.py create mode 100644 part1_basic/final_test/clicker.ahk create mode 100644 part1_basic/final_test/img.png diff --git a/.gitignore b/.gitignore index 5369c30..a01caac 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ config.ini data/ +.idea/ ### Python template # Byte-compiled / optimized / DLL files diff --git a/part1_basic/final_test/app.py b/part1_basic/final_test/app.py new file mode 100644 index 0000000..ceabb6d --- /dev/null +++ b/part1_basic/final_test/app.py @@ -0,0 +1,113 @@ +import os +import subprocess +import time +from tkinter import * + + +class ClickerGame: + """ Перед запуском проверьте и исправьте место установки AHK + Св-во класса AHK_PATH должно содержать полный путь до запускаемого файла + """ + AHK_PATH = r"C:\Users\pi3c\AppData\Local\Programs\AutoHotkey\UX\AutoHotkeyUX.exe" + + def __init__(self): + self.__root = Tk() + self.__root.geometry("500x400") + self.__root.minsize(500, 400) + self.__root.title("Clicker Game") + self.__root.bind("", self.key) + + self.process = None + + self.ahk_flag = False + self.frame = Frame(self.__root, relief=RAISED, borderwidth=5, bg='green') + self.frame.pack(fill=BOTH, expand=True, padx=5, pady=5) + self.label = Label(self.frame, text="Clicker Game", font=("Arial", 25), bg='green') + self.label.pack(side=TOP) + + self.score = 0 + self.message = StringVar() + self.message.set(f"Your score is: {self.score}") + self.label2 = Label(self.frame, textvariable=self.message, font=("Arial", 15), bg='green') + self.label2.pack(side=TOP) + + self.timer = 0 + self.start_time = time.time() + self.timer_message = StringVar() + self.timer_update() + + self.label3 = Label(self.frame, textvariable=self.timer_message, font=("Arial", 12), bg='green') + self.label3.pack(side=LEFT) + + self.img = PhotoImage(file=os.path.join(os.curdir, 'img.png')) + self.clicker = Button(self.frame, text="clickme", image=self.img, command=self.increment) + self.clicker.place(relx=0.5, rely=0.5, anchor='center') + + self.ahk_button = Button(self.__root, text="Manual run AHK", command=self.switcher_ahk) + self.ahk_button.pack(side=LEFT, padx=10, pady=10) + + self.close_button = Button(self.__root, text="EXIT", command=self.quit) + self.close_button.pack(side=RIGHT, padx=10, pady=10) + + self.ahk_button = Button(self.__root, text="Clicker RESET", command=self.clicker_reset) + self.ahk_button.pack(side=RIGHT, padx=10, pady=10) + + mainloop() + + def __del__(self): + """Завершаем поток АНК ели он запущен при выходе""" + if self.ahk_flag: + self.switcher_ahk() + + def key(self, event): + if event.keycode == 97: + # Переключаем статус АНК по numpad1 + self.switcher_ahk() + + if event.keycode == 73 or event.keycode == 17: + # Инкремент счетчика по хот кею Ctrl-i или Ctrl-ш в RU раскладке + self.increment() + + def increment(self, keys=None): + if keys is not None: + """Данный блок необходим, чтоб среда не ругалась на неиспользуемый + аргумент keys. При связывании горячей клавиши методом bind, сюда + передается инфо о нажатой комбинации. Тут она мне не нужна, поэтому ставим тупо + заглушку""" + pass + + self.score += 1 + self.message.set(f"Your score is: {self.score}") + + def switcher_ahk(self): + if self.ahk_flag: + print("Stop clicker") + self.ahk_flag = False + self.process.kill() + + else: + print("run clicker") + self.ahk_flag = True + self.process = subprocess.Popen( + [self.AHK_PATH, "clicker.ahk"] + ) + + def timer_update(self): + self.timer = int(time.time() - self.start_time) + self.timer_message.set(f"Elapsed time:\n{self.timer // 60}min. {self.timer % 60} sec.") + self.__root.after(1000, self.timer_update) + + def clicker_reset(self): + if self.ahk_flag: + self.switcher_ahk() + self.score = 0 + self.message.set(f"Your score is: {self.score}") + self.timer = 0 + self.start_time = time.time() + self.timer_update() + + def quit(self): + self.__root.destroy() + + +game = ClickerGame() diff --git a/part1_basic/final_test/clicker.ahk b/part1_basic/final_test/clicker.ahk new file mode 100644 index 0000000..6957814 --- /dev/null +++ b/part1_basic/final_test/clicker.ahk @@ -0,0 +1,10 @@ +#Requires AutoHotkey v2.0 + +SetTimer Click, 200 + +Click() +{ + if WinExist("Clicker Game") + WinActivate ; + Send "^i" +} \ No newline at end of file diff --git a/part1_basic/final_test/img.png b/part1_basic/final_test/img.png new file mode 100644 index 0000000000000000000000000000000000000000..c58e41be325d268bac020741ffe303af9652cf29 GIT binary patch literal 6449 zcmZ`;WmFVE*Itp%MRo~Ux?ySQ?h+IQTozbZq>)~wd+9U?rCYjFLSX4oNgY*>M7 ztE8(008}TC+#&I>edgDiFLVI_A5H)u2n_(-U{yg|0Ki)z0AR-g0FX`v0BBs(Tl8hI z14OQx#vT9wIp)9hK@uN1JywZtsiUC^xc_g-ZY%nT)exYxbkzt}@n~r1DZB?2*|91P zlo||Wg+y6Pzjn9A3V?`^uoSMgQ?lxtYP_C2^?g?Cqr>#OjrSR(g-WO&Q5Lj1<#6d z{Zw*gOg((=rZy{jrsX-@v6wj503-x@4gv==e^U$!3Qh#p{IE*)+m!O?6V%OHTbPUb z?0aZlxhh8$KHRq1e0ZCAnSRRogwO(s9D|ClPjz+W(m{h^Fh8>7m~%2p;)v>9O*(Q= zO5WGHM?FOjt|cYphV|!!(U*}U$wBOmRCEJ~wS2BzM4F^dX=px|@7fO-hFXW& z2{RB4U!#Ha-pWKDjkR0y;781Js#!eKOso_?{_!QTtdDv4?{)$}kFxe?qO9_S6QpACDF9pSVVk>Iy#z@4Axy zvcQ>%uZ)}|P$7)$=8^XtKdN;-p9zp`d}g~|1ck?NB+^!)RuNFsW^jaFdU)S@P~Uct z8H~`KljSRi&+XL;1@1BldI=o3Nk&6~*&FCyTXe}`&|#K7SxZYhE^2JllHeZOPZR)+ znSjg*T)5_|r2~O)&y}9i&60GqY$&5NbqoT!l*y76QA?j28JF~y|*y-p$ z(Ku_kL2H)m;G{y)Cs!jh#?)#Y$%^pK-yteZn_+?7g3`#Ez9|9p*r%=i0ODr6-{DBMBl zco447c^5EavO!{RC0TsBF?rd$w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