mailr15962 - in /branches/uf_redesign: gui/menu.py user_functions/objects.py user_functions/pipe.py


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

Header


Content

Posted by edward on May 04, 2012 - 11:53:
Author: bugman
Date: Fri May  4 11:53:03 2012
New Revision: 15962

URL: http://svn.gna.org/viewcvs/relax?rev=15962&view=rev
Log:
The user function GUI menu item is now being auto-generated.

This will require future work to support user functions not within a user 
function class.


Modified:
    branches/uf_redesign/gui/menu.py
    branches/uf_redesign/user_functions/objects.py
    branches/uf_redesign/user_functions/pipe.py

Modified: branches/uf_redesign/gui/menu.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/uf_redesign/gui/menu.py?rev=15962&r1=15961&r2=15962&view=diff
==============================================================================
--- branches/uf_redesign/gui/menu.py (original)
+++ branches/uf_redesign/gui/menu.py Fri May  4 11:53:03 2012
@@ -25,9 +25,11 @@
 """Module for the main relax menu bar."""
 
 # Python module imports.
+from string import split
 import wx
 
 # relax module imports.
+from graphics import fetch_icon
 from status import Status; status = Status()
 from user_functions.data import Uf_info; uf_info = Uf_info()
 
@@ -252,23 +254,40 @@
         user_functions = User_functions(self.gui)
 
         # Loop over the user functions.
+        class_item = None
         for name, data in uf_info.uf_loop():
             # Split up the name.
             class_name, uf_name = split(name, '.')
 
-            # Generate a submenu.
+            # Generate a sub menu.
             if class_name not in class_list:
+                # Add the last sub menu.
+                if class_item != None:
+                    menu.AppendItem(class_item)
+
                 # Get the user function class data object.
-                data = uf_info.get_class(class_name)
+                class_data = uf_info.get_class(class_name)
 
                 # Create a unique ID.
                 class_id = wx.NewId()
 
-                # Create the submenu.
-                menu.AppendItem(build_menu_item(menu, id=class_id, 
text=data.menu_text, icon=fetch_icon(data.gui_icon)))
-
-        # Add the menu.
-        uf_menus = Uf_menus(parent=self.gui, menu=menu)
+                # Create the menu entry.
+                class_item = build_menu_item(menu, id=class_id, 
text=class_data.menu_text, icon=fetch_icon(class_data.gui_icon, size='16x16'))
+
+                # Initialise the sub menu.
+                sub_menu = wx.Menu()
+                class_item.SetSubMenu(sub_menu)
+
+                # Add the class name to the list to block further sub menu 
creation.
+                class_list.append(class_name)
+
+            # Create the user function menu entry.
+            uf_id = wx.NewId()
+            sub_menu.AppendItem(build_menu_item(sub_menu, id=uf_id, 
text=data.menu_text, icon=fetch_icon(data.gui_icon, size='16x16')))
+
+        # Add the very last sub menu.
+        if class_item != None:
+            menu.AppendItem(class_item)
 
         # Add the sub-menu.
         title = "&User functions"

Modified: branches/uf_redesign/user_functions/objects.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/uf_redesign/user_functions/objects.py?rev=15962&r1=15961&r2=15962&view=diff
==============================================================================
--- branches/uf_redesign/user_functions/objects.py (original)
+++ branches/uf_redesign/user_functions/objects.py Fri May  4 11:53:03 2012
@@ -92,6 +92,10 @@
     @type desc:             str
     @ivar prompt_examples:  The examples of how to use the prompt front end.
     @type prompt_examples:  str or None
+    @ivar menu_text:        The text to use for the GUI menu entry.
+    @type menu_text:        str
+    @ivar gui_icon:         The code for the icon to use in the GUI.
+    @type gui_icon:         str or None
     """
 
     # The list of modifiable objects (anything else will be rejected to 
prevent coding errors).
@@ -101,7 +105,9 @@
             'kargs',
             'backend',
             'desc',
-            'prompt_examples'
+            'prompt_examples',
+            'menu_text',
+            'gui_icon'
     ]
 
 
@@ -115,6 +121,8 @@
         self.backend = None
         self.desc = None
         self.prompt_examples = None
+        self.menu_text = None
+        self.gui_icon = None
 
 
     def __setattr__(self, name, value):

Modified: branches/uf_redesign/user_functions/pipe.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/uf_redesign/user_functions/pipe.py?rev=15962&r1=15961&r2=15962&view=diff
==============================================================================
--- branches/uf_redesign/user_functions/pipe.py (original)
+++ branches/uf_redesign/user_functions/pipe.py Fri May  4 11:53:03 2012
@@ -35,6 +35,7 @@
 uf_class.menu_text = "&pipe"
 uf_class.gui_icon = "relax.pipe"
 
+
 # The pipe.copy user function.
 uf = uf_info.add_uf('pipe.copy')
 uf.title = "Copy a data pipe."
@@ -55,6 +56,9 @@
 
 relax> pipe.copy(pipe_to='m2')
 """
+uf.menu_text = "&copy"
+uf.gui_icon = "oxygen.actions.list-add"
+
 
 # The pipe.create user function.
 uf = uf_info.add_uf('pipe.create')
@@ -80,6 +84,9 @@
 
 relax> pipe.create('m5', 'mf')
 """
+uf.menu_text = "crea&te"
+uf.gui_icon = "oxygen.actions.list-add-relax-blue"
+
 
 # The pipe.current user function.
 uf = uf_info.add_uf('pipe.current')
@@ -91,6 +98,8 @@
 
 relax> pipe.current()
 """
+uf.menu_text = "c&urrent"
+
 
 # The pipe.delete user function.
 uf = uf_info.add_uf('pipe.delete')
@@ -101,6 +110,9 @@
 uf.desc = """
 This will permanently remove the data pipe and all of its contents from the 
relax data store.  If the pipe name is not given, then all data pipes will be 
deleted.
 """
+uf.menu_text = "&delete"
+uf.gui_icon = "oxygen.actions.list-remove"
+
 
 # The pipe.display user function.
 uf = uf_info.add_uf('pipe.display')
@@ -112,6 +124,8 @@
 
 relax> pipe.display()
 """
+uf.menu_text = "di&splay"
+
 
 # The pipe.hybridise user function.
 uf = uf_info.add_uf('pipe.hybridise')
@@ -132,6 +146,9 @@
 relax> pipe.hybridise('mixed model', ['N_sphere', 'C_ellipsoid'])
 relax> pipe.hybridise(hybrid='mixed model', pipes=['N_sphere', 
'C_ellipsoid'])
 """
+uf.menu_text = "&hybridise"
+uf.gui_icon = "relax.pipe_hybrid"
+
 
 # The pipe.switch user function.
 uf = uf_info.add_uf('pipe.switch')
@@ -148,3 +165,5 @@
 relax> pipe.switch('ellipsoid')
 relax> pipe.switch(pipe_name='ellipsoid')
 """
+uf.menu_text = "&switch"
+uf.gui_icon = "oxygen.actions.system-switch-user"




Related Messages


Powered by MHonArc, Updated Fri May 04 13:40:02 2012