Index: src/mlx/gui/cef.py
===================================================================
--- src/mlx/gui/cef.py	(revision 713)
+++ src/mlx/gui/cef.py	(revision 805)
@@ -1,11 +1,7 @@
 from common import *
 
-from mava_simbrief import MavaSimbriefIntegrator
-
 from mlx.util import secondaryInstallation
 
 from cefpython3 import cefpython
-from selenium import webdriver
-from selenium.webdriver.chrome.options import Options
 
 import platform
@@ -14,7 +10,12 @@
 import os
 import re
+import thread
 import threading
 import tempfile
 import traceback
+import urllib2
+from lxml import etree
+from StringIO import StringIO
+import lxml.html
 
 #------------------------------------------------------------------------------
@@ -29,223 +30,235 @@
 _toQuit = False
 
-# Indicate the users of the fast timeout handler. If it reaches zero, the
-# timeout will be stopped
-_fastTimeoutUsers = 0
-
-# The Selenium thread
-_seleniumHandler = None
-
-#------------------------------------------------------------------------------
-
-def getArgsFilePath():
-    """Get the path of the argument file."""
-    if os.name=="nt":
-        return os.path.join(tempfile.gettempdir(),
-                            "mlxcef.args" +
-                            (".secondary" if secondaryInstallation else ""))
-    else:
-        import pwd
-        return os.path.join(tempfile.gettempdir(),
-                            "mlxcef." + pwd.getpwuid(os.getuid())[0] + ".args" +
-                            (".secondary" if secondaryInstallation else ""))
-
-#------------------------------------------------------------------------------
-
-class ArgsFileWaiter(threading.Thread):
-    """A thread to wait for the appearance of the arguments file."""
-    def __init__(self, initializedCallback):
-        """Construct the thread."""
-        threading.Thread.__init__(self)
-        self.daemon = True
-
-        self._initializedCallback = initializedCallback
-
-    def run(self):
-        """Repeatedly check for the existence of the arguments file.
-
-        If it is found, read it, extract the arguments and insert a job into
-        the GUI loop to perform the actual initialization of CEF."""
-        argsFilePath = getArgsFilePath()
-        print "Waiting for the arguments file '%s' to appear" % (argsFilePath,)
-
-        while not os.path.exists(argsFilePath):
-            time.sleep(0.1)
-
-        print "Got arguments, reading them."""
-
-        with open(argsFilePath, "rt") as f:
-            args = f.read().split()
-
-        gobject.idle_add(_initializeCEF, args, self._initializedCallback)
-
-#------------------------------------------------------------------------------
-
-SIMBRIEF_PROGRESS_SEARCHING_BROWSER = MavaSimbriefIntegrator.PROGRESS_SEARCHING_BROWSER
-SIMBRIEF_PROGRESS_LOADING_FORM = MavaSimbriefIntegrator.PROGRESS_LOADING_FORM
-SIMBRIEF_PROGRESS_FILLING_FORM = MavaSimbriefIntegrator.PROGRESS_FILLING_FORM
-SIMBRIEF_PROGRESS_WAITING_LOGIN = MavaSimbriefIntegrator.PROGRESS_WAITING_LOGIN
-SIMBRIEF_PROGRESS_LOGGING_IN = MavaSimbriefIntegrator.PROGRESS_LOGGING_IN
-SIMBRIEF_PROGRESS_WAITING_RESULT = MavaSimbriefIntegrator.PROGRESS_WAITING_RESULT
-
-SIMBRIEF_PROGRESS_RETRIEVING_BRIEFING = MavaSimbriefIntegrator.PROGRESS_MAX + 1
+# The SimBrief handler
+_simBriefHandler = None
+
+#------------------------------------------------------------------------------
+
+SIMBRIEF_PROGRESS_SEARCHING_BROWSER = 1
+SIMBRIEF_PROGRESS_LOADING_FORM = 2
+SIMBRIEF_PROGRESS_FILLING_FORM = 3
+SIMBRIEF_PROGRESS_WAITING_LOGIN = 4
+SIMBRIEF_PROGRESS_LOGGING_IN = 5
+SIMBRIEF_PROGRESS_WAITING_RESULT = 6
+
+SIMBRIEF_PROGRESS_RETRIEVING_BRIEFING = 7
 SIMBRIEF_PROGRESS_DONE = 1000
 
