<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def on_right_click_listctrl(self, event):
 """ right click on the listctrl toggles measurement bad """

        g_index = event.GetIndex()

        if self.Data[self.s]['measurement_flag'][g_index] == 'g':
            self.mark_meas_bad(g_index)
        else:
            self.mark_meas_good(g_index)

        if self.data_model == 3.0:
            self.con.tables['measurements'].write_magic_file(dir_path=self.WD)
        else:
            pmag.magic_write(os.path.join(
                self.WD, "magic_measurements.txt"), self.mag_meas_data, "magic_measurements")

        self.recalculate_current_specimen_interpreatations()

        if self.ie_open:
            self.ie.update_current_fit_data()
        self.calculate_high_levels_data()
        self.update_selection()