Ignore:
Timestamp:
08/06/16 08:07:39 (8 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Simplified SimBrief handling by using the CEF API directly (re #310)

Location:
src/mlx/gui
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/gui/cef.py

    r713 r805  
    11from common import *
    22
    3 from mava_simbrief import MavaSimbriefIntegrator
    4 
    53from mlx.util import secondaryInstallation
    64
    75from cefpython3 import cefpython
    8 from selenium import webdriver
    9 from selenium.webdriver.chrome.options import Options
    106
    117import platform
     
    1410import os
    1511import re
     12import thread
    1613import threading
    1714import tempfile
    1815import traceback
     16import urllib2
     17from lxml import etree
     18from StringIO import StringIO
     19import lxml.html
    1920
    2021#------------------------------------------------------------------------------
     
    2930_toQuit = False
    3031
    31 # Indicate the users of the fast timeout handler. If it reaches zero, the
    32 # timeout will be stopped
    33 _fastTimeoutUsers = 0
    34 
    35 # The Selenium thread
    36 _seleniumHandler = None
    37 
    38 #------------------------------------------------------------------------------
    39 
    40 def getArgsFilePath():
    41     """Get the path of the argument file."""
    42     if os.name=="nt":
    43         return os.path.join(tempfile.gettempdir(),
    44                             "mlxcef.args" +
    45                             (".secondary" if secondaryInstallation else ""))
    46     else:
    47         import pwd
    48         return os.path.join(tempfile.gettempdir(),
    49                             "mlxcef." + pwd.getpwuid(os.getuid())[0] + ".args" +
    50                             (".secondary" if secondaryInstallation else ""))
    51 
    52 #------------------------------------------------------------------------------
    53 
    54 class ArgsFileWaiter(threading.Thread):
    55     """A thread to wait for the appearance of the arguments file."""
    56     def __init__(self, initializedCallback):
    57         """Construct the thread."""
    58         threading.Thread.__init__(self)
    59         self.daemon = True
    60 
    61         self._initializedCallback = initializedCallback
    62 
    63     def run(self):
    64         """Repeatedly check for the existence of the arguments file.
    65 
    66         If it is found, read it, extract the arguments and insert a job into
    67         the GUI loop to perform the actual initialization of CEF."""
    68         argsFilePath = getArgsFilePath()
    69         print "Waiting for the arguments file '%s' to appear" % (argsFilePath,)
    70 
    71         while not os.path.exists(argsFilePath):
    72             time.sleep(0.1)
    73 
    74         print "Got arguments, reading them."""
    75 
    76         with open(argsFilePath, "rt") as f:
    77             args = f.read().split()
    78 
    79         gobject.idle_add(_initializeCEF, args, self._initializedCallback)
    80 
    81 #------------------------------------------------------------------------------
    82 
    83 SIMBRIEF_PROGRESS_SEARCHING_BROWSER = MavaSimbriefIntegrator.PROGRESS_SEARCHING_BROWSER
    84 SIMBRIEF_PROGRESS_LOADING_FORM = MavaSimbriefIntegrator.PROGRESS_LOADING_FORM
    85 SIMBRIEF_PROGRESS_FILLING_FORM = MavaSimbriefIntegrator.PROGRESS_FILLING_FORM
    86 SIMBRIEF_PROGRESS_WAITING_LOGIN = MavaSimbriefIntegrator.PROGRESS_WAITING_LOGIN
    87 SIMBRIEF_PROGRESS_LOGGING_IN = MavaSimbriefIntegrator.PROGRESS_LOGGING_IN
    88 SIMBRIEF_PROGRESS_WAITING_RESULT = MavaSimbriefIntegrator.PROGRESS_WAITING_RESULT
    89 
    90 SIMBRIEF_PROGRESS_RETRIEVING_BRIEFING = MavaSimbriefIntegrator.PROGRESS_MAX + 1
     32# The SimBrief handler
     33_simBriefHandler = None
     34
     35#------------------------------------------------------------------------------
     36
     37SIMBRIEF_PROGRESS_SEARCHING_BROWSER = 1
     38SIMBRIEF_PROGRESS_LOADING_FORM = 2
     39SIMBRIEF_PROGRESS_FILLING_FORM = 3
     40SIMBRIEF_PROGRESS_WAITING_LOGIN = 4
     41SIMBRIEF_PROGRESS_LOGGING_IN = 5
     42SIMBRIEF_PROGRESS_WAITING_RESULT = 6
     43
     44SIMBRIEF_PROGRESS_RETRIEVING_BRIEFING = 7
    9145SIMBRIEF_PROGRESS_DONE = 1000
    9246
    93 SIMBRIEF_RESULT_NONE = MavaSimbriefIntegrator.RESULT_NONE
    94 SIMBRIEF_RESULT_OK = MavaSimbriefIntegrator.RESULT_OK
    95 SIMBRIEF_RESULT_ERROR_OTHER = MavaSimbriefIntegrator.RESULT_ERROR_OTHER
    96 SIMBRIEF_RESULT_ERROR_NO_FORM = MavaSimbriefIntegrator.RESULT_ERROR_NO_FORM
    97 SIMBRIEF_RESULT_ERROR_NO_POPUP = MavaSimbriefIntegrator.RESULT_ERROR_NO_POPUP
    98 SIMBRIEF_RESULT_ERROR_LOGIN_FAILED = MavaSimbriefIntegrator.RESULT_ERROR_LOGIN_FAILED
    99 
    100 #------------------------------------------------------------------------------
    101 
    102 class SeleniumHandler(threading.Thread):
    103     """Thread to handle Selenium operations."""
    104     def __init__(self, programDirectory):
    105         """Construct the thread."""
    106         threading.Thread.__init__(self)
    107         self.daemon = False
    108 
    109         self._programDirectory = programDirectory
    110 
    111         self._commandsCondition = threading.Condition()
    112         self._commands = []
    113 
    114         self._driver = None
    115 
    116         self._simBriefBrowser = None
    117 
    118         self._toQuit = False
    119 
    120     @property
    121     def programDirectory(self):
    122         """Get the program directory."""
    123         return self._programDirectory
    124 
    125     @property
    126     def simBriefInitURL(self):
    127         """Get the initial URL for the SimBrief browser."""
    128         return "file://" + os.path.join(self.programDirectory, "simbrief.html")
    129 
    130     def run(self):
    131         """Create the Selenium driver and the perform any operations
    132         requested."""
    133         scriptName = "mlx_cef_caller"
    134         if secondaryInstallation:
    135             scriptName += "_secondary"
    136         scriptName += ".bat" if os.name=="nt" else ".sh"
    137 
    138         scriptPath = os.path.join(self._programDirectory, scriptName)
    139         print "Creating the Selenium driver to call script", scriptPath
    140 
    141         options = Options()
    142         options.binary_location = scriptPath
    143         driver = self._driver = webdriver.Chrome(chrome_options = options)
    144         # try:
    145         # except:
    146         #     traceback.print_exc()
    147 
    148         print "Created Selenium driver."
    149         while not self._toQuit:
    150             with self._commandsCondition:
    151                 while not self._commands:
    152                     self._commandsCondition.wait()
    153 
    154                 command = self._commands[0]
    155                 del self._commands[0]
    156 
    157             command()
    158 
    159         driver.quit()
    160 
    161     def initializeSimBrief(self):
     47SIMBRIEF_RESULT_NONE = 0
     48SIMBRIEF_RESULT_OK = 1
     49SIMBRIEF_RESULT_ERROR_OTHER = 2
     50SIMBRIEF_RESULT_ERROR_NO_FORM = 11
     51SIMBRIEF_RESULT_ERROR_NO_POPUP = 12
     52SIMBRIEF_RESULT_ERROR_LOGIN_FAILED = 13
     53
     54#------------------------------------------------------------------------------
     55
     56class SimBriefHandler(object):
     57    """An object to store the state of a SimBrief query."""
     58    _formURL = "http://flare.privatedns.org/mava_simbrief/simbrief_form.html"
     59
     60    _querySettings = {
     61        'navlog': True,
     62        'etops': True,
     63        'stepclimbs': True,
     64        'tlr': True,
     65        'notams': True,
     66        'firnot': True,
     67        'maps': 'Simple',
     68        };
     69
     70
     71    def __init__(self):
     72        """Construct the handler."""
     73        self._browser = None
     74        self._plan = None
     75        self._getCredentials = None
     76        self._getCredentialsCount = 0
     77        self._updateProgressFn = None
     78        self._htmlFilePath = None
     79        self._lastProgress = SIMBRIEF_PROGRESS_SEARCHING_BROWSER
     80        self._timeoutID = None
     81
     82    def initialize(self):
    16283        """Create and initialize the browser used for Simbrief."""
    16384        windowInfo = cefpython.WindowInfo()
    16485        windowInfo.SetAsOffscreen(int(0))
    16586
    166         url = self.simBriefInitURL
    167         self._simBriefBrowser = \
     87        self._browser = \
    16888          cefpython.CreateBrowserSync(windowInfo, browserSettings = {},
    169                                       navigateUrl = self.simBriefInitURL)
    170         self._simBriefBrowser.SetClientHandler(OffscreenRenderHandler())
    171         self._simBriefBrowser.SetFocus(True)
    172 
    173     def callSimBrief(self, plan, getCredentials, updateProgress,
    174                      htmlFilePath):
     89                                      navigateUrl = SimBriefHandler._formURL)
     90        self._browser.SetClientHandler(OffscreenRenderHandler())
     91        self._browser.SetFocus(True)
     92        self._browser.SetClientCallback("OnLoadEnd", self._onLoadEnd)
     93
     94        bindings = cefpython.JavascriptBindings(bindToFrames=True,
     95                                                bindToPopups=True)
     96        bindings.SetFunction("briefingData", self._briefingDataAvailable)
     97        bindings.SetFunction("formFilled", self._formFilled)
     98        self._browser.SetJavascriptBindings(bindings)
     99
     100    def call(self, plan, getCredentials, updateProgress, htmlFilePath):
    175101        """Call SimBrief with the given plan."""
    176         self._enqueue(lambda:
    177                       self._callSimBrief(plan, self._driver,
    178                                          getCredentials, updateProgress,
    179                                          htmlFilePath))
    180 
    181     def quit(self):
    182         """Instruct the thread to quit and then join it."""
    183         self._enqueue(self._quit)
    184         self.join()
    185 
    186     def _enqueue(self, command):
    187         """Enqueue the given command.
    188 
    189         command should be a function to be executed in the thread."""
    190         with self._commandsCondition:
    191             self._commands.append(command)
    192             self._commandsCondition.notify()
    193 
    194     def _callSimBrief(self, plan, driver,
    195                       getCredentials, updateProgress, htmlFilePath):
    196         """Perform the SimBrief call."""
    197         self._simBriefBrowser.LoadUrl(self.simBriefInitURL)
    198 
    199         integrator = MavaSimbriefIntegrator(plan = plan, driver = driver)
    200         link = None
    201         try:
    202             link = integrator.get_xml_link(getCredentials, updateProgress,
    203                                            local_xml_debug = False,
    204                                            local_html_debug = False)
    205         except Exception, e:
    206             print "Failed to initiate the generation of the briefing:", e
    207             updateProgress(SIMBRIEF_PROGRESS_RETRIEVING_BRIEFING,
    208                            SIMBRIEF_RESULT_ERROR_OTHER, None)
    209 
    210         if link is not None:
    211             updateProgress(SIMBRIEF_PROGRESS_RETRIEVING_BRIEFING,
    212                            SIMBRIEF_RESULT_NONE, None)
    213 
    214             try:
    215                 flight_info = integrator.get_results(link,
    216                                                      html_file_path =
    217                                                      htmlFilePath)
    218 
    219                 updateProgress(SIMBRIEF_PROGRESS_DONE,
    220                                SIMBRIEF_RESULT_OK, flight_info)
    221             except Exception, e:
    222                 print "Failed to retrieve the briefing:", e
    223                 updateProgress(SIMBRIEF_PROGRESS_RETRIEVING_BRIEFING,
    224                                SIMBRIEF_RESULT_ERROR_OTHER, None)
    225 
    226     def _quit(self):
    227         """Set the _toQuit member variable to indicate that the thread should
    228         quit."""
    229         self._toQuit = True
    230 
    231 #------------------------------------------------------------------------------
    232 
    233 def initialize(programDirectory, initializedCallback):
     102        self._timeoutID = gobject.timeout_add(120*1000, self._timedOut)
     103
     104        self._plan = plan
     105        self._getCredentials = getCredentials
     106        self._getCredentialsCount = 0
     107        self._updateProgressFn = updateProgress
     108        self._htmlFilePath = htmlFilePath
     109
     110        self._browser.LoadUrl(SimBriefHandler._formURL)
     111        self._updateProgress(SIMBRIEF_PROGRESS_LOADING_FORM,
     112                             SIMBRIEF_RESULT_NONE, None)
     113
     114    def _onLoadEnd(self, browser, frame, httpCode):
     115        """Called when a page has been loaded in the SimBrief browser."""
     116        url = frame.GetUrl()
     117        print "gui.cef.SimBriefHandler._onLoadEnd", httpCode, url
     118        if httpCode>=300:
     119            self._updateProgress(self._lastProgress,
     120                                 SIMBRIEF_RESULT_ERROR_OTHER, None)
     121        elif url.startswith("http://flare.privatedns.org/mava_simbrief/simbrief_form.html"):
     122            if self._plan is None:
     123                return
     124
     125            self._updateProgress(SIMBRIEF_PROGRESS_FILLING_FORM,
     126                                 SIMBRIEF_RESULT_NONE, None)
     127
     128            js = "form=document.getElementById(\"sbapiform\");"
     129            for (name, value) in self._plan.iteritems():
     130                js += "form." + name + ".value=\"" + value + "\";"
     131            for (name, value) in SimBriefHandler._querySettings.iteritems():
     132                if isinstance(value, bool):
     133                    js += "form." + name + ".checked=" + \
     134                      ("true" if value else "false") + ";"
     135                elif isinstance(value, str):
     136                    js += "form." + name + ".value=\"" + value + "\";"
     137
     138            js += "form.submitform.click();"
     139            js += "window.formFilled();"
     140
     141            frame.ExecuteJavascript(js)
     142        elif url.startswith("http://www.simbrief.com/system/login.api.php"):
     143            (user, password) = self._getCredentials(self._getCredentialsCount)
     144            if user is None or password is None:
     145                self._updateProgress(SIMBRIEF_PROGRESS_WAITING_LOGIN,
     146                                     SIMBRIEF_RESULT_ERROR_LOGIN_FAILED, None)
     147                return
     148
     149            self._getCredentialsCount += 1
     150            js = "form=document.forms[0];"
     151            js += "form.user.value=\"" + user + "\";"
     152            js += "form.pass.value=\"" + password + "\";"
     153            js += "form.submit();"
     154            frame.ExecuteJavascript(js)
     155        elif url.startswith("http://www.simbrief.com/ofp/ofp.loader.api.php"):
     156            self._updateProgress(SIMBRIEF_PROGRESS_WAITING_RESULT,
     157                                 SIMBRIEF_RESULT_NONE, None)
     158        elif url.startswith("http://flare.privatedns.org/mava_simbrief/simbrief_briefing.php"):
     159            js = "form=document.getElementById(\"hiddenform\");"
     160            js += "window.briefingData(form.hidden_is_briefing_available.value, form.hidden_link.value);";
     161            frame.ExecuteJavascript(js)
     162
     163    def _formFilled(self):
     164        """Called when the form has been filled and submitted."""
     165        self._updateProgress(SIMBRIEF_PROGRESS_WAITING_LOGIN,
     166                             SIMBRIEF_RESULT_NONE, None)
     167
     168    def _briefingDataAvailable(self, available, link):
     169        """Called when the briefing data is available."""
     170        if available:
     171            link ="http://www.simbrief.com/ofp/flightplans/xml/" + link + ".xml"
     172
     173            self._updateProgress(SIMBRIEF_PROGRESS_RETRIEVING_BRIEFING,
     174                                 SIMBRIEF_RESULT_NONE, None)
     175
     176            thread = threading.Thread(target = self._getResults, args = (link,))
     177            thread.daemon = True
     178            thread.start()
     179        else:
     180            self._updateProgress(SIMBRIEF_PROGRESS_RETRIEVING_BRIEFING,
     181                                 SIMBRIEF_RESULT_ERROR_OTHER, None)
     182
     183    def _resultsAvailable(self, flightInfo):
     184        """Called from the result retrieval thread when the result is
     185        available.
     186
     187        It checks for the plan being not None, as we may time out."""
     188        if self._plan is not None:
     189            self._updateProgress(SIMBRIEF_PROGRESS_DONE,
     190                                 SIMBRIEF_RESULT_OK, flightInfo)
     191
     192    def _updateProgress(self, progress, results, flightInfo):
     193        """Update the progress."""
     194        self._lastProgress = progress
     195        if results!=SIMBRIEF_RESULT_NONE:
     196            gobject.source_remove(self._timeoutID)
     197            self._plan = None
     198
     199        self._updateProgressFn(progress, results, flightInfo)
     200
     201    def _timedOut(self):
     202        """Called when the timeout occurs."""
     203        if self._lastProgress==SIMBRIEF_PROGRESS_LOADING_FORM:
     204            result = SIMBRIEF_RESULT_ERROR_NO_FORM
     205        elif self._lastProgress==SIMBRIEF_PROGRESS_WAITING_LOGIN:
     206            result = SIMBRIEF_RESULT_ERROR_NO_POPUP
     207        else:
     208            result = SIMBRIEF_RESULT_ERROR_OTHER
     209
     210        self._updateProgress(self._lastProgress, result, None)
     211
     212        return False
     213
     214    def _getResults(self, link):
     215        """Get the result from the given link."""
     216        availableInfo = {}
     217        ## Holds analysis data to be used
     218        flightInfo = {}
     219
     220        # Obtaining the xml
     221        response = urllib2.urlopen(link)
     222        xmlContent = response.read()
     223        # Processing xml
     224        content = etree.iterparse(StringIO(xmlContent))
     225
     226        for (action, element) in content:
     227            # Processing tags that occur multiple times
     228            if element.tag == "weather":
     229                weatherElementList = list(element)
     230                for weatherElement in weatherElementList:
     231                    flightInfo[weatherElement.tag] = weatherElement.text
     232            else:
     233                availableInfo[element.tag] = element.text
     234
     235        # Processing plan_html
     236        ## Obtaining chart links
     237        imageLinks = []
     238        for imageLinkElement in lxml.html.find_class(availableInfo["plan_html"],
     239                                                     "ofpmaplink"):
     240            for imageLink in imageLinkElement.iterlinks():
     241                if imageLink[1] == 'src':
     242                    imageLinks.append(imageLink[2])
     243        flightInfo["image_links"] = imageLinks
     244        print(sorted(availableInfo.keys()))
     245        htmlFilePath = "simbrief_plan.html" if self._htmlFilePath is None \
     246          else self._htmlFilePath
     247        with open(htmlFilePath, 'w') as f:
     248            f.write(availableInfo["plan_html"])
     249
     250        gobject.idle_add(self._resultsAvailable, flightInfo)
     251
     252#------------------------------------------------------------------------------
     253
     254def initialize(initializedCallback):
    234255    """Initialize the Chrome Embedded Framework."""
    235     global _toQuit, _seleniumHandler
     256    global _toQuit, _simBriefHandler
    236257    _toQuit = False
    237258
    238259    gobject.threads_init()
    239260
    240     argsFilePath = getArgsFilePath()
    241     try:
    242         os.unlink(argsFilePath)
    243     except:
    244         pass
    245 
    246     _seleniumHandler = SeleniumHandler(programDirectory)
    247     _seleniumHandler.start()
    248 
    249     ArgsFileWaiter(initializedCallback).start()
     261    _simBriefHandler = SimBriefHandler()
     262    _initializeCEF([], initializedCallback)
    250263
    251264#------------------------------------------------------------------------------
     
    307320    """Start a browser instance in the given container with the given URL."""
    308321    if os.name=="nt":
    309         windowID = container.get_window().handle
     322        window = container.get_window()
     323        if window is None:
     324            print "mlx.gui.cef.startInContainer: no window found!"
     325            windowID = None
     326        else:
     327            windowID = window.handle
    310328    else:
    311329        m = re.search("GtkVBox at 0x(\w+)", str(container))
     
    314332
    315333    windowInfo = cefpython.WindowInfo()
    316     windowInfo.SetAsChild(windowID)
     334    if windowID is not None:
     335        windowInfo.SetAsChild(windowID)
    317336
    318337    return cefpython.CreateBrowserSync(windowInfo,
     
    376395def initializeSimBrief():
    377396    """Initialize the (hidden) browser window for SimBrief."""
    378     _seleniumHandler.initializeSimBrief()
     397    _simBriefHandler.initialize()
    379398
    380399#------------------------------------------------------------------------------
    381400
    382401def callSimBrief(plan, getCredentials, updateProgress, htmlFilePath):
    383     """Call SimBrief with the given plan."""
    384     _seleniumHandler.callSimBrief(plan, getCredentials,
    385                                   updateProgress, htmlFilePath)
     402    """Call SimBrief with the given plan.
     403
     404    The callbacks will be called in the main GUI thread."""
     405    _simBriefHandler.call(plan, getCredentials, updateProgress, htmlFilePath)
    386406
    387407#------------------------------------------------------------------------------
     
    389409def finalize():
    390410    """Finalize the Chrome Embedded Framework."""
    391     global _toQuit, _seleniumHandler
    392     toQuit = True
     411    global _toQuit
     412    _toQuit = True
    393413    cefpython.Shutdown()
    394     _seleniumHandler.quit()
    395414
    396415#------------------------------------------------------------------------------
     
    406425#------------------------------------------------------------------------------
    407426
    408 def startFastTimeout():
    409     """Start the fast timeout handler."""
    410     global _fastTimeoutUsers
    411 
    412     if _fastTimeoutUsers==0:
    413         _fastTimeoutUsers = 1
    414         gobject.timeout_add(1, _handleFastTimeout)
    415     else:
    416         _fastTimeoutUsers += 1
    417 
    418 #------------------------------------------------------------------------------
    419 
    420 def stopFastTimeout():
    421     """Stop the fast timeout handler."""
    422     global _fastTimeoutUsers
    423 
    424     assert _fastTimeoutUsers>0
    425     _fastTimeoutUsers -= 1
    426 
    427 #------------------------------------------------------------------------------
    428 
    429 def _handleFastTimeout():
    430     """Handle a (fast) timeout by running the CEF message loop."""
    431     if _toQuit or _fastTimeoutUsers==0:
    432         return False
    433     else:
    434         cefpython.MessageLoopWork()
    435         return True
    436 
    437 #------------------------------------------------------------------------------
    438 
    439427def _handleSizeAllocate(widget, sizeAlloc):
    440428    """Handle the size-allocate event."""
    441     cefpython.WindowUtils.OnSize(widget.get_window().handle, 0, 0, 0)
     429    window = widget.get_window()
     430    if widget is not None:
     431        cefpython.WindowUtils.OnSize(window.handle, 0, 0, 0)
  • src/mlx/gui/flight.py

    r798 r805  
    25002500        table.attach(self._rememberButton, 1, 2, 2, 3, ypadding = 8)
    25012501
    2502         self._credentialsCondition = threading.Condition()
    2503         self._credentialsAvailable = False
    2504         self._credentialsUserName = None
    2505         self._credentialsPassword = None
    2506 
    25072502        label = gtk.Label(xstr("simbrief_extra_fuel"))
    25082503        label.set_use_underline(True)
     
    26752670            self._wizard.gui.beginBusy(xstr("simbrief_calling"))
    26762671
    2677             cef.startFastTimeout()
    26782672            cef.callSimBrief(plan,
    2679                              self._getCredentialsCallback,
    2680                              self._simBriefProgressCallback,
     2673                             self._getCredentials,
     2674                             self._simBriefProgress,
    26812675                             SimBriefSetupPage.getHTMLFilePath())
    26822676
    26832677            startSound(const.SOUND_NOTAM)
    2684 
    2685     def _getCredentialsCallback(self, count):
    2686         """Called when the SimBrief home page requests the credentials."""
    2687         with self._credentialsCondition:
    2688             self._credentialsAvailable = False
    2689 
    2690             gobject.idle_add(self._getCredentials, count)
    2691 
    2692             while not self._credentialsAvailable:
    2693                 self._credentialsCondition.wait()
    2694 
    2695             return (self._credentialsUserName, self._credentialsPassword)
    26962678
    26972679    def _getCredentials(self, count):
     
    27012683        are returned. Otherwise a dialog box is displayed informing the user of
    27022684        invalid credentials and requesting another set of them."""
    2703         with self._credentialsCondition:
    2704             if count==0:
    2705                 self._credentialsUserName = self._userName.get_text()
    2706                 self._credentialsPassword = self._password.get_text()
     2685        print "_getCredentials", count
     2686        if count==0:
     2687            return (self._userName.get_text(), self._password.get_text())
     2688        else:
     2689            gui = self._wizard.gui
     2690            config = gui.config
     2691
     2692            dialog = SimBriefCredentialsDialog(gui,
     2693                                               config.simBriefUserName,
     2694                                               config.simBriefPassword,
     2695                                               config.rememberSimBriefPassword)
     2696            response = dialog.run()
     2697
     2698            if response==RESPONSETYPE_OK:
     2699                userName = dialog.userName
     2700                self._userName.set_text(userName)
     2701                password = dialog.password
     2702                self._password.set_text(password)
     2703                rememberPassword = dialog.rememberPassword
     2704
     2705                config.simBriefUserName = userName
     2706
     2707                config.simBriefPassword = \
     2708                    password if rememberPassword else ""
     2709                config.rememberSimBriefPassword = rememberPassword
     2710
     2711                config.save()
     2712
     2713                return (userName, password)
    27072714            else:
    2708                 gui = self._wizard.gui
    2709                 config = gui.config
    2710 
    2711                 dialog = SimBriefCredentialsDialog(gui,
    2712                                                    config.simBriefUserName,
    2713                                                    config.simBriefPassword,
    2714                                                    config.rememberSimBriefPassword)
    2715                 response = dialog.run()
    2716 
    2717                 if response==RESPONSETYPE_OK:
    2718                     self._credentialsUserName = dialog.userName
    2719                     self._userName.set_text(self._credentialsUserName)
    2720                     self._credentialsPassword = dialog.password
    2721                     self._password.set_text(self._credentialsPassword)
    2722                     rememberPassword = dialog.rememberPassword
    2723 
    2724                     config.simBriefUserName = self._credentialsUserName
    2725 
    2726                     config.simBriefPassword = \
    2727                         self._credentialsPassword if rememberPassword else ""
    2728                     config.rememberSimBriefPassword = rememberPassword
    2729 
    2730                     config.save()
    2731                 else:
    2732                     self._credentialsUserName = None
    2733                     self._credentialsPassword = None
    2734 
    2735             self._credentialsAvailable = True
    2736             self._credentialsCondition.notify()
    2737 
    2738     def _simBriefProgressCallback(self, progress, result, flightInfo):
    2739         """Called by the SimBrief handling thread."""
    2740         gobject.idle_add(self._simBriefProgress, progress, result, flightInfo)
     2715                return (None, None)
    27412716
    27422717    def _simBriefProgress(self, progress, result, flightInfo):
     
    27482723            self._wizard.gui.updateBusyState(xstr(message))
    27492724        else:
    2750             cef.stopFastTimeout()
    27512725            self._wizard.gui.endBusy()
    27522726
  • src/mlx/gui/gui.py

    r798 r805  
    450450            self.updateDone()
    451451
    452         cef.initialize(self._programDirectory, self._cefInitialized)
     452        cef.initialize(self._cefInitialized)
    453453
    454454        singleton.raiseCallback = self.raiseCallback
Note: See TracChangeset for help on using the changeset viewer.