-SIMBRIEF_RESULT_NONE = MavaSimbriefIntegrator.RESULT_NONE
-SIMBRIEF_RESULT_OK = MavaSimbriefIntegrator.RESULT_OK
-SIMBRIEF_RESULT_ERROR_OTHER = MavaSimbriefIntegrator.RESULT_ERROR_OTHER
-SIMBRIEF_RESULT_ERROR_NO_FORM = MavaSimbriefIntegrator.RESULT_ERROR_NO_FORM
-SIMBRIEF_RESULT_ERROR_NO_POPUP = MavaSimbriefIntegrator.RESULT_ERROR_NO_POPUP
-SIMBRIEF_RESULT_ERROR_LOGIN_FAILED = MavaSimbriefIntegrator.RESULT_ERROR_LOGIN_FAILED
-
-#------------------------------------------------------------------------------
-
-class SeleniumHandler(threading.Thread):
-    """Thread to handle Selenium operations."""
-    def __init__(self, programDirectory):
-        """Construct the thread."""
-        threading.Thread.__init__(self)
-        self.daemon = False
-
-        self._programDirectory = programDirectory
-
-        self._commandsCondition = threading.Condition()
-        self._commands = []
-
-        self._driver = None
-
-        self._simBriefBrowser = None
-
-        self._toQuit = False
-
-    @property
-    def programDirectory(self):
-        """Get the program directory."""
-        return self._programDirectory
-
-    @property
-    def simBriefInitURL(self):
-        """Get the initial URL for the SimBrief browser."""
-        return "file://" + os.path.join(self.programDirectory, "simbrief.html")
-
-    def run(self):
-        """Create the Selenium driver and the perform any operations
-        requested."""
-        scriptName = "mlx_cef_caller"
-        if secondaryInstallation:
-            scriptName += "_secondary"
-        scriptName += ".bat" if os.name=="nt" else ".sh"
-
-        scriptPath = os.path.join(self._programDirectory, scriptName)
-        print "Creating the Selenium driver to call script", scriptPath
-
-        options = Options()
-        options.binary_location = scriptPath
-        driver = self._driver = webdriver.Chrome(chrome_options = options)
-        # try:
-        # except:
-        #     traceback.print_exc()
-
-        print "Created Selenium driver."
-        while not self._toQuit:
-            with self._commandsCondition:
-                while not self._commands:
-                    self._commandsCondition.wait()
-
-                command = self._commands[0]
-                del self._commands[0]
-
-            command()
-
-        driver.quit()
-
-    def initializeSimBrief(self):
+SIMBRIEF_RESULT_NONE = 0
+SIMBRIEF_RESULT_OK = 1
+SIMBRIEF_RESULT_ERROR_OTHER = 2
+SIMBRIEF_RESULT_ERROR_NO_FORM = 11
+SIMBRIEF_RESULT_ERROR_NO_POPUP = 12
+SIMBRIEF_RESULT_ERROR_LOGIN_FAILED = 13
+
+#------------------------------------------------------------------------------
+
+class SimBriefHandler(object):
+    """An object to store the state of a SimBrief query."""
+    _formURL = "http://flare.privatedns.org/mava_simbrief/simbrief_form.html"
+
+    _querySettings = {
+        'navlog': True,
+        'etops': True,
+        'stepclimbs': True,
+        'tlr': True,
+        'notams': True,
+        'firnot': True,
+        'maps': 'Simple',
+        };
+
+
+    def __init__(self):
+        """Construct the handler."""
+        self._browser = None
+        self._plan = None
+        self._getCredentials = None
+        self._getCredentialsCount = 0
+        self._updateProgressFn = None
+        self._htmlFilePath = None
+        self._lastProgress = SIMBRIEF_PROGRESS_SEARCHING_BROWSER
+        self._timeoutID = None
+
+    def initialize(self):
         """Create and initialize the browser used for Simbrief."""
         windowInfo = cefpython.WindowInfo()
         windowInfo.SetAsOffscreen(int(0))
 
-        url = self.simBriefInitURL
-        self._simBriefBrowser = \
+        self._browser = \
           cefpython.CreateBrowserSync(windowInfo, browserSettings = {},
-                                      navigateUrl = self.simBriefInitURL)
-        self._simBriefBrowser.SetClientHandler(OffscreenRenderHandler())
-        self._simBriefBrowser.SetFocus(True)
-
-    def callSimBrief(self, plan, getCredentials, updateProgress,
-                     htmlFilePath):
+                                      navigateUrl = SimBriefHandler._formURL)
+        self._browser.SetClientHandler(OffscreenRenderHandler())
+        self._browser.SetFocus(True)
+        self._browser.SetClientCallback("OnLoadEnd", self._onLoadEnd)
+
+        bindings = cefpython.JavascriptBindings(bindToFrames=True,
+                                                bindToPopups=True)
+        bindings.SetFunction("briefingData", self._briefingDataAvailable)
+        bindings.SetFunction("formFilled", self._formFilled)
+        self._browser.SetJavascriptBindings(bindings)
+
+    def call(self, plan, getCredentials, updateProgress, htmlFilePath):
         """Call SimBrief with the given plan."""
