3
# This file is part of MAUS: http://micewww.pp.rl.ac.uk/projects/maus
5
# MAUS is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation, either version 3 of the License, or
8
# (at your option) any later version.
10
# MAUS is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with MAUS. If not, see <http://www.gnu.org/licenses/>.
19
The envelope tool enables the user to study the effects of lattice modifications
20
in an interactive environment.
22
GUI tools provide functionality for setting up, propagating and plotting beam
23
envelopes through electromagnetic lattices.
31
import gui.gui_exception_handler
32
from gui.window import Window
34
ENV_DIR = os.path.expandvars("${MAUS_ROOT_DIR}/bin/utilities/envelope_tool/")
35
sys.path.append(ENV_DIR+"lib")
37
# pylint: disable=F0401
39
from beam_setup import BeamSetup
40
from lattice import Lattice
41
from plotter import Plotter
42
from plot_setup import PlotSetup
43
from magnet_setup import MagnetSetup
45
SHARE_DIR = (ENV_DIR+"share/")
49
Setup share directories in submodules (used for loading aux files)
51
Lattice.share_dir = SHARE_DIR
52
PlotSetup.share_dir = SHARE_DIR
53
MagnetSetup.share_dir = SHARE_DIR
54
beam_setup.SHARE_DIR = SHARE_DIR
58
Defines the main window for the envelope tool GUI
61
"""Initialise the main window"""
62
self.window = Window(ROOT.gClient.GetRoot(), # pylint: disable=E1101
63
ROOT.gClient.GetRoot(), # pylint: disable=E1101
64
SHARE_DIR+"main_frame.json")
65
self.lattice = Lattice()
66
self.beam_setup = None
67
self.magnet_setup = None
68
self.plot_setup = None
69
self.plot_setup_options = [{"variable_type":0,
71
"plot_apertures":True}]
72
self.window.set_button_action("&Beam Setup", self.beam_button_action)
73
self.window.set_button_action("&Magnet Setup",
74
self.magnet_button_action)
75
self.window.set_button_action("&Plot Setup", self.plot_button_action)
76
self.window.set_button_action("E&xit", self.exit_button_action)
79
def beam_button_action(self):
80
"""Handle a Beam Setup button press"""
81
if self.beam_setup == None:
82
self.beam_setup = BeamSetup(self, self.window.main_frame)
83
ref, ellipse = self.lattice.get_beam()
84
self.beam_setup.set_reference(ref)
85
self.beam_setup.set_matrix(ellipse)
87
def magnet_button_action(self):
88
"""Handle a Magnet Setup button press"""
89
if self.magnet_setup == None:
90
self.magnet_setup = MagnetSetup(self, self.window.main_frame)
92
def plot_button_action(self):
93
"""Handle a Plot Setup button press"""
94
if self.plot_setup == None:
95
self.plot_setup = PlotSetup(self, self.window.main_frame,
96
self.plot_setup_options)
98
def exit_button_action(self):
99
"""Handle a Exit button press"""
100
self.window.close_window()
102
def update_plot(self):
103
"""Update the plot"""
104
canvas_frame = self.window.get_frame("main_canvas", "canvas")
105
canvas = canvas_frame.GetCanvas()
106
Plotter(self.plot_setup_options, canvas, self.lattice.ref_list,
107
self.lattice.ellipse_list, self.lattice.get_field_list())
111
The main function - build a MainWindow and poll to see if it has been closed
115
main_window = MainWindow()
116
gui.gui_exception_handler.set_error_level("exceptions")
117
while main_window.window.main_frame != None:
119
except KeyboardInterrupt:
120
print "Pressed Ctrl-C"
123
return 0 # pylint: disable=W0150
125
if __name__ == '__main__':