Skip to content

Commit c2e522c

Browse files
committed
Polishing new plotting, fixes
1 parent b178921 commit c2e522c

4 files changed

Lines changed: 299 additions & 288 deletions

File tree

src/gui.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ def translate(window: sg.Window, T2_num: int, lang: str):
261261
window['T1_colorHEX'].update(tr.gui_hex[lang])
262262
window['T1_add'].update(tr.gui_add[lang])
263263
window['T1_plot'].update(tr.gui_plot[lang])
264+
window['T1_clear'].update(tr.gui_clear[lang])
264265
window['T1_export'].update(tr.gui_export[lang])
265266
window['T2_title1'].update(tr.gui_input[lang])
266267
window['T2_title2'].update(tr.gui_output[lang])

src/main.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,13 @@ def launch_window():
6565
bitness = int(window['-bitness-'].get())
6666
rounding = int(window['-rounding-'].get())
6767

68-
T1_plot_list = [] # list of objects names to plot
69-
T1_plot_data = [] # list of X, Y and color for each object to plot
68+
T1_plot_data = [] # list of X, Y, color and name for each object to plot
7069

7170

7271
# Window events loop
7372

7473
while True:
75-
event, values = window.Read()
74+
event, values = window.read()
7675

7776
# Independent window events
7877

@@ -209,14 +208,12 @@ def launch_window():
209208
window['T1_list'].update(tuple(di.obj_dict(objectsDB, values['T1_tags'], lang).keys()))
210209

211210
elif event == 'T1_add' and values['T1_list'] != []:
212-
T1_plot_list.append(values['T1_list'][0])
213-
T1_plot_data.append((T1_nm, T1_curve, T1_rgb_show))
211+
T1_plot_data.append((T1_nm, T1_curve, T1_rgb_show, values['T1_list'][0]))
214212

215213
elif event == 'T1_plot':
216-
pl.plot_spectra(T1_plot_list, T1_plot_data, lang)
214+
pl.plot_spectra(T1_plot_data, lang)
217215

218216
elif event == 'T1_clear':
219-
T1_plot_list = []
220217
T1_plot_data = []
221218

222219
elif event == 'T1_export':

src/plotter.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,27 @@ def draw_figure(canvas, figure):
2424
figure_canvas_agg.get_tk_widget().pack(side='top', fill='both', expand=1)
2525
return figure_canvas_agg
2626

27-
def plot_spectra(names: list, objects: list, lang: str):
28-
title = tr.single_title_text[lang] + names[0] if len(names) == 1 else tr.batch_title_text[lang] + ', '.join(names)
29-
fig = plt.Figure(figsize=(6, 4), dpi=125)
27+
def plot_spectra(objects: list, lang: str):
28+
"""Creates a separate window with plotted spectra from the list"""
29+
fig = plt.Figure(figsize=(9, 6), dpi=100)
3030
ax = fig.add_subplot(111, xlabel=tr.xaxis_text[lang])
31-
for name, obj in zip(names, objects):
32-
ax.plot(obj[0], obj[1], color=obj[2], label=name)
33-
layout = [[sg.Text(title)], [sg.Canvas(key='-canvas-')]]
34-
window = sg.Window('True Color Tools: Plot', layout, finalize=True, font='arial 18')
31+
for obj in objects:
32+
ax.plot(obj[0], obj[1], color=obj[2], label=obj[3])
33+
if len(objects) > 0:
34+
ax.legend()
35+
title = tr.spectral_plot[lang]
36+
layout = [
37+
[sg.Text(title, font=('arial', 16)), sg.Push(), sg.InputText(visible=False, enable_events=True, key='-path-'),
38+
sg.FileSaveAs(tr.gui_save[lang], file_types=('PNG {png}', 'PDF {pdf}', 'SVG {svg}'), default_extension='.png')],
39+
[sg.Canvas(key='-canvas-')]
40+
]
41+
window = sg.Window(title, layout, finalize=True, element_justification='center')
3542
fig_canvas_agg = draw_figure(window['-canvas-'].TKCanvas, fig)
36-
event, values = window.read()
43+
while True:
44+
event, values = window.read()
45+
if event == sg.WIN_CLOSED:
46+
break
47+
elif event == '-path-':
48+
path = values['-path-']
49+
fig.savefig(path, dpi=133.4) # 1200x800
3750
window.close()

0 commit comments

Comments
 (0)