1
# This file is part of MAUS: http://micewww.pp.rl.ac.uk/projects/maus
3
# MAUS is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation, either version 3 of the License, or
6
# (at your option) any later version.
8
# MAUS is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with MAUS. If not, see <http://www.gnu.org/licenses/>.
17
GUI handler for setting up a plot
20
# Currently hands around a dictionary that defines the setup options. This needs
22
# Currently only handles one plot element; plan is to support multiple plots on
27
from xboa.Hit import Hit
29
from gui.window import Window
30
from gui.window import GuiError
34
GUI handler for defining data to be plotted
36
def __init__(self, main_window, parent, selected):
40
self.main_window = main_window
42
self.selected = selected
43
self.window = Window(ROOT.gClient.GetRoot(), # pylint: disable = E1101
45
self.share_dir+"plot_setup.json")
46
for i, item in enumerate(self.selected):
47
self.window.set_action("variable_type_"+str(i), "drop_down",
48
"Selected(Int_t)", self.select_action)
49
type_frame = self.window.get_frame("variable_type_"+str(i),
51
type_frame.Select(item["variable_type"])
52
self.window.set_button_action("&Okay", self.okay_action)
53
self.window.set_button_action("&Cancel", self.cancel_action)
55
def okay_action(self):
57
Handle Okay button press; get the plot selection and push it to the
60
type_int = self.window.get_frame_dict("variable_type_0",
61
"drop_down")["frame"].GetSelected()
62
first_int = self.window.get_frame_dict("first_var_0",
63
"drop_down")["frame"].GetSelected()
64
plot_apertures = self.window.get_frame("plot_apertures",
65
"check_button").IsOn()
66
if type_int != 0 and first_int == 0:
67
raise GuiError("Please select plot variable")
68
self.main_window.plot_setup_options = [{
69
"variable_type":type_int,
70
"first_var":first_int,
71
"plot_apertures":plot_apertures
73
self.main_window.update_plot()
74
self.window.close_window()
75
self.main_window.plot_setup = None
77
def cancel_action(self):
79
Handle Cancel button press; just close the window
81
self.window.close_window()
82
self.main_window.plot_setup = None
84
def select_action(self):
86
Dynamically change the list of items in first_var depending on
89
for i, item in enumerate(self.selected):
90
type_select = self.window.get_frame_dict("variable_type_"+str(i),
92
first_var_select = self.window.get_frame_dict("first_var_"+str(i),
94
selected_type_int = type_select.GetSelected()
95
selected_type_str = self.type_list[selected_type_int]
96
var_list_name = self.type_variables_dict[selected_type_str][0]
97
var_list = self.select_lists[var_list_name]
98
first_var_select.RemoveAll()
99
for i, entry in enumerate(var_list):
100
first_var_select.AddEntry(entry, i)
101
first_var_select.Select(item["first_var"])
104
def get_variable_type(options):
106
Return a string corresponding to integer variable_type selected
108
var_type_int = options[0]["variable_type"]
109
return PlotSetup.type_list[var_type_int]
112
def get_first_var(options):
114
Return a string corresponding to integer first_var selected
116
var_type_string = PlotSetup.get_variable_type(options)
117
select_list_key = PlotSetup.type_variables_dict[var_type_string][0]
118
select_list = PlotSetup.select_lists[select_list_key]
119
first_var_int = options[0]["first_var"]
120
return select_list[first_var_int]
122
my_hit_get_variables = [var for var in Hit.get_variables() if len(var)]
125
"<Select plot type>",
141
"<Select plot variable>",
147
"<Select plot variable>"
148
]+my_hit_get_variables, "kinematic_var":[
149
"<Select plot variable>",
157
"<Select plot variable>",
163
type_variables_dict = {
164
"<Select plot type>":["no_var"],
165
"mean":["physics_var"],
166
"envelope":["kinematic_var"],
167
"RMS":["kinematic_var"],
168
"beta":["optics_var"],
169
"alpha":["optics_var"],
170
"gamma":["optics_var"],
171
"emittance":["optics_var"],
172
"dispersion":["disp_var"],
173
"dispersion_prime":["disp_var"],