mailr14127 - in /branches/gui_testing/gui: menu.py user_functions/grace.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on August 04, 2011 - 14:07:
Author: bugman
Date: Thu Aug  4 14:07:19 2011
New Revision: 14127

URL: http://svn.gna.org/viewcvs/relax?rev=14127&view=rev
Log:
Implemented the grace.write user function page and menu entry.


Modified:
    branches/gui_testing/gui/menu.py
    branches/gui_testing/gui/user_functions/grace.py

Modified: branches/gui_testing/gui/menu.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/menu.py?rev=14127&r1=14126&r2=14127&view=diff
==============================================================================
--- branches/gui_testing/gui/menu.py (original)
+++ branches/gui_testing/gui/menu.py Thu Aug  4 14:07:19 2011
@@ -174,7 +174,8 @@
             ]],
             [wx.NewId(), "&gpl",   paths.icon_16x16.gnu_head, 
self.gui.user_functions.gpl.run, []],
             [wx.NewId(), "gra&ce", paths.icon_16x16.grace, None, [
-                [wx.NewId(), "&view",   paths.icon_16x16.grace, 
self.gui.user_functions.grace.view]
+                [wx.NewId(), "&view",   paths.icon_16x16.grace, 
self.gui.user_functions.grace.view],
+                [wx.NewId(), "&write",  paths.icon_16x16.save, 
self.gui.user_functions.grace.write]
             ]],
             [wx.NewId(), "&molecule", paths.icon_16x16.molecule, None, [
                 [wx.NewId(), "&copy",   paths.icon_16x16.copy, 
self.gui.user_functions.molecule.copy],

Modified: branches/gui_testing/gui/user_functions/grace.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/user_functions/grace.py?rev=14127&r1=14126&r2=14127&view=diff
==============================================================================
--- branches/gui_testing/gui/user_functions/grace.py (original)
+++ branches/gui_testing/gui/user_functions/grace.py Thu Aug  4 14:07:19 2011
@@ -26,8 +26,13 @@
 # Python module imports.
 import wx
 
+# relax module imports.
+from relax_errors import RelaxImplementError, RelaxNoPipeError
+import specific_fns
+
 # GUI module imports.
 from base import UF_base, UF_page
+from gui.errors import gui_raise
 from gui.misc import gui_to_str, str_to_gui
 from gui.paths import WIZARD_IMAGE_PATH
 from gui.wizard import Wiz_window
@@ -59,6 +64,28 @@
         wizard.run()
 
 
+    def write(self, event, file=None):
+        """The grace.write user function.
+
+        @param event:   The wx event.
+        @type event:    wx event
+        @keyword file:  The file to start the user function with.
+        @type file:     str
+        """
+
+        # Create the wizard.
+        wizard = Wiz_window(size_x=900, size_y=700, 
title=self.get_title('grace', 'write'))
+        page = Write_page(wizard, self.gui)
+        wizard.add_page(page)
+
+        # Default file name.
+        if file:
+            page.file.SetValue(file)
+
+        # Execute the wizard.
+        wizard.run()
+
+
 
 class View_page(UF_page):
     """The grace.view() user function page."""
@@ -93,3 +120,104 @@
 
         # Open the file.
         self.gui.interpreter.grace.view(file=file, grace_exe=grace_exe)
+
+
+
+class Write_page(UF_page):
+    """The grace.write() user function page."""
+
+    # Some class variables.
+    image_path = WIZARD_IMAGE_PATH + 'grace.png'
+    uf_path = ['grace', 'write']
+
+    def add_contents(self, sizer):
+        """Add the specific GUI elements.
+
+        @param sizer:   A sizer object.
+        @type sizer:    wx.Sizer instance
+        """
+
+        # The X-axis data.
+        self.x_data_type = self.combo_box(sizer, "The X-axis data type:", 
tooltip=self.uf._doc_args_dict['x_data_type'])
+        self.update_parameters(self.x_data_type)
+
+        # The Y-axis data.
+        self.y_data_type = self.combo_box(sizer, "The Y-axis data type:", 
tooltip=self.uf._doc_args_dict['y_data_type'])
+        self.update_parameters(self.y_data_type)
+
+        # The spin ID restriction.
+        self.spin_id = self.spin_id_element(sizer, "Restrict plotting to 
certain spins:")
+
+        # The plot data.
+        self.plot_data = self.combo_box(sizer, "The plot data:", ['value', 
'error', 'sims'], tooltip=self.uf._doc_args_dict['plot_data'], read_only=True)
+        self.plot_data.SetValue('value')
+
+        # Data normalisation.
+        self.norm = self.boolean_selector(sizer, "Data normalisation flag:", 
tooltip=self.uf._doc_args_dict['norm'])
+
+        # Add a file selection.
+        self.file = self.file_selection(sizer, "The Grace file:", 
message="Grace file selection", wildcard="Grace files (*.agr)|*.agr", 
style=wx.FD_SAVE, tooltip=self.uf._doc_args_dict['file'])
+
+        # The force flag.
+        self.force = self.boolean_selector(sizer, "Force flag:", 
tooltip=self.uf._doc_args_dict['force'])
+
+
+    def on_execute(self):
+        """Execute the user function."""
+
+        # Get the values.
+        x_data_type =   gui_to_int(self.x_data_type.GetValue())
+        y_data_type =   gui_to_int(self.y_data_type.GetValue())
+        spin_id_col =   gui_to_int(self.spin_id_col.GetValue())
+        plot_data =     gui_to_int(self.plot_data.GetValue())
+        norm =          gui_to_bool(self.norm.GetValue())
+
+        # The file name.
+        file = gui_to_str(self.file.GetValue())
+        if not file:
+            return
+
+        # Force flag.
+        force = gui_to_bool(self.force.GetValue())
+
+        # Open the file.
+        self.gui.interpreter.grace.write(x_data_type=x_data_type, 
y_data_type=y_data_type, spin_id=spin_id, plot_data=plot_data, file=file, 
force=force, norm=norm)
+
+
+    def update_parameters(self, combo_box):
+        """Fill out the list of parameters and their descriptions.
+
+        @param combo_box:   The combo box element to update.
+        @type combo_box:    wx.ComboBox instance
+        """
+
+        # Check the current data pipe.
+        if cdp == None:
+            gui_raise(RelaxNoPipeError())
+
+        # Get the specific functions.
+        data_names = specific_fns.setup.get_specific_fn('data_names', 
cdp.pipe_type, raise_error=False)
+        self.data_type = specific_fns.setup.get_specific_fn('data_type', 
cdp.pipe_type, raise_error=False)
+        return_data_desc = 
specific_fns.setup.get_specific_fn('return_data_desc', cdp.pipe_type, 
raise_error=False)
+
+        # The data names, if they exist.
+        try:
+            names = data_names(set='params')
+        except RelaxImplementError:
+            gui_raise(RelaxImplementError())
+
+        # Loop over the parameters.
+        for name in (data_names(set='params') + data_names(set='generic')):
+            # Get the description.
+            desc = return_data_desc(name)
+
+            # No description.
+            if not desc:
+                text = name
+
+            # The text.
+            else:
+                text = "'%s':  %s" % (name, desc)
+
+            # Append the description.
+            combo_box.Append(str_to_gui(text), name)




Related Messages


Powered by MHonArc, Updated Thu Aug 04 14:20:01 2011