From 5084e6adb17f4c5ba5b42aded8de992e4aa8f823 Mon Sep 17 00:00:00 2001 From: Vhou-Atroph Date: Thu, 9 May 2024 22:23:39 -0500 Subject: [PATCH] Use new GagButton widget will throw the new buttons in widgets soon --- src/tt_damage_calculator/app.py | 130 ++++++++++------------------ src/tt_damage_calculator/widgets.py | 10 +-- 2 files changed, 50 insertions(+), 90 deletions(-) diff --git a/src/tt_damage_calculator/app.py b/src/tt_damage_calculator/app.py index 3dd396c5..87ff96ac 100644 --- a/src/tt_damage_calculator/app.py +++ b/src/tt_damage_calculator/app.py @@ -22,129 +22,89 @@ window.iconphoto(True, whole_cream_pie_img) # Variables -organic = BooleanVar() - settings = tt_damage_calculator.Settings(window.asset_path + "/assets/settings.toml") # The Gags -class GagButton(Button): - def __init__(self, parent, image, gag): - self.gag = gag - Button.__init__(self, parent) - self['image'] = image - if self.gag.gtype == "Gag": - self['bg'] = '#1888D3' - self['activebackground'] = '#186AD3' - self['text'] = '0' - self['font'] = ('Impress BT', 8, 'bold') - self['compound'] = 'top' - self['fg'] = 'white' - self['activeforeground'] = 'white' - self['command'] = self.press - if parent: - self.grid(row=0, column=self.gag.level) - - def list(self): - match self.gag.track: - case "Trap": - return window.trap - case "Sound": - return window.sound - case "Throw": - return window.throw - case "Squirt": - return window.squirt - case "Drop": - return window.drop - - def press(self): - data = self.gag.button_press(window.organic.get()) - self.list().append(data[0]) - window.history.box.add("Gag used: " + data[1] + " (" + str(data[0]) + ")\n") - if self.gag.gtype == "Gag": - self.configure(text=int(self.cget("text")) + 1) - window.calculate() - gag_frame = Frame(window.column_0) # Sound snd_frame = Frame(gag_frame) bike_horn_img = PhotoImage(file=window.asset_path + '/assets/img/bike-horn.png') -bike_horn = GagButton(snd_frame, image=bike_horn_img, gag=tt_damage_calculator.Gag("Gag", "Bike Horn", "Sound", 0, 4)) +bike_horn = widgets.GagButton(window, snd_frame, image=bike_horn_img, gag=tt_damage_calculator.Gag("Gag", "Bike Horn", "Sound", 0, 4)) whistle_img = PhotoImage(file=window.asset_path + '/assets/img/whistle.png') -whistle = GagButton(snd_frame, image=whistle_img, gag=tt_damage_calculator.Gag("Gag", "Whistle", "Sound", 1, 7)) +whistle = widgets.GagButton(window, snd_frame, image=whistle_img, gag=tt_damage_calculator.Gag("Gag", "Whistle", "Sound", 1, 7)) bugle_img = PhotoImage(file=window.asset_path + '/assets/img/bugle.png') -bugle = GagButton(snd_frame, image=bugle_img, gag=tt_damage_calculator.Gag("Gag", "Bugle", "Sound", 2, 11)) +bugle = widgets.GagButton(window, snd_frame, image=bugle_img, gag=tt_damage_calculator.Gag("Gag", "Bugle", "Sound", 2, 11)) aoogah_img = PhotoImage(file=window.asset_path + '/assets/img/aoogah.png') -aoogah = GagButton(snd_frame, image=aoogah_img, gag=tt_damage_calculator.Gag("Gag", "Aoogah", "Sound", 3, 16)) +aoogah = widgets.GagButton(window, snd_frame, image=aoogah_img, gag=tt_damage_calculator.Gag("Gag", "Aoogah", "Sound", 3, 16)) elephant_trunk_img = PhotoImage(file=window.asset_path + '/assets/img/elephant-trunk.png') -elephant_trunk = GagButton(snd_frame, image=elephant_trunk_img, gag=tt_damage_calculator.Gag("Gag", "Elephant Trunk", "Sound", 4, 21)) +elephant_trunk = widgets.GagButton(window, snd_frame, image=elephant_trunk_img, gag=tt_damage_calculator.Gag("Gag", "Elephant Trunk", "Sound", 4, 21)) fog_horn_img = PhotoImage(file=window.asset_path + '/assets/img/fog-horn.png') -fog_horn = GagButton(snd_frame, image=fog_horn_img, gag=tt_damage_calculator.Gag("Gag", "Fog Horn", "Sound", 5, 50)) +fog_horn = widgets.GagButton(window, snd_frame, image=fog_horn_img, gag=tt_damage_calculator.Gag("Gag", "Fog Horn", "Sound", 5, 50)) opera_singer_img = PhotoImage(file=window.asset_path + '/assets/img/opera-singer.png') -opera_singer = GagButton(snd_frame, image=opera_singer_img, gag=tt_damage_calculator.Gag("Gag", "Opera Singer", "Sound", 6, 90)) +opera_singer = widgets.GagButton(window, snd_frame, image=opera_singer_img, gag=tt_damage_calculator.Gag("Gag", "Opera Singer", "Sound", 6, 90)) # Throw trw_frame = Frame(gag_frame) cupcake_img = PhotoImage(file=window.asset_path + '/assets/img/cupcake.png') -cupcake = GagButton(trw_frame, image=cupcake_img, gag=tt_damage_calculator.Gag("Gag", "Cupcake", "Throw", 0, 6)) +cupcake = widgets.GagButton(window, trw_frame, image=cupcake_img, gag=tt_damage_calculator.Gag("Gag", "Cupcake", "Throw", 0, 6)) fruit_pie_slice_img = PhotoImage(file=window.asset_path + '/assets/img/fruit-pie-slice.png') -fruit_pie_slice = GagButton(trw_frame, image=fruit_pie_slice_img, gag=tt_damage_calculator.Gag("Gag", "Fruit Pie Slice", "Throw", 1, 10)) +fruit_pie_slice = widgets.GagButton(window, trw_frame, image=fruit_pie_slice_img, gag=tt_damage_calculator.Gag("Gag", "Fruit Pie Slice", "Throw", 1, 10)) cream_pie_slice_img = PhotoImage(file=window.asset_path + '/assets/img/cream-pie-slice.png') -cream_pie_slice = GagButton(trw_frame, image=cream_pie_slice_img, gag=tt_damage_calculator.Gag("Gag", "Cream Pie Slice", "Throw", 2, 17)) +cream_pie_slice = widgets.GagButton(window, trw_frame, image=cream_pie_slice_img, gag=tt_damage_calculator.Gag("Gag", "Cream Pie Slice", "Throw", 2, 17)) whole_fruit_pie_img = PhotoImage(file=window.asset_path + '/assets/img/whole-fruit-pie.png') -whole_fruit_pie = GagButton(trw_frame, image=whole_fruit_pie_img, gag=tt_damage_calculator.Gag("Gag", "Whole Fruit Pie", "Throw", 3, 27)) -whole_cream_pie = GagButton(trw_frame, image=whole_cream_pie_img, gag=tt_damage_calculator.Gag("Gag", "Whole Cream Pie", "Throw", 4, 40)) +whole_fruit_pie = widgets.GagButton(window, trw_frame, image=whole_fruit_pie_img, gag=tt_damage_calculator.Gag("Gag", "Whole Fruit Pie", "Throw", 3, 27)) +whole_cream_pie = widgets.GagButton(window, trw_frame, image=whole_cream_pie_img, gag=tt_damage_calculator.Gag("Gag", "Whole Cream Pie", "Throw", 4, 40)) birthday_cake_img = PhotoImage(file=window.asset_path + '/assets/img/birthday-cake.png') -birthday_cake = GagButton(trw_frame, image=birthday_cake_img, gag=tt_damage_calculator.Gag("Gag", "Birthday Cake", "Throw", 5, 100)) +birthday_cake = widgets.GagButton(window, trw_frame, image=birthday_cake_img, gag=tt_damage_calculator.Gag("Gag", "Birthday Cake", "Throw", 5, 100)) wedding_cake_img = PhotoImage(file=window.asset_path + '/assets/img/wedding-cake.png') -wedding_cake = GagButton(trw_frame, image=wedding_cake_img, gag=tt_damage_calculator.Gag("Gag", "Wedding Cake", "Throw", 6, 120)) +wedding_cake = widgets.GagButton(window, trw_frame, image=wedding_cake_img, gag=tt_damage_calculator.Gag("Gag", "Wedding Cake", "Throw", 6, 120)) # Squirt sqt_frame = Frame(gag_frame) squirting_flower_img = PhotoImage(file=window.asset_path + '/assets/img/squirting-flower.png') -squirting_flower = GagButton(sqt_frame, image=squirting_flower_img, gag=tt_damage_calculator.Gag("Gag", "Squirting Flower", "Squirt", 0, 4)) +squirting_flower = widgets.GagButton(window, sqt_frame, image=squirting_flower_img, gag=tt_damage_calculator.Gag("Gag", "Squirting Flower", "Squirt", 0, 4)) water_glass_img = PhotoImage(file=window.asset_path + '/assets/img/glass-of-water.png') -water_glass = GagButton(sqt_frame, image=water_glass_img, gag=tt_damage_calculator.Gag("Gag", "Glass of Water", "Squirt", 1, 8)) +water_glass = widgets.GagButton(window, sqt_frame, image=water_glass_img, gag=tt_damage_calculator.Gag("Gag", "Glass of Water", "Squirt", 1, 8)) squirt_gun_img = PhotoImage(file=window.asset_path + '/assets/img/squirt-gun.png') -squirt_gun = GagButton(sqt_frame, image=squirt_gun_img, gag=tt_damage_calculator.Gag("Gag", "Squirt Gun", "Squirt", 2, 12)) +squirt_gun = widgets.GagButton(window, sqt_frame, image=squirt_gun_img, gag=tt_damage_calculator.Gag("Gag", "Squirt Gun", "Squirt", 2, 12)) seltzer_bottle_img = PhotoImage(file=window.asset_path + '/assets/img/seltzer-bottle.png') -seltzer_bottle = GagButton(sqt_frame, image=seltzer_bottle_img, gag=tt_damage_calculator.Gag("Gag", "Seltzer Bottle", "Squirt", 3, 21)) +seltzer_bottle = widgets.GagButton(window, sqt_frame, image=seltzer_bottle_img, gag=tt_damage_calculator.Gag("Gag", "Seltzer Bottle", "Squirt", 3, 21)) fire_hose_img = PhotoImage(file=window.asset_path + '/assets/img/fire-hose.png') -fire_hose = GagButton(sqt_frame, image=fire_hose_img, gag=tt_damage_calculator.Gag("Gag", "Fire Hose", "Squirt", 4, 30)) +fire_hose = widgets.GagButton(window, sqt_frame, image=fire_hose_img, gag=tt_damage_calculator.Gag("Gag", "Fire Hose", "Squirt", 4, 30)) storm_cloud_img = PhotoImage(file=window.asset_path + '/assets/img/storm-cloud.png') -storm_cloud = GagButton(sqt_frame, image=storm_cloud_img, gag=tt_damage_calculator.Gag("Gag", "Storm Cloud", "Squirt", 5, 80)) +storm_cloud = widgets.GagButton(window, sqt_frame, image=storm_cloud_img, gag=tt_damage_calculator.Gag("Gag", "Storm Cloud", "Squirt", 5, 80)) geyser_img = PhotoImage(file=window.asset_path + '/assets/img/geyser.png') -geyser = GagButton(sqt_frame, image=geyser_img, gag=tt_damage_calculator.Gag("Gag", "Geyser", "Squirt", 6, 105)) +geyser = widgets.GagButton(window, sqt_frame, image=geyser_img, gag=tt_damage_calculator.Gag("Gag", "Geyser", "Squirt", 6, 105)) # Drop drp_frame = Frame(gag_frame) flower_pot_img = PhotoImage(file=window.asset_path + '/assets/img/flower-pot.png') -flower_pot = GagButton(drp_frame, image=flower_pot_img, gag=tt_damage_calculator.Gag("Gag", "Flower Pot", "Drop", 0, 10)) +flower_pot = widgets.GagButton(window, drp_frame, image=flower_pot_img, gag=tt_damage_calculator.Gag("Gag", "Flower Pot", "Drop", 0, 10)) sandbag_img = PhotoImage(file=window.asset_path + '/assets/img/sandbag.png') -sandbag = GagButton(drp_frame, image=sandbag_img, gag=tt_damage_calculator.Gag("Gag", "Sandbag", "Drop", 1, 18)) +sandbag = widgets.GagButton(window, drp_frame, image=sandbag_img, gag=tt_damage_calculator.Gag("Gag", "Sandbag", "Drop", 1, 18)) anvil_img = PhotoImage(file=window.asset_path + '/assets/img/anvil.png') -anvil = GagButton(drp_frame, image=anvil_img, gag=tt_damage_calculator.Gag("Gag", "Anvil", "Drop", 2, 30)) +anvil = widgets.GagButton(window, drp_frame, image=anvil_img, gag=tt_damage_calculator.Gag("Gag", "Anvil", "Drop", 2, 30)) big_weight_img = PhotoImage(file=window.asset_path + '/assets/img/big-weight.png') -big_weight = GagButton(drp_frame, image=big_weight_img, gag=tt_damage_calculator.Gag("Gag", "Big Weight", "Drop", 3, 45)) +big_weight = widgets.GagButton(window, drp_frame, image=big_weight_img, gag=tt_damage_calculator.Gag("Gag", "Big Weight", "Drop", 3, 45)) safe_img = PhotoImage(file=window.asset_path + '/assets/img/safe.png') -safe = GagButton(drp_frame, image=safe_img, gag=tt_damage_calculator.Gag("Gag", "Safe", "Drop", 4, 70)) +safe = widgets.GagButton(window, drp_frame, image=safe_img, gag=tt_damage_calculator.Gag("Gag", "Safe", "Drop", 4, 70)) grand_piano_img = PhotoImage(file=window.asset_path + '/assets/img/grand-piano.png') -grand_piano = GagButton(drp_frame, image=grand_piano_img, gag=tt_damage_calculator.Gag("Gag", "Grand Piano", "Drop", 5, 170)) +grand_piano = widgets.GagButton(window, drp_frame, image=grand_piano_img, gag=tt_damage_calculator.Gag("Gag", "Grand Piano", "Drop", 5, 170)) toontanic_img = PhotoImage(file=window.asset_path + '/assets/img/toontanic.png') -toontanic = GagButton(drp_frame, image=toontanic_img, gag=tt_damage_calculator.Gag("Gag", "Toontanic", "Drop", 6, 180)) +toontanic = widgets.GagButton(window, drp_frame, image=toontanic_img, gag=tt_damage_calculator.Gag("Gag", "Toontanic", "Drop", 6, 180)) # Trap trp_frame = Frame(gag_frame) banana_peel_img = PhotoImage(file=window.asset_path + '/assets/img/banana-peel.png') -banana_peel = GagButton(trp_frame, image=banana_peel_img, gag=tt_damage_calculator.Gag("Gag", "Banana Peel", "Trap", 0, 12)) +banana_peel = widgets.GagButton(window, trp_frame, image=banana_peel_img, gag=tt_damage_calculator.Gag("Gag", "Banana Peel", "Trap", 0, 12)) rake_img = PhotoImage(file=window.asset_path + '/assets/img/rake.png') -rake = GagButton(trp_frame, image=rake_img, gag=tt_damage_calculator.Gag("Gag", "Rake", "Trap", 1, 18)) +rake = widgets.GagButton(window, trp_frame, image=rake_img, gag=tt_damage_calculator.Gag("Gag", "Rake", "Trap", 1, 18)) marbles_img = PhotoImage(file=window.asset_path + '/assets/img/marbles.png') -marbles = GagButton(trp_frame, image=marbles_img, gag=tt_damage_calculator.Gag("Gag", "Marbles", "Trap", 2, 35)) +marbles = widgets.GagButton(window, trp_frame, image=marbles_img, gag=tt_damage_calculator.Gag("Gag", "Marbles", "Trap", 2, 35)) quicksand_img = PhotoImage(file=window.asset_path + '/assets/img/quicksand.png') -quicksand = GagButton(trp_frame, image=quicksand_img, gag=tt_damage_calculator.Gag("Gag", "Quicksand", "Trap", 3, 50)) +quicksand = widgets.GagButton(window, trp_frame, image=quicksand_img, gag=tt_damage_calculator.Gag("Gag", "Quicksand", "Trap", 3, 50)) trapdoor_img = PhotoImage(file=window.asset_path + '/assets/img/trapdoor.png') -trapdoor = GagButton(trp_frame, image=trapdoor_img, gag=tt_damage_calculator.Gag("Gag", "Trapdoor", "Trap", 4, 85)) +trapdoor = widgets.GagButton(window, trp_frame, image=trapdoor_img, gag=tt_damage_calculator.Gag("Gag", "Trapdoor", "Trap", 4, 85)) tnt_img = PhotoImage(file=window.asset_path + '/assets/img/tnt.png') -tnt = GagButton(trp_frame, image=tnt_img, gag=tt_damage_calculator.Gag("Gag", "TNT", "Trap", 5, 180)) +tnt = widgets.GagButton(window, trp_frame, image=tnt_img, gag=tt_damage_calculator.Gag("Gag", "TNT", "Trap", 5, 180)) railroad_img = PhotoImage(file=window.asset_path + '/assets/img/railroad.png') -railroad = GagButton(trp_frame, image=railroad_img, gag=tt_damage_calculator.Gag("Gag", "Railroad", "Trap", 6, 200)) +railroad = widgets.GagButton(window, trp_frame, image=railroad_img, gag=tt_damage_calculator.Gag("Gag", "Railroad", "Trap", 6, 200)) gag_btns=[ bike_horn, whistle, bugle, aoogah, elephant_trunk, fog_horn, opera_singer, @@ -169,25 +129,25 @@ def use_groupless(name:str, damage:int): sos_cards = Frame(window) sos_trp = Frame(sos_cards) clerk_will_img = PhotoImage(file=window.asset_path + '/assets/img/clerkwill.png') -clerk_will = GagButton(sos_trp,image=clerk_will_img, gag=tt_damage_calculator.Gag("Sos", "Clerk Will", "Trap", 0, 60)) +clerk_will = widgets.GagButton(window, sos_trp,image=clerk_will_img, gag=tt_damage_calculator.Gag("Sos", "Clerk Will", "Trap", 0, 60)) clerk_penny_img = PhotoImage(file=window.asset_path + '/assets/img/clerkpenny.png') -clerk_penny = GagButton(sos_trp,image=clerk_penny_img, gag=tt_damage_calculator.Gag("Sos", "Clerk Penny", "Trap", 1, 120)) +clerk_penny = widgets.GagButton(window, sos_trp,image=clerk_penny_img, gag=tt_damage_calculator.Gag("Sos", "Clerk Penny", "Trap", 1, 120)) clerk_clara_img = PhotoImage(file=window.asset_path + '/assets/img/clerkclara.png') -clerk_clara = GagButton(sos_trp,image=clerk_clara_img, gag=tt_damage_calculator.Gag("Sos", "Clerk Clara", "Trap", 2, 180)) +clerk_clara = widgets.GagButton(window, sos_trp,image=clerk_clara_img, gag=tt_damage_calculator.Gag("Sos", "Clerk Clara", "Trap", 2, 180)) sos_snd = Frame(sos_cards) barb_img = PhotoImage(file=window.asset_path + '/assets/img/barbaraseville.png') -barb = GagButton(sos_snd,image=barb_img, gag=tt_damage_calculator.Gag("Sos", "Barbara Seville", "Sound", 0, 35)) +barb = widgets.GagButton(window, sos_snd,image=barb_img, gag=tt_damage_calculator.Gag("Sos", "Barbara Seville", "Sound", 0, 35)) sid_img = PhotoImage(file=window.asset_path + '/assets/img/sidsonata.png') -sid = GagButton(sos_snd,image=sid_img, gag=tt_damage_calculator.Gag("Sos", "Sid Sonata", "Sound", 1, 55)) +sid = widgets.GagButton(window, sos_snd,image=sid_img, gag=tt_damage_calculator.Gag("Sos", "Sid Sonata", "Sound", 1, 55)) moe_img = PhotoImage(file=window.asset_path + '/assets/img/moezart.png') -moe = GagButton(sos_snd,image=moe_img, gag=tt_damage_calculator.Gag("Sos", "Moe Zart", "Sound", 2, 75)) +moe = widgets.GagButton(window, sos_snd,image=moe_img, gag=tt_damage_calculator.Gag("Sos", "Moe Zart", "Sound", 2, 75)) sos_drp = Frame(sos_cards) ned_img = PhotoImage(file=window.asset_path + '/assets/img/clumsyned.png') -ned = GagButton(sos_drp,image=ned_img, gag=tt_damage_calculator.Gag("Sos", "Clumsy Ned", "Drop", 0, 60)) +ned = widgets.GagButton(window, sos_drp,image=ned_img, gag=tt_damage_calculator.Gag("Sos", "Clumsy Ned", "Drop", 0, 60)) franz_img = PhotoImage(file=window.asset_path + '/assets/img/franzneckvein.png') -franz = GagButton(sos_drp,image=franz_img, gag=tt_damage_calculator.Gag("Sos", "Franz Neckvein", "Drop", 1, 100)) +franz = widgets.GagButton(window, sos_drp,image=franz_img, gag=tt_damage_calculator.Gag("Sos", "Franz Neckvein", "Drop", 1, 100)) bess_img = PhotoImage(file=window.asset_path + '/assets/img/barnaclebessie.png') -bess = GagButton(sos_drp,image=bess_img, gag=tt_damage_calculator.Gag("Sos", "Barnacle Bessie", "Drop", 2, 170)) +bess = widgets.GagButton(window, sos_drp,image=bess_img, gag=tt_damage_calculator.Gag("Sos", "Barnacle Bessie", "Drop", 2, 170)) ### Keybinds window.bind('<' + settings.keybinds.defense + '>', lambda par: [window.defense_buff.set(tt_damage_calculator.advance_float([0.0,0.1,0.15,0.2,0.25], window.defense_buff.get())), window.calculate()]) @@ -261,7 +221,7 @@ def cog_health_calc_show(): def cgags(): global cgags def add_custom_gag(): - custom_gag = GagButton(None, None, tt_damage_calculator.Gag("Custom", "Custom " + custom_track.get(), custom_track.get(), 0, int(damage_entry.get(1.0, END)))) + custom_gag = widgets.GagButton(window, None, None, tt_damage_calculator.Gag("Custom", "Custom " + custom_track.get(), custom_track.get(), 0, int(damage_entry.get(1.0, END)))) custom_gag.press() cgags = Toplevel(window) diff --git a/src/tt_damage_calculator/widgets.py b/src/tt_damage_calculator/widgets.py index 92099ef0..e8b708a2 100644 --- a/src/tt_damage_calculator/widgets.py +++ b/src/tt_damage_calculator/widgets.py @@ -99,7 +99,7 @@ def __init__(self, window:Tk, parent:GagFrame, image:PhotoImage, gag:tt_damage_c self.gag = gag Button.__init__(self, parent) self['image'] = image - self['command'] = lambda: self.press(output, orgstate.get()) + self['command'] = lambda: self.press() if self.gag.gtype == "Gag": self['text'] = "0" self['font'] = ('Impress BT', 8, 'bold') @@ -135,15 +135,15 @@ def list(self): case "Drop": return self.window.drop - def press(self, output:HistoryBox, orgstate:bool): + def press(self): """Function to execute when Gag Button is pressed.""" - gaginfo = self.gag.button_press(orgstate) + gaginfo = self.gag.button_press(self.window.organic.get()) self.list().append(gaginfo[0]) - output.add("Gag used: " + gaginfo[1] + " (" + str(gaginfo[0]) + ")\n") + self.window.history.box.add("Gag used: " + gaginfo[1] + " (" + str(gaginfo[0]) + ")\n") if self.gag.gtype == "Gag": self.configure(text=int(self.cget("text")) + 1) - #TODO: implement gag calculation here + self.window.calculate() class App(Tk): """Class for the gag calculator's full app."""