Changeset 685:6391018c120b


Ignore:
Timestamp:
10/18/15 14:51:39 (9 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
cef
Phase:
public
Message:

Added some basic support for SimBrief (re #279)

Files:
2 added
1 edited

Legend:

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

    r682 r685  
    11from common import *
     2
     3from mava_simbrief import MavaSimbriefIntegrator
    24
    35from mlx.util import secondaryInstallation
     
    8789        self._commands = []
    8890
     91        self._driver = None
     92
    8993        self._toQuit = False
     94
     95    @property
     96    def programDirectory(self):
     97        """Get the program directory."""
     98        return self._programDirectory
    9099
    91100    def run(self):
     
    102111        options = Options()
    103112        options.binary_location = scriptPath
    104         driver = webdriver.Chrome(chrome_options = options)
     113        driver = self._driver = webdriver.Chrome(chrome_options = options)
    105114        # try:
    106115        # except:
     
    120129        driver.quit()
    121130
     131    def callSimBrief(self, plan, getCredentials, updateProgress,
     132                     htmlFilePath):
     133        """Call SimBrief with the given plan."""
     134        self._enqueue(lambda:
     135                      self._callSimBrief(plan, self._driver,
     136                                         getCredentials, updateProgress,
     137                                         htmlFilePath))
     138
    122139    def quit(self):
    123140        """Instruct the thread to quit and then join it."""
     
    132149            self._commands.append(command)
    133150            self._commandsCondition.notify()
     151
     152    def _callSimBrief(self, plan, driver,
     153                      getCredentials, updateProgress, htmlFilePath):
     154        """Perform the SimBrief call."""
     155        integrator = MavaSimbriefIntegrator(plan = plan, driver = driver)
     156        link = integrator.get_xml_link(getCredentials, updateProgress,
     157                                       local_xml_debug = False,
     158                                       local_html_debug = False)
     159
     160        updateProgress("Retrieving briefing...", False)
     161
     162        flight_info = integrator.get_results(link,
     163                                             html_file_path = htmlFilePath)
     164
     165        updateProgress("Done", True)
    134166
    135167    def _quit(self):
     
    231263#------------------------------------------------------------------------------
    232264
     265class OffscreenRenderHandler(object):
     266    def GetRootScreenRect(self, browser, rect):
     267        #print "GetRootScreenRect"
     268        rect += [0, 0, 800, 600]
     269        return True
     270
     271    def GetViewRect(self, browser, rect):
     272        #print "GetViewRect"
     273        rect += [0, 0, 800, 600]
     274        return True
     275
     276    def GetScreenPoint(self, browser, viewX, viewY, screenCoordinates):
     277        #print "GetScreenPoint", viewX, viewY
     278        rect += [viewX, viewY]
     279        return True
     280
     281    def GetScreenInfo(self, browser, screenInfo):
     282        #print "GetScreenInfo"
     283        pass
     284
     285    def OnPopupShow(self, browser, show):
     286        #print "OnPopupShow", show
     287        pass
     288
     289    def OnPopupSize(self, browser, rect):
     290        #print "OnPopupSize", rect
     291        pass
     292
     293    def OnPaint(self, browser, paintElementType, dirtyRects, buffer, width, height):
     294        #print "OnPaint", paintElementType, dirtyRects, buffer, width, height
     295        pass
     296
     297    def OnCursorChange(self, browser, cursor):
     298        #print "OnCursorChange", cursor
     299        pass
     300
     301    def OnScrollOffsetChanged(self, browser):
     302        #print "OnScrollOffsetChange"
     303        pass
     304
     305    def OnBeforePopup(self, browser, frame, targetURL, targetFrameName,
     306                      popupFeatures, windowInfo, client, browserSettings,
     307                      noJavascriptAccess):
     308        wInfo = cefpython.WindowInfo()
     309        wInfo.SetAsOffscreen(int(0))
     310
     311        windowInfo.append(wInfo)
     312
     313        return False
     314
     315#------------------------------------------------------------------------------
     316
     317def initializeSimBrief():
     318    """Initialize the (hidden) browser window for SimBrief."""
     319    windowInfo = cefpython.WindowInfo()
     320    windowInfo.SetAsOffscreen(int(0))
     321
     322    url = "file://" + os.path.join(_seleniumHandler.programDirectory,
     323                                   "simbrief.html")
     324    simBriefBrowser = cefpython.CreateBrowserSync(windowInfo,
     325                                                  browserSettings = {},
     326                                                  navigateUrl = url)
     327    simBriefBrowser.SetClientHandler(OffscreenRenderHandler())
     328
     329    simBriefBrowser.SetFocus(True)
     330
     331#------------------------------------------------------------------------------
     332
     333def callSimBrief(plan, getCredentials, updateProgress, htmlFilePath):
     334    """Call SimBrief with the given plan."""
     335    _seleniumHandler.callSimBrief(plan, getCredentials,
     336                                  updateProgress, htmlFilePath)
     337
     338#------------------------------------------------------------------------------
     339
    233340def finalize():
    234341    """Finalize the Chrome Embedded Framework."""
Note: See TracChangeset for help on using the changeset viewer.