当前位置: 首页>>代码示例>>Python>>正文


Python DesktopEntry.getTryExec方法代码示例

本文整理汇总了Python中xdg.DesktopEntry.DesktopEntry.getTryExec方法的典型用法代码示例。如果您正苦于以下问题:Python DesktopEntry.getTryExec方法的具体用法?Python DesktopEntry.getTryExec怎么用?Python DesktopEntry.getTryExec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xdg.DesktopEntry.DesktopEntry的用法示例。


在下文中一共展示了DesktopEntry.getTryExec方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: addDesktopEntry

# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import getTryExec [as 别名]
def addDesktopEntry(file):
    entry=DesktopEntry()
    try:
        entry.parse(file)
    except:
        return
    if entry.getNoDisplay():
        return
    tryexec=entry.getTryExec()
    if tryexec and not os.path.exists(tryexec):
        return

    entry.setLocale("C")
    display_name=entry.getName()
    catalog.insertEntry(file, display_name, run)
开发者ID:BackupTheBerlios,项目名称:ocha-svn,代码行数:17,代码来源:fill_catalog.py

示例2: parseMenu

# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import getTryExec [as 别名]
def parseMenu(menu, menuJSON):
    for submenu in menu.Entries:
      if isinstance(submenu, Menu):
          newmenu=parseMenu(submenu, []);
          #print ("Submenu icon: "+submenu.getIcon() + " is "+theme.getIconPath(submenu.getIcon()))
          iconpath=theme.getIconPath(submenu.getIcon(), None, 'Numix-Circle')
          #iconpath=theme.getIconPath(submenu.getIcon(), 128, 'future-green')
          #iconpath=theme.getIconPath(submenu.getIcon(), 128, 'Numix-Circle')
          iconpath=give_me_png(iconpath)
          
          if iconpath==None:
              iconpath=''
          print "cat icon: "+submenu.getIcon()+" is "+iconpath
          menuJSON.append({"id": unicode(submenu).replace(" ", "_"), "name":submenu.getName(), "icon":iconpath, "children":newmenu});

      elif isinstance(submenu, MenuEntry):
          # Description at
          # http://pyxdg.readthedocs.org/en/latest/_modules/xdg/DesktopEntry.html
          newitem={}
          
          filename="/usr/share/applications/"+unicode(submenu);
          item=False
          if (os.path.isfile(filename)):
            item=DesktopEntry(filename)
          else:
            # is kde4- prexifed?
            if (unicode(submenu)[0:5]=="kde4-"):
              filename="/usr/share/applications/kde4/"+unicode(submenu)[5:];
              item=DesktopEntry(filename)
            
          #print "!!"+item;
          if item is not False:
         
            newitem["id"]=unicode(submenu).replace(" ", "_")
            newitem["name"]=item.getName()
            #newitem["icon"]=item.getIcon()
            
            newitem["comment"]=item.getComment()
            newitem["tryexec"]=item.getTryExec()
            newitem["exec"]=item.getExec()
            newitem["path"]=item.getPath()
            iconpath=theme.getIconPath(item.getIcon(), 128, 'Numix-Circle')
            #iconpath=theme.getIconPath(item.getIcon(), 128, 'future-green')
            
            #iconname=item.getIcon();    # Convert png if not exists...
            #iconpath=give_me_png(iconname);
            iconpath=give_me_png(iconpath);
            
            
            if iconpath==None:
                iconpath=''
            #print "icon: "+item.getIcon()+" is "+iconpath
            #print ("Icon: "+item.getIcon() + " is "+iconpath)
            newitem["icon"]=iconpath
            #newitem["name"]=a.getName();
            #newitem["id"]=unicode(submenu)
  
            # Only Append if it's executable
  
            #if (item.findTryExec()):
            #     menuJSON.append(newitem);
            #if newitem["name"]!="":
            menuJSON.append(newitem);
          

    return menuJSON
开发者ID:joamuran,项目名称:corellian-sidebar,代码行数:68,代码来源:genmenu2.py

示例3: __init__

# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import getTryExec [as 别名]
class AutostartFile:
    def __init__(self, path):
        self.path = path
        self.filename = os.path.basename(path)
        self.dirname = os.path.dirname(path)
        self.de = DesktopEntry(path)

    def __eq__(self, other):
        return self.filename == other.filename

    def __str__(self):
        return self.path + " : " + self.de.getName()

    def _isexecfile(self, path):
        return os.access(path, os.X_OK)

    def _findFile(self, path, search, match_func):
        # check empty path
        if not path:
            return None
        # check absolute path
        if path[0] == "/":
            if match_func(path):
                return path
            else:
                return None
        else:
            # check relative path
            for dirname in search.split(os.pathsep):
                if dirname != "":
                    candidate = os.path.join(dirname, path)
                    if match_func(candidate):
                        return candidate

    def _alert(self, mstr, info=False):
        if info:
            print("\t " + mstr)
        else:
            print("\t*" + mstr)

    def _showInEnvironment(self, envs, verbose=False):
        default = not self.de.getOnlyShowIn()
        noshow = False
        force = False
        for i in self.de.getOnlyShowIn():
            if i in envs:
                force = True
        for i in self.de.getNotShowIn():
            if i in envs:
                noshow = True

        if verbose:
            if not default and not force:
                s = ""
                for i in self.de.getOnlyShowIn():
                    if s:
                        s += ", "
                    s += i
                self._alert("Excluded by: OnlyShowIn (" + s + ")")
            if default and noshow and not force:
                s = ""
                for i in self.de.getNotShowIn():
                    if s:
                        s += ", "
                    s += i
                self._alert("Excluded by: NotShowIn (" + s + ")")
        return (default and not noshow) or force

    def _shouldRun(self, envs, verbose=False):
        if not self.de.getExec():
            if verbose:
                self._alert("Excluded by: Missing Exec field")
            return False
        if self.de.getHidden():
            if verbose:
                self._alert("Excluded by: Hidden")
            return False
        if self.de.getTryExec():
            if not self._findFile(self.de.getTryExec(), os.getenv("PATH"), self._isexecfile):
                if verbose:
                    self._alert("Excluded by: TryExec (" + self.de.getTryExec() + ")")
                return False
        if not self._showInEnvironment(envs, verbose):
            return False
        return True

    def display(self, envs):
        if self._shouldRun(envs):
            print("[*] " + self.de.getName())
        else:
            print("[ ] " + self.de.getName())
        self._alert("File: " + self.path, info=True)
        if self.de.getExec():
            self._alert("Executes: " + self.de.getExec(), info=True)
        self._shouldRun(envs, True)
        print

    def run(self, envs):
        here = os.getcwd()
        if self.de.getPath():
#.........这里部分代码省略.........
开发者ID:joshiggins,项目名称:jwmsession,代码行数:103,代码来源:autostart.py


注:本文中的xdg.DesktopEntry.DesktopEntry.getTryExec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。