def SetValue(self, values): """Set up the list of lists values. @param values: The list of lists of values to add to the list. @type values: list of lists of str or None """ # No value. if values == None: return # Convert to a list of lists if needed. if is_list_of_lists(values): pass elif is_list(values): values = [values] # Not a list of lists. if not is_list_of_lists(values): return # Incorrect dimensions. if self.dim[0] != None and len(values) != self.dim[0]: return # Loop over the entries. for i in range(len(values)): # Incorrect dimensions. if self.dim[1] != None and len(values[i]) != self.dim[1]: continue # Append a row for variable dimension sequences (the first element already exists). if self.variable_length and i != 0: if dep_check.wx_classic: self.sequence.InsertStringItem(i, int_to_gui(i + 1)) else: self.sequence.InsertItem(i, int_to_gui(i + 1)) # Loop over the values. for j in range(self.dim[1]): # Set the value. if dep_check.wx_classic: self.sequence.SetStringItem( i, j + self.offset, self.convert_to_gui(values[i][j])) else: self.sequence.SetItem(i, j + self.offset, self.convert_to_gui(values[i][j])) # Refresh. self.Refresh()
def set_vals(self): """Set the free file format widget contents to the values from the relax data store.""" # The default GUI element. if self.element_type == 'default': # The column numbers. self.spin_id_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.spin_id_col)) self.mol_name_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.mol_name_col)) self.res_num_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.res_num_col)) self.res_name_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.res_name_col)) self.spin_num_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.spin_num_col)) self.spin_name_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.spin_name_col)) if hasattr(self, 'data_col'): self.data_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.data_col)) if hasattr(self, 'error_col'): self.error_col.SetValue(int_to_gui(ds.relax_gui.free_file_format.error_col)) # The column separator. if not ds.relax_gui.free_file_format.sep: self.sep.SetValue(str_to_gui("white space")) else: self.sep.SetValue(str_to_gui(ds.relax_gui.free_file_format.sep)) # The mini GUI element. elif self.element_type == 'mini': # The string. if self.data_cols: string = self.to_string(spin_id_col=ds.relax_gui.free_file_format.spin_id_col, mol_name_col=ds.relax_gui.free_file_format.mol_name_col, res_num_col=ds.relax_gui.free_file_format.res_num_col, res_name_col=ds.relax_gui.free_file_format.res_name_col, spin_num_col=ds.relax_gui.free_file_format.spin_num_col, spin_name_col=ds.relax_gui.free_file_format.spin_name_col, data_col=ds.relax_gui.free_file_format.data_col, error_col=ds.relax_gui.free_file_format.error_col, sep=ds.relax_gui.free_file_format.sep) else: string = self.to_string(spin_id_col=ds.relax_gui.free_file_format.spin_id_col, mol_name_col=ds.relax_gui.free_file_format.mol_name_col, res_num_col=ds.relax_gui.free_file_format.res_num_col, res_name_col=ds.relax_gui.free_file_format.res_name_col, spin_num_col=ds.relax_gui.free_file_format.spin_num_col, spin_name_col=ds.relax_gui.free_file_format.spin_name_col, sep=ds.relax_gui.free_file_format.sep) self.field.SetValue(str_to_gui(string))
def SetValue(self, values): """Set up the list of lists values. @param values: The list of lists of values to add to the list. @type values: list of lists of str or None """ # No value. if values == None: return # Not a list of lists. if not is_list_of_lists(values): return # Loop over the entries. for i in range(len(values)): # Append a row for variable dimension sequences (the first element already exists). if self.variable_length and i != 0: self.sequence.InsertStringItem(i, int_to_gui(i+1)) # Loop over the values. for j in range(self.dim[1]): # Set the value. self.sequence.SetStringItem(i, j+self.offset, self.convert_to_gui(values[i][j])) # Refresh. self.Refresh()
def test_value_set(self): """Test the full operation of the value.set user function GUI window.""" # Open the pipe.create user function window, set the args and execute. uf = uf_store['pipe.create'] uf._sync = True uf.create_wizard(parent=self.app.gui) uf.page.SetValue('pipe_name', str_to_gui('value.set user function test')) uf.page.SetValue('pipe_type', str_to_gui('mf')) uf.wizard._go_next(None) # Create a spin to add data to. uf = uf_store['spin.create'] uf._sync = True uf.create_wizard(parent=self.app.gui) uf.page.SetValue('res_num', int_to_gui(1)) uf.page.SetValue('res_name', str_to_gui('Gly')) uf.page.SetValue('spin_name', str_to_gui('N')) uf.wizard._go_next(None) # Open the value.set user function window. uf = uf_store['value.set'] uf._sync = True uf.create_wizard(parent=self.app.gui) uf.page.SetValue('val', float_to_gui(-0.000172)) uf.page.SetValue('param', str_to_gui('csa')) uf.wizard._go_next(None)
def test_structure_pdb_read(self): """Test the full operation of the structure.read_pdb user function GUI window.""" # Create the data pipe. self.exec_uf_pipe_create(pipe_name='PDB reading test') # Open the structure.read_pdb user function window. uf = uf_store['structure.read_pdb'] uf._sync = True uf.create_wizard(parent=self.app.gui) # The PDB file to operate on. file = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'structures' + sep + 'trunc_ubi_pcs.pdb' uf.page.SetValue('file', str_to_gui(file)) # Set the models to read. uf.page.SetValue('read_model', str_to_gui('6')) uf.page.uf_args['read_model'].selection_win_show() uf.page.uf_args['read_model'].sel_win.add_element(None) uf.page.uf_args['read_model'].sel_win.sequence.SetStringItem( 0, 1, int_to_gui(2)) uf.page.uf_args['read_model'].sel_win.sequence.SetStringItem( 1, 1, int_to_gui(4)) uf.page.uf_args['read_model'].selection_win_data() # Renumber the models. uf.page.uf_args['set_model_num'].selection_win_show() uf.page.uf_args['set_model_num'].sel_win.add_element(None) uf.page.uf_args['set_model_num'].sel_win.sequence.SetStringItem( 0, 1, int_to_gui(1)) uf.page.uf_args['set_model_num'].sel_win.sequence.SetStringItem( 1, 1, int_to_gui(3)) uf.page.uf_args['set_model_num'].selection_win_data() # GUI data checks. self.assertEqual(uf.page.uf_args['read_model'].GetValue(), [2, 4]) self.assertEqual(uf.page.uf_args['set_model_num'].GetValue(), [1, 3]) # Execute the user function. uf.wizard._go_next(None) # Check the structural data. self.assert_(hasattr(cdp, 'structure')) self.assert_(hasattr(cdp.structure, 'structural_data')) self.assertEqual(len(cdp.structure.structural_data), 2) self.assertEqual(cdp.structure.structural_data[0].num, 1) self.assertEqual(cdp.structure.structural_data[1].num, 3)
def SetValue(self, key, value): """Special method for setting the value of the GUI element corresponding to the key. @param key: The key corresponding to the desired GUI element. This can be one of ['spin_id_col', 'mol_name_col', 'res_num_col', 'res_name_col', 'spin_num_col', 'spin_name_col', 'data_col', 'error_col', 'sep']. @type key: str @param value: The value that the specific GUI element's SetValue() method expects. @type value: unknown """ # The default GUI element. if self.element_type == 'default': # Get the element. obj = getattr(self, key) # Convert the data. if key == 'sep': value = str_to_gui(value) else: value = int_to_gui(value) # Set the value. obj.SetValue(value) # The mini GUI element. elif self.element_type == 'mini': # Get the current values. settings = self.GetValue() # Replace the value. settings[key] = value # Set the values. if self.data_cols: string = self.to_string( spin_id_col=settings['spin_id_col'], mol_name_col=settings['mol_name_col'], res_num_col=settings['res_num_col'], res_name_col=settings['res_name_col'], spin_num_col=settings['spin_num_col'], spin_name_col=settings['spin_name_col'], data_col=settings['data_col'], error_col=settings['error_col'], sep=settings['sep']) else: string = self.to_string( spin_id_col=settings['spin_id_col'], mol_name_col=settings['mol_name_col'], res_num_col=settings['res_num_col'], res_name_col=settings['res_name_col'], spin_num_col=settings['spin_num_col'], spin_name_col=settings['spin_name_col'], sep=settings['sep']) self.field.SetValue(str_to_gui(string))
def add_element(self, event=None): """Append a new row to the list. @keyword event: The wx event. @type event: wx event """ # The next index. next = self.sequence.GetItemCount() # Add a new row with the index at the start. if self.variable_length: self.sequence.InsertStringItem(next, int_to_gui(next+1)) # Add a new empty row. else: self.sequence.InsertStringItem(next, str_to_gui(''))
def add_list(self, sizer): """Set up the list control. @param sizer: A sizer object. @type sizer: wx.Sizer instance """ # The control. self.sequence = Sequence_list_ctrl(self) # Set the column title. title = "%s%s" % (self.name[0].upper(), self.name[1:]) # Add the index column. if self.titles: self.sequence.InsertColumn(0, "Title") self.sequence.SetColumnWidth(0, 200) else: self.sequence.InsertColumn(0, "Number") self.sequence.SetColumnWidth(0, 70) # Add a single column, full width. self.sequence.InsertColumn(1, title) self.sequence.SetColumnWidth(1, wx.LIST_AUTOSIZE) # Add the table to the sizer. sizer.Add(self.sequence, 1, wx.ALL|wx.EXPAND, 0) # The fixed dimension sequence - add all the rows needed. if not self.variable_length: for i in range(self.dim): # Add a new row. self.add_element() # Add a title to the first column. if self.titles: self.sequence.SetStringItem(i, 0, str_to_gui(self.titles[i])) # Otherwise add numbers starting from 1. else: self.sequence.SetStringItem(i, 0, int_to_gui(i+1))
def SetValue(self, values): """Set up the list values. @param values: The list of values to add to the list. @type values: list of str or None """ # No value. if values == None: return # Invalid list, so do nothing. if not self.variable_length and is_list(values) and len(values) != self.dim: return # Single values. try: len(values) except TypeError: if self.seq_type == 'list': values = [values] elif self.seq_type == 'tuple': values = (values,) # Loop over the entries. for i in range(len(values)): # Fixed dimension sequences - set the values of the pre-created list. if not self.variable_length: self.sequence.SetStringItem(i, 1, self.convert_to_gui(values[i])) # Variable dimension sequences - append the item to the end of the blank list. else: # The first element already exists. if i != 0: # First add the index+1. self.sequence.InsertStringItem(i, int_to_gui(i+1)) # Then set the value. self.sequence.SetStringItem(i, 1, self.convert_to_gui(values[i]))
def test_value_set(self): """Test the full operation of the value.set user function GUI window.""" # Create the data pipe. self.exec_uf_pipe_create(pipe_name='value.set user function test') # Create a spin to add data to. uf = uf_store['spin.create'] uf._sync = True uf.create_wizard(parent=self.app.gui) uf.page.SetValue('res_num', int_to_gui(1)) uf.page.SetValue('res_name', str_to_gui('Gly')) uf.page.SetValue('spin_name', str_to_gui('N')) uf.wizard._go_next(None) # Open the value.set user function window. uf = uf_store['value.set'] uf._sync = True uf.create_wizard(parent=self.app.gui) uf.page.SetValue('val', float_to_gui(-0.000172)) uf.page.SetValue('param', str_to_gui('csa')) uf.wizard._go_next(None)
def SetValue(self, key, value): """Special method for setting the value of the GUI element corresponding to the key. @param key: The key corresponding to the desired GUI element. This can be one of ['spin_id_col', 'mol_name_col', 'res_num_col', 'res_name_col', 'spin_num_col', 'spin_name_col', 'data_col', 'error_col', 'sep']. @type key: str @param value: The value that the specific GUI element's SetValue() method expects. @type value: unknown """ # The default GUI element. if self.element_type == 'default': # Get the element. obj = getattr(self, key) # Convert the data. if key == 'sep': value = str_to_gui(value) else: value = int_to_gui(value) # Set the value. obj.SetValue(value) # The mini GUI element. elif self.element_type == 'mini': # Get the current values. settings = self.GetValue() # Replace the value. settings[key] = value # Set the values. if self.data_cols: string = self.to_string(spin_id_col=settings['spin_id_col'], mol_name_col=settings['mol_name_col'], res_num_col=settings['res_num_col'], res_name_col=settings['res_name_col'], spin_num_col=settings['spin_num_col'], spin_name_col=settings['spin_name_col'], data_col=settings['data_col'], error_col=settings['error_col'], sep=settings['sep']) else: string = self.to_string(spin_id_col=settings['spin_id_col'], mol_name_col=settings['mol_name_col'], res_num_col=settings['res_num_col'], res_name_col=settings['res_name_col'], spin_num_col=settings['spin_num_col'], spin_name_col=settings['spin_name_col'], sep=settings['sep']) self.field.SetValue(str_to_gui(string))
def test_structure_rotate(self): """Test the operation of the structure.rotate user function GUI window.""" # Create the data pipe. self.exec_uf_pipe_create(pipe_name='PDB rotation test') # Open the structure.read_pdb user function window. uf = uf_store['structure.read_pdb'] uf._sync = True uf.create_wizard(parent=self.app.gui) # The PDB file to operate on. file = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'structures' + sep + 'trunc_ubi_pcs.pdb' uf.page.SetValue('file', str_to_gui(file)) # Set the models to read. uf.page.SetValue('read_model', str_to_gui('6')) uf.page.uf_args['read_model'].selection_win_show() uf.page.uf_args['read_model'].sel_win.add_element(None) uf.page.uf_args['read_model'].sel_win.sequence.SetStringItem(index=0, col=1, label=int_to_gui(2)) uf.page.uf_args['read_model'].sel_win.sequence.SetStringItem(index=1, col=1, label=int_to_gui(4)) uf.page.uf_args['read_model'].selection_win_data() # Renumber the models. uf.page.uf_args['set_model_num'].selection_win_show() uf.page.uf_args['set_model_num'].sel_win.add_element(None) uf.page.uf_args['set_model_num'].sel_win.sequence.SetStringItem(index=0, col=1, label=int_to_gui(1)) uf.page.uf_args['set_model_num'].sel_win.sequence.SetStringItem(index=1, col=1, label=int_to_gui(3)) uf.page.uf_args['set_model_num'].selection_win_data() # GUI data checks. self.assertEqual(uf.page.uf_args['read_model'].GetValue(), [2, 4]) self.assertEqual(uf.page.uf_args['set_model_num'].GetValue(), [1, 3]) # Execute the user function. uf.wizard._go_next(None) # Open the structure.rotate user function window. uf = uf_store['structure.rotate'] uf._sync = True uf.create_wizard(parent=self.app.gui) # Change the rotation matrix in the Sequence_2D window, without changing anything, then check it. uf.page.uf_args['R'].selection_win_show() uf.page.uf_args['R'].sel_win.sequence.SetStringItem(index=1, col=1, label=int_to_gui(2)) uf.page.uf_args['R'].selection_win_data() R = uf.page.uf_args['R'].GetValue() print("Rotation matrix:\n%s" % R) self.assertEqual(len(R), 3) self.assertEqual(len(R[0]), 3) self.assertEqual(R[0][0], 1) self.assertEqual(R[0][1], 0) self.assertEqual(R[0][2], 0) self.assertEqual(R[1][0], 0) self.assertEqual(R[1][1], 2) self.assertEqual(R[1][2], 0) self.assertEqual(R[2][0], 0) self.assertEqual(R[2][1], 0) self.assertEqual(R[2][2], 1) # Set the rotation matrix to nothing in the wizard, open the Sequence_2D window, set a value, close the window, and check what happens. uf.page.uf_args['R'].SetValue(str_to_gui('')) uf.page.uf_args['R'].selection_win_show() uf.page.uf_args['R'].sel_win.sequence.SetStringItem(index=1, col=1, label=int_to_gui(2)) uf.page.uf_args['R'].selection_win_data() R = uf.page.uf_args['R'].GetValue() print("Rotation matrix:\n%s" % R) self.assertEqual(len(R), 3) self.assertEqual(len(R[0]), 3) self.assertEqual(R[0][0], None) self.assertEqual(R[0][1], None) self.assertEqual(R[0][2], None) self.assertEqual(R[1][0], None) self.assertEqual(R[1][1], 2) self.assertEqual(R[1][2], None) self.assertEqual(R[2][0], None) self.assertEqual(R[2][1], None) self.assertEqual(R[2][2], None) # Set the rotation matrix to nothing in the wizard, open the Sequence_2D window, close the window, and check that None comes back. uf.page.uf_args['R'].SetValue(str_to_gui('')) uf.page.uf_args['R'].selection_win_show() uf.page.uf_args['R'].selection_win_data() R = uf.page.uf_args['R'].GetValue() print("Rotation matrix:\n%s" % R) self.assertEqual(R, None) # Set the rotation matrix to a number of invalid values, checking that they are ignored. for val in ['2', 'die', '[1, 2, 3]', '[1]', '[[1, 2, 3], 1, 2, 3], [1, 2, 3]]']: uf.page.uf_args['R'].SetValue(str_to_gui(val)) uf.page.uf_args['R'].selection_win_show() uf.page.uf_args['R'].selection_win_data() R = uf.page.uf_args['R'].GetValue() print("Rotation matrix:\n%s" % R) self.assertEqual(R, None) # Set the Sequence_2D elements to invalid values. for val in ['x']: uf.page.uf_args['R'].SetValue(str_to_gui('')) uf.page.uf_args['R'].selection_win_show() uf.page.uf_args['R'].sel_win.sequence.SetStringItem(index=1, col=1, label=str_to_gui(val)) uf.page.uf_args['R'].sel_win.sequence.SetStringItem(index=0, col=0, label=int_to_gui(1)) uf.page.uf_args['R'].selection_win_data() R = uf.page.uf_args['R'].GetValue() print("Rotation matrix:\n%s" % R) self.assertEqual(len(R), 3) self.assertEqual(len(R[0]), 3) self.assertEqual(R[0][0], 1.0) self.assertEqual(R[0][1], None) self.assertEqual(R[0][2], None) self.assertEqual(R[1][0], None) self.assertEqual(R[1][1], None) self.assertEqual(R[1][2], None) self.assertEqual(R[2][0], None) self.assertEqual(R[2][1], None) self.assertEqual(R[2][2], None) # Check the structural data. self.assert_(hasattr(cdp, 'structure')) self.assert_(hasattr(cdp.structure, 'structural_data')) self.assertEqual(len(cdp.structure.structural_data), 2) self.assertEqual(cdp.structure.structural_data[0].num, 1) self.assertEqual(cdp.structure.structural_data[1].num, 3)
def test_structure_pdb_read(self): """Test the full operation of the structure.read_pdb user function GUI window.""" # Open the pipe.create user function window, set the args and execute. uf = uf_store['pipe.create'] uf._sync = True uf.create_wizard(parent=self.app.gui) uf.page.SetValue('pipe_name', str_to_gui('PDB reading test')) uf.page.SetValue('pipe_type', str_to_gui('mf')) uf.wizard._go_next(None) # Open the structure.read_pdb user function window. uf = uf_store['structure.read_pdb'] uf._sync = True uf.create_wizard(parent=self.app.gui) # The PDB file to operate on. file = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'structures' + sep + 'trunc_ubi_pcs.pdb' uf.page.SetValue('file', str_to_gui(file)) # Set the models to read. uf.page.SetValue('read_model', str_to_gui('6')) uf.page.uf_args['read_model'].selection_win_show() uf.page.uf_args['read_model'].sel_win.append_row(None) uf.page.uf_args['read_model'].sel_win.sequence.SetStringItem(index=0, col=0, label=int_to_gui(2)) uf.page.uf_args['read_model'].sel_win.sequence.SetStringItem(index=1, col=0, label=int_to_gui(4)) uf.page.uf_args['read_model'].selection_win_data() # Renumber the models. uf.page.uf_args['set_model_num'].selection_win_show() uf.page.uf_args['set_model_num'].sel_win.append_row(None) uf.page.uf_args['set_model_num'].sel_win.append_row(None) uf.page.uf_args['set_model_num'].sel_win.sequence.SetStringItem(index=0, col=0, label=int_to_gui(1)) uf.page.uf_args['set_model_num'].sel_win.sequence.SetStringItem(index=1, col=0, label=int_to_gui(3)) uf.page.uf_args['set_model_num'].selection_win_data() # GUI data checks. self.assertEqual(uf.page.uf_args['read_model'].GetValue(), [2, 4]) self.assertEqual(uf.page.uf_args['set_model_num'].GetValue(), [1, 3]) # Execute the user function. uf.wizard._go_next(None) # Check the structural data. self.assert_(hasattr(cdp, 'structure')) self.assert_(hasattr(cdp.structure, 'structural_data')) self.assertEqual(len(cdp.structure.structural_data), 2) self.assertEqual(cdp.structure.structural_data[0].num, 1) self.assertEqual(cdp.structure.structural_data[1].num, 3)
def test_structure_rotate(self): """Test the operation of the structure.rotate user function GUI window.""" # Create the data pipe. self.exec_uf_pipe_create(pipe_name='PDB rotation test') # Open the structure.read_pdb user function window. uf = uf_store['structure.read_pdb'] uf._sync = True uf.create_wizard(parent=self.app.gui) # The PDB file to operate on. file = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'structures' + sep + 'trunc_ubi_pcs.pdb' uf.page.SetValue('file', str_to_gui(file)) # Set the models to read. uf.page.SetValue('read_model', str_to_gui('6')) uf.page.uf_args['read_model'].selection_win_show() uf.page.uf_args['read_model'].sel_win.add_element(None) if dep_check.wx_classic: uf.page.uf_args['read_model'].sel_win.sequence.SetStringItem(0, 1, int_to_gui(2)) uf.page.uf_args['read_model'].sel_win.sequence.SetStringItem(1, 1, int_to_gui(4)) else: uf.page.uf_args['read_model'].sel_win.sequence.SetItem(0, 1, int_to_gui(2)) uf.page.uf_args['read_model'].sel_win.sequence.SetItem(1, 1, int_to_gui(4)) uf.page.uf_args['read_model'].selection_win_data() # Renumber the models. uf.page.uf_args['set_model_num'].selection_win_show() uf.page.uf_args['set_model_num'].sel_win.add_element(None) if dep_check.wx_classic: uf.page.uf_args['set_model_num'].sel_win.sequence.SetStringItem(0, 1, int_to_gui(1)) uf.page.uf_args['set_model_num'].sel_win.sequence.SetStringItem(1, 1, int_to_gui(3)) else: uf.page.uf_args['set_model_num'].sel_win.sequence.SetItem(0, 1, int_to_gui(1)) uf.page.uf_args['set_model_num'].sel_win.sequence.SetItem(1, 1, int_to_gui(3)) uf.page.uf_args['set_model_num'].selection_win_data() # GUI data checks. self.assertEqual(uf.page.uf_args['read_model'].GetValue(), [2, 4]) self.assertEqual(uf.page.uf_args['set_model_num'].GetValue(), [1, 3]) # Execute the user function. uf.wizard._go_next(None) # Open the structure.rotate user function window. uf = uf_store['structure.rotate'] uf._sync = True uf.create_wizard(parent=self.app.gui) # Change the rotation matrix in the Sequence_2D window, without changing anything, then check it. uf.page.uf_args['R'].selection_win_show() if dep_check.wx_classic: uf.page.uf_args['R'].sel_win.sequence.SetStringItem(1, 1, int_to_gui(2)) else: uf.page.uf_args['R'].sel_win.sequence.SetItem(1, 1, int_to_gui(2)) uf.page.uf_args['R'].selection_win_data() R = uf.page.uf_args['R'].GetValue() print("Rotation matrix:\n%s" % R) self.assertEqual(len(R), 3) self.assertEqual(len(R[0]), 3) self.assertEqual(R[0][0], 1) self.assertEqual(R[0][1], 0) self.assertEqual(R[0][2], 0) self.assertEqual(R[1][0], 0) self.assertEqual(R[1][1], 2) self.assertEqual(R[1][2], 0) self.assertEqual(R[2][0], 0) self.assertEqual(R[2][1], 0) self.assertEqual(R[2][2], 1) # Set the rotation matrix to nothing in the wizard, open the Sequence_2D window, set a value, close the window, and check what happens. uf.page.uf_args['R'].SetValue(str_to_gui('')) uf.page.uf_args['R'].selection_win_show() if dep_check.wx_classic: uf.page.uf_args['R'].sel_win.sequence.SetStringItem(1, 1, int_to_gui(2)) else: uf.page.uf_args['R'].sel_win.sequence.SetItem(1, 1, int_to_gui(2)) uf.page.uf_args['R'].selection_win_data() R = uf.page.uf_args['R'].GetValue() print("Rotation matrix:\n%s" % R) self.assertEqual(len(R), 3) self.assertEqual(len(R[0]), 3) self.assertEqual(R[0][0], None) self.assertEqual(R[0][1], None) self.assertEqual(R[0][2], None) self.assertEqual(R[1][0], None) self.assertEqual(R[1][1], 2) self.assertEqual(R[1][2], None) self.assertEqual(R[2][0], None) self.assertEqual(R[2][1], None) self.assertEqual(R[2][2], None) # Set the rotation matrix to nothing in the wizard, open the Sequence_2D window, close the window, and check that None comes back. uf.page.uf_args['R'].SetValue(str_to_gui('')) uf.page.uf_args['R'].selection_win_show() uf.page.uf_args['R'].selection_win_data() R = uf.page.uf_args['R'].GetValue() print("Rotation matrix:\n%s" % R) self.assertEqual(R, None) # Set the rotation matrix to a number of invalid values, checking that they are ignored. for val in ['2', 'die', '[1, 2, 3]', '[1]', '[[1, 2, 3], 1, 2, 3], [1, 2, 3]]']: uf.page.uf_args['R'].SetValue(str_to_gui(val)) uf.page.uf_args['R'].selection_win_show() uf.page.uf_args['R'].selection_win_data() R = uf.page.uf_args['R'].GetValue() print("Rotation matrix:\n%s" % R) self.assertEqual(R, None) # Set the Sequence_2D elements to invalid values. for val in ['x']: uf.page.uf_args['R'].SetValue(str_to_gui('')) uf.page.uf_args['R'].selection_win_show() if dep_check.wx_classic: uf.page.uf_args['R'].sel_win.sequence.SetStringItem(1, 1, str_to_gui(val)) uf.page.uf_args['R'].sel_win.sequence.SetStringItem(0, 0, int_to_gui(1)) else: uf.page.uf_args['R'].sel_win.sequence.SetItem(1, 1, str_to_gui(val)) uf.page.uf_args['R'].sel_win.sequence.SetItem(0, 0, int_to_gui(1)) uf.page.uf_args['R'].selection_win_data() R = uf.page.uf_args['R'].GetValue() print("Rotation matrix:\n%s" % R) self.assertEqual(len(R), 3) self.assertEqual(len(R[0]), 3) self.assertEqual(R[0][0], 1.0) self.assertEqual(R[0][1], None) self.assertEqual(R[0][2], None) self.assertEqual(R[1][0], None) self.assertEqual(R[1][1], None) self.assertEqual(R[1][2], None) self.assertEqual(R[2][0], None) self.assertEqual(R[2][1], None) self.assertEqual(R[2][2], None) # Check the structural data. self.assert_(hasattr(cdp, 'structure')) self.assert_(hasattr(cdp.structure, 'structural_data')) self.assertEqual(len(cdp.structure.structural_data), 2) self.assertEqual(cdp.structure.structural_data[0].num, 1) self.assertEqual(cdp.structure.structural_data[1].num, 3)
def test_structure_add_atom(self): """Test the operation of the structure.add_atom user function GUI window.""" # Open the structure.add_atom user function window. uf = uf_store['structure.add_atom'] uf._sync = True uf.create_wizard(parent=self.app.gui) # Set the y-value of a single pos, and check. #uf.page.uf_args['pos'].selection_win_show() #if dep_check.wx_classic: # uf.page.uf_args['pos'].sel_win.sequence.SetStringItem(1, 1, int_to_gui(2)) #else: # uf.page.uf_args['pos'].sel_win.sequence.SetItem(1, 1, int_to_gui(2)) #uf.page.uf_args['pos'].selection_win_data() #pos = uf.page.uf_args['pos'].GetValue() #print("Pos: %s" % pos) #self.assertEqual(len(pos), 3) #self.assertEqual(pos[0], None) #self.assertEqual(pos[1], 2.0) #self.assertEqual(pos[2], None) # Set the pos to nothing in the wizard, open the Sequence window, close the window, and check that None comes back. val = '' sys.stdout.write("Value: %40s; " % repr(val)) uf.page.uf_args['pos'].SetValue(str_to_gui(val)) uf.page.uf_args['pos'].selection_win_show() uf.page.uf_args['pos'].selection_win_data() pos = uf.page.uf_args['pos'].GetValue() sys.stdout.write("Return: %40s\n" % repr(pos)) self.assertEqual(pos, None) # Set a valid pos in the wizard, open and close the Sequence window (twice), and check that the pos comes back. val = '[1, 2, -3.]' sys.stdout.write("Value: %40s; " % repr(val)) uf.page.uf_args['pos'].SetValue(str_to_gui(val)) uf.page.uf_args['pos'].selection_win_show() uf.page.uf_args['pos'].selection_win_data() uf.page.uf_args['pos'].selection_win_show() uf.page.uf_args['pos'].selection_win_data() pos = uf.page.uf_args['pos'].GetValue() sys.stdout.write("Return: %40s\n" % repr(pos)) self.assertEqual(len(pos), 1) self.assertEqual(len(pos[0]), 3) self.assertEqual(pos[0][0], 1.0) self.assertEqual(pos[0][1], 2.0) self.assertEqual(pos[0][2], -3.0) # Set the pos to a number of invalid values, checking that they are ignored. for val in ['die', '[1, 2, 3', '[[1, 2, 3], 1, 2, 3], [1, 2, 3]]']: sys.stdout.write("Value: %40s; " % repr(val)) uf.page.uf_args['pos'].SetValue(str_to_gui(val)) uf.page.uf_args['pos'].selection_win_show() uf.page.uf_args['pos'].selection_win_data() pos = uf.page.uf_args['pos'].GetValue() sys.stdout.write("Return: %40s\n" % repr(pos)) self.assertEqual(pos, None) # Set the Sequence elements to invalid values. for val in ['x']: sys.stdout.write("Value: %40s; " % repr(val)) uf.page.uf_args['pos'].SetValue(str_to_gui('')) uf.page.uf_args['pos'].selection_win_show() uf.page.uf_args['pos'].sel_win.add_element() if dep_check.wx_classic: uf.page.uf_args['pos'].sel_win.sequence.SetStringItem(1, 1, str_to_gui(val)) uf.page.uf_args['pos'].sel_win.sequence.SetStringItem(0, 1, int_to_gui(1)) else: uf.page.uf_args['pos'].sel_win.sequence.SetItem(1, 1, str_to_gui(val)) uf.page.uf_args['pos'].sel_win.sequence.SetItem(0, 1, int_to_gui(1)) uf.page.uf_args['pos'].selection_win_data() pos = uf.page.uf_args['pos'].GetValue() sys.stdout.write("Return: %40s\n" % repr(pos)) #self.assertEqual(len(pos), 1) self.assertEqual(pos[0][0], 1.0)
def test_dx_map(self): """Test the operation of the dx.map user function GUI window.""" # Open the dx.map user function window. uf = uf_store['dx.map'] uf._sync = True uf.create_wizard(parent=self.app.gui) # Set the y-value of a single point, and check. uf.page.uf_args['point'].selection_win_show() if dep_check.wx_classic: uf.page.uf_args['point'].sel_win.sequence.SetStringItem(0, 2, int_to_gui(2)) else: uf.page.uf_args['point'].sel_win.sequence.SetItem(0, 2, int_to_gui(2)) uf.page.uf_args['point'].selection_win_data() points = uf.page.uf_args['point'].GetValue() print("Points: %s" % points) self.assertEqual(len(points), 1) self.assertEqual(len(points[0]), 3) self.assertEqual(points[0][0], None) self.assertEqual(points[0][1], 2.0) self.assertEqual(points[0][2], None) # Set the point to nothing in the wizard, open the Sequence_2D window, close the window, and check that None comes back. uf.page.uf_args['point'].SetValue(str_to_gui('')) uf.page.uf_args['point'].selection_win_show() uf.page.uf_args['point'].selection_win_data() points = uf.page.uf_args['point'].GetValue() print("Points: %s" % points) self.assertEqual(points, None) # Set a valid point in the wizard, open and close the Sequence_2D window (twice), and check that the point comes back. uf.page.uf_args['point'].SetValue(str_to_gui('[[1, 2, -3.]]')) uf.page.uf_args['point'].selection_win_show() uf.page.uf_args['point'].selection_win_data() uf.page.uf_args['point'].selection_win_show() uf.page.uf_args['point'].selection_win_data() points = uf.page.uf_args['point'].GetValue() print("Points: %s" % points) self.assertEqual(len(points), 1) self.assertEqual(len(points[0]), 3) self.assertEqual(points[0][0], 1.0) self.assertEqual(points[0][1], 2.0) self.assertEqual(points[0][2], -3.0) # Set 2 valid points in the wizard, open and close the Sequence_2D window (twice), and check that the points come back. uf.page.uf_args['point'].SetValue(str_to_gui('[[1, 2, 3], [-2, -3, -4]]')) uf.page.uf_args['point'].selection_win_show() uf.page.uf_args['point'].selection_win_data() uf.page.uf_args['point'].selection_win_show() uf.page.uf_args['point'].selection_win_data() points = uf.page.uf_args['point'].GetValue() print("Points: %s" % points) self.assertEqual(len(points), 2) self.assertEqual(len(points[0]), 3) self.assertEqual(len(points[1]), 3) self.assertEqual(points[0][0], 1.0) self.assertEqual(points[0][1], 2.0) self.assertEqual(points[0][2], 3.0) self.assertEqual(points[1][0], -2.0) self.assertEqual(points[1][1], -3.0) self.assertEqual(points[1][2], -4.0) # Set the points to a number of invalid values, checking that they are ignored. for val in ['2', 'die', '[1, 2, 3', '[1]', '[[1, 2, 3], 1, 2, 3], [1, 2, 3]]']: uf.page.uf_args['point'].SetValue(str_to_gui(val)) uf.page.uf_args['point'].selection_win_show() uf.page.uf_args['point'].selection_win_data() points = uf.page.uf_args['point'].GetValue() print("Points: %s" % points) self.assertEqual(points, None) # Set the Sequence_2D elements to invalid values. for val in ['x']: uf.page.uf_args['point'].SetValue(str_to_gui('')) uf.page.uf_args['point'].selection_win_show() if dep_check.wx_classic: uf.page.uf_args['point'].sel_win.sequence.SetStringItem(0, 2, str_to_gui(val)) uf.page.uf_args['point'].sel_win.sequence.SetStringItem(0, 1, int_to_gui(1)) else: uf.page.uf_args['point'].sel_win.sequence.SetItem(0, 2, str_to_gui(val)) uf.page.uf_args['point'].sel_win.sequence.SetItem(0, 1, int_to_gui(1)) uf.page.uf_args['point'].selection_win_data() points = uf.page.uf_args['point'].GetValue() print("Points: %s" % points) self.assertEqual(len(points), 1) self.assertEqual(len(points[0]), 3) self.assertEqual(points[0][0], 1.0) self.assertEqual(points[0][1], None) self.assertEqual(points[0][2], None)
def test_dx_map(self): """Test the operation of the dx.map user function GUI window.""" # Open the dx.map user function window. uf = uf_store['dx.map'] uf._sync = True uf.create_wizard(parent=self.app.gui) # Set the y-value of a single point, and check. uf.page.uf_args['point'].selection_win_show() uf.page.uf_args['point'].sel_win.sequence.SetStringItem(index=0, col=2, label=int_to_gui(2)) uf.page.uf_args['point'].selection_win_data() points = uf.page.uf_args['point'].GetValue() print("Points: %s" % points) self.assertEqual(len(points), 1) self.assertEqual(len(points[0]), 3) self.assertEqual(points[0][0], None) self.assertEqual(points[0][1], 2.0) self.assertEqual(points[0][2], None) # Set the point to nothing in the wizard, open the Sequence_2D window, close the window, and check that None comes back. uf.page.uf_args['point'].SetValue(str_to_gui('')) uf.page.uf_args['point'].selection_win_show() uf.page.uf_args['point'].selection_win_data() points = uf.page.uf_args['point'].GetValue() print("Points: %s" % points) self.assertEqual(points, None) # Set a valid point in the wizard, open and close the Sequence_2D window (twice), and check that the point comes back. uf.page.uf_args['point'].SetValue(str_to_gui('[[1, 2, -3.]]')) uf.page.uf_args['point'].selection_win_show() uf.page.uf_args['point'].selection_win_data() uf.page.uf_args['point'].selection_win_show() uf.page.uf_args['point'].selection_win_data() points = uf.page.uf_args['point'].GetValue() print("Points: %s" % points) self.assertEqual(len(points), 1) self.assertEqual(len(points[0]), 3) self.assertEqual(points[0][0], 1.0) self.assertEqual(points[0][1], 2.0) self.assertEqual(points[0][2], -3.0) # Set 2 valid points in the wizard, open and close the Sequence_2D window (twice), and check that the points come back. uf.page.uf_args['point'].SetValue(str_to_gui('[[1, 2, 3], [-2, -3, -4]]')) uf.page.uf_args['point'].selection_win_show() uf.page.uf_args['point'].selection_win_data() uf.page.uf_args['point'].selection_win_show() uf.page.uf_args['point'].selection_win_data() points = uf.page.uf_args['point'].GetValue() print("Points: %s" % points) self.assertEqual(len(points), 2) self.assertEqual(len(points[0]), 3) self.assertEqual(len(points[1]), 3) self.assertEqual(points[0][0], 1.0) self.assertEqual(points[0][1], 2.0) self.assertEqual(points[0][2], 3.0) self.assertEqual(points[1][0], -2.0) self.assertEqual(points[1][1], -3.0) self.assertEqual(points[1][2], -4.0) # Set the points to a number of invalid values, checking that they are ignored. for val in ['2', 'die', '[1, 2, 3]', '[1]', '[[1, 2, 3], 1, 2, 3], [1, 2, 3]]']: uf.page.uf_args['point'].SetValue(str_to_gui(val)) uf.page.uf_args['point'].selection_win_show() uf.page.uf_args['point'].selection_win_data() points = uf.page.uf_args['point'].GetValue() print("Points: %s" % points) self.assertEqual(points, None) # Set the Sequence_2D elements to invalid values. for val in ['x']: uf.page.uf_args['point'].SetValue(str_to_gui('')) uf.page.uf_args['point'].selection_win_show() uf.page.uf_args['point'].sel_win.sequence.SetStringItem(index=0, col=2, label=str_to_gui(val)) uf.page.uf_args['point'].sel_win.sequence.SetStringItem(index=0, col=1, label=int_to_gui(1)) uf.page.uf_args['point'].selection_win_data() points = uf.page.uf_args['point'].GetValue() print("Points: %s" % points) self.assertEqual(len(points), 1) self.assertEqual(len(points[0]), 3) self.assertEqual(points[0][0], 1.0) self.assertEqual(points[0][1], None) self.assertEqual(points[0][2], None)
def test_structure_add_atom(self): """Test the operation of the structure.add_atom user function GUI window.""" # Open the structure.add_atom user function window. uf = uf_store['structure.add_atom'] uf._sync = True uf.create_wizard(parent=self.app.gui) # Set the y-value of a single pos, and check. #uf.page.uf_args['pos'].selection_win_show() #uf.page.uf_args['pos'].sel_win.sequence.SetStringItem(index=1, col=1, label=int_to_gui(2)) #uf.page.uf_args['pos'].selection_win_data() #pos = uf.page.uf_args['pos'].GetValue() #print("Pos: %s" % pos) #self.assertEqual(len(pos), 3) #self.assertEqual(pos[0], None) #self.assertEqual(pos[1], 2.0) #self.assertEqual(pos[2], None) # Set the pos to nothing in the wizard, open the Sequence window, close the window, and check that None comes back. val = '' sys.stdout.write("Value: %40s; " % repr(val)) uf.page.uf_args['pos'].SetValue(str_to_gui(val)) uf.page.uf_args['pos'].selection_win_show() uf.page.uf_args['pos'].selection_win_data() pos = uf.page.uf_args['pos'].GetValue() sys.stdout.write("Return: %40s\n" % repr(pos)) self.assertEqual(pos, None) # Set a valid pos in the wizard, open and close the Sequence window (twice), and check that the pos comes back. val = '[1, 2, -3.]' sys.stdout.write("Value: %40s; " % repr(val)) uf.page.uf_args['pos'].SetValue(str_to_gui(val)) uf.page.uf_args['pos'].selection_win_show() uf.page.uf_args['pos'].selection_win_data() uf.page.uf_args['pos'].selection_win_show() uf.page.uf_args['pos'].selection_win_data() pos = uf.page.uf_args['pos'].GetValue() sys.stdout.write("Return: %40s\n" % repr(pos)) self.assertEqual(len(pos), 3) self.assertEqual(pos[0], 1.0) self.assertEqual(pos[1], 2.0) self.assertEqual(pos[2], -3.0) # Set the pos to a number of invalid values, checking that they are ignored. for val in ['die', '[1, 2, 3', '[[1, 2, 3], 1, 2, 3], [1, 2, 3]]']: sys.stdout.write("Value: %40s; " % repr(val)) uf.page.uf_args['pos'].SetValue(str_to_gui(val)) uf.page.uf_args['pos'].selection_win_show() uf.page.uf_args['pos'].selection_win_data() pos = uf.page.uf_args['pos'].GetValue() sys.stdout.write("Return: %40s\n" % repr(pos)) self.assertEqual(pos, None) # Set the Sequence elements to invalid values. for val in ['x']: sys.stdout.write("Value: %40s; " % repr(val)) uf.page.uf_args['pos'].SetValue(str_to_gui('')) uf.page.uf_args['pos'].selection_win_show() uf.page.uf_args['pos'].sel_win.add_element() uf.page.uf_args['pos'].sel_win.sequence.SetStringItem(index=1, col=1, label=str_to_gui(val)) uf.page.uf_args['pos'].sel_win.sequence.SetStringItem(index=0, col=1, label=int_to_gui(1)) uf.page.uf_args['pos'].selection_win_data() pos = uf.page.uf_args['pos'].GetValue() sys.stdout.write("Return: %40s\n" % repr(pos)) #self.assertEqual(len(pos), 3) self.assertEqual(pos[0], 1.0)