Skip to content

Commit

Permalink
gui-warp.py: Highlight "Save" button for INI/FW if config has been …
Browse files Browse the repository at this point in the history
…edited
  • Loading branch information
mezantrop committed Nov 10, 2024
1 parent 5369f80 commit 9299ff7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
19 changes: 16 additions & 3 deletions gui/gui-warp.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -157,6 +157,11 @@ class App:
ini_txt.grid(column=0, row=1, columnspan=2, sticky=tk.NSEW)
tab_ini.bind("<Visibility>", 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("<<Modified>>", 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)
Expand All @@ -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)
Expand All @@ -176,6 +182,11 @@ class App:
fw_txt.grid(column=0, row=1, columnspan=2, sticky=tk.NSEW)
tab_fw.bind("<Visibility>", 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("<<Modified>>", 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)
Expand Down Expand Up @@ -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):
"""
Expand Down
11 changes: 9 additions & 2 deletions gui/ports/macOS/gui-warp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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("<Visibility>", 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("<<Modified>>", 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)
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit 9299ff7

Please sign in to comment.