Index: src/mlx/gui/gui.py
===================================================================
--- src/mlx/gui/gui.py	(revision 178)
+++ src/mlx/gui/gui.py	(revision 182)
@@ -19,4 +19,5 @@
 import mlx.acft as acft
 import mlx.web as web
+import mlx.singleton as singleton
 from  mlx.i18n import xstr
 from mlx.pirep import PIREP
@@ -306,6 +307,8 @@
                                     self._mainWindow)
             self._updater.start()
-
+        
+        singleton.raiseCallback = self.raiseCallback
         gtk.main()
+        singleton.raiseCallback = None
 
         self._disconnect()
@@ -499,4 +502,14 @@
            (event.new_window_state&iconified)!=0:
             self.hideMainWindow(savePosition = False)
+
+    def raiseCallback(self):
+        """Callback for the singleton handling code."""
+        gobject.idle_add(self.raiseMainWindow)
+
+    def raiseMainWindow(self):
+        """SHow the main window if invisible, and raise it."""
+        if not self._mainWindow.get_visible():
+            self.showMainWindow()
+        self._mainWindow.present()
 
     def hideMainWindow(self, savePosition = True):
Index: src/mlx/mlx.py
===================================================================
--- src/mlx/mlx.py	(revision 160)
+++ src/mlx/mlx.py	(revision 182)
@@ -44,4 +44,9 @@
 def main():
     """The main operation of the program."""
+    from singleton import SingleInstance, raiseCallbackWrapper
+
+    instance = SingleInstance("mlx", raiseCallbackWrapper)
+    if not instance: return
+
     programDirectory = os.path.dirname(sys.argv[0])
 
@@ -79,3 +84,4 @@
 
 if __name__ == "__main__":
