コード例 #1
0
ファイル: menu.py プロジェクト: dladd/pyFormex
    def index(self,text):
        """Return the index of the specified item in the actionlist.

        If the requested item is not in the actionlist, -1 is returned.
        """
        try:
            return self.actionList().index(utils.strNorm(text))
        except ValueError:
            return -1
コード例 #2
0
    def index(self, text):
        """Return the index of the specified item in the actionlist.

        If the requested item is not in the actionlist, -1 is returned.
        """
        try:
            return self.actionList().index(utils.strNorm(text))
        except ValueError:
            return -1
コード例 #3
0
    def nextitem(self, text):
        """Returns the name of the next item.

        This can be used to replace the current item with another menu.
        If the item is the last, None is returned.
        """
        itemlist = self.actionList()
        i = itemlist.index(utils.strNorm(text))
        if i >= 0 and i < len(itemlist) - 1:
            return itemlist[i + 1]
        else:
            return None
コード例 #4
0
ファイル: menu.py プロジェクト: dladd/pyFormex
    def nextitem(self,text):
        """Returns the name of the next item.

        This can be used to replace the current item with another menu.
        If the item is the last, None is returned.
        """
        itemlist = self.actionList()
        i = itemlist.index(utils.strNorm(text))
        if i >= 0 and i < len(itemlist)-1:
            return itemlist[i+1]
        else:
            return None
コード例 #5
0
    def action(self, text):
        """Return the action with specified text.

        First, a normal action is tried. If none is found,
        a separator is tried.
        """
        if text is None:
            return None
        if text in self.actions():
            return text
        i = self.index(text)
        if i >= 0:
            return self.actions()[i]
        else:
            return self.separators.get(utils.strNorm(text), None)
コード例 #6
0
ファイル: menu.py プロジェクト: dladd/pyFormex
    def action(self,text):
        """Return the action with specified text.

        First, a normal action is tried. If none is found,
        a separator is tried.
        """
        if text is None:
            return None
        if text in self.actions():
            return text
        i = self.index(text)
        if i >= 0:
            return self.actions()[i]
        else:
            return self.separators.get(utils.strNorm(text),None)
コード例 #7
0
    def item(self, text):
        """Return the item with specified text.

        For a normal action or a separator, an action is returned.
        For a menu action, a menu is returned.
        """
        i = self.index(text)
        if i >= 0:
            a = self.actions()[i]
            m = a.menu()
            if m:
                return m
            else:
                return a
        else:
            return self.separators.get(utils.strNorm(text), None)
コード例 #8
0
ファイル: menu.py プロジェクト: dladd/pyFormex
    def item(self,text):
        """Return the item with specified text.

        For a normal action or a separator, an action is returned.
        For a menu action, a menu is returned.
        """
        i = self.index(text)
        if i >= 0:
            a = self.actions()[i]
            m = a.menu()
            if m:
                return m
            else:
                return a
        else:
            return self.separators.get(utils.strNorm(text),None)
コード例 #9
0
def createScriptMenu(parent=None,before=None):
    """Create the menu(s) with pyFormex scripts

    This creates a menu with all examples distributed with pyFormex.
    By default, this menu is put in the top menu bar with menu label 'Examples'.

    The user can add his own script directories through the configuration
    settings. In that case the 'Examples' menu and menus for all the
    configured script paths will be gathered in a top level popup menu labeled
    'Scripts'.

    The menu will be placed in the top menu bar before the specified item.
    If a menu item named 'Examples' or 'Scripts' already exists, it is
    replaced.
    """
    from odict import ODict
    scriptmenu = menu.Menu('&Scripts',parent=parent,before=before)
    scriptmenu.menuitems = ODict()
    # Create a copy to leave the cfg unchanged!
    scriptdirs = [] + GD.cfg['scriptdirs']
    # Fill in missing default locations : this enables the user
    # to keep the pyFormex installed examples in his config
    knownscriptdirs = { 'examples': GD.cfg['examplesdir'] }
    for i,item in enumerate(scriptdirs):
        if type(item[0]) is str and not item[1] and item[0].lower() in knownscriptdirs:
            scriptdirs[i] = (item[0].capitalize(),knownscriptdirs[item[0].lower()])

    for txt,dirname in scriptdirs:
        GD.debug("Loading script dir %s" % dirname)
        if os.path.exists(dirname):
            m = ScriptMenu(txt,dir=dirname,autoplay=True)
            scriptmenu.insert_menu(m)
            txt = utils.strNorm(txt)
            scriptmenu.menuitems[txt] = m

    scriptmenu.insertItems([
        ('---',None),
        (_('&Configure Script Paths'),setScriptDirs),
        (_('&Reload Script Menu'),reloadScriptMenu),
        ])
    
    return scriptmenu
コード例 #10
0
 def actionList(self):
     """Return a list with the current actions."""
     return [utils.strNorm(str(a.text())) for a in self.actions()]
コード例 #11
0
ファイル: menu.py プロジェクト: dladd/pyFormex
 def actionList(self):
     """Return a list with the current actions."""
     return [ utils.strNorm(str(a.text())) for a in self.actions() ]