-        self._enqueue(lambda:
-                      self._callSimBrief(plan, self._driver,
-                                         getCredentials, updateProgress,
-                                         htmlFilePath))
-
-    def quit(self):
-        """Instruct the thread to quit and then join it."""
-        self._enqueue(self._quit)
-        self.join()
-
-    def _enqueue(self, command):
-        """Enqueue the given command.
-
-        command should be a function to be executed in the thread."""
-        with self._commandsCondition:
-            self._commands.append(command)
-            self._commandsCondition.notify()
-
-    def _callSimBrief(self, plan, driver,
-                      getCredentials, updateProgress, htmlFilePath):
-        """Perform the SimBrief call."""
-        self._simBriefBrowser.LoadUrl(self.simBriefInitURL)
-
-        integrator = MavaSimbriefIntegrator(plan = plan, driver = driver)
-        link = None
-        try:
-            link = integrator.get_xml_link(getCredentials, updateProgress,
-                                           local_xml_debug = False,
-                                           local_html_debug = False)
-        except Exception, e:
-            print "Failed to initiate the generation of the briefing:", e
-            updateProgress(SIMBRIEF_PROGRESS_RETRIEVING_BRIEFING,
-                           SIMBRIEF_RESULT_ERROR_OTHER, None)
-
-        if link is not None:
-            updateProgress(SIMBRIEF_PROGRESS_RETRIEVING_BRIEFING,
-                           SIMBRIEF_RESULT_NONE, None)
-
-            try:
-                flight_info = integrator.get_results(link,
-                                                     html_file_path =
-                                                     htmlFilePath)
-
-                updateProgress(SIMBRIEF_PROGRESS_DONE,
-                               SIMBRIEF_RESULT_OK, flight_info)
-            except Exception, e:
-                print "Failed to retrieve the briefing:", e
-                updateProgress(SIMBRIEF_PROGRESS_RETRIEVING_BRIEFING,
-                               SIMBRIEF_RESULT_ERROR_OTHER, None)
-
-    def _quit(self):
-        """Set the _toQuit member variable to indicate that the thread should
-        quit."""
-        self._toQuit = True
-
-#------------------------------------------------------------------------------
-
-def initialize(programDirectory, initializedCallback):
+        self._timeoutID = gobject.timeout_add(120*1000, self._timedOut)
+
+        self._plan = plan
+        self._getCredentials = getCredentials
+        self._getCredentialsCount = 0
+        self._updateProgressFn = updateProgress
+        self._htmlFilePath = htmlFilePath
+
+        self._browser.LoadUrl(SimBriefHandler._formURL)
+        self._updateProgress(SIMBRIEF_PROGRESS_LOADING_FORM,
+                             SIMBRIEF_RESULT_NONE, None)
+
+    def _onLoadEnd(self, browser, frame, httpCode):
+        """Called when a page has been loaded in the SimBrief browser."""
+        url = frame.GetUrl()
+        print "gui.cef.SimBriefHandler._onLoadEnd", httpCode, url
+        if httpCode>=300:
+            self._updateProgress(self._lastProgress,
+                                 SIMBRIEF_RESULT_ERROR_OTHER, None)
+        elif url.startswith("http://flare.privatedns.org/mava_simbrief/simbrief_form.html"):
+            if self._plan is None:
+                return
+
+            self._updateProgress(SIMBRIEF_PROGRESS_FILLING_FORM,
+                                 SIMBRIEF_RESULT_NONE, None)
+
+            js = "form=document.getElementById(\"sbapiform\");"
+            for (name, value) in self._plan.iteritems():
+                js += "form." + name + ".value=\"" + value + "\";"
+            for (name, value) in SimBriefHandler._querySettings.iteritems():
+                if isinstance(value, bool):
+                    js += "form." + name + ".checked=" + \
+                      ("true" if value else "false") + ";"
+                elif isinstance(value, str):
+                    js += "form." + name + ".value=\"" + value + "\";"
+
+            js += "form.submitform.click();"
+            js += "window.formFilled();"
+
+            frame.ExecuteJavascript(js)
+        elif url.startswith("http://www.simbrief.com/system/login.api.php"):
+            (user, password) = self._getCredentials(self._getCredentialsCount)
+            if user is None or password is None:
+                self._updateProgress(SIMBRIEF_PROGRESS_WAITING_LOGIN,
+                                     SIMBRIEF_RESULT_ERROR_LOGIN_FAILED, None)
+                return
+
+            self._getCredentialsCount += 1
+            js = "form=document.forms[0];"
+            js += "form.user.value=\"" + user + "\";"
+            js += "form.pass.value=\"" + password + "\";"
+            js += "form.submit();"
+            frame.ExecuteJavascript(js)
+        elif url.startswith("http://www.simbrief.com/ofp/ofp.loader.api.php"):
+            self._updateProgress(SIMBRIEF_PROGRESS_WAITING_RESULT,
+                                 SIMBRIEF_RESULT_NONE, None)
+        elif url.startswith("http://flare.privatedns.org/mava_simbrief/simbrief_briefing.php"):
+            js = "form=document.getElementById(\"hiddenform\");"
+            js += "window.briefingData(form.hidden_is_briefing_available.value, form.hidden_link.value);";
+            frame.ExecuteJavascript(js)
+
+    def _formFilled(self):
+        """Called when the form has been filled and submitted."""
+        self._updateProgress(SIMBRIEF_PROGRESS_WAITING_LOGIN,
+                             SIMBRIEF_RESULT_NONE, None)
+
+    def _briefingDataAvailable(self, available, link):
+        """Called when the briefing data is available."""
+        if available:
+            link ="http://www.simbrief.com/ofp/flightplans/xml/" + link + ".xml"
+
+            self._updateProgress(SIMBRIEF_PROGRESS_RETRIEVING_BRIEFING,
+                                 SIMBRIEF_RESULT_NONE, None)
+
+            thread = threading.Thread(target = self._getResults, args = (link,))
+            thread.daemon = True
+            thread.start()
+        else:
+            self._updateProgress(SIMBRIEF_PROGRESS_RETRIEVING_BRIEFING,
+                                 SIMBRIEF_RESULT_ERROR_OTHER, None)
+
+    def _resultsAvailable(self, flightInfo):
+        """Called from the result retrieval thread when the result is
+        available.
+
+        It checks for the plan being not None, as we may time out."""
+        if self._plan is not None:
+            self._updateProgress(SIMBRIEF_PROGRESS_DONE,
+                                 SIMBRIEF_RESULT_OK, flightInfo)
+
+    def _updateProgress(self, progress, results, flightInfo):
+        """Update the progress."""
+        self._lastProgress = progress
+        if results!=SIMBRIEF_RESULT_NONE:
+            gobject.source_remove(self._timeoutID)
+            self._plan = None
+
+        self._updateProgressFn(progress, results, flightInfo)
+
+    def _timedOut(self):
+        """Called when the timeout occurs."""
+        if self._lastProgress==SIMBRIEF_PROGRESS_LOADING_FORM:
+            result = SIMBRIEF_RESULT_ERROR_NO_FORM
+        elif self._lastProgress==SIMBRIEF_PROGRESS_WAITING_LOGIN:
+            result = SIMBRIEF_RESULT_ERROR_NO_POPUP
+        else:
+            result = SIMBRIEF_RESULT_ERROR_OTHER
+
+        self._updateProgress(self._lastProgress, result, None)
+
+        return False
+
+    def _getResults(self, link):
+        """Get the result from the given link."""
+        availableInfo = {}
+        ## Holds analysis data to be used
+        flightInfo = {}
+
+        # Obtaining the xml
+        response = urllib2.urlopen(link)
+        xmlContent = response.read()
+        # Processing xml
+        content = etree.iterparse(StringIO(xmlContent))
+
+        for (action, element) in content:
+            # Processing tags that occur multiple times
+            if element.tag == "weather":
+                weatherElementList = list(element)
+                for weatherElement in weatherElementList:
+                    flightInfo[weatherElement.tag] = weatherElement.text
+            else:
+                availableInfo[element.tag] = element.text
+
+        # Processing plan_html
+        ## Obtaining chart links
+        imageLinks = []
+        for imageLinkElement in lxml.html.find_class(availableInfo["plan_html"],
+                                                     "ofpmaplink"):
+            for imageLink in imageLinkElement.iterlinks():
+                if imageLink[1] == 'src':
+                    imageLinks.append(imageLink[2])
+        flightInfo["image_links"] = imageLinks
+        print(sorted(availableInfo.keys()))
+        htmlFilePath = "simbrief_plan.html" if self._htmlFilePath is None \
+          else self._htmlFilePath
+        with open(htmlFilePath, 'w') as f:
+            f.write(availableInfo["plan_html"])
+
+        gobject.idle_add(self._resultsAvailable, flightInfo)
+
+#------------------------------------------------------------------------------
+
+def initialize(initializedCallback):
     """Initialize the Chrome Embedded Framework."""
