mailr11704 - in /branches/bieri_gui/gui_bieri: components/mol_res_spin_tree.py relax_gui.py


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

Header


Content

Posted by edward on December 06, 2010 - 14:20:
Author: bugman
Date: Mon Dec  6 14:20:17 2010
New Revision: 11704

URL: http://svn.gna.org/viewcvs/relax?rev=11704&view=rev
Log:
Built a tree view GUI element for the molecule, residue, and spin data.

This is a very basic element currently shown in a window.  The 'View->Show 
tree view' menu entry is
currently commented out.  This will be used as a basis for future expansion 
of the GUI.


Added:
    branches/bieri_gui/gui_bieri/components/mol_res_spin_tree.py
Modified:
    branches/bieri_gui/gui_bieri/relax_gui.py

Added: branches/bieri_gui/gui_bieri/components/mol_res_spin_tree.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/bieri_gui/gui_bieri/components/mol_res_spin_tree.py?rev=11704&view=auto
==============================================================================
--- branches/bieri_gui/gui_bieri/components/mol_res_spin_tree.py (added)
+++ branches/bieri_gui/gui_bieri/components/mol_res_spin_tree.py Mon Dec  6 
14:20:17 2010
@@ -1,0 +1,186 @@
+###############################################################################
+#                                                                            
 #
+# Copyright (C) 2010 Edward d'Auvergne                                       
 #
+#                                                                            
 #
+# This file is part of the program relax.                                    
 #
+#                                                                            
 #
+# relax is free software; you can redistribute it and/or modify              
 #
+# it under the terms of the GNU General Public License as published by       
 #
+# the Free Software Foundation; either version 2 of the License, or          
 #
+# (at your option) any later version.                                        
 #
+#                                                                            
 #
+# relax is distributed in the hope that it will be useful,                   
 #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of             
 #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              
 #
+# GNU General Public License for more details.                               
 #
+#                                                                            
 #
+# You should have received a copy of the GNU General Public License          
 #
+# along with relax; if not, write to the Free Software                       
 #
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
 #
+#                                                                            
 #
