-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.py
More file actions
105 lines (82 loc) · 3.95 KB
/
GUI.py
File metadata and controls
105 lines (82 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import sys
import yaml
import subprocess
import FreeSimpleGUI as sg
GUI_WIDTH = 700
GUI_HEIGHT = 500
_s = min(GUI_WIDTH / 700, GUI_HEIGHT / 500)
_FONT = f'any {int(12 * _s)}'
_FONT_BOLD = f'any {int(12 * _s)} bold'
config_file = 'config.yaml'
with open(config_file, 'r') as f:
cfg = yaml.safe_load(f)
fft_on = cfg.get('fftcoeff_step', True)
prot_on = cfg.get('protparam_step', True)
SECTION_FIELDS = {
'-FFTCOEFF_STEP-': ['-N_COEFFS-', '-ALIGNMENT-', '-DISMISS_RATIO-'],
'-PROTPARAM_STEP-': ['-PROTPARAM_MODE-'],
}
sg.theme('DarkPurple6')
sg.set_options(font=_FONT)
column = [
[sg.Text('Output directory:', s=(28, 1)), sg.In(default_text=cfg.get('output_dir', 'results'), size=(40, 1), key='-OUTPUT_DIR-')],
[sg.Text('_' * 75)],
[sg.Checkbox('FFT coefficients step', font=_FONT_BOLD, key='-FFTCOEFF_STEP-', default=fft_on, enable_events=True)],
[sg.Text(' - Number of coefficients:', s=(28, 1), pad=((20, 0), (0, 0))), sg.Input(default_text=str(cfg.get('n_coeffs', 128)), s=10, disabled=not fft_on, key='-N_COEFFS-')],
[sg.Text(' - Alignment:', s=(28, 1), pad=((20, 0), (0, 0))), sg.Combo(['fft_major_axis_polarized', 'fft_major_axis', 'fft_centroid'], default_value=cfg.get('alignment', 'fft_major_axis_polarized'), disabled=not fft_on, key='-ALIGNMENT-', readonly=True)],
[sg.Text(' - Dismiss ratio:', s=(28, 1), pad=((20, 0), (0, 0))), sg.Input(default_text=str(cfg.get('dismiss_ratio', 8)), s=10, disabled=not fft_on, key='-DISMISS_RATIO-')],
[sg.Text('_' * 75)],
[sg.Checkbox('Shape modes step', font=_FONT_BOLD, key='-SHAPEMODE_STEP-', default=cfg.get('shapemode_step', True))],
[sg.Text(' NOTE: requires FFT coefficients step results', pad=((20, 0), (0, 0)))],
[sg.Text('_' * 75)],
[sg.Checkbox('Protein parametrization step', font=_FONT_BOLD, key='-PROTPARAM_STEP-', default=prot_on, enable_events=True)],
[sg.Text(' NOTE: requires FFT coefficients step results', pad=((20, 0), (0, 0)))],
[sg.Text(' - Mode:', s=(28, 1), pad=((20, 0), (0, 0))), sg.Combo(['rings', 'warp'], default_value=cfg.get('protparam_mode', 'rings'), disabled=not prot_on, key='-PROTPARAM_MODE-', readonly=True)],
[sg.Text('_' * 75)],
[sg.Checkbox('Comparison step', font=_FONT_BOLD, key='-COMPARISON_STEP-', default=cfg.get('comparison_step', False))],
[sg.Text(' NOTE: requires protein parametrization and shape modes results', pad=((20, 0), (0, 0)))],
[sg.Text('_' * 75)],
[sg.Text('Generate plots:', s=(28, 1)), sg.Checkbox('', default=cfg.get('plot', True), key='-PLOT-')],
[sg.Text('Seed:', s=(28, 1)), sg.Input(default_text=str(cfg.get('seed', 0)), s=10, key='-SEED-')],
]
layout = [
[sg.Column(column, scrollable=True, vertical_scroll_only=True, size=(GUI_WIDTH, GUI_HEIGHT))],
[sg.Text('_' * 75)],
[sg.Button('Run'), sg.Button('Save Config'), sg.Button('Cancel')],
]
window = sg.Window('2D Shape Space', layout)
cancel = False
run = False
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Cancel':
cancel = True
break
if event == 'Save Config':
break
if event == 'Run':
run = True
break
if event in SECTION_FIELDS:
for field in SECTION_FIELDS[event]:
window[field].update(disabled=not values[event])
window.close()
if cancel:
sys.exit()
new_cfg = {
'output_dir': values['-OUTPUT_DIR-'],
'fftcoeff_step': values['-FFTCOEFF_STEP-'],
'shapemode_step': values['-SHAPEMODE_STEP-'],
'protparam_step': values['-PROTPARAM_STEP-'],
'comparison_step': values['-COMPARISON_STEP-'],
'n_coeffs': int(values['-N_COEFFS-']),
'alignment': values['-ALIGNMENT-'],
'dismiss_ratio': int(values['-DISMISS_RATIO-']),
'protparam_mode': values['-PROTPARAM_MODE-'],
'plot': values['-PLOT-'],
'seed': int(values['-SEED-']),
}
with open(config_file, 'w') as f:
yaml.dump(new_cfg, f, default_flow_style=False, sort_keys=False)
if run:
subprocess.run([sys.executable, 'process.py'])