From df2db15684de1fbefcf339a654174051203868c6 Mon Sep 17 00:00:00 2001 From: Wojciech Wojnowski <wojciech.wojnowski@pg.edu.pl> Date: Mon, 17 Feb 2025 19:01:32 +0000 Subject: [PATCH] Added a checkbox to toggle graph annotations; fixed window scaling at different screen resolutions. --- main.py | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index 4be8d32..0415435 100644 --- a/main.py +++ b/main.py @@ -17,9 +17,9 @@ colors = { } root = tk.Tk() -root.title('RAPI beta v.0.9') -root.geometry('1000x630') -root.resizable(False, False) +root.title('RAPI beta v.0.92') +root.geometry('1100x660') +root.minsize(1100, 660) root.iconbitmap('Icon.ico') root.configure(bg=colors['background']) @@ -55,6 +55,9 @@ s.map("Disabled.TMenubutton", foreground=[("disabled", colors["inactive"])], background=[("disabled", "#DDDDDD")]) +# Configure the TCheckbutton style to have a white background normally. +s.configure("TCheckbutton", background=colors["foreground"], foreground=colors["text"]) + # Mapping from color names to numerical values. color_values = { 'white': 0, @@ -82,7 +85,7 @@ coordinates = { '9': [(36.567, -15.459), (36.567, -36.382), (23.301, -46.02), (3.402, -39.554)], '10': [(38.67, -8.987), (50.968, 7.94), (45.901, 23.535), (26.002, 30)], } -# Use a simple mapping (adjust later if needed) + coord_keys = {i: str(i) for i in range(11)} # ============================================================================= @@ -234,6 +237,23 @@ right_frame = tk.Frame(root, bd=0, padx=2, pady=0, width=500, height=500, bg=col highlightcolor=colors['background']) right_frame.pack(side='right', anchor='n') + +# ============================================================================= +# ANNOTATION TOGGLE (Checkbutton) +# ============================================================================= + +annotate_var = tk.BooleanVar(value=False) + +def update_plot(): + if annotate_var.get(): + create_annotated_plot() + else: + create_plot() + +annotate_cb = ttk.Checkbutton(left_frame, text="Show Annotated Plot", + variable=annotate_var, command=update_plot) +annotate_cb.grid(row=0, column=0, sticky='e', padx=8, pady=4) + # ============================================================================= # TWO-STAGE DROPDOWN WIDGET (for criteria 1â5) # ============================================================================= @@ -269,7 +289,7 @@ class TwoStageDropdown: self.threshold_var.set("") self.threshold_menu.config(state='disabled', style='Disabled.TMenubutton') self.criterion.color.set('white_Kedge') - create_plot() + update_plot() else: options = self.table_mapping.get(value, []) self.threshold_options = {} @@ -283,11 +303,11 @@ class TwoStageDropdown: self.threshold_var.set(first_opt) self.threshold_menu.config(state='normal', style='TMenubutton') self.criterion.color.set(self.threshold_options[first_opt]) - create_plot() + update_plot() def threshold_selected(self, selection): self.threshold_var.set(selection) self.criterion.color.set(self.threshold_options[selection]) - create_plot() + update_plot() def reset(self): self.concentration_var.set("not tested") self.threshold_var.set("") @@ -314,7 +334,7 @@ class SingleDropdown: self.dropdown.pack(anchor='w', padx=4, pady=(0,4)) def change_dropdown(self, *args): self.criterion.color.set(self.options[self.var.get()]) - create_plot() + update_plot() def reset(self): default = list(self.options.keys())[0] self.var.set(default) @@ -447,11 +467,13 @@ def create_annotated_plot(): # ============================================================================= def save_image(): + fig = create_plot() ftypes = [('PNG file', '.png'), ('SVG file', '.svg'), ('All files', '*')] filename = filedialog.asksaveasfilename(filetypes=ftypes, defaultextension='.png') if filename: # Save the current figure exactly as displayed. current_fig.savefig(filename, bbox_inches='tight', dpi=300) + update_plot() def save_annotated_image(): fig = create_annotated_plot() @@ -459,7 +481,7 @@ def save_annotated_image(): filename = filedialog.asksaveasfilename(filetypes=ftypes, defaultextension='.png') if filename: fig.savefig(filename, bbox_inches='tight', dpi=300) - create_plot() + update_plot() def reset_scores(): for crit in criteria[1:]: @@ -471,7 +493,7 @@ def reset_scores(): dropdown8.reset() dropdown9.reset() dropdown10.reset() - create_plot() + update_plot() def call_info_popup(): win = tk.Toplevel() @@ -550,5 +572,5 @@ dropdown10 = SingleDropdown(left_frame, criteria[10], crit10_options, # MAIN LOOP # ============================================================================= -create_plot() +update_plot() root.mainloop() -- GitLab