[kupfer] objects: Treat AppLeaves created from files better
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer] objects: Treat AppLeaves created from files better
- Date: Thu, 10 Dec 2009 21:55:08 +0000 (UTC)
commit 55bd5f64cd4fd1769c1604399815f6e45cf7b43d
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Thu Dec 10 22:15:08 2009 +0100
objects: Treat AppLeaves created from files better
If we create an AppLeaf from a file (init_path=..) we have to take
care about the application's .get_id() method. File-based AppLeaves
now use the file path as ID.
This consolidates the application id methods to the new function
kupfer.launch.application_id() that takes a gio.AppInfo object as
parameter (and uses a trick: we "decorate" the objects we parse with
an extra attribute with the file's path).
We also include the path in the description so that you can
differentiate if you have many similar/equal .desktop files lying
around.
This solves an issue reported by Chmouel (I hope).
kupfer/launch.py | 16 +++++++++++-----
kupfer/objects.py | 26 ++++++++++++++++++--------
2 files changed, 29 insertions(+), 13 deletions(-)
---
diff --git a/kupfer/launch.py b/kupfer/launch.py
index 7956e49..ea11ac8 100644
--- a/kupfer/launch.py
+++ b/kupfer/launch.py
@@ -49,8 +49,14 @@ def _read_environ(pid, envcache=None):
if envcache is not None: envcache[pid] = environ
return environ
-def _app_id(app_info):
- app_id = app_info.get_id() or ""
+def application_id(app_info):
+ """Return an application id (string) for GAppInfo @app_info"""
+ app_id = app_info.get_id()
+ if not app_id:
+ try:
+ app_id = app_info.init_path
+ except AttributeError:
+ app_id = ""
if app_id.endswith(".desktop"):
app_id = app_id[:-len(".desktop")]
return app_id
@@ -83,7 +89,7 @@ def launch_application(app_info, files=(), uris=(), paths=(), track=True, activa
ctx.set_timestamp(gtk.get_current_event_time())
if track:
- app_id = _app_id(app_info)
+ app_id = application_id(app_info)
os.putenv(kupfer_env, app_id)
else:
app_id = ""
@@ -105,14 +111,14 @@ def launch_application(app_info, files=(), uris=(), paths=(), track=True, activa
return False
else:
if track:
- svc.launched_application(_app_id(app_info))
+ svc.launched_application(application_id(app_info))
finally:
os.unsetenv(kupfer_env)
return True
def application_is_running(app_info):
svc = GetApplicationsMatcherService()
- return svc.application_is_running(_app_id(app_info))
+ return svc.application_is_running(application_id(app_info))
class ApplicationsMatcherService (pretty.OutputMixin):
"""Handle launching applications and see if they still run.
diff --git a/kupfer/objects.py b/kupfer/objects.py
index 898d79a..4f64eda 100644
--- a/kupfer/objects.py
+++ b/kupfer/objects.py
@@ -379,6 +379,11 @@ class AppLeaf (Leaf, PicklingHelperMixin, pretty.OutputMixin):
from gio.unix import DesktopAppInfo, desktop_app_info_new_from_filename
if self.init_path and os.access(self.init_path, os.X_OK):
item = desktop_app_info_new_from_filename(self.init_path)
+ try:
+ # try to annotate the GAppInfo object
+ item.init_path = self.init_path
+ except AttributeError, exc:
+ self.output_debug(exc)
elif self.init_item_id:
try:
item = DesktopAppInfo(self.init_item_id)
@@ -390,18 +395,18 @@ class AppLeaf (Leaf, PicklingHelperMixin, pretty.OutputMixin):
raise InvalidDataError
def repr_key(self):
- return self.get_id() or self
+ return self.get_id()
def _get_package_name(self):
- package_name, ext = path.splitext(self.object.get_id() or "")
- return package_name
+ return os.path.basename(self.get_id())
def get_id(self):
"""Return the unique ID for this app.
- This is the GIO id "gedit.desktop" minus the .desktop part
+ This is the GIO id "gedit.desktop" minus the .desktop part for
+ system-installed applications.
"""
- return self._get_package_name()
+ return launch.application_id(self.object)
def get_actions(self):
if launch.application_is_running(self.object):
@@ -411,9 +416,14 @@ class AppLeaf (Leaf, PicklingHelperMixin, pretty.OutputMixin):
yield Launch()
def get_description(self):
- """Use Application's description, else use executable"""
- app_desc = self.object.get_description()
- return tounicode(app_desc if app_desc else self.object.get_executable())
+ # Use Application's description, else use executable
+ # for "file-based" applications we show the path
+ app_desc = tounicode(self.object.get_description())
+ ret = tounicode(app_desc if app_desc else self.object.get_executable())
+ if self.init_path:
+ app_path = utils.get_display_path_for_bytestring(self.init_path)
+ return u"(%s) %s" % (app_path, ret)
+ return ret
def get_gicon(self):
return self.object.get_icon()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]