author | John Rice <john.rice@sun.com> |
Tue, 10 Mar 2009 00:01:30 +0000 | |
changeset 927 | 2beb452e6245 |
parent 869 | 0197953cd88a |
child 942 | cb2774668721 |
permissions | -rw-r--r-- |
869
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.4 |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
2 |
# |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
3 |
# CDDL HEADER START |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
4 |
# |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
5 |
# The contents of this file are subject to the terms of the |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
6 |
# Common Development and Distribution License (the "License"). |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
7 |
# You may not use this file except in compliance with the License. |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
8 |
# |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
9 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
10 |
# or http://www.opensolaris.org/os/licensing. |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
11 |
# See the License for the specific language governing permissions |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
12 |
# and limitations under the License. |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
13 |
# |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
14 |
# When distributing Covered Code, include this CDDL HEADER in each |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
15 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
16 |
# If applicable, add the following below this CDDL HEADER, with the |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
17 |
# fields enclosed by brackets "[]" replaced with your own identifying |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
18 |
# information: Portions Copyright [yyyy] [name of copyright owner] |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
19 |
# |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
20 |
# CDDL HEADER END |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
21 |
# |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
22 |
# Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
23 |
# Use is subject to license terms. |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
24 |
# |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
25 |
|
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
26 |
import os |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
27 |
import sys |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
28 |
try: |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
29 |
import gobject |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
30 |
import gtk |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
31 |
except ImportError: |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
32 |
sys.exit(1) |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
33 |
|
927
2beb452e6245
6352 Add MimeType support for adding Authorities and Packages via PM
John Rice <john.rice@sun.com>
parents:
869
diff
changeset
|
34 |
def get_app_pixbuf(application_dir, icon_name): |
2beb452e6245
6352 Add MimeType support for adding Authorities and Packages via PM
John Rice <john.rice@sun.com>
parents:
869
diff
changeset
|
35 |
return get_pixbuf_from_path(application_dir + |
2beb452e6245
6352 Add MimeType support for adding Authorities and Packages via PM
John Rice <john.rice@sun.com>
parents:
869
diff
changeset
|
36 |
"/usr/share/package-manager/", icon_name) |
2beb452e6245
6352 Add MimeType support for adding Authorities and Packages via PM
John Rice <john.rice@sun.com>
parents:
869
diff
changeset
|
37 |
|
869
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
38 |
def get_icon_pixbuf(application_dir, icon_name): |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
39 |
return get_pixbuf_from_path(application_dir + |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
40 |
"/usr/share/icons/package-manager/", icon_name) |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
41 |
|
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
42 |
def get_pixbuf_from_path(path, icon_name): |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
43 |
icon = icon_name.replace(' ', '_') |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
44 |
|
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
45 |
# Performance: Faster to check if files exist rather than catching |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
46 |
# exceptions when they do not. Picked up open failures using dtrace |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
47 |
png_exists = os.path.exists(path + icon + ".png") |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
48 |
svg_exists = os.path.exists(path + icon + ".svg") |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
49 |
|
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
50 |
if not png_exists and not svg_exists: |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
51 |
return None |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
52 |
try: |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
53 |
return gtk.gdk.pixbuf_new_from_file(path + icon + ".png") |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
54 |
except gobject.GError: |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
55 |
try: |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
56 |
return gtk.gdk.pixbuf_new_from_file(path + icon + ".png") |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
57 |
except gobject.GError: |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
58 |
iconview = gtk.IconView() |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
59 |
icon = iconview.render_icon(getattr(gtk, |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
60 |
"STOCK_MISSING_IMAGE"), |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
61 |
size = gtk.ICON_SIZE_MENU, |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
62 |
detail = None) |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
63 |
# XXX Could return image-we don't want to show ugly icon. |
0197953cd88a
5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
64 |
return None |