Use subprocess module
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 20 May 2007 16:29:59 +0000 (18:29 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 20 May 2007 16:29:59 +0000 (18:29 +0200)
src/packages/kofoto/gkofoto/duplicateandopenimagedialog.py
src/packages/kofoto/gkofoto/imageversionslist.py
src/packages/kofoto/gkofoto/objectcollection.py

index ab4ff66..98df55f 100644 (file)
@@ -1,6 +1,7 @@
 import gtk
 import os
 import shutil
+import subprocess
 
 from kofoto.gkofoto.environment import env
 
@@ -47,8 +48,9 @@ class DuplicateAndOpenImageDialog:
                 self._imageversion.getLocation(),
                 duplicateLocation)
             command = env.openCommand % {"locations": duplicateLocation}
-            result = os.system(command.encode(env.localeEncoding) + " &")
-            if result != 0:
+            try:
+                subprocess.Popen(command, shell=True)
+            except OSError:
                 dialog = gtk.MessageDialog(
                     self._dialog,
                     gtk.DIALOG_MODAL,
index f40b8be..7f92a83 100644 (file)
@@ -1,4 +1,5 @@
 import os
+import subprocess
 import gtk
 from kofoto.alternative import Alternative
 from kofoto.shelf import ImageVersionType
@@ -284,8 +285,9 @@ class ImageVersionsList(gtk.ScrolledWindow):
             self.__imageWidgetToImageVersion[x].getLocation()
             for x in self.__getSelectedImageVersionsInOrder()]
         command = env.openCommand % {"locations": " ".join(locations)}
-        result = os.system(command.encode(env.localeEncoding) + " &")
-        if result != 0:
+        try:
+            subprocess.Popen(command, shell=True)
+        except OSError:
             dialog = gtk.MessageDialog(
                 type=gtk.MESSAGE_ERROR,
                 buttons=gtk.BUTTONS_OK,
@@ -368,16 +370,18 @@ class ImageVersionsList(gtk.ScrolledWindow):
             location = imageVersion.getLocation()
             env.pixbufLoader.unload_all(location)
             command = rotateCommand % {"location": location}
-            result = os.system(command.encode(env.localeEncoding))
-            if result == 0:
-                imageVersion.contentChanged()
-            else:
+            try:
+                subprocess.Popen(command, shell=True)
+            except OSError:
                 dialog = gtk.MessageDialog(
                     type=gtk.MESSAGE_ERROR,
                     buttons=gtk.BUTTONS_OK,
-                    message_format="Failed to execute command: \"%s\"" % command)
+                    message_format=
+                        "Failed to execute command: \"%s\"" % command)
                 dialog.run()
                 dialog.destroy()
+            else:
+                imageVersion.contentChanged()
         self.__singleObjectView.reload()
 
     def __getSelectedImageVersionsInOrder(self):
index 2ba7646..b10e3c6 100644 (file)
@@ -2,6 +2,7 @@ import os
 import gtk
 import gobject
 import gc
+import subprocess
 from kofoto.shelfexceptions import BadAlbumTagError
 from kofoto.timer import Timer
 from kofoto.gkofoto.environment import env
@@ -530,18 +531,19 @@ class ObjectCollection(object):
                 else:
                     commandString = env.rotateLeftCommand
                 command = commandString % { "location":location }
-                result = os.system(command.encode(env.localeEncoding))
-                if result == 0:
-                    imageversion.contentChanged()
-                    model = self.getUnsortedModel()
-                    self.__loadThumbnail(model, model.get_iter(rowNr))
-                else:
+                try:
+                    subprocess.Popen(command, shell=True)
+                except OSError:
                     dialog = gtk.MessageDialog(
                         type=gtk.MESSAGE_ERROR,
                         buttons=gtk.BUTTONS_OK,
                         message_format="Failed to execute command: \"%s\"" % command)
                     dialog.run()
                     dialog.destroy()
+                else:
+                    imageversion.contentChanged()
+                    model = self.getUnsortedModel()
+                    self.__loadThumbnail(model, model.get_iter(rowNr))
         self.reloadSingleObjectView()
 
     def rotateImageLeft(self, widget, *unused):
@@ -562,8 +564,9 @@ class ObjectCollection(object):
                 locations += location + " "
         if locations != "":
             command = env.openCommand % { "locations":locations }
-            result = os.system(command.encode(env.localeEncoding) + " &")
-            if result != 0:
+            try:
+                subprocess.Popen(command, shell=True)
+            except OSError:
                 dialog = gtk.MessageDialog(
                     type=gtk.MESSAGE_ERROR,
                     buttons=gtk.BUTTONS_OK,