Author: bugman Date: Fri Dec 31 18:19:58 2010 New Revision: 12086 URL: http://svn.gna.org/viewcvs/relax?rev=12086&view=rev Log: Created the residue.copy user function window and menu entry. Modified: branches/bieri_gui/gui_bieri/menu.py branches/bieri_gui/gui_bieri/user_functions/residue.py Modified: branches/bieri_gui/gui_bieri/menu.py URL: http://svn.gna.org/viewcvs/relax/branches/bieri_gui/gui_bieri/menu.py?rev=12086&r1=12085&r2=12086&view=diff ============================================================================== --- branches/bieri_gui/gui_bieri/menu.py (original) +++ branches/bieri_gui/gui_bieri/menu.py Fri Dec 31 18:19:58 2010 @@ -208,7 +208,8 @@ [wx.NewId(), "&read", paths.icon_16x16.open, self.gui.user_functions.relax_data.read] ]], [wx.NewId(), "resid&ue", paths.icon_16x16.residue, None, [ - [wx.NewId(), "&create", paths.icon_16x16.add, self.gui.user_functions.residue.create], + [wx.NewId(), "©", paths.icon_16x16.copy, self.gui.user_functions.residue.copy], + [wx.NewId(), "crea&te", paths.icon_16x16.add, self.gui.user_functions.residue.create], [wx.NewId(), "&delete", paths.icon_16x16.remove, self.gui.user_functions.residue.delete] ]], [wx.NewId(), "s&cript", paths.icon_16x16.uf_script, self.gui.user_functions.script.run, []], Modified: branches/bieri_gui/gui_bieri/user_functions/residue.py URL: http://svn.gna.org/viewcvs/relax/branches/bieri_gui/gui_bieri/user_functions/residue.py?rev=12086&r1=12085&r2=12086&view=diff ============================================================================== --- branches/bieri_gui/gui_bieri/user_functions/residue.py (original) +++ branches/bieri_gui/gui_bieri/user_functions/residue.py Fri Dec 31 18:19:58 2010 @@ -29,10 +29,11 @@ # relax module imports. from generic_fns.mol_res_spin import generate_spin_id, molecule_loop, residue_loop -from generic_fns import pipes +from generic_fns.pipes import cdp_name, pipe_names # GUI module imports. from base import UF_base, UF_window +from gui_bieri.misc import gui_to_str, str_to_gui from gui_bieri.paths import WIZARD_IMAGE_PATH from gui_bieri.user_functions.mol_res_spin import Mol_res_spin @@ -40,6 +41,19 @@ # The container class. class Residue(UF_base): """The container class for holding all GUI elements.""" + + def copy(self, event): + """The residue.copy user function. + + @param event: The wx event. + @type event: wx event + """ + + # The dialog. + window = Copy_window(self.gui, self.interpreter) + window.ShowModal() + window.Destroy() + def create(self, event, mol_name=None): """The residue.create user function. @@ -96,6 +110,138 @@ +class Copy_window(UF_window, Mol_res_spin): + """The residue.copy() user function window.""" + + # Some class variables. + size_x = 700 + size_y = 600 + frame_title = 'Copy a residue' + image_path = WIZARD_IMAGE_PATH + 'residue.png' + main_text = 'This dialog allows you to copy residues.' + title = 'Residue copy' + + + def add_uf(self, sizer): + """Add the residue specific GUI elements. + + @param sizer: A sizer object. + @type sizer: wx.Sizer instance + """ + + # The source pipe. + self.pipe_from = self.combo_box(sizer, "The source data pipe:", evt_fn=self.update_mol_list) + + # The molecule selection. + self.mol_from = self.combo_box(sizer, "The source molecule:", evt_fn=self.update_res_list) + + # The molecule selection. + self.res_from = self.combo_box(sizer, "The source residue:") + + # The destination pipe. + self.pipe_to = self.combo_box(sizer, "The destination data pipe name:", evt_fn=self.update_mol_list) + + # The destination molecule name. + self.mol_to = self.combo_box(sizer, "The destination molecule name:") + + # The new residue number. + self.res_num_to = self.input_field(sizer, "The new residue number:", tooltip='If left blank, the new residue will have the same number as the old.') + + # The new residue name. + self.res_name_to = self.input_field(sizer, "The new residue name:", tooltip='If left blank, the new residue will have the same name as the old.') + + + def execute(self): + """Execute the user function.""" + + # Get the pipe names. + pipe_from = gui_to_str(self.pipe_from.GetValue()) + pipe_to = gui_to_str(self.pipe_to.GetValue()) + + # The residue names. + res_from = self._get_res_id(suffix='_from') + res_to = self._get_res_id(suffix='_to') + if res_to == '': + res_to = None + + # Copy the molecule. + self.interpreter.residue.copy(pipe_from=pipe_from, res_from=res_from, pipe_to=pipe_to, res_to=res_to) + + # Update. + self.update(None) + + + def update(self, event): + """Update the UI. + + @param event: The wx event. + @type event: wx event + """ + + # Set the default pipe name. + if not gui_to_str(self.pipe_from.GetValue()): + self.pipe_from.SetValue(str_to_gui(cdp_name())) + if not gui_to_str(self.pipe_to.GetValue()): + self.pipe_to.SetValue(str_to_gui(cdp_name())) + + # The list of pipe names. + for name in pipe_names(): + self.pipe_from.Append(name) + self.pipe_to.Append(name) + + # Update the molecule list. + self.update_mol_list() + + + def update_mol_list(self, event=None): + """Update the list of molecules. + + @param event: The wx event. + @type event: wx event + """ + + # The source data pipe. + pipe_from = gui_to_str(self.pipe_from.GetValue()) + pipe_to = gui_to_str(self.pipe_to.GetValue()) + + # Clear the previous data. + self.mol_from.Clear() + self.mol_to.Clear() + + # The list of molecule names. + for mol in molecule_loop(pipe=pipe_from): + self.mol_from.Append(str_to_gui(mol.name)) + for mol in molecule_loop(pipe=pipe_to): + self.mol_to.Append(str_to_gui(mol.name)) + + # Update the residues too. + self.update_res_list() + + + def update_res_list(self, event=None): + """Update the list of molecules. + + @param event: The wx event. + @type event: wx event + """ + + # The source data pipe and molecule name. + pipe_from = gui_to_str(self.pipe_from.GetValue()) + mol_from = generate_spin_id(mol_name=gui_to_str(self.mol_from.GetValue())) + + # Clear the previous data. + self.res_from.Clear() + + # Nothing to do. + if mol_from == '': + return + + # The list of molecule names. + for res in residue_loop(mol_from, pipe=pipe_from): + self.res_from.Append(str_to_gui("%s %s" % (res.num, res.name))) + + + class Create_window(UF_window, Mol_res_spin): """The residue.create() user function window.""" @@ -160,7 +306,7 @@ self.mol.Clear() # The list of molecule names. - if pipes.cdp_name(): + if cdp_name(): for mol in molecule_loop(): self.mol.Append(mol.name) @@ -218,6 +364,6 @@ self.res.Clear() # The list of molecule names. - if pipes.cdp_name(): + if cdp_name(): for mol in molecule_loop(): self.mol.Append(mol.name)