From 9299ff7a117119489db910cc6b9767acad3c6a53 Mon Sep 17 00:00:00 2001 From: Mikhail Zakharov Date: Sun, 10 Nov 2024 17:06:38 +0100 Subject: [PATCH] `gui-warp.py`: Highlight "Save" button for INI/FW if config has been edited --- CHANGELOG.md | 3 +++ gui/gui-warp.py.in | 19 ++++++++++++++++--- gui/ports/macOS/gui-warp.py | 11 +++++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 732fb41..6a7432f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG +* **2024.11.10 Current** + * `gui-warp.py`: Highlight "Save" button for INI/FW if config has been edited. Thanks Radek Sipka for the request + * **2024.11.08 ts-warp-1.5.7, gui-warp-1.0.26 (gui-warp-v1.0.33-mac), ns-warp-1.0.7** * `ts-warp.sh`: Log-file truncating moved here * `gui-warp.py`: Minor changes about log-file size and FW-file selection under `Linux` diff --git a/gui/gui-warp.py.in b/gui/gui-warp.py.in index 269cd28..2d90608 100644 --- a/gui/gui-warp.py.in +++ b/gui/gui-warp.py.in @@ -147,8 +147,8 @@ class App: 'tsw01:' + subprocess.Popen([prefix + '/bin/ts-pass', self.tswhash.get().encode()], stdout=subprocess.PIPE).stdout.read().decode().strip('\n\r')) - sch = ttk.Label(frm_tab_ini_top, text='Save configuration:') - sch.grid(column=2, row=0, sticky=tk.E) + lbl_save_ini = ttk.Label(frm_tab_ini_top, text='Save INI file:') + lbl_save_ini.grid(column=2, row=0, sticky=tk.E) btn_save_ini = ttk.Button(frm_tab_ini_top, width=self._btnw, text='▲') btn_save_ini.grid(column=3, row=0, sticky=tk.W, padx=self._padx, pady=self._pady) btn_save_ini['command'] = lambda: self.savefile(ini_txt, inifile) @@ -157,6 +157,11 @@ class App: ini_txt.grid(column=0, row=1, columnspan=2, sticky=tk.NSEW) tab_ini.bind("", self.readfile_ini(ini_txt, inifile)) + def ini_modified(event=None): + lbl_save_ini['foreground'] = 'red' if ini_txt.edit_modified() else 'black' + ini_txt.edit_modified(False) + ini_txt.bind("<>", ini_modified) + scroll_ini = ttk.Scrollbar(tab_ini, orient=tk.VERTICAL) scroll_ini.grid(column=2, row=1, sticky=tk.NSEW) scroll_ini.config(command=ini_txt.yview) @@ -166,7 +171,8 @@ class App: tab_fw.columnconfigure(0, weight=1) tab_fw.rowconfigure(1, weight=1) - ttk.Label(tab_fw, text='Save changes:').grid(column=0, row=0, sticky=tk.E) + lbl_save_fw = ttk.Label(tab_fw, text='Save FW-rules:') + lbl_save_fw.grid(column=0, row=0, sticky=tk.E) btn_save_fw = ttk.Button(tab_fw, width=self._btnw, text='▲') btn_save_fw.grid(column=1, row=0, sticky=tk.W, padx=self._padx, pady=self._pady) @@ -176,6 +182,11 @@ class App: fw_txt.grid(column=0, row=1, columnspan=2, sticky=tk.NSEW) tab_fw.bind("", self.readfile_ini(fw_txt, fwfile)) + def fw_modified(event=None): + lbl_save_fw['foreground'] = 'red' if fw_txt.edit_modified() else 'black' + fw_txt.edit_modified(False) + fw_txt.bind("<>", fw_modified) + scroll_fw = ttk.Scrollbar(tab_fw, orient=tk.VERTICAL) scroll_fw.grid(column=2, row=1, sticky=tk.NSEW) scroll_fw.config(command=fw_txt.yview) @@ -381,6 +392,8 @@ It is a free and open-source software, but if you want to support it, please do' with open(filename, 'w', encoding='utf8') as f: f.write(t_widget.get('1.0', tk.END)[:-1]) # Strip extra newline + t_widget.edit_modified(False) + # ---------------------------------------------------------------------------------------------------------------- # def pauselog(self, btn, txt, filename): """ diff --git a/gui/ports/macOS/gui-warp.py b/gui/ports/macOS/gui-warp.py index a310578..21c6de2 100644 --- a/gui/ports/macOS/gui-warp.py +++ b/gui/ports/macOS/gui-warp.py @@ -166,8 +166,8 @@ def __init__(self, width=800, height=560, 'tsw01:' + subprocess.Popen(['./ts-pass', self.tswhash.get().encode()], stdout=subprocess.PIPE).stdout.read().decode().strip('\n\r')) - sch = ttk.Label(frm_tab_ini_top, text='Save configuration:', foreground='green') - sch.grid(column=2, row=0, sticky=tk.E) + lbl_sch = ttk.Label(frm_tab_ini_top, text='Save INI file:') + lbl_sch.grid(column=2, row=0, sticky=tk.E) btn_save_ini = ttk.Button(frm_tab_ini_top, width=self._btnw, text='▲') btn_save_ini.grid(column=3, row=0, sticky=tk.W, padx=self._padx, pady=self._pady) btn_save_ini['command'] = lambda: self.saveini(ini_txt, inifile) @@ -176,6 +176,11 @@ def __init__(self, width=800, height=560, ini_txt.grid(column=0, row=1, columnspan=2, sticky=tk.NSEW) tab_ini.bind("", self.readfile_ini(ini_txt, inifile)) + def ini_modified(event=None): + lbl_sch['foreground'] = 'red' if ini_txt.edit_modified() else 'black' + ini_txt.edit_modified(False) + ini_txt.bind("<>", ini_modified) + scroll_ini = ttk.Scrollbar(tab_ini, orient=tk.VERTICAL) scroll_ini.grid(column=2, row=1, sticky=tk.NSEW) scroll_ini.config(command=ini_txt.yview) @@ -369,6 +374,8 @@ def saveini(self, t_widget, filename): subprocess.run(['./ts-warp_autofw.sh', prefix], stdout=outfw, check=False) os.chown(fwfile, uid, gid) + t_widget.edit_modified(False) + # ---------------------------------------------------------------------------------------------------------------- # def pauselog(self, btn, txt, filename): """