mailr15869 - in /1.3/gui: wizard.py wizard_elements.py


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

Header


Content

Posted by edward on May 02, 2012 - 13:54:
Author: bugman
Date: Wed May  2 13:54:19 2012
New Revision: 15869

URL: http://svn.gna.org/viewcvs/relax?rev=15869&view=rev
Log:
Created a new String_list wizard GUI element class and associated 
element_string_list() method.

This special object is currently very similar to the input_field() object, 
but is set up as a class
in the gui.wizard_elements module.  The wizard page element_string_list() 
method has been added as
the interface for adding this element to a wizard page.  This method stores 
the String_list element
in the wizard page _element dictionary.


Added:
    1.3/gui/wizard_elements.py
Modified:
    1.3/gui/wizard.py

Modified: 1.3/gui/wizard.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/gui/wizard.py?rev=15869&r1=15868&r2=15869&view=diff
==============================================================================
--- 1.3/gui/wizard.py (original)
+++ 1.3/gui/wizard.py Wed May  2 13:54:19 2012
@@ -41,6 +41,7 @@
 from gui.misc import add_border, bool_to_gui, gui_to_int, gui_to_str, 
int_to_gui, open_file, protected_exec, str_to_gui
 from gui.message import Question
 from gui import paths
+from gui.wizard_elements import String_list
 
 
 class Wiz_page(wx.Panel):
@@ -548,6 +549,30 @@
 
         # Return the combo box element.
         return combo
+
+
+    def element_string_list(self, key, sizer, desc, tooltip=None, 
divider=None, padding=0, spacer=None):
+        """Set up the element and store it.
+
+        @param sizer:       The sizer to put the input field widget into.
+        @type sizer:        wx.Sizer instance
+        @param desc:        The text description.
+        @type desc:         str
+        @keyword tooltip:   The tooltip which appears on hovering over the 
text or input field.
+        @type tooltip:      str
+        @keyword divider:   The optional position of the divider.  If None, 
the class variable _div_left will be used.
+        @type divider:      None or int
+        @keyword padding:   Spacing to the left and right of the widgets.
+        @type padding:      int
+        @keyword spacer:    The amount of spacing to add below the field in 
pixels.  If None, a stretchable spacer will be used.
+        @type spacer:       None or int
+        """
+
+        # Create the element.
+        element = String_list(self, sizer, desc, tooltip=tooltip, 
divider=divider, padding=padding, spacer=spacer)
+
+        # Store it.
+        self._elements[key] = element
 
 
     def file_selection(self, sizer, desc, message='File selection', 
wildcard=wx.FileSelectorDefaultWildcardStr, style=wx.FD_DEFAULT_STYLE, 
tooltip=None, divider=None, padding=0, spacer=None, preview=True):
@@ -852,7 +877,7 @@
     def on_execute(self):
         """To be over-ridden if an action is to be performed just before 
exiting the page.
 
-        This method is called when terminating the wizard or hitting the 
apply button. 
+        This method is called when terminating the wizard or hitting the 
apply button.
         """
 
 
@@ -1446,7 +1471,7 @@
         # Return the next page.
         return self._current_page + 1
 
-        
+
     def _ok(self, event):
         """Accept the operation.
 

Added: 1.3/gui/wizard_elements.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/gui/wizard_elements.py?rev=15869&view=auto
==============================================================================
--- 1.3/gui/wizard_elements.py (added)
+++ 1.3/gui/wizard_elements.py Wed May  2 13:54:19 2012
@@ -1,0 +1,117 @@
+###############################################################################
+#                                                                            
 #
+# Copyright (C) 2012 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.
+"""Module containing a set of special GUI elements to be used in the relax 
wizards."""
+
+# Python module imports.
+import wx
+
+# relax GUI module imports.
+from gui.fonts import font
+
+
+class String_list:
+    """Wizard GUI element for the input of lists of strings."""
+
+    def __init__(self, parent, sizer, desc, tooltip=None, divider=None, 
padding=0, spacer=None):
+        """Set up the element.
+
+        @param parent:      The wizard GUI element.
+        @type parent:       wx.Panel instance
+        @param sizer:       The sizer to put the input field widget into.
+        @type sizer:        wx.Sizer instance
+        @param desc:        The text description.
+        @type desc:         str
+        @keyword tooltip:   The tooltip which appears on hovering over the 
text or input field.
+        @type tooltip:      str
+        @keyword divider:   The optional position of the divider.  If None, 
the class variable _div_left will be used.
+        @type divider:      None or int
+        @keyword padding:   Spacing to the left and right of the widgets.
+        @type padding:      int
+        @keyword spacer:    The amount of spacing to add below the field in 
pixels.  If None, a stretchable spacer will be used.
+        @type spacer:       None or int
+        """
+
+        # Init.
+        sub_sizer = wx.BoxSizer(wx.HORIZONTAL)
+
+        # Left padding.
+        sub_sizer.AddSpacer(padding)
+
+        # The description.
+        text = wx.StaticText(parent, -1, desc, style=wx.ALIGN_LEFT)
+        text.SetFont(font.normal)
+        sub_sizer.Add(text, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0)
+
+        # The divider.
+        if not divider:
+            divider = parent._div_left
+
+        # Spacing.
+        x, y = text.GetSize()
+        sub_sizer.AddSpacer((divider - x, 0))
+
+        # The input field.
+        self._field = wx.TextCtrl(parent, -1, '')
+        self._field.SetMinSize((50, parent.height_element))
+        self._field.SetFont(font.normal)
+        sub_sizer.Add(self._field, 1, 
wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0)
+
+        # Right padding.
+        sub_sizer.AddSpacer(padding)
+
+        # Add to the main sizer.
+        sizer.Add(sub_sizer, 1, wx.EXPAND|wx.ALL, 0)
+
+        # Spacing below the widget.
+        if spacer == None:
+            sizer.AddStretchSpacer()
+        else:
+            sizer.AddSpacer(spacer)
+
+        # Tooltip.
+        if tooltip:
+            text.SetToolTipString(tooltip)
+            self._field.SetToolTipString(tooltip)
+
+
+    def GetValue(self):
+        """Special method for returning the value of the GUI element.
+
+        @return:    The string list value.
+        @rtype:     list of str
+        """
+
+        # Convert and return the value.
+        return gui_to_list(self._field.GetValue())
+
+
+    def SetValue(self, value):
+        """Special method for setting the value of the GUI element.
+
+        @param value:   The value to set.
+        @type value:    list of str
+        """
+
+        # Convert and set the value.
+        self._field.SetValue(list_to_gui(value))




Related Messages


Powered by MHonArc, Updated Wed May 02 16:40:01 2012