コード例 #1
0
 def test_beam_setup_cancel(self):
     """Test beam_setup cancel button"""
     test_matrix = self.beam_setup.get_matrix()
     test_ref = self.beam_setup.get_reference()
     self.beam_setup.window.get_frame("&Okay", "button").Clicked()
     self.main_window.window.get_frame("&Beam Setup", "button").Clicked()
     self.beam_setup = self.main_window.beam_setup
     self.beam_setup.set_matrix(self.cov)
     self.beam_setup.set_reference(self.hit_red)
     self.beam_setup.window.get_frame("&Cancel", "button").Clicked()
     for var in Hit.get_variables():
         self.assertAlmostEqual(self.main_window.lattice.ref_list[0][var],
                                test_ref[var], 3)
     self._ell_equal(self.main_window.lattice.ellipse_list[0], test_matrix)
コード例 #2
0
 def test_beam_setup_cancel(self):
     """Test beam_setup cancel button"""
     test_matrix = self.beam_setup.get_matrix()
     test_ref = self.beam_setup.get_reference()
     self.beam_setup.window.get_frame("&Okay", "button").Clicked()
     self.main_window.window.get_frame("&Beam Setup", "button").Clicked()
     self.beam_setup = self.main_window.beam_setup
     self.beam_setup.set_matrix(self.cov)
     self.beam_setup.set_reference(self.hit_red)
     self.beam_setup.window.get_frame("&Cancel", "button").Clicked()
     for var in Hit.get_variables():
         self.assertAlmostEqual(self.main_window.lattice.ref_list[0][var],
                                test_ref[var], 3)
     self._ell_equal(self.main_window.lattice.ellipse_list[0], test_matrix)
コード例 #3
0
class PlotSetup():
    """
    GUI handler for defining data to be plotted
    """
    def __init__(self, main_window, parent, selected):
        """
        Initialise the window
        """
        self.main_window = main_window
        self.parent = parent
        self.selected = selected
        self.window = Window(
            ROOT.gClient.GetRoot(),  # pylint: disable = E1101
            parent,
            self.share_dir + "plot_setup.json")
        for i, item in enumerate(self.selected):
            self.window.set_action("variable_type_" + str(i), "drop_down",
                                   "Selected(Int_t)", self.select_action)
            type_frame = self.window.get_frame("variable_type_" + str(i),
                                               "drop_down")
            type_frame.Select(item["variable_type"])
        self.window.set_button_action("&Okay", self.okay_action)
        self.window.set_button_action("&Cancel", self.cancel_action)

    def okay_action(self):
        """
        Handle Okay button press; get the plot selection and push it to the
        main window
        """
        type_int = self.window.get_frame_dict(
            "variable_type_0", "drop_down")["frame"].GetSelected()
        first_int = self.window.get_frame_dict(
            "first_var_0", "drop_down")["frame"].GetSelected()
        plot_apertures = self.window.get_frame("plot_apertures",
                                               "check_button").IsOn()
        if type_int != 0 and first_int == 0:
            raise GuiError("Please select plot variable")
        self.main_window.plot_setup_options = [{
            "variable_type": type_int,
            "first_var": first_int,
            "plot_apertures": plot_apertures
        }]
        self.main_window.update_plot()
        self.window.close_window()
        self.main_window.plot_setup = None

    def cancel_action(self):
        """
        Handle Cancel button press; just close the window
        """
        self.window.close_window()
        self.main_window.plot_setup = None

    def select_action(self):
        """
        Dynamically change the list of items in first_var depending on
        variable_type
        """
        for i, item in enumerate(self.selected):
            type_select = self.window.get_frame_dict("variable_type_" + str(i),
                                                     "drop_down")["frame"]
            first_var_select = self.window.get_frame_dict(
                "first_var_" + str(i), "drop_down")["frame"]
            selected_type_int = type_select.GetSelected()
            selected_type_str = self.type_list[selected_type_int]
            var_list_name = self.type_variables_dict[selected_type_str][0]
            var_list = self.select_lists[var_list_name]
            first_var_select.RemoveAll()
            for i, entry in enumerate(var_list):
                first_var_select.AddEntry(entry, i)
            first_var_select.Select(item["first_var"])

    @staticmethod
    def get_variable_type(options):
        """
        Return a string corresponding to integer variable_type selected
        """
        var_type_int = options[0]["variable_type"]
        return PlotSetup.type_list[var_type_int]

    @staticmethod
    def get_first_var(options):
        """
        Return a string corresponding to integer first_var selected
        """
        var_type_string = PlotSetup.get_variable_type(options)
        select_list_key = PlotSetup.type_variables_dict[var_type_string][0]
        select_list = PlotSetup.select_lists[select_list_key]
        first_var_int = options[0]["first_var"]
        return select_list[first_var_int]

    my_hit_get_variables = [var for var in Hit.get_variables() if len(var)]

    type_list = [
        "<Select plot type>", "mean", "envelope", "RMS", "beta", "alpha",
        "gamma", "emittance", "dispersion", "dispersion_prime"
    ]

    select_lists = {
        "no_var": [
            "",
        ],
        "optics_var":
        ["<Select plot variable>", "x", "y", "transverse", "longitudinal"],
        "physics_var": ["<Select plot variable>"] + my_hit_get_variables,
        "kinematic_var":
        ["<Select plot variable>", "x", "y", "px", "py", "t", "energy"],
        "disp_var": ["<Select plot variable>", "x", "y"]
    }

    type_variables_dict = {
        "<Select plot type>": ["no_var"],
        "mean": ["physics_var"],
        "envelope": ["kinematic_var"],
        "RMS": ["kinematic_var"],
        "beta": ["optics_var"],
        "alpha": ["optics_var"],
        "gamma": ["optics_var"],
        "emittance": ["optics_var"],
        "dispersion": ["disp_var"],
        "dispersion_prime": ["disp_var"],
    }

    share_dir = ""