mailr15877 - in /1.3/gui: user_functions/bmrb.py 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 - 17:58:
Author: bugman
Date: Wed May  2 17:58:23 2012
New Revision: 15877

URL: http://svn.gna.org/viewcvs/relax?rev=15877&view=rev
Log:
Created a new wizard GUI element for lists of lists of strings.

This is similar to the list of strings GUI element, but has been extended for 
list of lists.  It is
now used by the bmrb.citation user function.


Modified:
    1.3/gui/user_functions/bmrb.py
    1.3/gui/wizard.py
    1.3/gui/wizard_elements.py

Modified: 1.3/gui/user_functions/bmrb.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/gui/user_functions/bmrb.py?rev=15877&r1=15876&r2=15877&view=diff
==============================================================================
--- 1.3/gui/user_functions/bmrb.py (original)
+++ 1.3/gui/user_functions/bmrb.py Wed May  2 17:58:23 2012
@@ -62,7 +62,7 @@
 
         # The fields.
         self.cite_id = self.input_field(sizer, "The citation ID:", 
tooltip=self.uf._doc_args_dict['cite_id'])
-        self.authors = self.element_string_list(key='authors', sizer=sizer, 
desc="The author list:", tooltip=self.uf._doc_args_dict['authors'])
+        self.authors = self.element_string_list_of_lists(key='authors', 
titles=["First name", "Last name", "First initial", "Middle initials"], 
sizer=sizer, desc="The author list:", 
tooltip=self.uf._doc_args_dict['authors'])
 
 
     def on_execute(self):

Modified: 1.3/gui/wizard.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/gui/wizard.py?rev=15877&r1=15876&r2=15877&view=diff
==============================================================================
--- 1.3/gui/wizard.py (original)
+++ 1.3/gui/wizard.py Wed May  2 17:58:23 2012
@@ -41,7 +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
+from gui.wizard_elements import String_list, String_list_of_lists
 
 
 class Wiz_page(wx.Panel):
