From d899970092292a6e2109fbe8f2db3147d5788c1e Mon Sep 17 00:00:00 2001 From: Vhou-Atroph <79807240+Vhou-Atroph@users.noreply.github.com> Date: Tue, 26 Mar 2024 16:12:08 -0500 Subject: [PATCH] CalculationResults new class to hold calc results frame --- src/tt_damage_calculator/app.py | 18 +++++------------- src/tt_damage_calculator/widgets.py | 23 +++++++++++++++++++---- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/tt_damage_calculator/app.py b/src/tt_damage_calculator/app.py index f61c47bb..1b4c6cb1 100644 --- a/src/tt_damage_calculator/app.py +++ b/src/tt_damage_calculator/app.py @@ -61,8 +61,8 @@ # Total damage calculation def calc_dmg(*args): tot_dmg = tt_damage_calculator.full_calc(trp_used, snd_used, trw_used, sqt_used, drp_used, no_group.get(), lured.get(), dmg_down.get(), dmg_up.get()) - cog_level_indicator.configure(text=tt_damage_calculator.lvl_ind_string(tt_damage_calculator.lvl_ind(tot_dmg), int(dmg_down.get() * 100), int(dmg_up.get() * 100))) - dmg_indicator.configure(text=str(tot_dmg)) + calc_results.level_counter.configure(text=tt_damage_calculator.lvl_ind_string(tt_damage_calculator.lvl_ind(tot_dmg), int(dmg_down.get() * 100), int(dmg_up.get() * 100))) + calc_results.damage_counter.configure(text=str(tot_dmg)) # Pin window to top def pin(): @@ -226,11 +226,7 @@ def use_groupless(name:str, damage:int): cog_calc = Button(hist, text="Show Health and\n SOS Cards") # Calculation results -calc_results = Frame(col0) -dmg_this_round = Label(calc_results, text="Damage this round:", font=('Arial', 16, 'normal')) -dmg_indicator = Label(calc_results, text="0", font=('Arial', 16, 'bold')) -cog_level_indicator = Label(calc_results, text="Level 0", font=('Arial', 8, 'normal')) -org_indicator = Label(calc_results, text="Organic = OFF", font=('Arial', 10, 'bold')) +calc_results = widgets.CalculationResults(col0) # Cog HP cog_health_sheet = Frame(window) @@ -272,7 +268,7 @@ def use_groupless(name:str, damage:int): def organic_toggle(*arg): data = tt_damage_calculator.orgswap(organic.get()) organic.set(data[0]) - org_indicator.configure(text="Organic = " + data[1]) + calc_results.organic_indicator.configure(text="Organic = " + data[1]) for i in gag_btns: i.configure(bg=data[2], activebackground=data[3]) org_btn.configure(command=organic_toggle) @@ -285,7 +281,7 @@ def clear_inputs(*arg): global sqt_used global drp_used global trp_used - hist_box.add(tt_damage_calculator.CalculationResults(int(dmg_indicator.cget("text")), tt_damage_calculator.lvl_ind(int(dmg_indicator.cget("text"))), lured.get(), dmg_down.get(), dmg_up.get()).build()) + hist_box.add(tt_damage_calculator.CalculationResults(int(calc_results.damage_counter.cget("text")), tt_damage_calculator.lvl_ind(int(calc_results.damage_counter.cget("text"))), lured.get(), dmg_down.get(), dmg_up.get()).build()) if organic.get(): organic_toggle() snd_used = [] @@ -349,10 +345,6 @@ def cog_health_calc_show(): # Geometry - Calculation Results calc_results.grid(column=0, row=0) -dmg_this_round.grid(column=0, row=0) -dmg_indicator.grid(column=1, row=0) -cog_level_indicator.grid(column=2, row=0) -org_indicator.grid(column=0, row=1, columnspan=3) ### Custom Gags ### global custom_track diff --git a/src/tt_damage_calculator/widgets.py b/src/tt_damage_calculator/widgets.py index 1b910850..b14131d3 100644 --- a/src/tt_damage_calculator/widgets.py +++ b/src/tt_damage_calculator/widgets.py @@ -2,15 +2,30 @@ TT-Damage-Calculator Copyright (C) 2022-2024 Vhou-Atroph """ -from tkinter import BooleanVar, Frame, Text, Button, PhotoImage, NORMAL, DISABLED, WORD, END +from tkinter import BooleanVar, Frame, Label, Text, Button, PhotoImage, NORMAL, DISABLED, WORD, END from . import tt_damage_calculator +class CalculationResults(Frame): + """Class for the Calculation Results frame.""" + + def __init__(self, parent:Frame): + Frame.__init__(self, parent) + self.damage_label = Label(self, text="Damage this round:", font=('Arial', 16, 'normal')) + self.damage_counter = Label(self, text="0", font=('Arial', 16, 'bold')) + self.level_counter = Label(self, text="Level 0", font=('Arial', 8, 'normal')) + self.organic_indicator = Label(self, text="Organic = OFF", font=('Arial', 10, 'bold')) + + self.damage_label.grid(column=0, row=0) + self.damage_counter.grid(column=1, row=0) + self.level_counter.grid(column=2, row=0) + self.organic_indicator.grid(column=0, row=1, columnspan=3) + class HistoryBox(Text): """Class for the History Box widget, a more complicated version of the normal tkinter Text widget.""" - def __init__(self, frame: Frame): - Text.__init__(self, frame) + def __init__(self, parent:Frame): + Text.__init__(self, parent) self['width'] = 25 self['height'] = 22 self['state'] = DISABLED @@ -67,7 +82,7 @@ def recolor(self, orgstate:bool): def press(self, output:HistoryBox, orgstate:bool): """Function to execute when Gag Button is pressed.""" - + gaginfo = self.gag.button_press(orgstate) self.configure(text=int(self.cget("text")) + 1) output.add("Gag used: " + gaginfo[1] + " (" + str(gaginfo[0]) + ")\n")