-    main()
+    if instance:
+        main()
Index: src/mlx/singleton.py
===================================================================
--- src/mlx/singleton.py	(revision 182)
+++ src/mlx/singleton.py	(revision 182)
@@ -0,0 +1,270 @@
+# Module to allow for a single instance of an application to run
+
+import os
+import time
+
+#----------------------------------------------------------------------------
+
+if os.name=="nt":
+    import win32event
+    import win32file
+    import win32pipe
+    import win32api
+    import winerror
+
+    import threading
+
+    class _PipeServer(threading.Thread):
+        """A server that creates a named pipe, and waits for messages on
+        that."""
+        
+        BUFFER_SIZE = 4096
+        
+        def __init__(self, pipeName, raiseCallback):
+            """Construct the server thread."""
+            super(_PipeServer, self).__init__()
+            
+            self._pipeName = pipeName
+            self._raiseCallback = raiseCallback
+            self.daemon = True
+
+        def run(self):
+            """Perform the operation of the thread."""
+            try:
+                while True:
+                    handle = self._createPipe()
+
+                    if handle is None:
+                        break
+
+                    print "singleton._PipeServer.run: created the pipe"
+                    try:
+                        if win32pipe.ConnectNamedPipe(handle)==0:
+                            print "singleton._PipeServer.run: client connection received"
+                            (code, message) = \
+                                win32file.ReadFile(handle,
+                                                   _PipeServer.BUFFER_SIZE,
+                                                   None)
+
+                            if code==0:
+                                print "singleton._PipeServer.run: message received from client"
+                                self._raiseCallback()
+                            else:
+                                print "singleton._PipeServer.run: failed to read from the pipe"
+                    except Exception, e:
+                        print "singleton._PipeServer.run: exception:", str(e)
+                    finally:
+                        win32pipe.DisconnectNamedPipe(handle)
+                        win32file.CloseHandle(handle)
+            except Exception, e:
+                print "singleton._PipeServer.run: fatal exception:", str(e)
+                            
+        def _createPipe(self):
+            """Create the pipe."""
+            handle = win32pipe.CreateNamedPipe(self._pipeName,
+                                               win32pipe.PIPE_ACCESS_INBOUND,
+                                               win32pipe.PIPE_TYPE_BYTE |
+                                               win32pipe.PIPE_READMODE_BYTE |
+                                               win32pipe.PIPE_WAIT,
+                                               win32pipe.PIPE_UNLIMITED_INSTANCES,
+                                               _PipeServer.BUFFER_SIZE,
+                                               _PipeServer.BUFFER_SIZE,
+                                               1000,
+                                               None)
+            if handle==win32file.INVALID_HANDLE_VALUE:
+                print "singleton._PipeServer.run: could not create the handle"
+                return None
+            else:
+                return handle            
+
+    class SingleInstance(object):
+        """Creating an instance of this object checks if only one instance of
+        the process runs."""
+        def __init__(self, baseName, raiseCallback):
+            """Construct the single instance object.
+
+            raiseCallback is a function that will be called, if another
+            instance of the program is started."""
+            self._name = baseName + "_" + win32api.GetUserName()
+            self._mutex = win32event.CreateMutex(None, False, self._name)
+            self._isSingle = win32api.GetLastError() != \
+                             winerror.ERROR_ALREADY_EXISTS
+            if self._isSingle:
+                self._startPipeServer(raiseCallback)
+            else:
+                self._notifySingleton()
+
+        def _getPipeName(self):
+            """Get the name of the pipe to be used for communication."""
+            return r'\\.\pipe\\' + self._name
+
+        def _startPipeServer(self, raiseCallback):
+            """Start the pipe server"""
+            pipeServer = _PipeServer(self._getPipeName(),
+                                     raiseCallback)
+            pipeServer.start()
+
+        def _notifySingleton(self):
+            """Notify the already running instance of the program of our
+            presence."""
+            pipeName = self._getPipeName()
+            for i in range(0, 3):
+                try:
+                    f = open(pipeName, "wb")
+                    f.write("hello")
+                    f.close()
+                    return
+                except Exception, e:
+                    print "SingleInstance._notifySingleton: failed:", str(e)
+                    time.sleep(0.5)
+        
+        def __nonzero__(self):
+            """Return a boolean representation of the object.
+
+            It is True, if this is the single instance of the program."""
+            return self._isSingle            
+                
+        def __del__(self):
+            """Destroy the object."""
+            if self._mutex:
+                win32api.CloseHandle(self._mutex)
+#----------------------------------------------------------------------------
+
+else:     # os.name=="nt"
+    import fcntl
+    import socket
+    import tempfile
+    import threading
+    
+    class _SocketServer(threading.Thread):
+        """Server thread to handle the Unix socket through which we are
+        notified of other instances starting."""
+        def __init__(self, socketName, raiseCallback):
+            """Construct the server."""
+            super(_SocketServer, self).__init__()
+
+            self._socketName = socketName
+            self._raiseCallback = raiseCallback
+
+            self.daemon = True
+            
+
+        def run(self):
+            """Perform the thread's operation."""
+            try:
+                try:
+                    os.remove(self._socketName)
+                except:
+                    pass
+                
+                s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
+                s.bind(self._socketName)
+
+                while True:
+                    s.recv(64)
+                    self._raiseCallback()
+            except Exception, e:
+                print "singleton._SocketServer.run: fatal exception:", str(e)            
+    
+    class SingleInstance(object):
+        """Creating an instance of this object checks if only one instance of
+        the process runs."""
+        def __init__(self, baseName, raiseCallback):
+            """Construct the single instance object.
+
+            raiseCallback is a function that will be called, if another
+            instance of the program is started."""
+            baseName = baseName + "_" + os.environ["LOGNAME"]
+
+            tempDir = tempfile.gettempdir()
+            self._lockName = os.path.join(tempDir, baseName + ".lock")
+            self._socketName = os.path.join(tempDir, baseName + ".sock")
+            
+            self._lockFile = open(self._lockName, "w")
+
+            self._isSingle = False
+            try:
+                fcntl.lockf(self._lockFile, fcntl.LOCK_EX | fcntl.LOCK_NB)
+                self._isSingle = True
+            except Exception, e:
+                self._lockFile.close()
+                self._lockFile = None
+                pass
+
+            if self._isSingle:
+                self._startSocketServer(raiseCallback)
+            else:
+                self._notifySingleton()
+
+        def _startSocketServer(self, raiseCallback):
+            """Start the pipe server"""
+            pipeServer = _SocketServer(self._socketName, raiseCallback)
+            pipeServer.start()
+
+        def _notifySingleton(self):
+            """Notify the already running instance of the program of our
+            presence."""
+            s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
+            for i in range(0, 3):
+                try:
+                    s.connect(self._socketName)
+                    s.send("hello")
+                    s.close()
+                    return
+                except Exception, e:
+                    print "singleton.SingleInstance._notifySingleton: failed:", str(e)
+                    time.sleep(0.5)
+
+        def __nonzero__(self):
+            """Return a boolean representation of the object.
+
+            It is True, if this is the single instance of the program."""
+            return self._isSingle            
+
+        def __del__(self):
+            """Destroy the object."""
+            if self._isSingle:
+                self._lockFile.close()
+                try:
+                    os.remove(self._lockName)
+                except:
+                    pass
+                try:
+                    os.remove(self._socketName)
+                except:
+                    pass
+                
+#----------------------------------------------------------------------------
+#----------------------------------------------------------------------------
+
+# MAVA Logger X-specific stuff
+
+#----------------------------------------------------------------------------
+
+# The callback to use
+raiseCallback = None
+
+#----------------------------------------------------------------------------
+
+def raiseCallbackWrapper():
+    """The actual function to be used as the callback.
+
+    It checks if raiseCallback is None, and if not, it calls that."""
+    callback = raiseCallback
+    if callback is not None:
+        callback()
+
+#----------------------------------------------------------------------------
+#----------------------------------------------------------------------------
+
+if __name__=="__main__":
+    def raiseCallback():
+        print "Raise the window!"
+
+    instance = SingleInstance("mlx", raiseCallback)
+    if instance:
+        print "The first instance"
+        time.sleep(10)
+    else:
+        print "The program is already running."
+
