Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Handling uncaught SIGS in GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
MuriloChianfa committed May 6, 2022
1 parent 1d30aab commit b6896ac
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 45 deletions.
10 changes: 9 additions & 1 deletion core/GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions core/GUISetter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions core/ThreadManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down
Binary file added images/Modules/FoodEater.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
148 changes: 111 additions & 37 deletions modules/FoodEater.py
Original file line number Diff line number Diff line change
@@ -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()
10 changes: 5 additions & 5 deletions modules/Root.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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])

Expand Down Expand Up @@ -201,6 +201,7 @@ def SetVariablesFromLoadedJson():

SetVariablesFromLoadedJson()

self.root.Protocol(Exit)
self.root.loop()


Expand Down Expand Up @@ -291,8 +292,7 @@ def OpenCreatureInfo():


def OpenFoodEater():
print("FoodEater In Development...")
# FoodEater(root)
FoodEater(root, MOUSE_OPTION)


def OpenFPSChanger():
Expand Down
4 changes: 4 additions & 0 deletions scripts/GUILoader.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
"BellowThan": 30,
"CheckStageOne": true
},
"FoodEaterLoader": {
"CheckPrint": false,
"HotkeyFood": "Shift + F12"
},
"RingLoader": {
"CheckPrint": false,
"CheckBuff": false,
Expand Down
4 changes: 2 additions & 2 deletions scripts/conf.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"configured": false,
"hwnd": 524888,
"configured": true,
"hwnd": 460820,
"preferences_name": "NewConfig.json",
"platform": "windows"
}

0 comments on commit b6896ac

Please sign in to comment.