本文整理汇总了Python中xdg.DesktopEntry.DesktopEntry.getExec方法的典型用法代码示例。如果您正苦于以下问题:Python DesktopEntry.getExec方法的具体用法?Python DesktopEntry.getExec怎么用?Python DesktopEntry.getExec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xdg.DesktopEntry.DesktopEntry
的用法示例。
在下文中一共展示了DesktopEntry.getExec方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __new__
# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import getExec [as 别名]
def __new__(cls, desk):
desk = DesktopEntry(str(a))
name = desk.getName()
icon = getIconPath(desk.getIcon())
exe = shlex.split(re.sub('%[fFuUdDnNickvm]', '', desk.getExec()))
launch = partial(QProcess.startDetached, exe[0], exe[1:])
return super().__new__(cls, name, icon, launch)
示例2: ShowAll
# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import getExec [as 别名]
def ShowAll(self):#elenca tutti i file nelle 4 cartelle di autostart
autolist = []
path = self.user_autostart
for file_name in os.listdir(path):
myitem = DesktopEntry(path + '/' + file_name)
#print(path + '/' + file_name)
a = DeskStruct()
a.Name = myitem.getName()
a.Exec = myitem.getExec()
a.Icon = myitem.getIcon()
a.Comment = myitem.getComment()
autolist.append(a) #lista di oggetti Deskstruct
#path=self.xdg_autostart
#autolist.append(' XDG files')
#for file_name in os.listdir(path):
# autolist.append(path+'/'+file_name)
#
#path=self.sys_autostart
#autolist.append(' Sys Files')
#for file_name in os.listdir(path):
# autolist.append(path+'/'+file_name)
#path=self.gdm_autostart
#autolist.append(' GDM files')
#for file_name in os.listdir(path):
# autolist.append(path+'/'+file_name)
return autolist
示例3: launch_desktop
# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import getExec [as 别名]
def launch_desktop(self, request, handler, desktop):
entry = DesktopEntry()
entry.parse(desktop)
exec_ = entry.getExec()
self.launch(
request, handler, '/bin/bash -c "%s"' % exec_.replace('"', '\\"')
) # Is it really necessary to call bash ?
示例4: provide
# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import getExec [as 别名]
def provide(self):
from fnmatch import fnmatch
from xdg.DesktopEntry import DesktopEntry
items = []
for app_directory in map(os.path.expanduser, self.app_directories):
for root, dirs, files in os.walk(app_directory):
for filename in files:
if fnmatch(filename, "*.desktop"):
app_entry = DesktopEntry(os.path.join(root, filename))
icon_theme = Gtk.IconTheme.get_default()
if app_entry.getNoDisplay():
continue
if app_entry.getIcon() == "":
icon = Gtk.IconTheme.load_icon(icon_theme, "image-missing", self.icon_size, 0)
elif "/" in app_entry.getIcon():
try:
unscaled_icon = GdkPixbuf.Pixbuf.new_from_file(app_entry.getIcon())
icon = unscaled_icon.scale_simple(self.icon_size, self.icon_size, GdkPixbuf.InterpType.BILINEAR)
except:
icon = Gtk.IconTheme.load_icon(icon_theme, "image-missing", self.icon_size, 0)
else:
try:
unscaled_icon = Gtk.IconTheme.load_icon(icon_theme, app_entry.getIcon(), self.icon_size, 0)
icon = unscaled_icon.scale_simple(self.icon_size, self.icon_size, GdkPixbuf.InterpType.BILINEAR)
except:
icon = Gtk.IconTheme.load_icon(icon_theme, "image-missing", self.icon_size, 0)
words = app_entry.getName().split()
# words.append(app_entry.getExec())
command = self.escape_command(app_entry.getExec())
if app_entry.getTerminal():
command = "%s '%s'" % (self.terminal_emulator_command, command)
item = {
"indexer": self,
"name": app_entry.getName(),
"description": app_entry.getComment(),
"icon": icon,
"command": command,
"words": words,
}
items.append(item)
items.sort(key=lambda i: i["name"])
return items
示例5: __init__
# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import getExec [as 别名]
def __init__(self, parent=None, **kwargs):
super(LaunchButton, self).__init__(parent)
self.setObjectName("LaunchButton")
self.launcher_size = kwargs.get("launcher_size")
self.icon_size = kwargs.get("icon_size")
self.name, self.comment, self.icon, self.command = None, None, None, None
# Load in details from a .desktop file, if there is one.
if kwargs.get("desktop_file"):
de = DesktopEntry(kwargs.get("desktop_file"))
self.name = de.getName()
self.comment = de.getComment()
self.icon = de.getIcon()
self.command = de.getExec()
# This allows for overriding the settings in DesktopEntry
self.name = kwargs.get("name", self.name)
self.comment = kwargs.get("comment", self.comment)
self.icon = kwargs.get("icon", self.icon)
self.command = kwargs.get("command", self.command)
# Create the layouts and widgets to hold the information
toplayout = QHBoxLayout()
leftlayout = QVBoxLayout()
# The button's title
title = QLabel(self.name)
title.setObjectName("LaunchButtonTitle")
leftlayout.addWidget(title)
# The button's descriptive comment
comment = QLabel(self.comment)
comment.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
comment.setWordWrap(True)
comment.setObjectName("LaunchButtonDescription")
leftlayout.addWidget(comment)
# The button's icon, if there is one
iconpane = QLabel()
icon = (self.icon and icon_anyway_you_can(self.icon, kwargs.get("aggressive_icon_search", False))) or QIcon()
pixmap = icon.pixmap(*self.icon_size)
if not pixmap.isNull():
pixmap = pixmap.scaled(*self.icon_size)
iconpane.setPixmap(pixmap)
# Add everything to layouts and layouts to the button
toplayout.addWidget(iconpane)
toplayout.addLayout(leftlayout)
self.setLayout(toplayout)
# Set the button's size from config.
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self.setMinimumSize(QSize(*self.launcher_size))
# Connect the callback
self.connect(self, SIGNAL("clicked()"), self.callback)
示例6: test_values
# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import getExec [as 别名]
def test_values(self):
entry = DesktopEntry(self.test_file)
self.assertEqual(entry.getName(), 'gedit')
self.assertEqual(entry.getGenericName(), 'Text Editor')
self.assertEqual(entry.getNoDisplay(), False)
self.assertEqual(entry.getComment(), 'Edit text files')
self.assertEqual(entry.getIcon(), 'accessories-text-editor')
self.assertEqual(entry.getHidden(), False)
self.assertEqual(entry.getOnlyShowIn(), [])
self.assertEqual(entry.getExec(), 'gedit %U')
self.assertEqual(entry.getTerminal(), False)
self.assertEqual(entry.getMimeTypes(), ['text/plain'])
self.assertEqual(entry.getCategories(), ['GNOME', 'GTK', 'Utility', 'TextEditor'])
self.assertEqual(entry.getTerminal(), False)
示例7: _populate
# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import getExec [as 别名]
def _populate(self):
for item in self.EDITORS:
if os.path.isfile(item):
args = self.EDITORS[item]
desktop_entry = DesktopEntry(item)
command = desktop_entry.getExec()
# For .desktop files with ' %U' or ' # %F'
command = command.split(" ")[0]
name = desktop_entry.getName()
icon_name = desktop_entry.getIcon()
self._add_item(icon_name, name, command, args)
if len(self.get_model()):
self.empty = False
else:
self.empty = True
示例8: __init__
# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import getExec [as 别名]
class VeraCCModule:
""" An object representing a Vera Control Center module. """
def __init__(self, module_name, module_path):
""" Initialize the object """
self.module_is_external = False
self.module_name = module_name
self.module_path = module_path
self.launcher_icon = None
self.launcher_name = None
self.launcher_comment = None
self.launcher_section = None
self.module_launcher = DesktopEntry(os.path.join(self.module_path, "%s.desktop" % self.module_name))
# Icon
self.launcher_icon = self.module_launcher.getIcon()
if not self.launcher_icon:
self.launcher_icon = "preferences-system"
#ICON_THEME.connect("changed", lambda x: self.replace_icon(icon))
# Name
self.launcher_name = self.module_launcher.getName()
# Comment
self.launcher_comment = self.module_launcher.getComment()
# Section
self.launcher_section = self.module_launcher.get("X-VeraCC-Section")
# Keywords
self.launcher_keywords = [x.lower() for x in self.module_launcher.getKeywords()]
# External?
_exec = self.module_launcher.getExec()
if _exec:
# Yeah!
self.module_is_external = True
self.module_path = _exec
示例9: on_drag_data_received
# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import getExec [as 别名]
def on_drag_data_received(self, widget, context,
x, y,
selection,
target,
timestamp,
box):
droppeduris = selection.get_uris()
# url-unquote the list, strip file:// schemes, handle .desktop-s
pathlist = []
app = None
for uri in droppeduris:
scheme, _, path, _, _ = urlsplit(uri)
if scheme != "file":
pathlist.append(uri)
else:
filename = url2pathname(path)
desktopentry = DesktopEntry()
try:
desktopentry.parse(filename)
except xdg.Exceptions.ParsingError:
pathlist.append(filename)
continue
if desktopentry.getType() == 'Link':
pathlist.append(desktopentry.getURL())
if desktopentry.getType() == 'Application':
app = desktopentry.getExec()
if app and len(droppeduris) == 1:
text = app
else:
text = str.join("", (shell_quote(path) + " " for path in pathlist))
box.terminal.feed_child(text)
return True
示例10: parseMenu
# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import getExec [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
示例11: __init__
# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import getExec [as 别名]
def __init__(self, parent=None, **kwargs):
"""Construct a LaunchButton"""
super(LaunchButton, self).__init__(parent)
self.setObjectName("LaunchButton")
self.launcher_size = kwargs.get("launcher_size")
self.icon_size = kwargs.get("icon_size")
self.name = None
self.comment = None
self.icon = None
self.command = None
self.categories = None
# Load in details from a .desktop file, if there is one.
desktop_file = kwargs.get("desktop_file")
if desktop_file:
if os.access(desktop_file, os.R_OK):
de = DesktopEntry(desktop_file)
self.name = de.getName()
self.comment = de.getComment()
self.icon = de.getIcon()
self.command = de.getExec()
self.categories = [c.lower() for c in de.getCategories()]
else:
sys.stderr.write(
"Read access denied on manually-specified "
"desktop file {}. Button may be missing data.\n"
.format(desktop_file))
# This allows for overriding the settings in DesktopEntry
self.name = kwargs.get("name", self.name)
self.comment = kwargs.get("comment", self.comment)
self.icon = kwargs.get("icon", self.icon)
self.command = kwargs.get("command", self.command)
# Create the layouts and widgets to hold the information
toplayout = QHBoxLayout()
leftlayout = QVBoxLayout()
# The button's title
title = QLabel(self.name)
title.setObjectName("LaunchButtonTitle")
leftlayout.addWidget(title)
# The button's descriptive comment
comment = QLabel(self.comment)
comment.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
comment.setWordWrap(True)
comment.setObjectName("LaunchButtonDescription")
leftlayout.addWidget(comment)
# The button's icon, if there is one
iconpane = QLabel()
icon = (
self.icon
and icon_anyway_you_can(
self.icon,
kwargs.get("aggressive_icon_search", False)
)
) or QIcon()
pixmap = icon.pixmap(*self.icon_size)
if not pixmap.isNull():
pixmap = pixmap.scaled(*self.icon_size)
iconpane.setPixmap(pixmap)
# Add everything to layouts and layouts to the button
toplayout.addWidget(iconpane)
toplayout.addLayout(leftlayout)
self.setLayout(toplayout)
# Set the button's size from config.
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self.setMinimumSize(QSize(*self.launcher_size))
# Connect the callback
self.clicked.connect(self.callback)
示例12: __init__
# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import getExec [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():
#.........这里部分代码省略.........
示例13: steam_desktop_files
# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import getExec [as 别名]
def steam_desktop_files():
'''Yields Steam-enabled .desktop files in the XDG data applications paths.'''
for filepath in xdg_desktop_files():
entry = DesktopEntry(filepath)
if entry.getExec().startswith('steam'):
yield filepath
示例14: load_data_paths
# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import getExec [as 别名]
#!/usr/bin/env python3
# Author: Juho Teperi
from xdg.BaseDirectory import load_data_paths
from xdg.DesktopEntry import DesktopEntry
from glob import glob
from re import sub
# To remove duplicates
data = {}
for d in load_data_paths("applications"):
for app in glob(d + "/*.desktop"):
desktop = DesktopEntry(app)
name = desktop.getName()
if (not desktop.getHidden() and not desktop.getNoDisplay()) and name not in data:
# Remove %u, %U, %f, %F from commands
cmd = sub(r'(?i)(%U|%F)', '', desktop.getExec()).strip()
# Android studio cmd is surrounded by ", bash won't like that
if cmd.startswith("\"") and cmd.endswith("\""):
cmd = cmd[1:-1]
data[name] = cmd
for name, cmd in data.items():
print('{}\t{}'.format(name, cmd))