-    global _toQuit, _seleniumHandler
+    global _toQuit, _simBriefHandler
     _toQuit = False
 
     gobject.threads_init()
 
-    argsFilePath = getArgsFilePath()
-    try:
-        os.unlink(argsFilePath)
-    except:
-        pass
-
-    _seleniumHandler = SeleniumHandler(programDirectory)
-    _seleniumHandler.start()
-
-    ArgsFileWaiter(initializedCallback).start()
+    _simBriefHandler = SimBriefHandler()
+    _initializeCEF([], initializedCallback)
 
 #------------------------------------------------------------------------------
@@ -307,5 +320,10 @@
     """Start a browser instance in the given container with the given URL."""
     if os.name=="nt":
-        windowID = container.get_window().handle
+        window = container.get_window()
+        if window is None:
+            print "mlx.gui.cef.startInContainer: no window found!"
+            windowID = None
+        else:
+            windowID = window.handle
     else:
         m = re.search("GtkVBox at 0x(\w+)", str(container))
@@ -314,5 +332,6 @@
 
     windowInfo = cefpython.WindowInfo()
-    windowInfo.SetAsChild(windowID)
+    if windowID is not None:
+        windowInfo.SetAsChild(windowID)
 
     return cefpython.CreateBrowserSync(windowInfo,
@@ -376,12 +395,13 @@
 def initializeSimBrief():
     """Initialize the (hidden) browser window for SimBrief."""
-    _seleniumHandler.initializeSimBrief()
+    _simBriefHandler.initialize()
 
 #------------------------------------------------------------------------------
 
 def callSimBrief(plan, getCredentials, updateProgress, htmlFilePath):
-    """Call SimBrief with the given plan."""
-    _seleniumHandler.callSimBrief(plan, getCredentials,
-                                  updateProgress, htmlFilePath)
+    """Call SimBrief with the given plan.
+
+    The callbacks will be called in the main GUI thread."""
+    _simBriefHandler.call(plan, getCredentials, updateProgress, htmlFilePath)
 
 #------------------------------------------------------------------------------
@@ -389,8 +409,7 @@
 def finalize():
     """Finalize the Chrome Embedded Framework."""
-    global _toQuit, _seleniumHandler
-    toQuit = True
+    global _toQuit
+    _toQuit = True
     cefpython.Shutdown()
-    _seleniumHandler.quit()
 
 #------------------------------------------------------------------------------
@@ -406,36 +425,7 @@
 #------------------------------------------------------------------------------
 
-def startFastTimeout():
-    """Start the fast timeout handler."""
-    global _fastTimeoutUsers
-
-    if _fastTimeoutUsers==0:
-        _fastTimeoutUsers = 1
-        gobject.timeout_add(1, _handleFastTimeout)
-    else:
-        _fastTimeoutUsers += 1
-
-#------------------------------------------------------------------------------
-
-def stopFastTimeout():
-    """Stop the fast timeout handler."""
-    global _fastTimeoutUsers
-
-    assert _fastTimeoutUsers>0
-    _fastTimeoutUsers -= 1
-
-#------------------------------------------------------------------------------
-
-def _handleFastTimeout():
-    """Handle a (fast) timeout by running the CEF message loop."""
-    if _toQuit or _fastTimeoutUsers==0:
-        return False
-    else:
-        cefpython.MessageLoopWork()
-        return True
-
-#------------------------------------------------------------------------------
-
 def _handleSizeAllocate(widget, sizeAlloc):
     """Handle the size-allocate event."""
-    cefpython.WindowUtils.OnSize(widget.get_window().handle, 0, 0, 0)
+    window = widget.get_window()
+    if widget is not None:
+        cefpython.WindowUtils.OnSize(window.handle, 0, 0, 0)
Index: src/mlx/gui/flight.py
===================================================================
--- src/mlx/gui/flight.py	(revision 798)
+++ src/mlx/gui/flight.py	(revision 805)
@@ -2500,9 +2500,4 @@
         table.attach(self._rememberButton, 1, 2, 2, 3, ypadding = 8)
 
-        self._credentialsCondition = threading.Condition()
-        self._credentialsAvailable = False
-        self._credentialsUserName = None
-        self._credentialsPassword = None
-
         label = gtk.Label(xstr("simbrief_extra_fuel"))
         label.set_use_underline(True)
@@ -2675,23 +2670,10 @@
             self._wizard.gui.beginBusy(xstr("simbrief_calling"))
 
-            cef.startFastTimeout()
             cef.callSimBrief(plan,
-                             self._getCredentialsCallback,
-                             self._simBriefProgressCallback,
+                             self._getCredentials,
+                             self._simBriefProgress,
                              SimBriefSetupPage.getHTMLFilePath())
 
             startSound(const.SOUND_NOTAM)
-
-    def _getCredentialsCallback(self, count):
-        """Called when the SimBrief home page requests the credentials."""
-        with self._credentialsCondition:
-            self._credentialsAvailable = False
-
-            gobject.idle_add(self._getCredentials, count)
-
-            while not self._credentialsAvailable:
-                self._credentialsCondition.wait()
-
-            return (self._credentialsUserName, self._credentialsPassword)
 
     def _getCredentials(self, count):
@@ -2701,42 +2683,35 @@
         are returned. Otherwise a dialog box is displayed informing the user of
         invalid credentials and requesting another set of them."""
-        with self._credentialsCondition:
-            if count==0:
-                self._credentialsUserName = self._userName.get_text()
-                self._credentialsPassword = self._password.get_text()
+        print "_getCredentials", count
+        if count==0:
+            return (self._userName.get_text(), self._password.get_text())
+        else:
+            gui = self._wizard.gui
+            config = gui.config
+
+            dialog = SimBriefCredentialsDialog(gui,
+                                               config.simBriefUserName,
+                                               config.simBriefPassword,
+                                               config.rememberSimBriefPassword)
+            response = dialog.run()
+
+            if response==RESPONSETYPE_OK:
+                userName = dialog.userName
+                self._userName.set_text(userName)
+                password = dialog.password
+                self._password.set_text(password)
+                rememberPassword = dialog.rememberPassword
+
+                config.simBriefUserName = userName
+
+                config.simBriefPassword = \
+                    password if rememberPassword else ""
+                config.rememberSimBriefPassword = rememberPassword
+
+                config.save()
+
+                return (userName, password)
             else:
-                gui = self._wizard.gui
-                config = gui.config
-
-                dialog = SimBriefCredentialsDialog(gui,
-                                                   config.simBriefUserName,
-                                                   config.simBriefPassword,
-                                                   config.rememberSimBriefPassword)
-                response = dialog.run()
-
-                if response==RESPONSETYPE_OK:
-                    self._credentialsUserName = dialog.userName
-                    self._userName.set_text(self._credentialsUserName)
-                    self._credentialsPassword = dialog.password
-                    self._password.set_text(self._credentialsPassword)
-                    rememberPassword = dialog.rememberPassword
-
-                    config.simBriefUserName = self._credentialsUserName
-
-                    config.simBriefPassword = \
-                        self._credentialsPassword if rememberPassword else ""
-                    config.rememberSimBriefPassword = rememberPassword
-
-                    config.save()
-                else:
-                    self._credentialsUserName = None
-                    self._credentialsPassword = None
-
-            self._credentialsAvailable = True
-            self._credentialsCondition.notify()
-
-    def _simBriefProgressCallback(self, progress, result, flightInfo):
-        """Called by the SimBrief handling thread."""
-        gobject.idle_add(self._simBriefProgress, progress, result, flightInfo)
+                return (None, None)
 
     def _simBriefProgress(self, progress, result, flightInfo):
@@ -2748,5 +2723,4 @@
             self._wizard.gui.updateBusyState(xstr(message))
         else:
-            cef.stopFastTimeout()
             self._wizard.gui.endBusy()
 
Index: src/mlx/gui/gui.py
===================================================================
--- src/mlx/gui/gui.py	(revision 798)
+++ src/mlx/gui/gui.py	(revision 805)
@@ -450,5 +450,5 @@
             self.updateDone()
 
-        cef.initialize(self._programDirectory, self._cefInitialized)
+        cef.initialize(self._cefInitialized)
 
         singleton.raiseCallback = self.raiseCallback
Index: src/mlx/gui/mava_simbrief.py
===================================================================
--- src/mlx/gui/mava_simbrief.py	(revision 701)
+++ 	(revision )
@@ -1,390 +1,0 @@
-# needed for os specific separators
-import os
-# selenium is needed for browser manipulation
-from selenium import webdriver
-from selenium.common.exceptions import NoSuchElementException
-from selenium.common.exceptions import NoSuchWindowException
-from selenium.webdriver.common.by import By
-from selenium.webdriver.support.ui import WebDriverWait, Select
-from selenium.webdriver.support import expected_conditions as EC
-from selenium.webdriver.common.keys import Keys
-# urllib is needed to obtain the xml
-import urllib2
-# xmlparser
-from lxml import etree
-from StringIO import StringIO
-import lxml.html
-import time
-
-
-class MavaSimbriefIntegrator():
-    """Implements the integration with the excellent Simbrief pilot briefing
-    system for MALEV Virtual."""
-
-    # Progress stage: searching the suitable browser window
-    PROGRESS_SEARCHING_BROWSER = 1
-
-    # Progress stage: retrieving the form from the server
-    PROGRESS_LOADING_FORM = 2
-
-    # Progress stage: filling the form
-    PROGRESS_FILLING_FORM = 3
-
-    # Progress stage: waiting for the login
-    PROGRESS_WAITING_LOGIN = 4
-
-    # Progress stage: logging in
-    PROGRESS_LOGGING_IN = 5
-
-    # Progress stage: waiting for result
-    PROGRESS_WAITING_RESULT = 6
-
-    # The maximal reserved progress stage
-    PROGRESS_MAX = 16
-
-    # Result code: none (i.e. the SimBrief query is in progress).
-    RESULT_NONE = 0
-
-    # Result code: success
-    RESULT_OK = 1
-
-    # Result code: other error
-    RESULT_ERROR_OTHER = 2
-
-    # Result code: form could not be loaded
-    RESULT_ERROR_NO_FORM = 11
-
-    # Result code: no popup (i.e. login) window found
-    RESULT_ERROR_NO_POPUP = 12
-
-    # Result code: login failed
-    RESULT_ERROR_LOGIN_FAILED = 13
-
-    # The maximal reserved result code
-    RESULT_MAX = 32
-
-    def __init__(self,
-                 plan,
-                 driver=None,
-                 simbrief_query_settings=None,
-                 mava_simbrief_url=None,
-                 xml_link_fix_part=None):
-        """Init the integrator with settings that are typical of our use.
-        @param: plan - flightplan dictionary
-        @param: webdriver - a selenium webdriver
-        @param: simbrief_query_settings - a dictionary of query settings
-        @param: mava_simbrief_url - url to the form that is sent to simbrief
-        on the mava server
-        @param: xml_link_fix_part = url to the simbrief website under which the
-        xml is to be found"""
-        self.plan = plan
-        if simbrief_query_settings is None:
-            self.simbrief_query_settings = {
-                'navlog': True,
-                'etops': True,
-                'stepclimbs': True,
-                'tlr': True,
-                'notams': True,
-                'firnot': True,
-                'maps': 'Simple',
-            }
-        else:
-            self.simbrief_query_settings = simbrief_query_settings
-
-        if driver is None:
-            self.driver = webdriver.Firefox()
-        else:
-            self.driver = driver
-
-        if mava_simbrief_url is None:
-            self.mava_simbrief_url = "http://flare.privatedns.org/" \
-                                     "mava_simbrief/simbrief_form.html"
-        else:
-            self.mava_simbrief_url = mava_simbrief_url
-
-        if xml_link_fix_part is None:
-            self.xml_link_fix_part = "http://www.simbrief.com/ofp/" \
-                                     "flightplans/xml/"
-        else:
-            self.xml_link_fix_part = xml_link_fix_part
-
-    def fill_form(self,
-                  plan,
-                  simbrief_query_settings):
-        """Fills the form of the webpage using the paramteres that the class
-        has been initialized with.
-        @param: driver - a selenium webdriver
-        @param: plan - dictionary containing plan details
-        @param: simbrief_query_settings - dictionary containing plan settings"""
-        for plan_input_field in plan.iterkeys():
-            self.driver.find_element_by_name(plan_input_field).send_keys(
-                plan[plan_input_field])
-        for option_checkbox in simbrief_query_settings.iterkeys():
-            if (isinstance(simbrief_query_settings[option_checkbox], bool) and
-                    simbrief_query_settings[option_checkbox]):
-                # if setting is a boolean type and true
-                self.driver.find_element_by_name(option_checkbox).click()
-            elif isinstance(simbrief_query_settings[option_checkbox], str):
-                # if setting is a select
-                Select(self.driver.find_element_by_name(option_checkbox)).\
-                    select_by_visible_text(simbrief_query_settings[
-                    option_checkbox])
-
-    def get_xml_link(self,
-                     get_credentials, update_progress,
-                     local_xml_debug=False,
-                     local_html_debug=False):
-        """Obtains the link of the xml to be processed.
-        @param get_credentials - a function, which should return a pair of the
-        user name and password to log in to SimBrief. It gets an integer which
-        is the number of times it has been called so far.
-        @param local_xml_debug - if True then not the real location will be
-        checked but the current working dir will be searched for 'xml.xml'
-        @param local_html_debug - if True then not real mava_simbrief_url will
-        be used but the current working dir will be searched for
-        'mava_simbrief.html'
-        @returns: the string of the xml link if it could be obtained and None
-        otherwise"""
-        # Finding xml_link
-        is_briefing_available = False
-        if local_xml_debug:
-            # set link for locally debugging an existing xml file
-            xml_link = ("file://"
-                        + os.getcwd()
-                        + os.sep
-                        + "xml.xml")
-            is_briefing_available = True
-        else:
-            update_progress(MavaSimbriefIntegrator.PROGRESS_SEARCHING_BROWSER,
-                            MavaSimbriefIntegrator.RESULT_NONE, None)
-            # There must be window whose title is 'SimBrief' so that we
-            # could find our one among several
-            if self._find_window_by_title("SimBrief") is None:
-                print "No SimBrief window was found!"
-                update_progress(MavaSimbriefIntegrator.PROGRESS_SEARCHING_BROWSER,
-                                MavaSimbriefIntegrator.RESULT_ERROR_OTHER, None)
-                return None
-
-            # normal operation with a real xml file
-            update_progress(MavaSimbriefIntegrator.PROGRESS_LOADING_FORM,
-                            MavaSimbriefIntegrator.RESULT_NONE, None)
-            if local_html_debug:
-                self.driver.get(
-                    "file://" + os.getcwd() + os.sep + "simbrief_form.html")
-                is_briefing_available = True
-            else:
-                self.driver.get(self.mava_simbrief_url)
-
-            main_handle = self._find_window_by_title("Malev Virtual Simbrief Integration System")
-            if main_handle is None:
-                print "No SimBrief Integration window was found!"
-                update_progress(MavaSimbriefIntegrator.PROGRESS_LOADING_FORM,
-                                MavaSimbriefIntegrator.RESULT_ERROR_NO_FORM, None)
-                return None
-
-            # Make a copy of the window handles before submitting the form,
-            # so that we could find the popup
-            handles = self.driver.window_handles[:]
-
-            # Entering form data
-            update_progress(MavaSimbriefIntegrator.PROGRESS_FILLING_FORM,
-                            MavaSimbriefIntegrator.RESULT_NONE, None)
-            self.driver.switch_to_window(main_handle)
-            self.fill_form(self.plan,
-                           self.simbrief_query_settings)
-
-            # Loading page
-            button = self.driver.find_element_by_name("submitform")
-            button.send_keys(Keys.RETURN)
-
-            update_progress(MavaSimbriefIntegrator.PROGRESS_WAITING_LOGIN,
-                            MavaSimbriefIntegrator.RESULT_NONE, None)
-            popup_handle = self._find_popup(handles)
-            if popup_handle is None:
-                update_progress(MavaSimbriefIntegrator.PROGRESS_WAITING_LOGIN,
-                                MavaSimbriefIntegrator.RESULT_ERROR_NO_POPUP, None)
-                return None
-
-            login_count = 0
-            end_time = time.time() + 120.0
-            while not is_briefing_available and end_time > time.time():
-                try:
-                    self.driver.switch_to.window(popup_handle)
-
-                    userElement = self.driver.find_element_by_name("user")
-
-                    if userElement is not None:
-                        update_progress(MavaSimbriefIntegrator.PROGRESS_LOGGING_IN,
-                                        MavaSimbriefIntegrator.RESULT_NONE, None)
-                        (userName, password) = get_credentials(login_count)
-                        end_time = time.time() + 120.0
-                        if userName is None or password is None:
-                            update_progress(MavaSimbriefIntegrator.PROGRESS_WAITING_LOGIN,
-                                            MavaSimbriefIntegrator.RESULT_ERROR_LOGIN_FAILED, None)
-                            return None
-
-                        userElement.send_keys(userName)
-                        self.driver.find_element_by_name("pass").send_keys(password)
-                        self.driver.find_element_by_name("staylogged").click()
-
-                        self.driver.find_element(By.XPATH,
-                                                "//input[@value='Login']").send_keys(Keys.RETURN)
-                        login_count += 1
-                except NoSuchElementException:
-                    pass
-                except NoSuchWindowException:
-                    pass
-
-                update_progress(MavaSimbriefIntegrator.PROGRESS_WAITING_RESULT,
-                                MavaSimbriefIntegrator.RESULT_NONE, None)
-                self.driver.switch_to.window(main_handle)
-                try:
-                    if self.driver.find_element_by_name("hidden_is_briefing_available") is not None:
-                        is_briefing_available = True
-                        xml_link_element = self.driver.find_element_by_name(
-                            'hidden_link')
-                        xml_link_generated_part = xml_link_element.get_attribute(
-                            'value')
-                        xml_link = self.xml_link_fix_part + xml_link_generated_part + '.xml'
-                        print(xml_link)
-                except NoSuchElementException:
-                    pass
-
-        if is_briefing_available:
-            return xml_link
-        else:
-            update_progress(MavaSimbriefIntegrator.PROGRESS_WAITING_RESULT,
-                            MavaSimbriefIntegrator.RESULT_ERROR_OTHER, None)
-            return None
-
-    def get_results(self,
-                    xml_link,
-                    html_file_path = None):
-        """Parses the xml for information.
-        @param xml_link - a path to the xml file
-        @return a dictionary of the found information"""
-        # Setup variables
-        ## Holds analysis data not used
-        available_info = {}
-        ## Holds analysis data to be used
-        flight_info = {}
-        ## Holds notams
-        notams_list = []
-        ## Notam counter
-        i = 0
-        # Obtaining the xml
-        response = urllib2.urlopen(xml_link)
-        xml_content = response.read()
-        # Processing xml
-        tree = etree.parse(StringIO(xml_content))
-        context = etree.iterparse(StringIO(xml_content))
-        for action, element in context:
-            # Processing tags that occur multiple times
-            ## NOTAMS
-            if element.tag == 'notamdrec':
-                notams_element_list = list(element)
-                notam_dict = {}
-                for notam in notams_element_list:
-                    notam_dict[notam.tag] = notam.text
-                notams_list.append(notam_dict)
-                i += 1
-            ## WEATHER
-            elif element.tag == 'weather':
-                weather_element_list = list(element)
-                for weather in weather_element_list:
-                    flight_info[weather.tag] = weather.text
-            else:
-                available_info[element.tag] = element.text
-        # Processing plan_html
-        ## Obtaining chart links
-        image_links = []
-        for image_link_a_element in lxml.html.find_class(
-                available_info['plan_html'], 'ofpmaplink'):
-            for image_link_tuple in image_link_a_element.iterlinks():
-                if image_link_tuple[1] == 'src':
-                    image_links.append(image_link_tuple[2])
-        flight_info['image_links'] = image_links
-        print(sorted(available_info.keys()))
-        if html_file_path is None:
-            html_file_path = 'simbrief_plan.html'
-        with open(html_file_path, 'w') as f:
-            f.write(available_info['plan_html'])
-        return flight_info
-
-    def _find_window_by_title(self, title, timeout = 10.0):
-        """Find the window with the given title.
-
-        Switch to that window and return its handle."""
-        def predicate(handle):
-            self.driver.switch_to.window(handle)
-            return self.driver.title == title
-
-        return self._find_window(predicate, timeout = timeout)
-
-    def _find_popup(self, handles, timeout = 10.0):
-        """Find a popup, i.e. a new window being created.
-
-        handles is a list of window handles that existed before the popup was
-        expected to be created. If a new handle is found, that is assumed to be
-        the popup window."""
-        return self._find_window(lambda handle: handle not in handles,
-                                 timeout = timeout)
-
-    def _find_window(self, predicate, timeout = 10.0):
-        """Find a window that fulfills the given predicate."""
-        window_handle = None
-        end_time = time.time() + timeout
-        while window_handle is None and end_time > time.time():
-            for handle in self.driver.window_handles:
-                if predicate(handle):
-                    window_handle = handle
-                    break
-
-        return window_handle
-
-if __name__ == "__main__":
-    mava_simbrief_url = "http://flare.privatedns.org/" \
-                        "mava_simbrief/simbrief_form.html"
-    xml_link_fix_part = "http://www.simbrief.com/ofp/" \
-                        "flightplans/xml/"
-    plan = {
-        'airline': 'MAH',
-        'fltnum': '764',
-        'type': 'B738',
-        'orig': 'LHBP',
-        'dest': 'LSZH',
-        'date': '25FEB15',
-        'deph': '20',
-        'depm': '00',
-        'route': 'GILEP DCT ARSIN UL851 SITNI UL856 NEGRA',
-        'steh': '22',
-        'stem': '05',
-        'reg': 'HA-LOC',
-        'fin': 'LOC',
-        'selcal': 'XXXX',
-        'pax': '100',
-        'altn': 'LSGG',
-        'fl': '36000',
-        'cpt': 'BALINT SZEBENYI',
-        'pid': 'P008',
-        'fuelfactor': 'P000',
-        'manualzfw': '42.7',
-        'addedfuel': '2.5',
-        'contpct': '0.05',
-        'resvrule': '45',
-        'taxiout': '10',
-        'taxiin': '4',
-        'cargo': '5.0',
-        'origrwy': '31L',
-        'destrwy': '34',
-        'climb': '250/300/78',
-        'descent': '80/280/250',
-        'cruise': 'LRC',
-        'civalue': 'AUTO',
-    }
-    integrator = MavaSimbriefIntegrator(plan=plan)
-    link = integrator.get_xml_link(local_xml_debug=False,
-                                   local_html_debug=False)
-    flight_info = integrator.get_results(link)
-    print(flight_info)
-
