diff src/browser/sat_browser/base_menu.py @ 662:ebb602d8b3f2 frontends_multi_profiles

browser_side: replace all instances of 'str' with 'unicode'
author souliane <souliane@mailoo.org>
date Tue, 03 Mar 2015 06:51:13 +0100
parents 6d3142b782c3
children 849ffb24d5bf
line wrap: on
line diff
--- a/src/browser/sat_browser/base_menu.py	Tue Mar 03 06:24:27 2015 +0100
+++ b/src/browser/sat_browser/base_menu.py	Tue Mar 03 06:51:13 2015 +0100
@@ -36,13 +36,16 @@
 import re
 
 
+unicode = str  # FIXME: pyjamas workaround
+
+
 class MenuCmd(object):
     """Return an object with an "execute" method that can be set to a menu item callback"""
 
     def __init__(self, object_, handler=None, data=None):
         """
         @param object_ (object): a callable or a class instance
-        @param handler (str): method name if object_ is a class instance
+        @param handler (unicode): method name if object_ is a class instance
         @param data (dict): data to pass as the callback argument
         """
         if handler is None:
@@ -80,7 +83,7 @@
 
     def __init__(self, name=None, item=None, menu=None, flat_level=0):
         """
-        @param name (str): node name
+        @param name (unicode): node name
         @param item (MenuItem): associated menu item
         @param menu (GenericMenuBar): associated menu bar
         @param flat_level (int): sub-menus until that level see their items
@@ -96,9 +99,9 @@
         """Return the requested category. If create is True, path_i18n and
         types are specified, recursively create the category and its parent.
 
-        @param path (list[str]): path to the category
-        @param path_i18n (list[str]): internationalized path to the category
-        @param types (list[str]): types of the category and its parents
+        @param path (list[unicode]): path to the category
+        @param path_i18n (list[unicode]): internationalized path to the category
+        @param types (list[unicode]): types of the category and its parents
         @param create (bool): if True, create the category
         @param sub_menu (GenericMenuBar): instance to popup as the category
         sub-menu, if it is created. Otherwise keep the previous sub-menu.
@@ -122,7 +125,7 @@
         """Return all the categories of the current node, or those of the
         sub-category which is specified by target_path.
 
-        @param target_path (list[str]): path to the target node
+        @param target_path (list[unicode]): path to the target node
         @return: list[MenuNode]
         """
         assert(self.menu)  # this method applies to category nodes
@@ -135,9 +138,9 @@
     def addMenuItem(self, path, path_i18n, types, callback=None, asHTML=False):
         """Recursively add a new node, which could be a category or a leaf node.
 
-        @param path (list[str], str): path to the item
-        @param path_i18n (list[str], str): internationalized path to the item
-        @param types (list[str], str): types of the item and its parents
+        @param path (list[unicode], unicode): path to the item
+        @param path_i18n (list[unicode], unicode): internationalized path to the item
+        @param types (list[unicode], unicode): types of the item and its parents
         @param callback (MenuCmd, PluginMenuCmd or GenericMenuBar): instance to
         execute as a leaf's callback or to popup as a category sub-menu
         @param asHTML (boolean): True to display the UI item as HTML
@@ -148,9 +151,9 @@
         category = isinstance(callback, GenericMenuBar)
         assert(not leaf_node or not category)
 
-        path = [path] if isinstance(path, str) else path
-        path_i18n = [path_i18n] if isinstance(path_i18n, str) else path_i18n
-        types = [types for dummy in range(len(path_i18n))] if isinstance(types, str) else types
+        path = [path] if isinstance(path, unicode) else path
+        path_i18n = [path_i18n] if isinstance(path_i18n, unicode) else path_i18n
+        types = [types for dummy in range(len(path_i18n))] if isinstance(types, unicode) else types
 
         if category:
             return self._getOrCreateCategory(path, path_i18n, types, True, callback)
@@ -164,9 +167,9 @@
     def addCategory(self, path, path_i18n, types, menu_bar=None):
         """Recursively add a new category.
 
-        @param path (list[str], str): path to the category
-        @param path_i18n (list[str], str): internationalized path to the category
-        @param types (list[str], str): types of the category and its parents
+        @param path (list[unicode], unicode): path to the category
+        @param path_i18n (list[unicode], unicode): internationalized path to the category
+        @param types (list[unicode], unicode): types of the category and its parents
         @param menu_bar (GenericMenuBar): instance to popup as the category sub-menu.
         """
         if menu_bar:
@@ -181,7 +184,7 @@
         @param item: see MenuBar.addItem
         @param asHTML: see MenuBar.addItem
         @param popup: see MenuBar.addItem
-        @param name (str): the item node's name
+        @param name (unicode): the item node's name
         """
         if item is None:  # empty string is allowed to set a separator
             return None
@@ -212,7 +215,7 @@
             if len(path) != len(path_i18n):
                 log.error("inconsistency between menu paths")
                 continue
-            if isinstance(action_id, str):
+            if isinstance(action_id, unicode):
                 callback = PluginMenuCmd(self.menu.host, action_id, menu_data)
             elif callable(action_id):
                 callback = MenuCmd(action_id, data=menu_data)
@@ -248,9 +251,9 @@
         """Build the html to be used for displaying a category item.
 
         Inheriting classes may overwrite this method.
-        @param menu_name_i18n (str): internationalized category name
-        @param type_ (str): category type
-        @return: str
+        @param menu_name_i18n (unicode): internationalized category name
+        @param type_ (unicode): category type
+        @return: unicode
         """
         return menu_name_i18n