Made GKofoto start on Windows again. To achieve this, the gkofoto
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 14 Jul 2004 14:44:01 +0000 (14:44 +0000)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 14 Jul 2004 14:44:01 +0000 (14:44 +0000)
script had to be renamed to some other name (chosen name: "start").
When installing via setup.py, the program is called gkofoto, though.

Split the old gkofoto program into three files: start, main.py and
controller.py. Moved WidgetsWrapper to environment.py.

setup.py
src/gkofoto/controller.py [new file with mode: 0644]
src/gkofoto/environment.py
src/gkofoto/gkofoto [deleted file]
src/gkofoto/gkofoto.pyw [deleted file]
src/gkofoto/main.py [new file with mode: 0644]
src/gkofoto/start [new file with mode: 0755]
src/gkofoto/start.pyw [new file with mode: 0644]

index c987a0b..6c206e9 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -13,12 +13,6 @@ packages = [
     "kofoto.output",
     "gkofoto",
     ]
-scripts = [
-    "src/cmdline/renameimage",
-    "src/cmdline/kofoto",
-    "src/cmdline/kofoto-upload",
-    "src/gkofoto/gkofoto",
-    ]
 data_files = [
     ("share/gkofoto/glade", ["src/gkofoto/glade/gkofoto.glade"]),
     ("share/gkofoto/icons", ["src/gkofoto/icons/album.png",
@@ -29,6 +23,15 @@ data_files = [
                              "src/gkofoto/icons/unknownimage.png"])
     ]
 if os.name == "posix":
+    import shutil
+    shutil.copy("src/gkofoto/start", "src/gkofoto/gkofoto")
+    scripts = [
+        "src/cmdline/renameimage",
+        "src/cmdline/kofoto",
+        "src/cmdline/kofoto-upload",
+        "src/gkofoto/gkofoto",
+        ]
+    os.unlink("src/gkofoto/gkofoto")
     if os.system("cd src/web && make") != 0:
         import sys
         sys.exit(1)
@@ -38,6 +41,10 @@ if os.name == "posix":
     data_files.append(("share/kofotoweb/static", [
         "src/web/static/webkofoto.css",
         ]))
+else:
+    scripts = [
+        "src/cmdline/kofoto",
+        ]
 
 setup(
     name="kofoto",
diff --git a/src/gkofoto/controller.py b/src/gkofoto/controller.py
new file mode 100644 (file)
index 0000000..76378e7
--- /dev/null
@@ -0,0 +1,74 @@
+import gtk
+from kofoto.shelf import ShelfLockedError
+from gkofoto.mainwindow import MainWindow
+from gkofoto.environment import env
+
+class Controller:
+    def __init__(self):
+        self.__clipboard = None
+
+    def start(self, setupOk):
+        if setupOk:
+            try:
+                env.shelf.begin()
+            except ShelfLockedError, e:
+                env.startupNotices += [
+                    "Error: Could not open shelf \"%s\"." % e +
+                    " Another process is locking it.\n"]
+                setupOk = False
+        if env.startupNotices:
+            if setupOk:
+                dialogtype = gtk.MESSAGE_INFO
+            else:
+                dialogtype = gtk.MESSAGE_ERROR
+            dialog = gtk.MessageDialog(
+                type=dialogtype,
+                buttons=gtk.BUTTONS_OK,
+                message_format="".join(env.startupNotices))
+            if setupOk:
+                # Doesn't work with x[0].destroy(). Don't know why.
+                dialog.connect("response", lambda *x: x[0].hide())
+            else:
+                # Doesn't work with gtk.main_quit(). Don't know why.
+                dialog.connect("response", lambda *x: sys.exit(1))
+            dialog.run()
+        if setupOk:
+            self.__mainWindow = MainWindow()
+            env.widgets["mainWindow"].connect("destroy", self.quit, False)
+            env.widgets["mainWindow"].show()
+        gtk.main()
+
+    def quit(self, app, cancelButton=True):
+        if env.shelf.isModified():
+            widgets = gtk.glade.XML(env.gladeFile, "quitDialog")
+            quitDialog = widgets.get_widget("quitDialog")
+            if not cancelButton:
+                widgets.get_widget("cancel").set_sensitive(False)
+            result = quitDialog.run()
+            if result == 0:
+                env.shelf.commit()
+                gtk.main_quit()
+            elif result == 1:
+                env.shelf.rollback()
+                gtk.main_quit()
+            else:
+                quitDialog.destroy()
+                return
+        else:
+            env.shelf.rollback()
+            gtk.main_quit()
+
+    def save(self, app):
+        env.shelf.commit()
+        env.shelf.begin()
+
+    def revert(self, app):
+        dialog = gtk.MessageDialog(
+            type=gtk.MESSAGE_QUESTION,
+            buttons=gtk.BUTTONS_YES_NO,
+            message_format="Revert to the previously saved state and lose all changes?")
+        if dialog.run() == gtk.RESPONSE_YES:
+            env.shelf.rollback()
+            env.shelf.begin()
+            self.__mainWindow.reload()
+        dialog.destroy()
index 16ac4d4..acddf48 100644 (file)
@@ -1,16 +1,29 @@
 import sys
 import os
-import gtk
 import getopt
 import locale
 import re
 
+import pygtk
+pygtk.require('2.0')
+import gtk
+import gobject
+import gtk.gdk
+import gtk.glade
+
 from kofoto.clientenvironment import *
 from kofoto.common import *
 from kofoto.shelf import *
 from kofoto.config import *
 from kofoto.imagecache import *
 
+class WidgetsWrapper:
+    def __init__(self):
+        self.widgets = gtk.glade.XML(env.gladeFile, "mainWindow")
+
+    def __getitem__(self, key):
+        return self.widgets.get_widget(key)
+
 class Environment(ClientEnvironment):
     def __init__(self):
         ClientEnvironment.__init__(self)
@@ -51,6 +64,8 @@ class Environment(ClientEnvironment):
         from clipboard import Clipboard
         self.clipboard = Clipboard()
 
+        self.widgets = WidgetsWrapper()
+
         self.isDebug = False # TODO get as a command line parameter
         return True
 
diff --git a/src/gkofoto/gkofoto b/src/gkofoto/gkofoto
deleted file mode 100755 (executable)
index 167b808..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import os
-
-if sys.platform.startswith("win"):
-    import _winreg
-    import msvcrt
-    try:
-        k = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\GTK\\2.0")
-    except EnvironmentError:
-        print "You must install the Gtk+ 2.2 Runtime Environment to run this program"
-        while not msvcrt.kbhit():
-            pass
-        sys.exit(1)
-    else:
-        gtkdir = _winreg.QueryValueEx(k, "Path")
-        import os
-        os.environ["PATH"] += ";%s/lib;%s/bin" % (gtkdir[0], gtkdir[0])
-
-# Find libraries if installed in ../lib (like in the source tree).
-if os.path.islink(sys.argv[0]):
-    link = os.readlink(sys.argv[0])
-    absloc = os.path.normpath(
-        os.path.join(os.path.dirname(sys.argv[0]), link))
-    bindir = os.path.dirname(absloc)
-else:
-    bindir = os.path.dirname(sys.argv[0])
-sys.path.insert(0, os.path.join(bindir, "..", "lib"))
-sys.path.insert(0, os.path.join(bindir, ".."))
-
-import pygtk
-pygtk.require('2.0')
-import gtk
-import gobject
-import gtk.gdk
-import gtk.glade
-from kofoto.imagecache import *
-from gkofoto.mainwindow import *
-from gkofoto.registerimagesdialog import RegisterImagesDialog
-from gkofoto.environment import env
-
-class WidgetsWrapper:
-    def __init__(self):
-        self.widgets = gtk.glade.XML(env.gladeFile, "mainWindow")
-
-    def __getitem__(self, key):
-        return self.widgets.get_widget(key)
-
-class Controller:
-    def __init__(self):
-        self.__clipboard = None
-
-    def start(self, setupOk):
-        if setupOk:
-            try:
-                env.shelf.begin()
-            except ShelfLockedError, e:
-                env.startupNotices += [
-                    "Error: Could not open shelf \"%s\"." % e +
-                    " Another process is locking it.\n"]
-                setupOk = False
-        if env.startupNotices:
-            if setupOk:
-                dialogtype = gtk.MESSAGE_INFO
-            else:
-                dialogtype = gtk.MESSAGE_ERROR
-            dialog = gtk.MessageDialog(
-                type=dialogtype,
-                buttons=gtk.BUTTONS_OK,
-                message_format="".join(env.startupNotices))
-            if setupOk:
-                # Doesn't work with x[0].destroy(). Don't know why.
-                dialog.connect("response", lambda *x: x[0].hide())
-            else:
-                # Doesn't work with gtk.main_quit(). Don't know why.
-                dialog.connect("response", lambda *x: sys.exit(1))
-            dialog.run()
-        if setupOk:
-            self.__mainWindow = MainWindow()
-            env.widgets["mainWindow"].connect("destroy", self.quit, False)
-            env.widgets["mainWindow"].show()
-        gtk.main()
-
-    def quit(self, app, cancelButton=True):
-        if env.shelf.isModified():
-            widgets = gtk.glade.XML(env.gladeFile, "quitDialog")
-            quitDialog = widgets.get_widget("quitDialog")
-            if not cancelButton:
-                widgets.get_widget("cancel").set_sensitive(False)
-            result = quitDialog.run()
-            if result == 0:
-                env.shelf.commit()
-                gtk.main_quit()
-            elif result == 1:
-                env.shelf.rollback()
-                gtk.main_quit()
-            else:
-                quitDialog.destroy()
-                return
-        else:
-            env.shelf.rollback()
-            gtk.main_quit()
-
-    def save(self, app):
-        env.shelf.commit()
-        env.shelf.begin()
-
-    def revert(self, app):
-        dialog = gtk.MessageDialog(
-            type=gtk.MESSAGE_QUESTION,
-            buttons=gtk.BUTTONS_YES_NO,
-            message_format="Revert to the previously saved state and lose all changes?")
-        if dialog.run() == gtk.RESPONSE_YES:
-            env.shelf.rollback()
-            env.shelf.begin()
-            self.__mainWindow.reload()
-        dialog.destroy()
-
-######################################################################
-### Start
-
-setupOk = env.setup(bindir)
-env.widgets = WidgetsWrapper()
-env.controller = Controller()
-env.controller.start(setupOk)
diff --git a/src/gkofoto/gkofoto.pyw b/src/gkofoto/gkofoto.pyw
deleted file mode 100644 (file)
index fbb41dd..0000000
+++ /dev/null
@@ -1 +0,0 @@
-execfile("gkofoto")
diff --git a/src/gkofoto/main.py b/src/gkofoto/main.py
new file mode 100644 (file)
index 0000000..5ce01a0
--- /dev/null
@@ -0,0 +1,8 @@
+import sys
+from gkofoto.environment import env
+from gkofoto.controller import Controller
+
+def main(bindir, argv):
+    setupOk = env.setup(bindir)
+    env.controller = Controller()
+    env.controller.start(setupOk)
diff --git a/src/gkofoto/start b/src/gkofoto/start
new file mode 100755 (executable)
index 0000000..10dd846
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+
+import sys
+import os
+
+if sys.platform.startswith("win"):
+    import _winreg
+    import msvcrt
+    try:
+        k = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\GTK\\2.0")
+    except EnvironmentError:
+        print "You must install the Gtk+ 2.2 Runtime Environment to run this program"
+        while not msvcrt.kbhit():
+            pass
+        sys.exit(1)
+    else:
+        gtkdir = _winreg.QueryValueEx(k, "Path")
+        import os
+        os.environ["PATH"] += ";%s/lib;%s/bin" % (gtkdir[0], gtkdir[0])
+
+# Find libraries if installed in ../lib (like in the source tree).
+if os.path.islink(sys.argv[0]):
+    link = os.readlink(sys.argv[0])
+    absloc = os.path.normpath(
+        os.path.join(os.path.dirname(sys.argv[0]), link))
+    bindir = os.path.dirname(absloc)
+else:
+    bindir = os.path.dirname(sys.argv[0])
+sys.path.insert(0, os.path.join(bindir, "..", "lib"))
+sys.path.insert(0, os.path.join(bindir, ".."))
+
+from gkofoto.main import main
+main(bindir, sys.argv)
diff --git a/src/gkofoto/start.pyw b/src/gkofoto/start.pyw
new file mode 100644 (file)
index 0000000..0e35cae
--- /dev/null
@@ -0,0 +1,4 @@
+# This file makes it possible to run GKofoto in Windows directly from
+# the source directory by double-clicking on it.
+
+execfile("start")