def add_exp_type(self, index): """Add the experiment type info to the element. @param index: The column index for the data. @type index: int @return: True if the data exists, False otherwise. @rtype: bool """ # Append a column. self.element.InsertColumn(index, u("Experiment type")) # No data. if not hasattr(cdp, 'spectrum_ids') or not hasattr(cdp, 'exp_type'): return True # Set the values. for i in range(len(cdp.spectrum_ids)): # No value. if cdp.spectrum_ids[i] not in cdp.exp_type: continue # Set the value. self.element.SetStringItem(i, index, float_to_gui(cdp.exp_type[cdp.spectrum_ids[i]])) # Successful. return True
def gui_to_int_or_list(string): """Convert the GUI obtained string to a list. @param string: The list in string form. @type string: str or unicode @return: The integer or list of integers. @rtype: int or int list """ # No value. if string in ['', u(''), None]: return None # Already an int or list. if isinstance(string, int) or isinstance(string, list): return string # Convert. try: val = eval(string) # Failure, so return the original value. except NameError: return string # Return the list. return val
def add_disp_point(self, index): """Add the dispersion point info to the element. This is either the CPMG pulse frequency or the spin-lock field strength. Both share the same column. @param index: The column index for the data. @type index: int @return: True if the data exists, False otherwise. @rtype: bool """ # Append a column. self.element.InsertColumn(index, u("\u03BDCPMG (Hz) or Spin-lock \u03BD1 (Hz)")) # No data. if not hasattr(cdp, 'spectrum_ids'): return True # Set the values. for i in range(len(cdp.spectrum_ids)): # Set the CPMG frequency. if hasattr(cdp, 'cpmg_frqs') and cdp.spectrum_ids[i] in cdp.cpmg_frqs: self.element.SetStringItem(i, index, float_to_gui(cdp.cpmg_frqs[cdp.spectrum_ids[i]])) # Set the spin-lock field strength. if hasattr(cdp, 'spin_lock_nu1') and cdp.spectrum_ids[i] in cdp.spin_lock_nu1: self.element.SetStringItem(i, index, float_to_gui(cdp.spin_lock_nu1[cdp.spectrum_ids[i]])) # Successful. return True
def add_exp_type(self, index): """Add the experiment type info to the element. @param index: The column index for the data. @type index: int @return: True if the data exists, False otherwise. @rtype: bool """ # Append a column. self.element.InsertColumn(index, u("Experiment type")) # No data. if not hasattr(cdp, 'spectrum_ids') or not hasattr(cdp, 'exp_type'): return True # Set the values. for i in range(len(cdp.spectrum_ids)): # No value. if cdp.spectrum_ids[i] not in cdp.exp_type: continue # Set the value. if dep_check.wx_classic: self.element.SetStringItem( i, index, float_to_gui(cdp.exp_type[cdp.spectrum_ids[i]])) else: self.element.SetItem( i, index, float_to_gui(cdp.exp_type[cdp.spectrum_ids[i]])) # Successful. return True
def add_frqs(self, index): """Add the spectrometer frequency info to the element. @param index: The column index for the data. @type index: int @return: True if the frequency data exists, False otherwise. @rtype: bool """ # Append a column. self.element.InsertColumn(index, u("\u03C9H (MHz)")) # No data. if not hasattr(cdp, 'spectrum_ids'): return True if not hasattr(cdp, 'spectrometer_frq') or not len( cdp.spectrometer_frq): return True # Set the values. for i in range(len(cdp.spectrum_ids)): # No value. if cdp.spectrum_ids[i] not in cdp.spectrometer_frq: continue # Set the value (in MHz). self.element.SetStringItem( i, index, float_to_gui(cdp.spectrometer_frq[cdp.spectrum_ids[i]] / 1e6)) # Successful. return True
def gui_to_float(string): """Convert the GUI obtained string to an float. @param string: The number in string form. @type string: str or unicode @return: The float @rtype: float or None """ # No input. if string in ['', u(''), None]: return None # Already a float. if isinstance(string, float): return string # Convert. val = eval(string) # An int. if isinstance(val, int): val = float(val) # Not a float! if not isinstance(val, float): return string # A float. return val
def add_offset(self, index): """Add the offset info to the element. @param index: The column index for the data. @type index: int @return: True if the data exists, False otherwise. @rtype: bool """ # Append a column. self.element.InsertColumn(index, u("Offset \u03C9_rf (ppm)")) # No data. if not hasattr(cdp, 'spectrum_ids'): return True # Set the values. for i in range(len(cdp.spectrum_ids)): if hasattr(cdp, 'spin_lock_offset' ) and cdp.spectrum_ids[i] in cdp.spin_lock_offset: if dep_check.wx_classic: self.element.SetStringItem( i, index, float_to_gui( cdp.spin_lock_offset[cdp.spectrum_ids[i]])) else: self.element.SetItem( i, index, float_to_gui( cdp.spin_lock_offset[cdp.spectrum_ids[i]])) # Successful. return True
def gui_to_int(string): """Convert the GUI obtained string to an int. @param string: The number in string form. @type string: str or unicode @return: The integer @rtype: int or None """ # No input. if string in ['', u(''), None]: return None # Already an int. if isinstance(string, int): return string # Convert. try: val = eval(string) except: val = None # Not an int! if not isinstance(val, int): return string # An int. return val
def add_frqs(self, index): """Add the spectrometer frequency info to the element. @param index: The column index for the data. @type index: int @return: True if the frequency data exists, False otherwise. @rtype: bool """ # Append a column. self.element.InsertColumn(index, u("\u03C9H (MHz)")) # No data. if not hasattr(cdp, 'spectrum_ids'): return True if not hasattr(cdp, 'spectrometer_frq') or not len(cdp.spectrometer_frq): return True # Set the values. for i in range(len(cdp.spectrum_ids)): # No value. if cdp.spectrum_ids[i] not in cdp.spectrometer_frq: continue # Set the value (in MHz). self.element.SetStringItem(i, index, float_to_gui(cdp.spectrometer_frq[cdp.spectrum_ids[i]]/1e6)) # Successful. return True
def gui_to_bool(string): """Convert the GUI obtained string to a bool. @param string: The bool in string form. @type string: str or unicode @return: The bool. @rtype: bool """ # No value. if string in ['', u(''), None]: return None # Convert. return eval(string)
def gui_to_str(string): """Convert the GUI obtained string to a string. @param string: The number in string form. @type string: str or unicode @return: The string. @rtype: str """ # No value. if string in ['', u(''), None]: return None # Convert. return str(string)
def add_disp_point(self, index): """Add the dispersion point info to the element. This is either the CPMG pulse frequency or the spin-lock field strength. Both share the same column. @param index: The column index for the data. @type index: int @return: True if the data exists, False otherwise. @rtype: bool """ # Append a column. self.element.InsertColumn( index, u("\u03BDCPMG (Hz) or Spin-lock \u03BD1 (Hz)")) # No data. if not hasattr(cdp, 'spectrum_ids'): return True # Set the values. for i in range(len(cdp.spectrum_ids)): # Set the CPMG frequency. if hasattr(cdp, 'cpmg_frqs') and cdp.spectrum_ids[i] in cdp.cpmg_frqs: if dep_check.wx_classic: self.element.SetStringItem( i, index, float_to_gui(cdp.cpmg_frqs[cdp.spectrum_ids[i]])) else: self.element.SetItem( i, index, float_to_gui(cdp.cpmg_frqs[cdp.spectrum_ids[i]])) # Set the spin-lock field strength. if hasattr(cdp, 'spin_lock_nu1' ) and cdp.spectrum_ids[i] in cdp.spin_lock_nu1: if dep_check.wx_classic: self.element.SetStringItem( i, index, float_to_gui(cdp.spin_lock_nu1[cdp.spectrum_ids[i]])) else: self.element.SetItem( i, index, float_to_gui(cdp.spin_lock_nu1[cdp.spectrum_ids[i]])) # Successful. return True
def gui_to_list(string): """Convert the GUI obtained string to a list. @param string: The list in string form. @type string: str or unicode @return: The list. @rtype: list """ # No value. if string in ['', u(''), None]: return [] # Convert. val = eval(string) if not isinstance(val, list): val = [val] # Return the list. return val
def gui_to_tuple(string): """Convert the GUI obtained string to a tuple. @param string: The list in string form. @type string: str or unicode @return: The list. @rtype: list """ # No value. if string in ['', u(''), None]: return () # Convert. val = eval(string) if isinstance(val, list): val = tuple(val) elif not isinstance(val, tuple): val = (val,) # Return the list. return val
def gui_to_py(string): """Super function for converting the GUI string to a Python object. @param string: The Python object in string form. @type string: str or unicode @return: The value. @rtype: python object """ # No value. if string in ['', u(''), None]: return None # Use an eval call to create a standard object. try: value = eval(string) # A string or sequence of strings. except: value = str(string) # Return the python type. return value
def gui_to_str_or_list(string): """Convert the GUI obtained string to a list. @param string: The list in string form. @type string: str or unicode @return: The integer or list of integers. @rtype: int or int list """ # No value. if string in ['', u(''), None]: return None # Try converting to a list. try: val = eval(string) # Catch failures, and try as a string. except NameError: return str(string) # Return the list. return val
def add_offset(self, index): """Add the offset info to the element. @param index: The column index for the data. @type index: int @return: True if the data exists, False otherwise. @rtype: bool """ # Append a column. self.element.InsertColumn(index, u("Offset \u03C9_rf (ppm)")) # No data. if not hasattr(cdp, 'spectrum_ids'): return True # Set the values. for i in range(len(cdp.spectrum_ids)): if hasattr(cdp, 'spin_lock_offset') and cdp.spectrum_ids[i] in cdp.spin_lock_offset: self.element.SetStringItem(i, index, float_to_gui(cdp.spin_lock_offset[cdp.spectrum_ids[i]])) # Successful. return True
Some of these text elements are operating system dependent due to the incompleteness of the unicode fonts on certain systems. """ # relax module imports. from lib.compat import SYSTEM, u # OS Flags. win = False mac = False if SYSTEM == 'Windows': win = True if SYSTEM == 'Darwin': mac = True # Relaxation data GUI text elements. r1 = u("R\u2081") r2 = u("R\u2082") rx = u("R\u2093") iinf = u("I\u221E") if win: r1 = "R1" r2 = "R2" rx = "Rx" iinf = "Iinf" # Model-free GUI text elements. s2 = u("S\u00B2") s2f = u("S\u00B2f") s2s = u("S\u00B2s") local_tm = u("local \u03C4\u2098") tm = u("\u03C4\u2098")
def generate_popup_menu(self, id=None): """Create the popup menu. @keyword id: The spectrum ID string for the row that was clicked on. @type id: str @return: The popup menu. @rtype: list of dict of wxID, str, str, method """ # The right click popup menu. popup_menus = [ { 'id': MENU_SPECTRUM_BASEPLANE_RMSD, 'text': "Set the &baseplane RMSD", 'icon': fetch_icon(uf_info.get_uf('spectrum.baseplane_rmsd').gui_icon), 'method': self.action_spectrum_baseplane_rmsd }, { 'id': MENU_SPECTRUM_DELETE, 'text': "&Delete the peak intensities", 'icon': fetch_icon(uf_info.get_uf('spectrum.delete').gui_icon), 'method': self.action_spectrum_delete }, { 'id': MENU_SPECTRUM_INTEGRATION_POINTS, 'text': "Set the number of integration &points", 'icon': fetch_icon(uf_info.get_uf('spectrum.integration_points').gui_icon), 'method': self.action_spectrum_integration_points }, { 'id': MENU_SPECTRUM_REPLICATED, 'text': "Specify which spectra are &replicated", 'icon': fetch_icon(uf_info.get_uf('spectrum.replicated').gui_icon), 'method': self.action_spectrum_replicated } ] if self.relax_disp_flag: popup_menus.append({ 'id': MENU_RELAX_DISP_EXP_TYPE, 'text': "Set the &experiment type", 'icon': None, 'method': self.action_relax_disp_exp_type }) if self.relax_fit_flag: popup_menus.append({ 'id': MENU_RELAX_FIT_RELAX_TIME, 'text': "Set the relaxation &time", 'icon': fetch_icon(uf_info.get_uf('relax_fit.relax_time').gui_icon), 'method': self.action_relax_fit_relax_time }) if self.relax_disp_flag: popup_menus.append({ 'id': MENU_RELAX_DISP_RELAX_TIME, 'text': "Set the relaxation &time", 'icon': fetch_icon(uf_info.get_uf('relax_disp.relax_time').gui_icon), 'method': self.action_relax_disp_relax_time }) popup_menus.append({ 'id': MENU_SPECTROMETER_FRQ, 'text': "Set the spectrometer &frequency", 'icon': fetch_icon("relax.spectrometer"), 'method': self.action_spectrometer_frq }) if self.relax_disp_flag and is_r1rho_exp_type(id): popup_menus.append({ 'id': MENU_RELAX_DISP_SPIN_LOCK_FIELD, 'text': u("Set the spin-&lock field strength \u03BD1"), 'icon': fetch_icon("relax.relax_disp"), 'method': self.action_relax_disp_spin_lock_field }) popup_menus.append({ 'id': MENU_RELAX_DISP_SPIN_LOCK_OFFSET, 'text': u("Set the spin-&lock offset \u03C9_rf"), 'icon': fetch_icon("relax.relax_disp"), 'method': self.action_relax_disp_spin_lock_offset }) if self.relax_disp_flag and is_cpmg_exp_type(id): popup_menus.append({ 'id': MENU_RELAX_DISP_CPMG_SETUP, 'text': u("Set the &CPMG pulse sequence information"), 'icon': fetch_icon("relax.relax_disp"), 'method': self.action_relax_disp_cpmg_setup }) # Return the menu. return popup_menus
def generate_popup_menu(self, id=None): """Create the popup menu. @keyword id: The spectrum ID string for the row that was clicked on. @type id: str @return: The popup menu. @rtype: list of dict of wxID, str, str, method """ # The right click popup menu. popup_menus = [{ 'id': MENU_SPECTRUM_BASEPLANE_RMSD, 'text': "Set the &baseplane RMSD", 'icon': fetch_icon(uf_info.get_uf('spectrum.baseplane_rmsd').gui_icon), 'method': self.action_spectrum_baseplane_rmsd }, { 'id': MENU_SPECTRUM_DELETE, 'text': "&Delete the peak intensities", 'icon': fetch_icon(uf_info.get_uf('spectrum.delete').gui_icon), 'method': self.action_spectrum_delete }, { 'id': MENU_SPECTRUM_INTEGRATION_POINTS, 'text': "Set the number of integration &points", 'icon': fetch_icon(uf_info.get_uf('spectrum.integration_points').gui_icon), 'method': self.action_spectrum_integration_points }, { 'id': MENU_SPECTRUM_REPLICATED, 'text': "Specify which spectra are &replicated", 'icon': fetch_icon(uf_info.get_uf('spectrum.replicated').gui_icon), 'method': self.action_spectrum_replicated }] if self.relax_disp_flag: popup_menus.append({ 'id': MENU_RELAX_DISP_EXP_TYPE, 'text': "Set the &experiment type", 'icon': None, 'method': self.action_relax_disp_exp_type }) if self.relax_fit_flag: popup_menus.append({ 'id': MENU_RELAX_FIT_RELAX_TIME, 'text': "Set the relaxation &time", 'icon': fetch_icon(uf_info.get_uf('relax_fit.relax_time').gui_icon), 'method': self.action_relax_fit_relax_time }) if self.relax_disp_flag: popup_menus.append({ 'id': MENU_RELAX_DISP_RELAX_TIME, 'text': "Set the relaxation &time", 'icon': fetch_icon(uf_info.get_uf('relax_disp.relax_time').gui_icon), 'method': self.action_relax_disp_relax_time }) popup_menus.append({ 'id': MENU_SPECTROMETER_FRQ, 'text': "Set the spectrometer &frequency", 'icon': fetch_icon("relax.spectrometer"), 'method': self.action_spectrometer_frq }) if self.relax_disp_flag and is_r1rho_exp_type(id): popup_menus.append({ 'id': MENU_RELAX_DISP_SPIN_LOCK_FIELD, 'text': u("Set the spin-&lock field strength \u03BD1"), 'icon': fetch_icon("relax.relax_disp"), 'method': self.action_relax_disp_spin_lock_field }) popup_menus.append({ 'id': MENU_RELAX_DISP_SPIN_LOCK_OFFSET, 'text': u("Set the spin-&lock offset \u03C9_rf"), 'icon': fetch_icon("relax.relax_disp"), 'method': self.action_relax_disp_spin_lock_offset }) if self.relax_disp_flag and is_cpmg_exp_type(id): popup_menus.append({ 'id': MENU_RELAX_DISP_CPMG_SETUP, 'text': u("Set the &CPMG pulse sequence information"), 'icon': fetch_icon("relax.relax_disp"), 'method': self.action_relax_disp_cpmg_setup }) # Return the menu. return popup_menus