1 # Copyright (C) 2006 Ulrik Sverdrup
3 # dragbox -- Commandline drag-and-drop tool for GNOME
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
21 def get_icon_for_uri(uri
, icon_size
=48):
23 Returns a pixbuf representing the file at
24 the URI generally (mime-type based)
26 @param icon_size: a pixel size of the icon
27 @type icon_size: an integer object.
30 from gtk
import icon_theme_get_default
, ICON_LOOKUP_USE_BUILTIN
31 from gnomevfs
import get_mime_type
32 from gnome
.ui
import ThumbnailFactory
, icon_lookup
34 mtype
= get_mime_type(uri
)
35 icon_theme
= icon_theme_get_default()
36 thumb_factory
= ThumbnailFactory(16)
37 icon_name
, num
= icon_lookup(icon_theme
, thumb_factory
, file_uri
=uri
, custom_icon
="")
38 icon
= icon_theme
.load_icon(icon_name
, icon_size
, ICON_LOOKUP_USE_BUILTIN
)
41 def run_process(proc
, args
):
45 @param proc: The name of the executable
46 @type proc: a string object.
48 @param args: A list of arguments to the program
49 @type args: a list object.
51 from os
import fork
, execvp
52 args
= [proc
] + args
# strange but true
59 print_error("Failed to run %s %s" % (proc
, str(args
)))
65 terinates the gtk loop and exits
69 from gtk
import main_quit
72 # Make sure we output it all
73 from sys
import exit
, stdout
, stderr
79 def print_error(string
):
82 writes an error to stderr, with a special prefix
85 from sys
import stderr
86 stderr
.write("Error: " + string
+ "\n")
88 def print_debug(string
):
91 writes an debug message to stderr, with a special prefix
96 from sys
import stderr
97 stderr
.write("Debug: " + string
+ "\n")
101 This will find the $DESTDIR if that has been used
102 Useful for finding back to datafiles
104 Limitation: the binary must be installed "inside" the prefix
108 from globals import prefix
109 pre
= path
.normpath(path
.expanduser(prefix
.strip()))
111 pre
= "/bin" # Trick that works for this special case
112 absp
= path
.normpath(path
.abspath(argv
[0]))
113 datadir_index
= absp
.find(pre
)
114 if datadir_index
== -1:
116 datadir_guess
= absp
[:datadir_index
]
117 print_debug("It seems like DESTDIR is " + datadir_guess
)