+###############################################################################
+
+# Module docstring.
+"""The molecule, residue, and spin tree view GUI elements."""
+
+
+# Python module imports.
+import wx
+
+# relax module imports.
+from generic_fns.pipes import get_pipe
+
+
+
+class Mol_res_spin_tree(wx.Panel):
+    """The tree view class."""
+
+    def __init__(self, parent=None, id=None):
+        """Set up the tree GUI element.
+
+        @keyword parent:    The parent GUI element that this is to be 
attached to.
+        @type parent:       wx object
+        """
+
+        # Execute the base class method.
+        wx.Panel.__init__(self, parent, id, style=wx.WANTS_CHARS)
+
+        # The tree.
+        self.tree = wx.TreeCtrl(parent=self, id=-1, pos=wx.DefaultPosition, 
size=wx.DefaultSize, style=wx.TR_DEFAULT_STYLE)
+
+        # Resize the tree element.
+        self.Bind(wx.EVT_SIZE, self._resize)
+
+        # The tree roots.
+        self.root = self.tree.AddRoot("Spin system information")
+
+        # Populate the tree.
+        self._tree_update()
+
+
+    def _resize(self, event):
+        """Resize the tree element.
+
+        @param event:   The wx event.
+        @type event:    wx event
+        """
+
+        # The panel dimensions.
+        width, height = self.GetClientSizeTuple()
+
+        # Set the tree dimensions.
+        self.tree.SetDimensions(0, 0, width, height)
+
+
+    def _tree_update(self, pipe_name=None):
+        """Update the tree view using the given data pipe."""
+
+        # The data pipe.
+        if not pipe_name:
+            pipe = cdp
+        else:
+            pipe = get_pipe(pipe_name)
+
+        # No data pipe, so do nothing.
+        if not pipe:
+            return
+
+        # The molecules.
+        for mol in pipe.mol:
+            # Append a molecule with name to the tree.
+            mol_branch = self.tree.AppendItem(self.root, "Molecule %s" % 
mol.name)
+            self.tree.SetPyData(mol_branch, None)
+
+            # The residues.
+            for res in mol.res:
+                # Append a residue with name and number to the tree.
+                res_branch = self.tree.AppendItem(mol_branch, "Residue %s 
%s" % (res.num, res.name))
+                self.tree.SetPyData(res_branch, None)
+
+                # The spins.
+                for spin in res.spin:
+                    # Append a spin with name and number to the tree.
+                    spin_branch = self.tree.AppendItem(res_branch, "Spin %s 
%s" % (spin.num, spin.name))
+                    self.tree.SetPyData(spin_branch, None)
+
+            # Expand the molecule view.
+            self.tree.Expand(mol_branch)
+
+        # Expand the root.
+        self.tree.Expand(self.root)
+
+
+
+class Tree_window(wx.Frame):
+    """A window element for the tree view."""
+
+    def __init__(self, *args, **kwds):
+        """Set up the relax prompt."""
+
+        # Store the parent object.
+        self.gui = kwds.pop('parent')
+
+        # Create GUI elements
+        kwds["style"] = wx.DEFAULT_FRAME_STYLE
+        wx.Frame.__init__(self, *args, **kwds)
+
+        # Some default values.
+        self.size_x = 500
+        self.size_y = 1000
+        self.border = 0
+
+        # Set up the window.
+        sizer = self.setup_window()
+
+        # Add the tree view panel.
+        self.tree_panel = Mol_res_spin_tree(parent=self, id=-1)
+        sizer.Add(self.tree_panel, 1, wx.EXPAND|wx.ALL, self.border)
+
+
+    def Show(self, show=True):
+        """Change the behaviour of showing the window to update the content.
+
+        @keyword show:  A flag which is True shows the window.
+        @type show:     bool
+        """
+
+        # First update.
+        self.tree_panel._tree_update()
+
+        # Then show the window using the baseclass method.
+        wx.Frame.Show(self, show)
+
+
+    def handler_close(self, event):
+        """Event handler for the close window action.
+
+        @param event:   The wx event.
+        @type event:    wx event
+        """
+
+        # Close the window.
+        self.Hide()
+
+
+    def setup_window(self):
+        """Set up the window.
+
+        @return:    The sizer object.
+        @rtype:     wx.Sizer instance
+        """
+
+        # Set the frame title.
+        self.SetTitle("The molecule, residue, and spin window")
+
+        # Use a box sizer for packing the shell.
+        sizer = wx.BoxSizer(wx.VERTICAL)
+        self.SetSizer(sizer)
+
+        # Close the window cleanly (hide so it can be reopened).
+        self.Bind(wx.EVT_CLOSE, self.handler_close)
+
+        # Set the default size of the controller.
+        self.SetSize((self.size_x, self.size_y))
+
+        # Return the sizer.
+        return sizer

Modified: branches/bieri_gui/gui_bieri/relax_gui.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/bieri_gui/gui_bieri/relax_gui.py?rev=11704&r1=11703&r2=11704&view=diff
==============================================================================
--- branches/bieri_gui/gui_bieri/relax_gui.py (original)
+++ branches/bieri_gui/gui_bieri/relax_gui.py Mon Dec  6 14:20:17 2010
@@ -52,6 +52,7 @@
 from analyses.results import Results_summary
 from analyses.results_analysis import see_results
 from base_classes import Container
+from components.mol_res_spin_tree import Tree_window
 from controller import Controller
 from filedialog import opendir, openfile, savefile
 from message import dir_message, error_message, question
@@ -126,6 +127,9 @@
         # Build the relax prompt, but don't show it.
         self.relax_prompt = Prompt(None, -1, "", parent=self)
 
+        # Build the tree view window, but don't show it.
+        self.mol_res_spin_tree = Tree_window(None, -1, "", parent=self)
+
         rx_data = ds.relax_gui.analyses[self.noe_index[0]]
         self.frame_1_statusbar = self.CreateStatusBar(3, 0)
 
@@ -287,11 +291,13 @@
         menu = wx.Menu()
         menu.AppendItem(self.build_menu_sub_item(menu, id=50, 
text="&Controller\tCtrl+Z", icon=CONTROLLER_ICON))
         menu.AppendItem(self.build_menu_sub_item(menu, id=51, text="relax 
&prompt\tCtrl+P", icon=RELAX_PROMPT_ICON))
+        #menu.AppendItem(self.build_menu_sub_item(menu, id=52, text="Spin 
&tree view\tCtrl+T"))
         menubar.Append(menu, "&View")
 
         # The 'View' actions.
         self.Bind(wx.EVT_MENU, self.show_controller,    id=50)
         self.Bind(wx.EVT_MENU, self.show_prompt,        id=51)
+        #self.Bind(wx.EVT_MENU, self.show_tree,          id=52)
 
         # The 'Molecule' menu entries.
         menu = wx.Menu()
@@ -462,6 +468,7 @@
             self.dialog_about_gui.Destroy()
             self.dialog_about_relax.Destroy()
             self.relax_prompt.Destroy()
+            self.mol_res_spin_tree.Destroy()
 
             # Destroy the main window.
             self.Destroy()
@@ -692,6 +699,17 @@
         self.relax_prompt.Show()
 
 
+    def show_tree(self, event):
+        """Display the molecule, residue, and spin tree window.
+
+        @param event:   The wx event.
+        @type event:    wx event
+        """
+
+        # Open the window.
+        self.mol_res_spin_tree.Show()
+
+
     def state_load(self, event):
         """Load the program state.
 




Related Messages


Powered by MHonArc, Updated Mon Dec 06 19:20:02 2010