From aaf3ebcb87650e74d7ed79626febaff6584928b0 Mon Sep 17 00:00:00 2001 From: Steffen Hirtle Date: Sat, 30 Sep 2023 13:07:18 +0200 Subject: [PATCH] Added manual selection of AI directory --- graxpert/background_extraction.py | 8 +------- graxpert/gui.py | 2 +- graxpert/help_panel.py | 29 +++++++++++++++++++++++------ graxpert/preferences.py | 7 ++++++- locales/de_DE/LC_MESSAGES/base.mo | Bin 8641 -> 8703 bytes locales/de_DE/LC_MESSAGES/base.po | 3 +++ 6 files changed, 34 insertions(+), 15 deletions(-) diff --git a/graxpert/background_extraction.py b/graxpert/background_extraction.py index b187bc1..f22ea43 100644 --- a/graxpert/background_extraction.py +++ b/graxpert/background_extraction.py @@ -24,7 +24,7 @@ def extract_background(in_imarray, background_points, interpolation_type, smoothing, - downscale_factor, sample_size, RBF_kernel, spline_order, corr_type): + downscale_factor, sample_size, RBF_kernel, spline_order, corr_type, AI_dir): shm_imarray = shared_memory.SharedMemory(create=True, size=in_imarray.nbytes) shm_background = shared_memory.SharedMemory(create=True, size=in_imarray.nbytes) @@ -53,12 +53,6 @@ def extract_background(in_imarray, background_points, interpolation_type, smooth if num_colors == 1: imarray_shrink = np.array([imarray_shrink[:,:,0],imarray_shrink[:,:,0],imarray_shrink[:,:,0]]) imarray_shrink = np.moveaxis(imarray_shrink, 0, -1) - - AI_dir = "" - if getattr(sys, 'frozen', False): - AI_dir = os.path.join(os.path.dirname(sys.executable), 'bg_model') - else: - AI_dir = os.path.join(os.path.dirname(__file__), '../bg_model') model = tf.keras.models.load_model(AI_dir) diff --git a/graxpert/gui.py b/graxpert/gui.py index 1068199..51af13a 100644 --- a/graxpert/gui.py +++ b/graxpert/gui.py @@ -663,7 +663,7 @@ def calculate(self): self.interpol_type.get(),self.smoothing.get(), downscale_factor, self.sample_size.get(), self.RBF_kernel.get(),self.spline_order.get(), - self.corr_type.get() + self.corr_type.get(), self.prefs["AI_directory"] )) self.images["Processed"] = AstroImage(self.stretch_option_current, self.saturation) diff --git a/graxpert/help_panel.py b/graxpert/help_panel.py index 240ffde..0614648 100644 --- a/graxpert/help_panel.py +++ b/graxpert/help_panel.py @@ -272,8 +272,25 @@ def __init__(self, master, canvas, app): self.spline_order_menu.grid(column=0, row=10, pady=(5*scaling,5*scaling), padx=(40,30), sticky="ews") + + def AI_directory_clicked(): + AI_directory = tk.filedialog.askdirectory( + initialdir = self.app.prefs["AI_directory"] + ) + + if AI_directory != "": + self.app.prefs["AI_directory"] = AI_directory + + self.AI_directory_button = ttk.Button(self.advanced_panel_window, + text=_("Select AI directory"), + command=AI_directory_clicked) + + self.AI_directory_button.grid(column=0, row=11, pady=(30*scaling,5*scaling), padx=(40,30), sticky="ews") + + + text = tk.Message(self.advanced_panel_window, text=_("Correction"), width=240 * scaling, font=heading_font2, anchor="center") - text.grid(column=0, row=11, padx=(10*scaling,10*scaling), pady=(20*scaling,10*scaling), sticky="ew") + text.grid(column=0, row=12, padx=(10*scaling,10*scaling), pady=(20*scaling,10*scaling), sticky="ew") self.app.corr_types = ["Subtraction", "Division"] @@ -283,14 +300,14 @@ def __init__(self, master, canvas, app): self.app.corr_type.set(self.app.prefs["corr_type"]) self.corr_menu = ttk.OptionMenu(self.advanced_panel_window, self.app.corr_type, self.app.corr_type.get(), *self.app.corr_types) - self.corr_menu.grid(column=0, row=12, pady=(5*scaling,5*scaling), padx=(40,30), sticky="ews") + self.corr_menu.grid(column=0, row=13, pady=(5*scaling,5*scaling), padx=(40,30), sticky="ews") text = tk.Message(self.advanced_panel_window, text=_("Interface"), width=240 * scaling, font=heading_font2, anchor="center") - text.grid(column=0, row=13, padx=(40,30), pady=(20*scaling,10*scaling), sticky="ew") + text.grid(column=0, row=14, padx=(40,30), pady=(20*scaling,10*scaling), sticky="ew") text = tk.Message(self.advanced_panel_window, text=_("Language"), width=240*scaling, anchor="center") - text.grid(column=0, row=14, pady=(5*scaling,5*scaling), padx=(40,30), sticky="ews") + text.grid(column=0, row=15, pady=(5*scaling,5*scaling), padx=(40,30), sticky="ews") def lang_change(lang): messagebox.showerror("", _("Please restart the program to change the language.")) @@ -304,7 +321,7 @@ def lang_change(lang): self.app.lang.set("English") self.lang_menu = ttk.OptionMenu(self.advanced_panel_window, self.app.lang, self.app.lang.get(), *self.app.langs, command=lang_change) - self.lang_menu.grid(column=0, row=15, pady=(5*scaling,5*scaling), padx=(40,30), sticky="ews") + self.lang_menu.grid(column=0, row=16, pady=(5*scaling,5*scaling), padx=(40,30), sticky="ews") def scaling_change(): @@ -317,7 +334,7 @@ def scaling_change(): self.scaling_slider = Slider(self.advanced_panel_window, self.app.scaling, "Scaling", 0.5, 2, 1, scaling, scaling_change) - self.scaling_slider.grid(column=0, row=16, pady=(10*scaling,10*scaling), padx=(40,30), sticky="ew") + self.scaling_slider.grid(column=0, row=17, pady=(10*scaling,10*scaling), padx=(40,30), sticky="ew") diff --git a/graxpert/preferences.py b/graxpert/preferences.py index 60610fd..b58a3b6 100644 --- a/graxpert/preferences.py +++ b/graxpert/preferences.py @@ -1,6 +1,7 @@ import json import logging import os +import sys import shutil from datetime import datetime from typing import AnyStr, List, TypedDict @@ -29,6 +30,7 @@ class Prefs(TypedDict): lang: AnyStr corr_type: AnyStr scaling: float + AI_directory: AnyStr DEFAULT_PREFS: Prefs = { "working_dir": os.getcwd(), @@ -49,7 +51,8 @@ class Prefs(TypedDict): "spline_order": 3, "lang": None, "corr_type": "Subtraction", - "scaling": 1.0 + "scaling": 1.0, + "AI_directory": os.path.join(os.path.dirname(sys.executable), 'bg_model') } @@ -119,6 +122,8 @@ def merge_json(prefs: Prefs, json) -> Prefs: prefs["corr_type"] = json["corr_type"] if "scaling" in json: prefs["scaling"] = json["scaling"] + if "AI_dir" in json: + prefs["AI_directory"] = json["AI_directory"] return prefs diff --git a/locales/de_DE/LC_MESSAGES/base.mo b/locales/de_DE/LC_MESSAGES/base.mo index 8216ad44d02bb3a5fd24656c9bfd101ce42e30cb..63dfbef4760bebdbca8f3bf8793a9db826ceb214 100644 GIT binary patch delta 1353 z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MESSAGES/base.po +++ b/locales/de_DE/LC_MESSAGES/base.po @@ -337,3 +337,6 @@ msgstr "Skalierung" msgid "Please restart the program to apply the changes to UI scaling." msgstr "Bitte das Programm neu starten, um die Änderungen an der Nutzeroberflächenskalierung anzuwenden." + +msgid "Select AI directory" +msgstr "AI Verzeichnis auswählen"