def __init__(self, WD=None, name='Main Frame', dmodel=None, title=None, contribution=None): try: version = pmag.get_version() except: version = "" if not title: title = "MagIC GUI version: %s" % version #if sys.platform in ['win32', 'win64']: # title += " Powered by Enthought Canopy" wx.Frame.__init__(self, None, wx.ID_ANY, title, name=name) # self.grid_frame = None self.panel = wx.Panel(self, size=wx.GetDisplaySize(), name='main panel') print('-I- Fetching working directory') self.WD = os.path.realpath(WD) or os.getcwd() print('-I- Initializing magic data model') if dmodel is None: dmodel = data_model3.DataModel() self.data_model = dmodel self.edited = False self.validation_mode = False print('-I- Initializing interface') self.InitUI() print('-I- Completed interface') if contribution: self.contribution = contribution elif not WD: wx.CallAfter(self.on_change_dir_button) else: wx.CallAfter(self.get_wd_data)
""" tests for magic_gui """ import wx import unittest import os from programs import magic_gui from pmagpy import new_builder as nb from dialogs import grid_frame3 as grid_frame #import dialogs.pmag_widgets as pmag_widgets from pmagpy import pmag from pmagpy import data_model3 as data_model # set constants DMODEL = data_model.DataModel() WD = pmag.get_test_WD() PROJECT_WD = os.path.join(WD, "data_files", "magic_gui", "3_0") class TestMainFrame(unittest.TestCase): def setUp(self): self.app = wx.App() self.frame = magic_gui.MainFrame(PROJECT_WD, name="best frame ever", dmodel=DMODEL) self.frame.get_wd_data() self.pnl = self.frame.GetChildren()[0] def tearDown(self): # wx.CallAfter(self.frame.Destroy)
def InitUI(self): pnl1 = self.panel box_sizers = [] self.text_controls = {} self.info_options = {} add_buttons = [] remove_buttons = [] if not self.contribution.data_model: self.contribution.data_model = data_model.DataModel() dmodel = self.contribution.data_model for table in self.table_list: N = self.table_list.index(table) label = table # make sure all tables have any actual headers (read from file) # plus any required headers reqd_headers = dmodel.get_reqd_headers(table) if table in self.contribution.tables: df_container = self.contribution.tables[table] actual_headers = df_container.df.columns.union(reqd_headers) else: actual_headers = reqd_headers # add any extra headers (i.e., reqd but not present), into the table add_headers = actual_headers.difference(df_container.df.columns) if table in ['sites', 'locations']: if 'age' not in add_headers and 'age' not in actual_headers: add_headers = add_headers.append(pd.Index(['age'])) for head in add_headers: df_container.df[head] = None # define actual (includes reqd) vs optional headers actual_headers = df_container.df.columns optional_headers = dmodel.dm[table].index.difference( actual_headers) box_sizer = wx.StaticBoxSizer( wx.StaticBox(self.panel, wx.ID_ANY, table), wx.VERTICAL) box_sizers.append(box_sizer) text_control = wx.TextCtrl(self.panel, id=-1, size=(210, 250), style=wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL, name=table) self.text_controls[table] = text_control info_option = wx.ListBox(choices=optional_headers, id=-1, name=table, parent=self.panel, size=(200, 250), style=0) self.info_options[table] = info_option add_button = wx.Button(self.panel, id=-1, label='add', name=table) add_buttons.append(add_button) self.Bind(wx.EVT_BUTTON, self.on_add_button, add_button) remove_button = wx.Button(self.panel, id=-1, label='remove', name=table) self.Bind(wx.EVT_BUTTON, self.on_remove_button, remove_button) #------ box_sizer.Add( wx.StaticText(pnl1, label='{} header list:'.format(table)), wx.ALIGN_TOP) box_sizer.Add(text_control, wx.ALIGN_TOP) box_sizer.Add(wx.StaticText(pnl1, label='{} optional:'.format(table)), flag=wx.ALIGN_TOP | wx.TOP, border=10) box_sizer.Add(info_option, wx.ALIGN_TOP) box_sizer.Add(add_button, wx.ALIGN_TOP) box_sizer.Add(remove_button, wx.ALIGN_TOP) # need headers self.update_text_box(actual_headers, text_control) hbox1 = wx.BoxSizer(wx.HORIZONTAL) self.okButton = wx.Button(self.panel, wx.ID_OK, "&OK") self.Bind(wx.EVT_BUTTON, self.on_okButton, self.okButton) self.okButton.SetDefault() self.cancelButton = wx.Button(self.panel, wx.ID_CANCEL, '&Cancel') self.Bind(wx.EVT_BUTTON, self.on_cancelButton, self.cancelButton) self.Bind(wx.EVT_CLOSE, self.on_cancelButton) self.helpButton = wx.Button(self.panel, wx.ID_ANY, '&Help') self.Bind(wx.EVT_BUTTON, self.on_helpButton, self.helpButton) hbox1.Add(self.okButton, flag=wx.ALL, border=5) hbox1.Add(self.cancelButton, flag=wx.ALL, border=5) hbox1.Add(self.helpButton, flag=wx.ALL, border=5) #------ vbox = wx.BoxSizer(wx.VERTICAL) hbox = wx.BoxSizer(wx.HORIZONTAL) hbox.AddSpacer(5) for sizer in box_sizers: hbox.Add(sizer, flag=wx.ALIGN_LEFT | wx.BOTTOM, border=5) hbox.AddSpacer(5) hbox.AddSpacer(5) text = wx.StaticText( self.panel, label= "Step 0:\nChoose the headers for your specimens, samples, sites, locations and ages text files.\nOnce you have selected all necessary headers, click the OK button to move on to step 1.\nFor more information, click the help button below." ) vbox.Add(text, flag=wx.ALIGN_LEFT | wx.ALL, border=20) #vbox.AddSpacer(20) vbox.Add(hbox) vbox.AddSpacer(20) vbox.Add(hbox1, flag=wx.ALIGN_CENTER_HORIZONTAL) vbox.AddSpacer(20) # if they are not already present # add some strongly-recommended categories to age text_box if 'ages' in self.contribution.tables: actual_age_headers = list( self.contribution.tables['ages'].df.columns) else: actual_age_headers = dmodel.get_reqd_headers('ages') for extra_header in ['age', 'age_unit', 'site']: if extra_header not in actual_age_headers: actual_age_headers.append(extra_header) self.contribution.tables['ages'].df[extra_header] = None add_age_headers = list(set(actual_age_headers)) self.update_text_box(add_age_headers, self.text_controls['ages']) self.panel.SetSizer(vbox) vbox.Fit(self) self.Show() self.Centre() # these two lines ensure that everything shows up wx.CallAfter(self.Refresh) self.Update()
def convert_specimen_dm3_table(spec_df): """ Convert MagIC specimen headers to short/readable headers for a figure (used by ipmag.specimens_extract) """ from pmagpy import data_model3 as dm3 # get the data model dm = dm3.DataModel() # get the specimen absolute intensity column headers meas_group = ['meas_step_min', 'meas_step_max', 'meas_step_unit'] pint_group = dm.get_group_headers('specimens', 'Paleointensity') arai_group = dm.get_group_headers('specimens', 'Paleointensity Arai Statistics') # filter out the relative intensity stuff dm3_columns = list(meas_group) + list(pint_group) + list(arai_group) dm3_columns = filter(lambda x: '_rel' not in x, dm3_columns) # apply to specimen dataframe meas_group_columns = ['meas_step_min', 'meas_step_max', 'meas_step_unit'] pint_group_columns = list(spec_df.columns.intersection(pint_group)) arai_group_columns = list(spec_df.columns.intersection(arai_group)) columns = ['specimen', 'sample']+meas_group_columns + \ pint_group_columns+arai_group_columns spec_df = spec_df.copy()[columns] muT_list = ['int_abs', 'int_abs_sigma', 'int_treat_dc_field'] meas_list = ['meas_step_min', 'meas_step_max'] for el in muT_list: if el in columns: spec_df[el] = 1e6 * spec_df[el] if 'meas_step_unit' in columns: for el in meas_list: spec_df.loc[spec_df['meas_step_unit'] == 'K', el] = spec_df[el] - 273 spec_df.loc[spec_df['meas_step_unit'] == 'T', el] = 1e3 * spec_df[el] spec_df.loc[spec_df['meas_step_unit'] == 'K', 'meas_step_unit'] = 'C' spec_df.loc[spec_df['meas_step_unit'] == 'T', 'meas_step_unit'] = 'mT' spec_df['meas_step_min'] = spec_df['meas_step_min'].astype('int') spec_df['meas_step_max'] = spec_df['meas_step_max'].astype('int') dm3_columns = [ 'meas_step_min', 'meas_step_max', 'meas_step_unit', 'int_abs', 'int_abs_sigma', 'int_abs_sigma_perc', 'int_n_measurements', 'int_corr', 'int_corr_cooling_rate', 'int_corr_aniso', 'int_corr_nlt', 'int_corr_arm', 'int_viscosity_index', 'int_treat_dc_field', 'int_b', 'int_b_sigma', 'int_b_beta', 'int_rsc', 'int_f', 'int_fvds', 'int_frac', 'int_g', 'int_gmax', 'int_q', 'int_w', 'int_k', 'int_k_sse', 'int_k_prime', 'int_k_prime_sse', 'int_scat', 'int_r2_corr', 'int_r2_det', 'int_z', 'int_z_md' ] table_columns = [ 'Min', 'Max', 'Units', 'B (uT)', 'sigma', 'percent', 'N', 'c/u', 'CR', 'Aniso.', 'NLT', 'AARM', 'VI', 'Lab Field', 'b', 'b sigma', 'beta', 'R2', 'f', 'fvds', 'frac', 'g', 'gap max', 'q', 'w', 'k', 'k sse', 'k prime', 'k prime sse', 'scat', 'r2 corr', 'r2 det', 'Z', 'Z md' ] spec_mapping = dict(list(zip(dm3_columns, table_columns))) spec_df_out = spec_df.rename(columns=spec_mapping) if 'N' in spec_df_out.columns: spec_df_out['N'] = spec_df_out['N'].astype('int') if 'Lab Field' in spec_df_out.columns: spec_df_out['Lab Field'] = spec_df_out['Lab Field'].round().astype( 'int') return spec_df_out