Skip to content

Commit d8943bc

Browse files
committed
Add HTML-saving button to the GUI as well
1 parent ce31c54 commit d8943bc

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

neutron-heatmap/gui.py

+29-13
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import tkinter
2626
import traceback
2727
from logger import Logger
28-
from tkinter import ttk
28+
from tkinter import filedialog, ttk
2929
from typing import List, Optional, Tuple
3030

3131

@@ -70,29 +70,39 @@ def _setup_window(self):
7070
).grid(column=1, row=1, sticky=tkinter.E)
7171
ttk.Label(
7272
self._mainframe,
73-
text="open heatmap in a browser window using current zoom settings",
73+
text="open heatmap in a browser window, using current zoom settings",
7474
).grid(column=2, row=1, sticky=tkinter.W)
75-
# 2. Interstitial
75+
# 2. Save
76+
ttk.Button(
77+
self._mainframe,
78+
text="Save",
79+
command=functools.partial(self._handle_long_op, self._handle_save),
80+
).grid(column=1, row=2, sticky=tkinter.E)
81+
ttk.Label(
82+
self._mainframe,
83+
text="save heatmap to a file, using current zoom settings",
84+
).grid(column=2, row=2, sticky=tkinter.W)
85+
# 3. Interstitial
7686
ttk.Label(
7787
self._mainframe,
78-
text="NOTE: Zoom in/out are effective at the next 'Display'",
79-
).grid(column=1, row=2, columnspan=2, sticky=tkinter.W)
80-
# 3. Zoom In
88+
text="NOTE: Zoom in/out are effective at the next 'Display' or 'Save'",
89+
).grid(column=1, row=3, columnspan=2, sticky=tkinter.W)
90+
# 4. Zoom In
8191
ttk.Button(
8292
self._mainframe,
8393
text="Zoom In",
8494
command=functools.partial(self._handle_long_op, self._handle_zoom_in),
85-
).grid(column=1, row=3, sticky=tkinter.E)
95+
).grid(column=1, row=4, sticky=tkinter.E)
8696
zoomin_data_frame = self._build_zoomin_data_frame(self._mainframe)
8797
zoomin_data_frame.grid(
88-
column=2, row=3, sticky=(tkinter.N, tkinter.W, tkinter.E, tkinter.S)
98+
column=2, row=4, sticky=(tkinter.N, tkinter.W, tkinter.E, tkinter.S)
8999
)
90-
# 4. Zoom Out
100+
# 5. Zoom Out
91101
ttk.Button(
92102
self._mainframe, text="Zoom Out", command=self._handle_zoom_out
93-
).grid(column=1, row=4, sticky=tkinter.E)
103+
).grid(column=1, row=5, sticky=tkinter.E)
94104
ttk.Label(self._mainframe, text="zoom out to the initial state").grid(
95-
column=2, row=4, sticky=tkinter.W
105+
column=2, row=5, sticky=tkinter.W
96106
)
97107

98108
# Add a progress bar for long operations; this will be created on-demand
@@ -104,7 +114,7 @@ def _setup_window(self):
104114
self._mainframe,
105115
textvariable=self._status_text,
106116
relief="sunken",
107-
).grid(column=1, row=6, columnspan=2, sticky=(tkinter.W, tkinter.E))
117+
).grid(column=1, row=7, columnspan=2, sticky=(tkinter.W, tkinter.E))
108118

109119
# Setup padding for all children of the mainframe
110120
for child in self._mainframe.winfo_children():
@@ -122,6 +132,12 @@ def log(self, s: str):
122132
def _handle_display(self, *args):
123133
self._systems.display()
124134

135+
def _handle_save(self, *args):
136+
filename = filedialog.asksaveasfilename(
137+
defaultextension=".html", filetypes=[("HTML file", ".html")]
138+
)
139+
self._systems.save(filename)
140+
125141
def _handle_zoom_in(self, *args):
126142
try:
127143
coord0 = (int(self.x0.get()), int(self.z0.get()))
@@ -180,7 +196,7 @@ def _progressbar_start(self):
180196
)
181197
self._progressbar.grid_configure(padx=5, pady=5)
182198
self._progressbar.grid(
183-
column=1, row=5, columnspan=2, sticky=(tkinter.W, tkinter.E)
199+
column=1, row=6, columnspan=2, sticky=(tkinter.W, tkinter.E)
184200
)
185201
self._progressbar.start()
186202

0 commit comments

Comments
 (0)