@@ -572,6 +572,34 @@
 
         # Create the element.
         element = String_list(name=key, parent=self, sizer=sizer, desc=desc, 
tooltip=tooltip, divider=divider, padding=padding, spacer=spacer)
+
+        # Store it.
+        self._elements[key] = element
+
+
+    def element_string_list_of_lists(self, key=None, titles=None, 
sizer=None, desc=None, tooltip=None, divider=None, padding=0, spacer=None):
+        """Set up the element and store it.
+
+        @keyword key:       The dictionary key to store the element with.
+        @type key:          str
+        @keyword titles:    The titles of each of the elements of the fixed 
width second dimension.
+        @type titles:       list of str
+        @keyword sizer:     The sizer to put the input field widget into.
+        @type sizer:        wx.Sizer instance
+        @keyword 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_of_lists(name=key, titles=titles, parent=self, 
sizer=sizer, desc=desc, tooltip=tooltip, divider=divider, padding=padding, 
spacer=spacer)
 
         # Store it.
         self._elements[key] = element

Modified: 1.3/gui/wizard_elements.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/gui/wizard_elements.py?rev=15877&r1=15876&r2=15877&view=diff
==============================================================================
--- 1.3/gui/wizard_elements.py (original)
+++ 1.3/gui/wizard_elements.py Wed May  2 17:58:23 2012
@@ -25,6 +25,7 @@
 
 # Python module imports.
 from string import upper
+import sys
 import wx
 import wx.lib.mixins.listctrl
 
@@ -207,6 +208,47 @@
 
 
 
+class String_list_of_lists(List):
+    """Wizard GUI element for the input of a list of lists of strings."""
+
+    def __init__(self, name=None, titles=None, parent=None, sizer=None, 
desc=None, tooltip=None, divider=None, padding=0, spacer=None):
+        """Set up the element.
+
+        @keyword name:      The name of the element to use in titles, etc.
+        @type name:         str
+        @keyword titles:    The titles of each of the elements of the fixed 
width second dimension.
+        @type titles:       list of str
+        @keyword parent:    The wizard GUI element.
+        @type parent:       wx.Panel instance
+        @keyword sizer:     The sizer to put the input field widget into.
+        @type sizer:        wx.Sizer instance
+        @keyword 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
+        """
+
+        # Store some of the args.
+        self.titles = titles
+
+        # Initialise the base class.
+        List.__init__(self, name=name, parent=parent, sizer=sizer, 
desc=desc, tooltip=tooltip, divider=divider, padding=padding, spacer=spacer)
+
+
+    def init_window(self):
+        """Set up the specific window type."""
+
+        # Specify the window type to open.
+        return String_list_of_lists_window(name=self.name, 
titles=self.titles)
+
+
+
 class String_list_ctrl(wx.ListCtrl, wx.lib.mixins.listctrl.TextEditMixin, 
wx.lib.mixins.listctrl.ListCtrlAutoWidthMixin):
     """The string list ListCtrl object."""
 
@@ -408,3 +450,216 @@
 
         # Delete.
         self.list.DeleteAllItems()
+
+
+
+class String_list_of_lists_window(wx.Dialog):
+    """The string list of lists editor window."""
+
+    # The window size.
+    SIZE = (600, 600)
+
+    # A border.
+    BORDER = 10
+
+    # Sizes.
+    SIZE_BUTTON = (150, 33)
+
+    def __init__(self, name='', titles=None):
+        """Set up the string list editor window.
+
+        @keyword name:      The name of the window.
+        @type name:         str
+        @keyword titles:    The titles of each of the elements of the fixed 
width second dimension.
+        @type titles:       list of str
+        """
+
+        # Store the args.
+        self.name = name
+        self.titles = titles
+
+        # The number of elements.
+        self.num = len(self.titles)
+
+        # The title of the dialog.
+        title = "The list of %s" % name
+
+        # Set up the dialog.
+        wx.Dialog.__init__(self, None, id=-1, title=title)
+
+        # Initialise some values
+        self.width = self.SIZE[0] - 2*self.BORDER
+
+        # Set the frame properties.
+        self.SetSize(self.SIZE)
+        self.Centre()
+        self.SetFont(font.normal)
+
+        # The main box sizer.
+        main_sizer = wx.BoxSizer(wx.VERTICAL)
+
+        # Pack the sizer into the frame.
+        self.SetSizer(main_sizer)
+
+        # Build the central sizer, with borders.
+        sizer = add_border(main_sizer, border=self.BORDER, 
packing=wx.VERTICAL)
+
+        # Add the list control.
+        self.add_list(sizer)
+
+        # Some spacing.
+        sizer.AddSpacer(self.BORDER)
+
+        # Add the bottom buttons.
+        self.add_buttons(sizer)
+
+
+    def GetValue(self):
+        """Return the values as a list of lists of strings.
+
+        @return:    The list of lists of values.
+        @rtype:     list of lists of str
+        """
+
+        # Init.
+        values = []
+
+        # Loop over the entries.
+        for i in range(self.list.GetItemCount()):
+            # Append a new list.
+            values.append([])
+
+            # Loop over the items.
+            for j in range(self.num):
+                # The item.
+                item = self.list.GetItem(i, j)
+
+                # Append the value.
+                values[-1].append(gui_to_str(item.GetText()))
+
+        # Return the list.
+        return values
+
+
+    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
+        """
+
+        # Loop over the entries.
+        print `values`
+        for i in range(len(values)):
+            # The first value.
+            self.list.InsertStringItem(sys.maxint, str_to_gui(values[i][0]))
+
+            # Loop over the values.
+            for j in range(1, self.num):
+                # Set the value.
+                self.list.SetStringItem(i, j, str_to_gui(values[i][j]))
+
+        # Refresh.
+        self.Refresh()
+
+
+    def add_buttons(self, sizer):
+        """Add the buttons to the sizer.
+
+        @param sizer:   A sizer object.
+        @type sizer:    wx.Sizer instance
+        """
+
+        # Create a horizontal layout for the buttons.
+        button_sizer = wx.BoxSizer(wx.HORIZONTAL)
+        sizer.Add(button_sizer, 0, wx.ALIGN_CENTER|wx.ALL, 0)
+
+        # The add button.
+        button = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, "  
Add")
+        button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.add, 
wx.BITMAP_TYPE_ANY))
+        button.SetFont(font.normal)
+        button.SetToolTipString("Add a row to the list.")
+        button.SetMinSize(self.SIZE_BUTTON)
+        button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0)
+        self.Bind(wx.EVT_BUTTON, self.append_row, button)
+
+        # Spacer.
+        button_sizer.AddSpacer(20)
+
+        # The delete all button.
+        button = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, "  
Delete all")
+        button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.edit_delete, 
wx.BITMAP_TYPE_ANY))
+        button.SetFont(font.normal)
+        button.SetToolTipString("Delete all items.")
+        button.SetMinSize(self.SIZE_BUTTON)
+        button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0)
+        self.Bind(wx.EVT_BUTTON, self.delete_all, button)
+
+        # Spacer.
+        button_sizer.AddSpacer(20)
+
+        # The Ok button.
+        button = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, "  
Ok")
+        button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.dialog_ok, 
wx.BITMAP_TYPE_ANY))
+        button.SetFont(font.normal)
+        button.SetMinSize(self.SIZE_BUTTON)
+        button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0)
+        self.Bind(wx.EVT_BUTTON, self.close, button)
+
+
+    def add_list(self, sizer):
+        """Set up the list control.
+
+        @param sizer:   A sizer object.
+        @type sizer:    wx.Sizer instance
+        """
+
+        # The control.
+        self.list = String_list_ctrl(self)
+
+        # Set the column title.
+        title = "%s%s" % (upper(self.name[0]), self.name[1:])
+
+        # Add the columns.
+        for i in range(self.num):
+            self.list.InsertColumn(i, self.titles[i])
+            self.list.SetColumnWidth(i, self.width/self.num)
+
+        # Add the table to the sizer.
+        sizer.Add(self.list, 1, wx.ALL|wx.EXPAND, 0)
+
+
+    def append_row(self, event):
+        """Append a new row to the list.
+
+        @param event:   The wx event.
+        @type event:    wx event
+        """
+
+        # The next index.
+        next = self.list.GetItemCount()
+
+        # Add a new empty row.
+        self.list.InsertStringItem(next, '')
+
+
+    def close(self, event):
+        """Close the window.
+
+        @param event:   The wx event.
+        @type event:    wx event
+        """
+
+        # Destroy the window.
+        self.Destroy()
+
+
+    def delete_all(self, event):
+        """Remove all items from the list.
+
+        @param event:   The wx event.
+        @type event:    wx event
+        """
+
+        # Delete.
+        self.list.DeleteAllItems()




Related Messages


Powered by MHonArc, Updated Wed May 02 18:00:01 2012