From eb76d53d9e91fd156bb3e7a1f365af659af8741a Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Thu, 30 Mar 2006 03:24:04 +0000 Subject: [PATCH] fix launch routine svn: r6230 --- ChangeLog | 3 ++- src/DisplayTabs.py | 6 +----- src/Utils.py | 42 +++++++++++++++++++++++++++++++++++++----- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index e96cf28bf..4226686f7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,7 +8,8 @@ * src/plugins/DetAncestralReport.py: remove use of deprecated functions 2006-03-29 Don Allingham - * src/DisplayTabs.py: fix import + * src/Utils.py: provide launch function for spawning processes + * src/DisplayTabs.py: fix import, move launch function * src/Editors/_EditPerson.py: Fix imports of EditMediaRef, remove specific edit image from top image window. * src/glade/gramps.glade: remove unused dialogs, replaced by diff --git a/src/DisplayTabs.py b/src/DisplayTabs.py index 35b93f8c7..d268b89e6 100644 --- a/src/DisplayTabs.py +++ b/src/DisplayTabs.py @@ -2004,9 +2004,5 @@ class BackRefModel(gtk.ListStore): yield True yield False -def launch(prog,path): - print prog, path - os.spawnvpe(os.P_NOWAIT, prog, [ prog, path], os.environ) - def make_launcher(prog, path): - return lambda x: launch(prog, path) + return lambda x: Utils.launch(prog, path) diff --git a/src/Utils.py b/src/Utils.py index c926dc1d4..62406e60a 100644 --- a/src/Utils.py +++ b/src/Utils.py @@ -592,11 +592,7 @@ def view_photo(photo): prog = data[0] except: return - - args = prog.split() - args.append(photo.get_path()) - - os.spawnvpe(os.P_NOWAIT, args[0], args, os.environ) + launch(prog,photo.get_path()) def find_file( filename): # try the filename we got @@ -1294,3 +1290,39 @@ class ProgressMeter: Close the progress meter """ self.ptop.destroy() + +def launch(prog_str,path): + + subval = { + '%i' : None, + '%F' : (True,path), + '%f' : (True,path), + '%u' : (True,path), + '%U' : (True,path), + '%n' : (True,path), + '%N' : (True,path), + '"%c"' : (False,'"%s"' % path), + } + + prog_data = prog_str.split() + prog = prog_data[0] + prog_list = [] + need_path = True + + if len(prog_data) > 1: + for item in prog_data: + value = subval.get(item,item) + if not value: + continue + if type(value) == tuple: + if value[0]: + need_path = False + prog_list.append(value[1]) + elif value[0] != '%': + prog_list.append(value) + else: + prog_list = [prog_data[0]] + + if need_path: + prog_list.append(path) + os.spawnvpe(os.P_NOWAIT, prog, prog_list, os.environ)