From b6896ac6cd6189892ac5939bfd2ac2fbc38049b4 Mon Sep 17 00:00:00 2001 From: MuriloChianfa <60560085+MuriloChianfa@users.noreply.github.com> Date: Fri, 6 May 2022 00:31:57 -0300 Subject: [PATCH] Handling uncaught SIGS in GUI --- core/GUI.py | 10 ++- core/GUISetter.py | 5 ++ core/ThreadManager.py | 3 + images/Modules/FoodEater.png | Bin 0 -> 1356 bytes modules/FoodEater.py | 148 ++++++++++++++++++++++++++--------- modules/Root.py | 10 +-- scripts/GUILoader.json | 4 + scripts/conf.json | 4 +- 8 files changed, 139 insertions(+), 45 deletions(-) create mode 100644 images/Modules/FoodEater.png diff --git a/core/GUI.py b/core/GUI.py index 0b9097a..681e47c 100644 --- a/core/GUI.py +++ b/core/GUI.py @@ -65,7 +65,15 @@ def InvisibleWindow(self, BackgroundImage): self.windowID.attributes("-transparentcolor", "black") def loop(self): - self.windowID.mainloop() + try: + self.windowID.mainloop() + except KeyboardInterrupt: + print('Received SIGINT') + except SystemExit: + print('Received SIGTERM') + finally: + self.windowID.destroy() + raise SystemExit def Protocol(self, Function): return self.windowID.protocol("WM_DELETE_WINDOW", Function) diff --git a/core/GUISetter.py b/core/GUISetter.py index a61566e..604520f 100644 --- a/core/GUISetter.py +++ b/core/GUISetter.py @@ -6,6 +6,11 @@ def GetData(): return ConfManager.get('GUILoader.json') +def check_gui(gui_changes, init, get, name): + if get != init: + gui_changes.append((name, get)) + + class GUISetter: def __init__(self, Locate): self.Locate = Locate diff --git a/core/ThreadManager.py b/core/ThreadManager.py index 63a3e0f..5792e4a 100644 --- a/core/ThreadManager.py +++ b/core/ThreadManager.py @@ -51,6 +51,9 @@ def HandleTarget(PipeOBJ): Event.set() TheThread = self.ThreadHandler(Target=self.Target, Qqueue=Queue, Name=self.Name) + # This thread dies when main thread + TheThread.daemon = True + TheThread.start() ActivatedThreads.append((TheThread, str(self.Name))) diff --git a/images/Modules/FoodEater.png b/images/Modules/FoodEater.png new file mode 100644 index 0000000000000000000000000000000000000000..0269b7b39017e4635e84f4e3f0bfc3b7970cda26 GIT binary patch literal 1356 zcmeAS@N?(olHy`uVBq!ia0y~yU^D`<_j51-$xnZeD*!3R;vjb?hIQv;UIIBR>5jgR z3=A9lx&I`x0{NT;9+AZi419+{nDKc2iWH!lhn_BuAr*0N@7&G3Vogus;Vh&- zl1u;jxrnjtciGO!`>QwoVdVLGeuB>Y22_{qJoowk^50+j9v`m%@_PN2`sY3Q&-_mo z&E0SJQC|DBWc{}DZqr`>`C4iF?@`a<{q@gp@2@;I|Lx|9Pp!hwXZJ4rTe4sG^4)1G zwePzB&RrdQfBpBDavH(;ug_mQt$f=iW@l;avmb)xCyM6&4S081_uA`S_ttHB{q|Jh z--_zjC!@9BR+Znb4GDks>+0=qyJ8>mMXoFU8X$N6U0vYv*!9=HrdxlV8N0h^&%L^Z zGs|l0bFSZgw=MpMZRyg#TjI7{t~*k@DdzdBg*oE=>EHi(?XC;0eQ?cu%er;&uKQ`t)eU)2%cU?id&UMZ9O>=kM zunW+CC6mA2Zs+}Nx4!}TFd>6|)h-W|$tbXrp{eg3=mrz5_VcNG=X&%0tC zc`m(v`Hjtg3ax(EvrK=Q1C*HcbpQGDPk))%r|xX~J9m-H9oy4yS?0S+My^Y&U#`Kv zeV^{`!+#4aqxF*Om#>J-Q~#lJ>O>LmZ);b}9l`gf-TrU${QH*f@b&H=x5XU$=NGv7 zj^Brj*rKoBDh$J5W|ZH%{i$x+-*E*9*wv+?evZNnpx9sbIQF< zoObuCMrsPw;g$KP7lni`k6m;9`0eeV5zdL60yARyKHdAR+n*YNyFk^$q)j zr!+_3pN1R+lTs~@JXb!=3U=DG$JJq*=A8ZK_pzwtyv^PF(>K1+KQd7j6Se&O_tk#! XV)kVfzr50bB_M;RtDnm{r-UW|L3W+B literal 0 HcmV?d00001 diff --git a/modules/FoodEater.py b/modules/FoodEater.py index 77e36eb..4192d3b 100644 --- a/modules/FoodEater.py +++ b/modules/FoodEater.py @@ -1,46 +1,120 @@ -from engine.GUI import * +""" +Food eater module +""" -EnabledFoodEater = False +from conf.Hotkeys import Hotkey + +from core.GUI import * +from core.GUIManager import * +from core.GUISetter import GUISetter, check_gui +from core.ThreadManager import ThreadManager class FoodEater: - def __init__(self, root): - self.FoodEater = GUI('FoodEater', 'Module: Food Eater') - self.FoodEater.DefaultWindow('DefaultWindow') - - def SetFoodEater(): - global EnabledFoodEater - if not EnabledFoodEater: - EnabledFoodEater = True - ButtonEnabled.configure(text='FoodEater: ON') - ScanFoodEater() - else: - EnabledFoodEater = False - ButtonEnabled.configure(text='FoodEater: OFF') - - def ScanFoodEater(): - if EnabledFoodEater: - print("Try Lock FoodEater") - print("Try This") - - root.after(300, ScanFoodEater) - - CheckPrint = tk.BooleanVar() - LowMana = tk.BooleanVar() - - self.FoodEater.addButton('Ok', self.FoodEater.destroyWindow, [84, 29, 130, 504], [127, 17, 8], [123, 13, 5]) - - global EnabledFoodEater - if not EnabledFoodEater: - ButtonEnabled = self.FoodEater.addButton('FoodEater: OFF', SetFoodEater, [328, 29, 12, 469], - [127, 17, 8], [123, 13, 5]) + started = False + enabled = False + + gui_changes = [] + + def __init__(self, root, MOUSE_OPTION): + self.root = root + self.window = GUI('FoodEater', 'Module: Food Eater') + self.window.DefaultWindow('FoodEater', [306, 191], [1.2, 2.29]) + self.Setter = GUISetter("FoodEaterLoader") + self.SendToClient = Hotkey(MOUSE_OPTION) + self.ThreadManager = ThreadManager("ThreadFoodEater") + + self.gui_vars() + self.gui() + + self.check() + self.check_state() + + self.window.Protocol(self.destroy) + self.window.loop() + + def trigger(self): + if FoodEater.enabled: + FoodEater.enabled = False + self.enabled_button.configure(text='FoodEater: OFF', relief=RAISED, bg=rgb((127, 17, 8))) + self.pause() + else: + FoodEater.enabled = True + self.enabled_button.configure(text='FoodEater: ON', relief=SUNKEN, bg=rgb((158, 46, 34))) + self.run() + + self.check() + self.check_state() + + def run(self): + if not FoodEater.started: + self.ThreadManager.NewThread(self.execute) + FoodEater.started = False + else: + self.ThreadManager.UnPauseThread() + print('FoodEater: ON') + + def pause(self): + self.ThreadManager.PauseThread() + print('FoodEater: OFF') + + def execute(self): + while FoodEater.enabled: + print('Hotkey to eat food: ', self.food_hotkey.get()) + + def destroy(self): + check_gui(FoodEater.gui_changes, self.init_check_print, self.check_print.get(), 'CheckPrint') + check_gui(FoodEater.gui_changes, self.init_food_hotkey, self.food_hotkey.get(), 'HotkeyFood') + + if len(FoodEater.gui_changes) != 0: + for each_change in range(len(FoodEater.gui_changes)): + self.Setter.SetVariables.SetVar( + FoodEater.gui_changes[each_change][0], + FoodEater.gui_changes[each_change][1] + ) + + if not FoodEater.enabled: + print('Killing thread: ', self.ThreadManager) + self.ThreadManager.KillThread() + + self.window.destroyWindow() + + def gui_vars(self): + self.check_print, self.init_check_print = self.Setter.Variables.Bool('CheckPrint') + self.food_hotkey, self.init_food_hotkey = self.Setter.Variables.Str('HotkeyFood') + + def gui(self): + self.label = self.window.addLabel('Hotkey To Press', [110, 24]) + + self.hotkey_button = self.window.addOption(self.food_hotkey, self.SendToClient.Hotkeys, [105, 50], 10) + + self.check_print_button = self.window.addCheck(self.check_print, [11, 100], self.init_check_print, + "Print on Tibia's screen") + self.check_print_button.configure(bg=rgb((114, 94, 48)), activebackground=rgb((114, 94, 48)), + selectcolor=rgb((114, 94, 48))) + + if not FoodEater.enabled: + self.enabled_button = self.window.addButton('FoodEater: OFF', self.trigger, [287, 23], [11, 132]) else: - ButtonEnabled = self.FoodEater.addButton('FoodEater: ON', SetFoodEater, [328, 29, 12, 469], - [127, 17, 8], [123, 13, 5]) + self.enabled_button = self.window.addButton('FoodEater: ON', self.trigger, [287, 23], [11, 132]) \ + .configure(relief=SUNKEN, bg=rgb((158, 46, 34))) - ButtonPrint = self.FoodEater.addCheck(CheckPrint, [10, 408], [120, 98, 51], 0, "Print on Tibia's screen") + self.ok_button = self.window.addButton('Ok', self.destroy, [73, 21], [115, 161]) - ButtonLowMana = self.FoodEater.addCheck(LowMana, [10, 440], [120, 98, 51], 0, "Low Mana Warnings") + def check(self): + if FoodEater.enabled: + self.hotkey_button.configure(state='disabled') + else: + self.hotkey_button.configure(state='normal') - self.FoodEater.loop() + def check_state(self): + if FoodEater.enabled: + Disable(self.label) + Disable(self.hotkey_button) + Disable(self.check_print_button) + else: + Enable(self.label) + Enable(self.hotkey_button) + Enable(self.check_print_button) + ExecGUITrigger() diff --git a/modules/Root.py b/modules/Root.py index 059182c..cd1ad17 100644 --- a/modules/Root.py +++ b/modules/Root.py @@ -19,7 +19,7 @@ from modules.CaveBot import CaveBot # from modules.ColorChange import ColorChange # from modules.CreatureInfo import CreatureInfo -# from modules.FoodEater import FoodEater +from modules.FoodEater import FoodEater # from modules.FPSChanger import FPSChanger # from modules.GeneralOptions import GeneralOptions # from modules.HealerFriend import HealerFriend @@ -71,7 +71,7 @@ def __init__(self, CharName, LoadedJson): self.root.addButton('Ammo Restack', OpenAmmoRestack, [92, 23], [23, 135]).configure(state='disabled') self.root.addButton('Auto Looter', OpenAutoLooter, [92, 23], [23, 160]).configure(state='disabled') - self.root.addButton('Food Eater', OpenFoodEater, [92, 23], [23, 210]).configure(state='disabled') + self.root.addButton('Food Eater', OpenFoodEater, [92, 23], [23, 210]) self.root.addButton('Auto Grouping', OpenAutoGrouping, [92, 23], [23, 236]).configure(state='disabled') self.root.addButton('Sort Loot', OpenSortLoot, [92, 23], [23, 262]).configure(state='disabled') self.root.addButton('Auto Banker', OpenAutoBanker, [92, 23], [23, 288]).configure(state='disabled') @@ -103,7 +103,7 @@ def __init__(self, CharName, LoadedJson): def Exit(): print("Exiting...") - self.root.destroyWindow() + raise SystemExit self.root.addButton('Exit', Exit, [92, 23], [10, 498]) @@ -201,6 +201,7 @@ def SetVariablesFromLoadedJson(): SetVariablesFromLoadedJson() + self.root.Protocol(Exit) self.root.loop() @@ -291,8 +292,7 @@ def OpenCreatureInfo(): def OpenFoodEater(): - print("FoodEater In Development...") - # FoodEater(root) + FoodEater(root, MOUSE_OPTION) def OpenFPSChanger(): diff --git a/scripts/GUILoader.json b/scripts/GUILoader.json index 459c877..1178a42 100644 --- a/scripts/GUILoader.json +++ b/scripts/GUILoader.json @@ -51,6 +51,10 @@ "BellowThan": 30, "CheckStageOne": true }, + "FoodEaterLoader": { + "CheckPrint": false, + "HotkeyFood": "Shift + F12" + }, "RingLoader": { "CheckPrint": false, "CheckBuff": false, diff --git a/scripts/conf.json b/scripts/conf.json index 9fa7420..9758b68 100644 --- a/scripts/conf.json +++ b/scripts/conf.json @@ -1,6 +1,6 @@ { - "configured": false, - "hwnd": 524888, + "configured": true, + "hwnd": 460820, "preferences_name": "NewConfig.json", "platform": "windows" } \ No newline at end of file